@vtx/cs-map
Version:
React components for Vortex
100 lines (96 loc) • 4.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _cesium = require("cesium");
var _colors = _interopRequireDefault(require("./assets/colors1.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 PolylineTrailLinkMaterialProperty = /*#__PURE__*/function () {
function PolylineTrailLinkMaterialProperty() {
var option = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, PolylineTrailLinkMaterialProperty);
this._definitionChanged = new _cesium.Event();
this._color = undefined;
this._colorSubscription = undefined;
this.color = option.color ? option.color : new _cesium.Color(0.0, 0.0, 1.0, 0.5);
this.duration = option.duration ? option.duration : 5000;
this.image = option.image ? option.image : _colors["default"];
this._time = new Date().getTime();
// 类型(会自动加载到 cesium 中)
this.type = option.type ? option.type : 'PolylineTrailLink';
// 着色器
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;\n material.diffuse = colorImage.rgb;\n return material;\n }\n ";
this.addMaterial();
}
return _createClass(PolylineTrailLinkMaterialProperty, [{
key: "getType",
value: function getType() {
return 'PolylineTrailLink';
}
}, {
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 PolylineTrailLinkMaterialProperty && _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(0.0, 0.0, 1.0, 0.5),
image: this.image,
time: 100
},
source: this.source
},
translucent: function translucent() {
return true;
}
});
// 注意 defineProperties 会报错,需要改为 Object
Object.defineProperties(PolylineTrailLinkMaterialProperty.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"] = PolylineTrailLinkMaterialProperty;
//# sourceMappingURL=PolylineTrailLinkMaterialProperty.js.map