@vtx/cs-map
Version:
React components for Vortex
258 lines (238 loc) • 14.7 kB
JavaScript
;
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(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 _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function set(target, property, value, receiver) { if (typeof Reflect !== "undefined" && Reflect.set) { set = Reflect.set; } else { set = function set(target, property, value, receiver) { var base = _superPropBase(target, property); var desc; if (base) { desc = Object.getOwnPropertyDescriptor(base, property); if (desc.set) { desc.set.call(receiver, value); return true; } else if (!desc.writable) { return false; } } desc = Object.getOwnPropertyDescriptor(receiver, property); if (desc) { if (!desc.writable) { return false; } desc.value = value; Object.defineProperty(receiver, property, desc); } else { _defineProperty(receiver, property, value); } return true; }; } return set(target, property, value, receiver); }
function _set(target, property, value, receiver, isStrict) { var s = set(target, property, value, receiver || target); if (!s && isStrict) { throw new TypeError('failed to set property'); } return value; }
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); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
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 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) {
_inherits(FlyLineLayer, _CustomDataSource);
var _super = _createSuper(FlyLineLayer);
function FlyLineLayer(option) {
var _thisSuper, _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 = _super.call(this, option);
_set((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(FlyLineLayer.prototype)), "show", show, _thisSuper, true);
// 图层标识
_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;
}
// 重写父类的属性访问器
_createClass(FlyLineLayer, [{
key: "show",
get: function get() {
return _get(_getPrototypeOf(FlyLineLayer.prototype), "show", this);
},
set: function set(value) {
this.setVisible(value);
}
// 获取地图
}, {
key: "getMap",
value: function getMap() {
return this.map;
}
// 设置图层显示隐藏
}, {
key: "setVisible",
value: function setVisible(visible) {
_set(_getPrototypeOf(FlyLineLayer.prototype), "show", visible, this, true); // 将属性传递给父类
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;
}
}]);
return FlyLineLayer;
}(_cesium.CustomDataSource);
//# sourceMappingURL=FlyLineLayer.js.map