"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 _colors = _interopRequireDefault(require("./assets/colors2.png"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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,
  Event = _Cesium.Event,
  Color = _Cesium.Color,
  Property = _Cesium.Property,
  createPropertyDescriptor = _Cesium.createPropertyDescriptor,
  Material = _Cesium.Material,
  defined = _Cesium.defined;
;
var PolylineTrailMaterialProperty = /*#__PURE__*/function () {
  function PolylineTrailMaterialProperty() {
    var option = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    _classCallCheck(this, PolylineTrailMaterialProperty);
    this._definitionChanged = new Event();
    this._color = undefined;
    this._colorSubscription = undefined;
    this._time = new Date().getTime();
    this.color = option.color ? option.color : 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();
  }
  _createClass(PolylineTrailMaterialProperty, [{
    key: "getType",
    value: function getType() {
      return 'PolylineTrail';
    }
  }, {
    key: "getValue",
    value: function getValue(time, result) {
      var _result = result;
      if (!defined(_result)) {
        _result = {};
      }
      _result.color = Property.getValueOrClonedDefault(this._color, time, 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 && Property.equals(this._color, other._color);
    }
  }, {
    key: "addMaterial",
    value: function addMaterial() {
      var _this = this;
      Material._materialCache.addMaterial(this.type, {
        fabric: {
          type: this.type,
          uniforms: {
            color: new 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: createPropertyDescriptor('color'),
          configurable: true,
          writable: true
        }
      });
    }
  }]);
  return PolylineTrailMaterialProperty;
}();
var _default = PolylineTrailMaterialProperty;
exports["default"] = _default;
//# sourceMappingURL=PolylineTrailMaterialProperty.js.map
