UNPKG

@vtx/cs-map

Version:

React components for Vortex

268 lines (243 loc) 10.6 kB
"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 _cesium = require("cesium"); var _Grate = _interopRequireDefault(require("./Grate.js")); var _Well = _interopRequireDefault(require("./Well.js")); var _transformRgb = _interopRequireDefault(require("../_util/transformRgb")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } 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); } function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure 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 _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 _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } var _cache = {}; // 获取立方体 var getBoxGeometry = function getBoxGeometry() { if (_cache.boxGeometry) return _cache.boxGeometry; _cache.boxGeometry = _Grate["default"].fromDimensions({ vertexFormat: _cesium.VertexFormat.POSITION_NORMAL_AND_ST, dimensions: new _cesium.Cartesian3(1.5, 1, 4.0) // 长宽高 }); return _cache.boxGeometry; }; // 获取圆柱 var getCylinderGeometry = function getCylinderGeometry() { if (_cache.cylinderGeometry) return _cache.cylinderGeometry; var cylinder = new _Well["default"]({ length: 5.0, // 长度 topRadius: 1.5, // 顶部半径 bottomRadius: 1.5 // 底部半径 // slices: 4 }); _cache.cylinderGeometry = _Well["default"].createGeometry(cylinder); return _cache.cylinderGeometry; }; // 根据类型获取几何体 var getGeometryByType = function getGeometryByType(type) { var _split = (type || 'cylinder').split('_'), _split2 = _slicedToArray(_split, 1), TYPE = _split2[0]; return { box: getBoxGeometry, cylinder: getCylinderGeometry, grate: getBoxGeometry, well: getCylinderGeometry }[TYPE](); }; 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.key = options.key; // 图层名称 this.name = options.name; // 标签字段 this.labelField = options.labelField; // 模版内容 this.template = options.template; // 图例 this.legend = options.legend; // 图层控制 this.layerControl = options.layerControl; // 取消气泡 this.cancelPopup = options.cancelPopup; // 气泡模板 this.tipTemplate = options.tipTemplate; // 仅展示 this.viewOnly = options.viewOnly; this.style = options.style; 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$loaded; this.data = data; var map = this.map; var show = this.show; var style = this.style; this.destroy(); this.primitives = []; var types = {}, colors = {}; data.map(function (item) { var data = item.data; var type = item.type || 'cylinder'; var color = item.color || _this.color; var geometry = getGeometryByType(type); // 缓存颜色对应的数据 if (color) { // 缓存颜色 colors[color] = colors[color] || { item: item, _instances: [], data: [], color: color }; // 缓存颜色对应的数据 colors[color]._instances.push(new _cesium.GeometryInstance({ geometry: geometry, modelMatrix: _cesium.Matrix4.multiplyByTranslation(_cesium.Transforms.eastNorthUpToFixedFrame(_cesium.Cartesian3.fromDegrees(data[0], data[1])), new _cesium.Cartesian3(0.0, 0.0, data[2] || 0.0), new _cesium.Matrix4()), id: item.id })); colors[color].data.push(item); } else if (style[type]) { // 缓存颜色 types[type] = types[type] || { item: item, _instances: [], data: [], type: type }; types[type]._instances.push(new _cesium.GeometryInstance({ geometry: geometry, modelMatrix: _cesium.Matrix4.multiplyByTranslation(_cesium.Transforms.eastNorthUpToFixedFrame(_cesium.Cartesian3.fromDegrees(data[0], data[1])), new _cesium.Cartesian3(0.0, 0.0, data[2] || 0.0), new _cesium.Matrix4()), id: item.id })); types[type].data.push(item); } }); for (var color_str in colors) { var _colors$color_str = colors[color_str], color = _colors$color_str.color, _data = _colors$color_str.data, _instances = _colors$color_str._instances; var primitive = new _cesium.Primitive({ geometryInstances: _instances, show: show, appearance: new _cesium.MaterialAppearance({ material: new _cesium.Material({ fabric: { type: 'Color', uniforms: { color: _cesium.Color.fromCssColorString((0, _transformRgb["default"])(color, 1)) } } }), faceForward: true }), asynchronous: false }); this.setAttribute(primitive, _data); map.scene.primitives.add(primitive); this.primitives.push(primitive); } for (var type in types) { var _types$type = types[type], _data2 = _types$type.data, _instances2 = _types$type._instances; var _primitive = new _cesium.Primitive({ geometryInstances: _instances2, show: show, appearance: new _cesium.MaterialAppearance({ material: new _cesium.Material({ fabric: { type: 'Image', uniforms: { image: style[type] } } }), faceForward: true }), asynchronous: false }); this.setAttribute(_primitive, _data2); map.scene.primitives.add(_primitive); this.primitives.push(_primitive); } (_this$loaded = this.loaded) === null || _this$loaded === void 0 || _this$loaded.call(this, this.primitives); } }, { key: "setAttribute", value: function setAttribute(primitive, data) { // 图层标识 primitive.key = this.key; // 数据 primitive.data = data; // 图层名称 primitive.name = this.name; // 标签字段 primitive.labelField = this.labelField; // 模版内容 primitive.template = this.template; // 图例 primitive.legend = this.legend; // 图层控制 primitive.layerControl = this.layerControl; // 取消气泡 primitive.cancelPopup = this.cancelPopup; // 气泡模板 primitive.tipTemplate = this.tipTemplate; // 仅展示 primitive.viewOnly = this.viewOnly; } }, { 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=ThreePointLayer.js.map