UNPKG

@vtx/cs-map

Version:

React components for Vortex

131 lines (126 loc) 7.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _cesium = require("cesium"); var _transformRgb = _interopRequireDefault(require("../_util/transformRgb")); 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 _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 _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 circleSource = "\nczm_material czm_getMaterial(czm_materialInput materialInput)\n{\n czm_material material = czm_getDefaultMaterial(materialInput);\n vec2 st = materialInput.st;\n vec3 diffuse = color.rgb;\n float alpha = 0.0;\n float u_time = (czm_frameNumber / 60.0);\n float dis = distance(st, vec2(0.5));\n\n\n alpha = 0.0;\n\n if(dis < fract(u_time * 0.5) / 2.0 ) {\n diffuse = color.rgb;\n }\n\n if(dis < fract(u_time * 0.5 - 0.5) / 2.0 ) {\n diffuse = color.rgb;\n alpha = dis / fract(u_time * 0.5 - 0.5);\n }\n\n\n material.diffuse = diffuse;\n material.alpha = alpha;\n return material;\n}"; var ThreePointLayer = /*#__PURE__*/function () { function ThreePointLayer(options) { var _this$data; _classCallCheck(this, ThreePointLayer); var _options$show = options.show, show = _options$show === void 0 ? true : _options$show; this.map = options.map; this.data = options.data; this.color = options.color; this.primitives = []; this.show = show; if ((_this$data = this.data) !== null && _this$data !== void 0 && _this$data.length) { this.loadData(this.data); } } _createClass(ThreePointLayer, [{ key: "show", set: function set(value) { var _this$primitives; if ((_this$primitives = this.primitives) !== null && _this$primitives !== void 0 && _this$primitives.length) { this.primitives.map(function (primitive) { primitive.show = value; }); } } }, { key: "loadData", value: function loadData(data) { var _this = this; this.data = data; var map = this.map; var show = this.show; this.destroy(); this.primitives = []; var colors = {}; data.map(function (item) { var data = item.data, radius = item.radius; var color_str = item.color || _this.color || '#0080ff'; // 缓存颜色 colors[color_str] = colors[color_str] || { item: item, _instances: [], color: color_str }; // 缓存颜色对应的数据 colors[color_str]._instances.push(new _cesium.GeometryInstance({ geometry: new _cesium.EllipseGeometry({ center: _cesium.Cartesian3.fromDegrees.apply(_cesium.Cartesian3, _toConsumableArray(data)), radio: new _cesium.Cartesian3(10.0, 10.0, 10.0), semiMajorAxis: radius || 100.0, semiMinorAxis: radius || 100.0 }) })); }); for (var color_str in colors) { var _colors$color_str = colors[color_str], color = _colors$color_str.color, _instances = _colors$color_str._instances; var circle = new _cesium.Primitive({ geometryInstances: _instances, show: show, appearance: new _cesium.EllipsoidSurfaceAppearance({ material: new _cesium.Material({ fabric: { type: 'mym', uniforms: { color: _cesium.Color.fromCssColorString((0, _transformRgb["default"])(color, 1)) // 颜色 }, source: circleSource } }) }), modelMatrix: _cesium.Matrix4.IDENTITY, vertexCacheOptimize: false, interleave: false, compressVertices: true, releaseGeometryInstances: true, allowPicking: true, cull: true, asynchronous: true, debugShowBoundingVolume: false, shadows: _cesium.ShadowMode.DISABLED }); map.scene.primitives.add(circle); this.primitives.push(circle); } } }, { key: "destroy", value: function destroy() { var _this$primitives2; var map = this.map; if ((_this$primitives2 = this.primitives) !== null && _this$primitives2 !== void 0 && _this$primitives2.length) { this.primitives.map(function (primitive) { map.scene.primitives.remove(primitive); }); this.primitives = null; } } }]); return ThreePointLayer; }(); var _default = exports["default"] = ThreePointLayer; //# sourceMappingURL=DiffuseCircle.js.map