@vtx/cs-map
Version:
React components for Vortex
271 lines (244 loc) • 11 kB
JavaScript
"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(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 _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); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
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(arr) { if (Array.isArray(arr)) return arr; }
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);
}
}
_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;
}
}
}]);
return ThreePointLayer;
}();
var _default = exports["default"] = ThreePointLayer;
//# sourceMappingURL=ThreePointLayer.js.map