(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory();
	else if(typeof define === 'function' && define.amd)
		define("olRender3D", [], factory);
	else if(typeof exports === 'object')
		exports["olRender3D"] = factory();
	else
		root["olRender3D"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// identity function for calling harmony imports with the correct context
/******/ 	__webpack_require__.i = function(value) { return value; };
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "../";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 221);
/******/ })
/************************************************************************/
/******/ ({

/***/ 221:
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
  value: true
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

ol.layer.Vector.prototype.setRender3D = function (render) {
  render.setLayer(this);
};

ol.render.render3D = function () {
  var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

  var options = params;

  this.maxResolution_ = options['maxResolution'] || 100;

  this.defaultHeight_ = options['defaultHeight'] || 0;

  this.height_ = this.getHeight_(options['height']);

  this.baseStyle = {
    stroke: {
      strokeWidth: 1,
      strokeColor: 'rgba(196,189,181,1)'
    },
    fill: {
      fillColor: 'rgba(248,238,228,1)'
    },
    text: {
      stroke: {
        strokeWidth: 1,
        strokeColor: 'rgba(87,87,87,1)'
      },
      fill: {
        fillColor: 'rgba(255,255,255,0.5)'
      },
      textAlign: 'center',
      textBaseline: 'bottom',
      textScale: 1
    }
  };
  if (options['style']) {
    this.eachObject(this.baseStyle, options['style']);
  }
};

ol.render.render3D.prototype.eachObject = function () {
  var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  for (var key in base) {
    if (key && base[key] && params[key]) {
      if (_typeof(base[key]) === 'object') {
        this.eachObject(base[key], params[key]);
      } else {
        base[key] = params[key];
      }
    }
  }
};

ol.render.render3D.prototype.postcompose_ = function (event) {
  var _this = this;

  var res = event.frameState.viewState.resolution;
  if (res <= this.maxResolution_) {
    this.res_ = res * 400;
    if (this.animate_) {
      var elapsed = event.frameState.time - this.animate_;
      if (elapsed < this.animateDuration_) {
        this.elapsedRatio_ = this.easing_(elapsed / this.animateDuration_);
        event.frameState.animate = true;
      } else {
        this.animate_ = false;
        this.height_ = this.toHeight_;
      }
    }
    var ratio = event.frameState.pixelRatio;
    var ctx = event.context;
    var matrix = this.matrix_ = event.frameState.coordinateToPixelTransform;
    if (!matrix) {
      matrix = event.frameState.coordinateToPixelMatrix;
      matrix[2] = matrix[4];
      matrix[3] = matrix[5];
      matrix[4] = matrix[12];
      matrix[5] = matrix[13];
    }
    this.center_ = [ctx.canvas.width / 2 / ratio, ctx.canvas.height / ratio];
    var features_ = this.layer_.getSource().getFeaturesInExtent(event.frameState.extent);
    ctx.save();
    ctx.scale(ratio, ratio);
    ctx.lineWidth = this.baseStyle.stroke.strokeWidth;
    ctx.strokeStyle = this.baseStyle.stroke.strokeColor;
    ctx.fillStyle = this.baseStyle.fill.fillColor;
    var builds = [];
    features_.forEach(function (feature) {
      builds.push(_this.getFeature3D_(feature, _this.getFeatureHeight(feature)));
    });
    this.drawFeature3D_(ctx, builds);
    ctx.restore();
  } else {}
};

ol.render.render3D.prototype.setLayer = function (layer) {
  if (layer) {
    if (this.layer_) {
      this.layer_.un('postcompose', this.postcompose_, this);
    }
    this.layer_ = layer;
    this.layer_.on('postcompose', this.postcompose_, this);
  }
};

ol.render.render3D.prototype.getHeight_ = function (height) {
  var that = this;
  var rHeight = function rHeight() {
    return 10;
  };
  switch (typeof height === 'undefined' ? 'undefined' : _typeof(height)) {
    case 'function':
      rHeight = height;
      break;
    case 'string':
      rHeight = function rHeight(feature) {
        return Number(feature.get(height)) || that.defaultHeight_;
      };
      break;
    case 'number':
      rHeight = function rHeight(feature) {
        return height;
      };
      break;
  }
  return rHeight;
};

ol.render.render3D.prototype.animate = function () {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

  this.toHeight_ = this.getHeight_(options.height);
  this.animate_ = new Date().getTime();
  this.animateDuration_ = options.duration || 1000;
  this.easing_ = options.easing || ol.easing.easeOut;
  this.layer_.changed();
};

ol.render.render3D.prototype.animating = function () {
  if (this.animate_ && new Date().getTime() - this.animate_ > this.animateDuration_) {
    this.animate_ = false;
  }
  return !!this.animate_;
};

ol.render.render3D.prototype.getFeatureHeight = function (feature) {
  if (this.animate_) {
    var h1 = this.height_(feature);
    var h2 = this.toHeight_(feature);
    return h1 * (1 - this.elapsedRatio_) + this.elapsedRatio_ * h2;
  } else {
    return this.height_(feature);
  }
};

ol.render.render3D.prototype.handleVector_ = function (point, height) {
  var point0 = [point[0] * this.matrix_[0] + point[1] * this.matrix_[1] + this.matrix_[4], point[0] * this.matrix_[2] + point[1] * this.matrix_[3] + this.matrix_[5]];
  var point1 = [point0[0] + height / this.res_ * (point0[0] - this.center_[0]), point0[1] + height / this.res_ * (point0[1] - this.center_[1])];
  return [point0, point1];
};

ol.render.render3D.prototype.getFeature3D_ = function (feature, height) {
  var coordinates = feature.getGeometry().getCoordinates();
  var json = {
    type: '',
    feature: feature,
    geom: ''
  };
  switch (feature.getGeometry().getType()) {
    case 'Polygon':
      coordinates = [coordinates];
      json.type = 'MultiPolygon';
      json.geom = this.getBuilds_(coordinates, height);
      break;
    case 'MultiPolygon':
      json.type = 'MultiPolygon';
      json.geom = this.getBuilds_(coordinates, height);
      break;
    case 'Point':
      json.type = 'Point';
      json.geom = this.handleVector_(coordinates, height);
      break;
    default:
      json = {};
      break;
  }
  return json;
};

ol.render.render3D.prototype.getBuilds_ = function (coordinates, height) {
  var _this2 = this;

  var build = [];
  coordinates.forEach(function (coords) {
    if (coords && Array.isArray(coords) && coords.length > 0) {
      coords.forEach(function (coord) {
        if (coord && Array.isArray(coord) && coord.length > 0) {
          var bear = [];
          coord.forEach(function (cod) {
            bear.push(_this2.handleVector_(cod, height));
          });
          build.push(bear);
        }
      });
    }
  });
  return build;
};

ol.render.render3D.prototype.drawFeature3D_ = function (ctx, buildings) {
  for (var i = 0; i < buildings.length; i++) {
    switch (buildings[i].type) {
      case 'MultiPolygon':
        for (var j = 0; j < buildings[i].geom.length; j++) {
          var b = buildings[i].geom[j];
          for (var k = 0; k < b.length; k++) {
            var _geom_ = b[k];
            ctx.beginPath();
            ctx.moveTo(_geom_[0][0], _geom_[0][1]);
            ctx.lineTo(_geom_[1][0], _geom_[1][1]);
            ctx.stroke();
          }
        }
        break;
      case 'Point':
        var geom_ = buildings[i].geom;
        ctx.beginPath();
        ctx.moveTo(geom_[0][0], geom_[0][1]);
        ctx.lineTo(geom_[1][0], geom_[1][1]);
        ctx.stroke();
        break;
    }
  }
  for (var _i = 0; _i < buildings.length; _i++) {
    switch (buildings[_i].type) {
      case 'MultiPolygon':
        {
          ctx.beginPath();
          for (var _j = 0; _j < buildings[_i].geom.length; _j++) {
            var _geom_2 = buildings[_i].geom[_j];
            if (_j === 0) {
              ctx.moveTo(_geom_2[0][1][0], _geom_2[0][1][1]);
              for (var _k = 1; _k < _geom_2.length; _k++) {
                ctx.lineTo(_geom_2[_k][1][0], _geom_2[_k][1][1]);
              }
            } else {
              ctx.moveTo(_geom_2[0][1][0], _geom_2[0][1][0]);
              for (var _k2 = _geom_2.length - 2; _k2 >= 0; _k2--) {
                ctx.lineTo(_geom_2[_k2][1][0], _geom_2[_k2][1][1]);
              }
            }
            ctx.closePath();
          }
          ctx.fill('evenodd');
          ctx.stroke();
          break;
        }
      case 'Point':
        {
          var build = buildings[_i];
          var _ref = [build.feature.get('label'), build.geom[1], ctx.fillStyle],
              label = _ref[0],
              point = _ref[1],
              fill = _ref[2];

          ctx.fillStyle = this.baseStyle.text.stroke.strokeColor;
          ctx.textAlign = this.baseStyle.text.textAlign;
          ctx.textBaseline = this.baseStyle.text.textBaseline;
          ctx.fillText(label, point[0], point[1]);
          var m = ctx.measureText(label);
          var h = Number(ctx.font.match(/\d+(\.\d+)?/g).join([]));
          ctx.fillStyle = this.baseStyle.text.fill.fillColor;
          ctx.fillRect(point[0] - m.width / 2 - 5, point[1] - h - 5, m.width + 10, h + 10);
          ctx.strokeRect(point[0] - m.width / 2 - 5, point[1] - h - 5, m.width + 10, h + 10);
          ctx.fillStyle = fill;
        }
    }
  }
};

var olRender3D = ol.render.render3D;
exports.default = olRender3D;
module.exports = exports['default'];

/***/ })

/******/ });
});
//# sourceMappingURL=olRender3D.js.map