"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _createFeatureCollection = require("../feature-layer/createFeatureCollection");
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var _Cesium = Cesium,
  Cartesian2 = _Cesium.Cartesian2,
  Cartesian3 = _Cesium.Cartesian3,
  defined = _Cesium.defined;
;
var createDom = function createDom(src, width, height) {
  var img = document.createElement("img");
  img.src = src;
  img.style.width = width + 'px';
  img.style.height = height + 'px';
  img.style.position = 'absolute';
  img.style.zIndex = 3;
  img.style.pointerEvents = 'none';
  return img;
};
var GifDomLayer = /*#__PURE__*/function () {
  function GifDomLayer(options) {
    var _options$data;
    _classCallCheck(this, GifDomLayer);
    this.image = options.image;
    this.width = options.width;
    this.height = options.height;
    this.map = options.map;
    this.container = options.container;

    // 图层标识
    this.key = options.key;

    // 图层名称
    this.name = options.name;

    // 标签字段
    this.labelField = options.labelField;

    // 模版内容
    this.template = options.template;
    if ((_options$data = options.data) !== null && _options$data !== void 0 && _options$data.length) {
      this.loadData(options.data);
    }
  }
  _createClass(GifDomLayer, [{
    key: "loadData",
    value: function loadData(data) {
      var _this = this;
      var map = this.map;
      var container = this.container;
      var image = this.image;
      var width = this.width;
      var height = this.height;
      map.scene.preRender.removeEventListener(_this.render.bind(_this));
      if (data !== null && data !== void 0 && data.length) {
        data.map(function (obj) {
          if (!obj.htmlOverlay) {
            obj.htmlOverlay = createDom(image, width, height);
            container.appendChild(obj.htmlOverlay);
          }
        });
        this.data = data;
        map.scene.preRender.addEventListener(_this.render.bind(_this));
      }
    }
  }, {
    key: "render",
    value: function render() {
      var map = this.map;
      var width = this.width;
      var height = this.height;
      var scratch = new Cartesian2();
      this.data.map(function (obj) {
        var _transformGeometry = (0, _createFeatureCollection.transformGeometry)(obj.geometryInfo),
          coordinates = _transformGeometry.coordinates;
        var position = Cartesian3.fromDegrees.apply(Cartesian3, _toConsumableArray(coordinates).concat([0]));
        var canvasPosition = map.scene.cartesianToCanvasCoordinates(position, scratch);
        if (defined(canvasPosition)) {
          obj.htmlOverlay.style.top = canvasPosition.y - height + "px";
          obj.htmlOverlay.style.left = canvasPosition.x - width / 2 + "px";
        }
      });
    }
  }, {
    key: "destroy",
    value: function destroy() {
      var _this = this;
      this.map.scene.preRender.removeEventListener(_this.render.bind(_this));
    }
  }]);
  return GifDomLayer;
}();
exports["default"] = GifDomLayer;
//# sourceMappingURL=GifDomLayer.js.map
