UNPKG

@vtx/cs-map

Version:

React components for Vortex

258 lines (238 loc) 13.4 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 _LineFlowMaterialProperty = _interopRequireDefault(require("./LineFlowMaterialProperty")); var _createFeatureCollection = require("../feature-layer/createFeatureCollection"); var _lodash = require("lodash"); var _transformRgb = _interopRequireDefault(require("../_util/transformRgb")); var _parabola = _interopRequireDefault(require("../_util/parabola")); 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 _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; } function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _superPropSet(t, e, o, r, p, f) { return _set(_getPrototypeOf(f ? t.prototype : t), e, o, r, p); } function set(e, r, t, o) { return set = "undefined" != typeof Reflect && Reflect.set ? Reflect.set : function (e, r, t, o) { var f, i = _superPropBase(e, r); if (i) { if ((f = Object.getOwnPropertyDescriptor(i, r)).set) return f.set.call(o, t), !0; if (!f.writable) return !1; } if (f = Object.getOwnPropertyDescriptor(o, r)) { if (!f.writable) return !1; f.value = t, Object.defineProperty(o, r, f); } else _defineProperty(o, r, t); return !0; }, set(e, r, t, o); } function _set(e, r, t, o, f) { if (!set(e, r, t, o || e) && f) throw new TypeError("failed to set property"); return t; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, 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 _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); return t; } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(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 _getCoordinates = function getCoordinates(geometryInfo) { if (geometryInfo) { if ((0, _lodash.isString)(geometryInfo)) { var _geometryInfo$split = geometryInfo.split(','), _geometryInfo$split2 = _slicedToArray(_geometryInfo$split, 3), start = _geometryInfo$split2[0], end = _geometryInfo$split2[1], z = _geometryInfo$split2[2]; return [Number(start), Number(end), Number(z || 0)]; } else if ((0, _lodash.isArray)(geometryInfo)) { var _geometryInfo = _slicedToArray(geometryInfo, 3), _start = _geometryInfo[0], _end = _geometryInfo[1], _z = _geometryInfo[2]; return [Number(_start), Number(_end), Number(_z || 0)]; } else if ((0, _lodash.isObject)(geometryInfo)) { if (geometryInfo.geometryInfo) { return _getCoordinates(geometryInfo.geometryInfo); } var _transformGeometry$co = _slicedToArray((0, _createFeatureCollection.transformGeometry)(geometryInfo).coordinates, 3), _start2 = _transformGeometry$co[0], _end2 = _transformGeometry$co[1], _z2 = _transformGeometry$co[2]; return [Number(_start2), Number(_end2), Number(_z2 || 0)]; } } }; var FlyLineLayer = exports["default"] = /*#__PURE__*/function (_CustomDataSource) { function FlyLineLayer(option) { var _this; _classCallCheck(this, FlyLineLayer); var data = option.data, key = option.key, labelField = option.labelField, template = option.template, height = option.height, count = option.count, color = option.color, speed = option.speed, width = option.width, _option$opacity = option.opacity, opacity = _option$opacity === void 0 ? 0.3 : _option$opacity, flyWidth = option.flyWidth, name = option.name, layerControl = option.layerControl, _option$show = option.show, show = _option$show === void 0 ? true : _option$show, map = option.map, _option$number = option.number, number = _option$number === void 0 ? 1 : _option$number, glowPower = option.glowPower; _this = _callSuper(this, FlyLineLayer, [option]); _superPropSet((_this, FlyLineLayer), "show", show, _this, 1, 1); // 图层标识 _this.key = key; // 图层名称 _this.name = name; // 标签字段 _this.labelField = labelField; // 模版内容 _this.template = template; _this.data = data; // 颜色 _this.color = color || '#0080ff'; // 高度 _this.height = height; // 数量 _this.count = count || 1; // 速度 _this.speed = speed || 10; // 轨迹线宽度 _this.width = width || 1; // 飞线数量 _this.number = number || 1; // 发光强度 _this.glowPower = glowPower || 0; // 轨迹颜色透明度 _this.opacity = opacity || 0.3; // 地图 _this.map = map; // 飞线宽度 _this.flyWidth = flyWidth || 3; _this.layerControl = layerControl; if (data !== null && data !== void 0 && data.length) { _this.loadData(data); } return _this; } // 重写父类的属性访问器 _inherits(FlyLineLayer, _CustomDataSource); return _createClass(FlyLineLayer, [{ key: "show", get: function get() { return _superPropGet(FlyLineLayer, "show", this, 1); }, set: function set(value) { this.setVisible(value); } // 获取地图 }, { key: "getMap", value: function getMap() { return this.map; } // 设置图层显示隐藏 }, { key: "setVisible", value: function setVisible(visible) { _superPropSet(FlyLineLayer, "show", visible, this, 1, 1); // 将属性传递给父类 var map = this.getMap && this.getMap(); if (map) { map.layers.emit('visible', this, visible); } } }, { key: "loadData", value: function loadData(data) { var _this2 = this; this.entities.removeAll(); data.map(function (v) { var height = _this2.height || 0; var count = _this2.count; var color = _this2.color; var startPosition = [], endPosition = []; if ((0, _lodash.isArray)(v)) { startPosition = v[0]; endPosition = v[1]; } else { var start = v.start, end = v.end; height = v.height || height; count = v.count || count; color = v.color || color; startPosition = _getCoordinates(start); endPosition = _getCoordinates(end); } var positions = (0, _parabola["default"])({ startPosition: startPosition, endPosition: endPosition, height: height, count: count }); // 创建飞线 for (var i = 0; i < _this2.number; i++) { // 创建飞线 var entity_fly = _this2.entities.add({ polyline: { positions: positions, width: _this2.flyWidth, material: new _LineFlowMaterialProperty["default"]({ color: _cesium.Color.fromCssColorString(color), speed: _this2.speed * Math.random(), percent: 0.1, gradient: 0.01 }) } }); entity_fly.type = _this2.modalType || _this2.key; entity_fly.key = _this2.key; // 处理图层搜索的时候出现重复数据的问题 entity_fly.ignoreSearch = true; entity_fly.properties = v.properties || {}; } var material = _this2.glowPower ? new _cesium.PolylineGlowMaterialProperty({ glowPower: _this2.glowPower, // 发光强度 color: _cesium.Color.fromCssColorString((0, _transformRgb["default"])(color, _this2.opacity)) }) : _cesium.Color.fromCssColorString((0, _transformRgb["default"])(color, _this2.opacity)); // 创建轨迹线 var entity = _this2.entities.add({ polyline: { positions: positions, width: _this2.width, material: material } }); entity.type = _this2.modalType || _this2.key; entity.key = _this2.key; entity.properties = v.properties || {}; }); } // 根据条件获取图形数据 }, { key: "getFeatureByFieldValue", value: function getFeatureByFieldValue(field, value) { return this.getFeatures().find(function (v) { var _v$properties; return (v === null || v === void 0 || (_v$properties = v.properties) === null || _v$properties === void 0 || (_v$properties = _v$properties[field]) === null || _v$properties === void 0 ? void 0 : _v$properties._value) === value; }); } // 获取当前图层的所有图形 }, { key: "getFeatures", value: function getFeatures() { return this.entities.values; } }]); }(_cesium.CustomDataSource); //# sourceMappingURL=FlyLineLayer.js.map