@vtx/cs-map
Version:
React components for Vortex
101 lines (97 loc) • 5.22 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(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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(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 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();
}
_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
}
});
}
}]);
return PolylineTrailLinkMaterialProperty;
}();
var _default = exports["default"] = PolylineTrailLinkMaterialProperty;
//# sourceMappingURL=PolylineTrailLinkMaterialProperty.js.map