UNPKG

@vtx/cs-map

Version:

React components for Vortex

297 lines (295 loc) 15.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _FeatureLayer = _interopRequireDefault(require("../feature-layer/FeatureLayer")); var _cesium = require("cesium"); var _CircleRippleMaterialProperty = _interopRequireDefault(require("../map/material/CircleRippleMaterialProperty")); var _Marker = _interopRequireDefault(require("../marker/Marker")); var _LineFlowLayer = _interopRequireDefault(require("../line-flow-layer/LineFlowLayer")); var _transformRgb = _interopRequireDefault(require("../_util/transformRgb")); var _RoadLineLayer = _interopRequireDefault(require("../road-line-layer/RoadLineLayer")); var _excluded = ["fill", "stroke", "color"]; 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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } 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); } /** * 图层高亮操作 */ /** * @description: wms图层点击获取的数据处理 * @param {*} data * @return {*} */ var handleData = function handleData(data, map) { var _data = []; var datas = Array.isArray(data) ? data : [data]; datas.map(function (v) { var _v$data; // 影像图层的数据 if (v instanceof _cesium.ImageryLayerFeatureInfo || v !== null && v !== void 0 && (_v$data = v.data) !== null && _v$data !== void 0 && (_v$data = _v$data.geometry) !== null && _v$data !== void 0 && _v$data.coordinates) { var item = v.data || {}; var geometry = item.geometry; var _ref = geometry || {}, _ref$coordinates = _ref.coordinates, coordinates = _ref$coordinates === void 0 ? [] : _ref$coordinates; _data.push(_objectSpread(_objectSpread({}, item), {}, { geometryInfo: _objectSpread(_objectSpread({}, geometry), {}, { lngLats: coordinates }) })); } else { var _v$position, _v$_polyline, _v$_polygon; if (v !== null && v !== void 0 && (_v$position = v.position) !== null && _v$position !== void 0 && _v$position._value) { var _v$position2; handlePositionData({ data: _data, position: v === null || v === void 0 || (_v$position2 = v.position) === null || _v$position2 === void 0 ? void 0 : _v$position2._value, map: map, feature: v }); } else if (v !== null && v !== void 0 && (_v$_polyline = v._polyline) !== null && _v$_polyline !== void 0 && (_v$_polyline = _v$_polyline._positions) !== null && _v$_polyline !== void 0 && _v$_polyline._value) { var _v$_polyline2; handlePositionData({ data: _data, position: v === null || v === void 0 || (_v$_polyline2 = v._polyline) === null || _v$_polyline2 === void 0 || (_v$_polyline2 = _v$_polyline2._positions) === null || _v$_polyline2 === void 0 ? void 0 : _v$_polyline2._value, map: map, feature: v, type: 'Polyline' }); } else if (v !== null && v !== void 0 && (_v$_polygon = v._polygon) !== null && _v$_polygon !== void 0 && (_v$_polygon = _v$_polygon._hierarchy) !== null && _v$_polygon !== void 0 && (_v$_polygon = _v$_polygon._value) !== null && _v$_polygon !== void 0 && _v$_polygon.positions) { var _v$_polygon2; handlePositionData({ data: _data, position: v === null || v === void 0 || (_v$_polygon2 = v._polygon) === null || _v$_polygon2 === void 0 || (_v$_polygon2 = _v$_polygon2._hierarchy) === null || _v$_polygon2 === void 0 || (_v$_polygon2 = _v$_polygon2._value) === null || _v$_polygon2 === void 0 ? void 0 : _v$_polygon2.positions, map: map, feature: v, type: 'Polygon' }); } } }); return _data; }; var handlePositionData = function handlePositionData(_ref2) { var data = _ref2.data, position = _ref2.position, map = _ref2.map, feature = _ref2.feature, _ref2$type = _ref2.type, type = _ref2$type === void 0 ? 'point' : _ref2$type; var lngLats = []; if (Array.isArray(position)) { position.map(function (v) { lngLats.push(getLngLats(v)); }); } else { // 点 lngLats = getLngLats(position); } data.push(_objectSpread(_objectSpread({}, map.getProperties(feature)), {}, { geometryInfo: { type: type, lngLats: lngLats } })); }; var getLngLats = function getLngLats(position) { var lngLats = []; var cartographic = _cesium.Cartographic.fromCartesian(position); var lng = _cesium.Math.toDegrees(cartographic === null || cartographic === void 0 ? void 0 : cartographic.longitude); lngLats.push(lng); var lat = _cesium.Math.toDegrees(cartographic === null || cartographic === void 0 ? void 0 : cartographic.latitude); lngLats.push(lat); return lngLats; }; var getPolygonStyle = function getPolygonStyle(style) { var _ref3 = style || {}, _ref3$fill = _ref3.fill, fill = _ref3$fill === void 0 ? {} : _ref3$fill, _ref3$stroke = _ref3.stroke, stroke = _ref3$stroke === void 0 ? {} : _ref3$stroke, color = _ref3.color, otherStyle = _objectWithoutProperties(_ref3, _excluded); return _objectSpread({ type: 'Polygon', style: { stroke: _objectSpread({ color: color || '#f7ff01', opacity: 1, width: 2 }, stroke), fill: _objectSpread({ color: color || '#f7ff01', opacity: 0.35 }, fill) } }, otherStyle); }; var getMarkerStyle = function getMarkerStyle(style) { return { type: 'Marker', style: _objectSpread({ type: 'CommonIcon2' }, style) }; }; var getLineStyle = function getLineStyle(style) { var _ref4 = style || {}, color = _ref4.color; return { type: 'Polyline', style: { stroke: { color: color || '#f7ff01', opacity: 1, width: 5 } } }; }; var pointStyle = function pointStyle(style) { var _ref5 = style || {}, color = _ref5.color; return { style: { type: 'PointIcon', color: color || '#f7ff01', size: 10, horizontalOrigin: _cesium.HorizontalOrigin.CENTER, verticalOrigin: _cesium.VerticalOrigin.BOTTOM, pixelOffset: new _cesium.Cartesian2(0, 10) } }; }; var HighlightLayer = exports["default"] = /*#__PURE__*/function () { function HighlightLayer(options) { var _this = this; _classCallCheck(this, HighlightLayer); // 高亮图层增加feature _defineProperty(this, "addHighlightFeature", function (feature) { var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (feature && !feature.hideHighlight && !_this.map.hideHighlight) { _this.clearHighlight(); if (feature instanceof _cesium.Cesium3DTileFeature) { return _this.addHighlight3DTileFeature(feature, _this.color); } else if (feature.primitive) { return _this.addHighlightPrimitive(feature); } else { var _feature$data, _feature$_polyline, _feature$_polygon; var type = feature === null || feature === void 0 || (_feature$data = feature.data) === null || _feature$data === void 0 || (_feature$data = _feature$data.geometry) === null || _feature$data === void 0 ? void 0 : _feature$data.type; if (feature instanceof _Marker["default"]) { _this.layer.style = getMarkerStyle(feature._billboard.mapIcon); } else if (['LineString', 'MultiLineString'].includes(type)) { _this.layer.style = getLineStyle({ color: _this.color }); } else if (['Polygon', 'MultiPolygon'].includes(type)) { _this.layer.style = getPolygonStyle(_objectSpread(_objectSpread({}, style), {}, { color: _this.color })); } else if (['Point'].includes(type)) { _this.layer.style = pointStyle({ color: _this.color }); } else if (feature !== null && feature !== void 0 && (_feature$_polyline = feature._polyline) !== null && _feature$_polyline !== void 0 && (_feature$_polyline = _feature$_polyline._positions) !== null && _feature$_polyline !== void 0 && _feature$_polyline._value) { _this.layer.style = getLineStyle(_this.map.dark); } else if (feature !== null && feature !== void 0 && (_feature$_polygon = feature._polygon) !== null && _feature$_polygon !== void 0 && (_feature$_polygon = _feature$_polygon._hierarchy) !== null && _feature$_polygon !== void 0 && (_feature$_polygon = _feature$_polygon._value) !== null && _feature$_polygon !== void 0 && _feature$_polygon.positions) { _this.layer.style = getPolygonStyle(style); } else { _this.layer.style = pointStyle({ color: _this.color }); } var data = handleData(feature, _this.map, _this.layer); _this.layer.data = data; _this.layer.loadData(data); } } }); _defineProperty(this, "addHighlight3DTileFeature", function (feature, color) { if (_this.feature === feature && feature !== undefined) { return; } if (_this.feature && _this.oldColor && !_this.feature.content.isDestroyed()) { _this.feature.color = _this.oldColor; } _this.oldColor = _cesium.Color.clone(feature.color); feature.color = _cesium.Color.fromCssColorString((0, _transformRgb["default"])(color || '#f7ff01', 0.3)); _this.feature = feature; }); _defineProperty(this, "addHighlightPrimitive", function (feature) { if (feature.primitive instanceof _LineFlowLayer["default"] || feature.primitive instanceof _RoadLineLayer["default"]) { _this.clearPrimitive(); var data = [feature.values_]; _this.primitiveLayer = new _LineFlowLayer["default"]({ fadeOutColor: _this.color, data: [feature.values_] }); _this.map.scene.primitives.add(_this.primitiveLayer); _this.map.scene.primitives.raiseToTop(_this.primitiveLayer); _this.layer.data = data; _this.layer.loadData(data); } }); var _options$isFit = options.isFit, isFit = _options$isFit === void 0 ? true : _options$isFit, _color = options.color; this.map = options.map; this.layer = new _FeatureLayer["default"]({ style: getLineStyle(this.map.dark) }); this.map.dataSources.add(this.layer); this.color = _color || '#f7ff01'; this.primitiveLayer = null; } _createClass(HighlightLayer, [{ key: "clear3DTileFeature", value: function clear3DTileFeature() { if (this.oldColor && this.feature) { this.feature.color = this.oldColor; } this.feature = null; this.oldColor = null; } }, { key: "clearPrimitive", value: function clearPrimitive() { if (this.primitiveLayer) { if (this.map.scene.primitives.contains(this.primitiveLayer)) { this.map.scene.primitives.remove(this.primitiveLayer); } this.primitiveLayer = null; } } }, { key: "clearHighlight", value: function clearHighlight() { this.clearPrimitive(); this.clear3DTileFeature(); } }, { key: "clearFeatures", value: function clearFeatures() { this.layer.entities.removeAll(); this.clearHighlight(); } }, { key: "destroy", value: function destroy() { this.map.dataSources.remove(this.layer); this.clearHighlight(); } }]); return HighlightLayer; }(); //# sourceMappingURL=HighlightLayer.js.map