UNPKG

@vtx/cs-map

Version:

React components for Vortex

129 lines (125 loc) 6.88 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(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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } 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 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); } } return _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; } } }]); }(); var _default = exports["default"] = ThreePointLayer; //# sourceMappingURL=DiffuseCircle.js.map