"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _cesium = require("cesium");
var _createFeatureCollection = require("../feature-layer/createFeatureCollection");
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); }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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 = exports["default"] = /*#__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);
    }
  }
  return _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 _cesium.Cartesian2();
      this.data.map(function (obj) {
        var _transformGeometry = (0, _createFeatureCollection.transformGeometry)(obj.geometryInfo),
          coordinates = _transformGeometry.coordinates;
        var position = _cesium.Cartesian3.fromDegrees.apply(_cesium.Cartesian3, _toConsumableArray(coordinates).concat([0]));
        var canvasPosition = map.scene.cartesianToCanvasCoordinates(position, scratch);
        if ((0, _cesium.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));
    }
  }]);
}();
//# sourceMappingURL=GifDomLayer.js.map
