"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _cesium = require("cesium");
var _colors = _interopRequireDefault(require("./assets/colors2.png"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 _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 PolylineTrailMaterialProperty = /*#__PURE__*/function () {
  function PolylineTrailMaterialProperty() {
    var option = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    _classCallCheck(this, PolylineTrailMaterialProperty);
    this._definitionChanged = new _cesium.Event();
    this._color = undefined;
    this._colorSubscription = undefined;
    this._time = new Date().getTime();
    this.color = option.color ? option.color : _cesium.Color.fromCssColorString('rgba(90, 90, 255, 1)');
    this.duration = option.duration ? option.duration : 5000;
    this.trailImage = option.trailImage ? option.trailImage : _colors["default"];

    // 类型（会自动加载到 cesium 中）
    this.type = option.type ? option.type : 'PolylineTrail';

    // 着色器
    this.source = option.source ? option.source : "\n    czm_material czm_getMaterial(czm_materialInput materialInput)\n      {\n        czm_material material = czm_getDefaultMaterial(materialInput);\n        vec2 st = materialInput.st;\n        vec4 colorImage = texture2D(image, vec2(fract(st.s - time), st.t));\n        material.alpha = colorImage.a * color.a;\n        material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n        return material;\n      }\n    ";
    this.addMaterial();
  }
  return _createClass(PolylineTrailMaterialProperty, [{
    key: "getType",
    value: function getType() {
      return 'PolylineTrail';
    }
  }, {
    key: "getValue",
    value: function getValue(time, result) {
      var _result = result;
      if (!(0, _cesium.defined)(_result)) {
        _result = {};
      }
      _result.color = _cesium.Property.getValueOrClonedDefault(this._color, time, _cesium.Color.WHITE, _result.color);
      _result.image = this.trailImage;
      _result.time = (new Date().getTime() - this._time) % this.duration / this.duration;
      return _result;
    }
  }, {
    key: "equals",
    value: function equals(other) {
      return this === other || other instanceof PolylineTrailMaterialProperty && _cesium.Property.equals(this._color, other._color);
    }
  }, {
    key: "addMaterial",
    value: function addMaterial() {
      var _this = this;
      _cesium.Material._materialCache.addMaterial(this.type, {
        fabric: {
          type: this.type,
          uniforms: {
            color: new _cesium.Color(1.0, 0.0, 0.0, 0.5),
            image: this.trailImage,
            time: 100
          },
          source: this.source
        },
        translucent: function translucent() {
          return true;
        }
      });

      // 注意 defineProperties 会报错，需要改为 Object
      Object.defineProperties(PolylineTrailMaterialProperty.prototype, {
        isConstant: {
          get: function get() {
            return false;
          },
          configurable: true
        },
        definitionChanged: {
          get: function get() {
            return _this._definitionChanged;
          },
          configurable: true
        },
        color: {
          value: (0, _cesium.createPropertyDescriptor)('color'),
          configurable: true,
          writable: true
        }
      });
    }
  }]);
}();
var _default = exports["default"] = PolylineTrailMaterialProperty;
//# sourceMappingURL=PolylineTrailMaterialProperty.js.map
