@vtx/cs-map
Version:
React components for Vortex
296 lines (294 loc) • 14.1 kB
JavaScript
"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(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 _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 _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
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(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); } /**
* 图层高亮操作
*/
/**
* @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;
}
return _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();
}
}]);
}();
//# sourceMappingURL=HighlightLayer.js.map