"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 _renderer = require("../renderer");
var _libgif = _interopRequireDefault(require("libgif"));
var _excluded = ["geometry", "properties", "style"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
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); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var _Cesium = Cesium,
  Entity = _Cesium.Entity,
  Cartesian3 = _Cesium.Cartesian3,
  PropertyBag = _Cesium.PropertyBag,
  CallbackProperty = _Cesium.CallbackProperty;
;
var Marker = /*#__PURE__*/function (_Entity) {
  _inherits(Marker, _Entity);
  var _super = _createSuper(Marker);
  function Marker(options) {
    var _this;
    _classCallCheck(this, Marker);
    var geometry = options.geometry,
      properties = options.properties,
      style = options.style,
      other = _objectWithoutProperties(options, _excluded);
    var props = _objectSpread({
      clampToGround: true,
      position: Cartesian3.fromDegrees.apply(Cartesian3, _toConsumableArray(geometry)),
      properties: new PropertyBag(properties),
      billboard: _objectSpread(_objectSpread({}, (0, _renderer.Marker)(_objectSpread({}, style))), {}, {
        scaleByDistance: new Cesium.NearFarScalar(1000, 1, 100000, 0.5),
        eyeOffset: new Cesium.Cartesian3(0, 0, -200),
        pixelOffset: new Cesium.Cartesian2(0, -10) //偏移量
      })
    }, other);
    _this = _super.call(this, props);
    if (style !== null && style !== void 0 && style.image && style !== null && style !== void 0 && style.imageType) {
      var imageType = style.imageType,
        image = style.image,
        imageKey = style.imageKey;
      if (imageType === 'gif') {
        _this.setGifImage(image, imageKey);
      }
    }
    return _this;
  }

  // 设置 gif 图标
  _createClass(Marker, [{
    key: "setGifImage",
    value: function setGifImage(image, imageKey) {
      var _this2 = this;
      var gifDiv = document.createElement('div');
      var gifImg = document.createElement('img');

      // gif库需要img标签配置下面两个属性
      gifImg.setAttribute('rel:animated_src', image);
      gifImg.setAttribute('rel:auto_play', '1'); // 设置自动播放属性
      gifDiv.appendChild(gifImg);
      var superGif = new _libgif["default"]({
        gif: gifImg
      });
      window.gifImages = window.gifImages || {};
      window.gifImages[imageKey] = superGif;

      // 解析gif每帧图片，按时间序列进行切换
      superGif.load(function () {
        _this2.billboard.image = new CallbackProperty(function () {
          return superGif.get_canvas().toDataURL();
        }, false);
      });
    }
  }, {
    key: "setGeometry",
    value: function setGeometry(geometry) {
      this.position.setValue(Cartesian3.fromDegrees.apply(Cartesian3, _toConsumableArray(geometry)));
    }
  }, {
    key: "setProperties",
    value: function setProperties(properties) {
      this.properties.setValue(new PropertyBag(properties));
    }
  }, {
    key: "getProperties",
    value: function getProperties() {
      return this.properties;
    }
  }, {
    key: "setStyle",
    value: function setStyle(style) {
      (0, _renderer.setEntityStyle)(this.billboard, (0, _renderer.Marker)(_objectSpread({}, style)));
    }
  }]);
  return Marker;
}(Entity);
exports["default"] = Marker;
//# sourceMappingURL=Marker.js.map
