deeptwins-engine-3d 0.1.66 → 0.1.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/esm/constant.d.ts +9 -0
  2. package/dist/esm/constant.js +10 -1
  3. package/dist/esm/graphicLayer/BaseLayer.d.ts +23 -0
  4. package/dist/esm/graphicLayer/BaseLayer.js +387 -65
  5. package/dist/esm/graphicLayer/BasePrimitiveInstance.d.ts +0 -1
  6. package/dist/esm/graphicLayer/BasePrimitiveInstance.js +0 -7
  7. package/dist/esm/graphicLayer/BaseSource.d.ts +1 -1
  8. package/dist/esm/graphicLayer/BoxPrimitiveInstance.d.ts +0 -1
  9. package/dist/esm/graphicLayer/BoxPrimitiveInstance.js +4 -8
  10. package/dist/esm/graphicLayer/EllipsePrimitiveInstance.d.ts +0 -1
  11. package/dist/esm/graphicLayer/EllipsePrimitiveInstance.js +5 -9
  12. package/dist/esm/graphicLayer/EllipsoidPrimitiveInstance.d.ts +0 -1
  13. package/dist/esm/graphicLayer/EllipsoidPrimitiveInstance.js +5 -9
  14. package/dist/esm/graphicLayer/GraphicLayerCollection.js +20 -27
  15. package/dist/esm/graphicLayer/ModelPrimitiveInstance.d.ts +0 -1
  16. package/dist/esm/graphicLayer/ModelPrimitiveInstance.js +0 -7
  17. package/dist/esm/graphicLayer/PolygonGroundPrimitiveImageMaterialInstance.js +5 -2
  18. package/dist/esm/graphicLayer/PolygonPrimitiveImageMaterialInstance.js +5 -2
  19. package/dist/esm/graphicLayer/PolygonPrimitiveInstance.d.ts +0 -1
  20. package/dist/esm/graphicLayer/PolygonPrimitiveInstance.js +5 -9
  21. package/dist/esm/graphicLayer/PolylineGroundPrimitiveInstance.d.ts +0 -1
  22. package/dist/esm/graphicLayer/PolylineGroundPrimitiveInstance.js +4 -8
  23. package/dist/esm/graphicLayer/PolylinePrimitiveInstance.d.ts +0 -1
  24. package/dist/esm/graphicLayer/PolylinePrimitiveInstance.js +4 -8
  25. package/dist/esm/graphicLayer/PolylineVolumePrimitiveInstance.d.ts +0 -1
  26. package/dist/esm/graphicLayer/PolylineVolumePrimitiveInstance.js +4 -8
  27. package/dist/esm/graphicLayer/WallPrimitiveInstance.d.ts +0 -1
  28. package/dist/esm/graphicLayer/WallPrimitiveInstance.js +4 -8
  29. package/dist/esm/index.js +2 -2
  30. package/dist/esm/material/WeatherEffects.d.ts +64 -14
  31. package/dist/esm/material/WeatherEffects.js +279 -95
  32. package/dist/esm/material/shader/RainShader.glsl +44 -6
  33. package/dist/esm/material/shader/lightning.glsl +70 -0
  34. package/dist/esm/tileLayer/MvtVectorLoad.d.ts +12 -0
  35. package/dist/esm/tileLayer/MvtVectorLoad.js +245 -49
  36. package/dist/umd/deeptwins-engine-3d.min.js +1 -1
  37. package/package.json +1 -1
@@ -255,6 +255,15 @@ export declare const DEFAULT_RAIN: () => {
255
255
  direction: number;
256
256
  size: number;
257
257
  speed: number;
258
+ density: number;
259
+ opacity: number;
260
+ gloominess: number;
261
+ color: string;
262
+ lightningEnabled: boolean;
263
+ lightningFrequency: number;
264
+ lightningIntensity: number;
265
+ lightningTint: string;
266
+ lightningDuration: number;
258
267
  };
259
268
  export declare const DEFAULT_FOG: () => {
260
269
  startDistance: number;
@@ -723,7 +723,16 @@ export var DEFAULT_RAIN = function DEFAULT_RAIN() {
723
723
  return {
724
724
  direction: -30,
725
725
  size: 10,
726
- speed: 10
726
+ speed: 10,
727
+ density: 40,
728
+ opacity: 0.5,
729
+ gloominess: 0.5,
730
+ color: '#a8c6df',
731
+ lightningEnabled: false,
732
+ lightningFrequency: 20,
733
+ lightningIntensity: 0.35,
734
+ lightningTint: '#dfe8ff',
735
+ lightningDuration: 0.18
727
736
  };
728
737
  };
729
738
 
@@ -1,5 +1,8 @@
1
1
  export default class BaseLayer {
2
2
  private readonly _mapContext;
3
+ private _layerVisible;
4
+ private _layerStyle;
5
+ private _styleOverridesByIndex;
3
6
  id: any;
4
7
  type: any;
5
8
  options: any;
@@ -13,9 +16,29 @@ export default class BaseLayer {
13
16
  private readonly _renderClass;
14
17
  constructor({ id, source, options, entity, mapContext }: any);
15
18
  getMap(): any;
19
+ private _isCollectionPrimitiveType;
20
+ private _isBatchPrimitiveType;
21
+ private _getLayerVisibleState;
22
+ private _setEntityVisible;
23
+ private _resolveSource;
24
+ private _getCurrentSource;
25
+ private _mergeLayerStyle;
26
+ private _getStyleTemplate;
27
+ private _getOriginStyle;
28
+ private _trimStyleOverridesByLength;
29
+ private _shiftStyleOverridesAfterRemove;
30
+ private _setStyleOverrideByIndex;
31
+ private _canHotUpdateBatchPrimitiveStyle;
16
32
  private _createPrimitiveCollection;
33
+ private _initializePrimitiveLayers;
34
+ private _mountPrimitiveCollection;
35
+ private _disposePrimitiveCollection;
17
36
  private _createEntity;
18
37
  private _createPrimitive;
38
+ private _syncIncrementalData;
39
+ private _setEntityData;
40
+ private _setCollectionPrimitiveData;
41
+ private _rebuildBatchPrimitiveData;
19
42
  private _canOperate;
20
43
  show(isShow: boolean): void;
21
44
  private _getOne;
@@ -1,4 +1,11 @@
1
1
  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); }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ 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."); }
4
+ 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; } }
5
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
7
+ 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); }
8
+ 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; }
2
9
  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; }
3
10
  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; }
4
11
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -8,7 +15,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
8
15
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
16
  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); }
10
17
  import * as Cesium from 'deeptwins-cesium';
11
- import { cloneDeep, flattenDeep, isFunction, isString } from 'lodash';
18
+ import { cloneDeep, flattenDeep, isFunction, isString, merge } from 'lodash';
12
19
  import { v4 as uuidv4 } from 'uuid';
13
20
  import * as constant from "../constant";
14
21
  import BaseSource from "../graphicLayer/BaseSource";
@@ -23,9 +30,12 @@ import PolylineGroundPrimitive from "./PolylineGroundPrimitive";
23
30
  import PolylinePrimitive from "./PolylinePrimitive";
24
31
  import PolylineVolumePrimitive from "./PolylineVolumePrimitive";
25
32
  import WallPrimitive from "./WallPrimitive";
33
+ var COLLECTION_PRIMITIVE_TYPES = new Set(['pointP', 'billboardP', 'labelP']);
26
34
  var BaseLayer = /*#__PURE__*/function () {
27
35
  function BaseLayer(_ref) {
28
- var _this = this;
36
+ var _this$_layerStyle$sho,
37
+ _this$_layerStyle,
38
+ _this = this;
29
39
  var id = _ref.id,
30
40
  source = _ref.source,
31
41
  options = _ref.options,
@@ -33,6 +43,11 @@ var BaseLayer = /*#__PURE__*/function () {
33
43
  mapContext = _ref.mapContext;
34
44
  _classCallCheck(this, BaseLayer);
35
45
  _defineProperty(this, "_mapContext", void 0);
46
+ _defineProperty(this, "_layerVisible", true);
47
+ _defineProperty(this, "_layerStyle", void 0);
48
+ // batch primitive 没有稳定的实例级更新能力,这里按 source 顺序保存局部样式覆盖,
49
+ // 后续 setData / removeOne 重建时再按索引重新应用。
50
+ _defineProperty(this, "_styleOverridesByIndex", new Map());
36
51
  _defineProperty(this, "id", void 0);
37
52
  _defineProperty(this, "type", void 0);
38
53
  _defineProperty(this, "options", void 0);
@@ -54,7 +69,11 @@ var BaseLayer = /*#__PURE__*/function () {
54
69
  this._mapContext = mapContext;
55
70
  this.id = id;
56
71
  this.type = options.type;
57
- this.options = options;
72
+ this.options = _objectSpread(_objectSpread({}, options), {}, {
73
+ style: cloneDeep(options.style || {})
74
+ });
75
+ this._layerStyle = cloneDeep(this.options.style || {});
76
+ this._layerVisible = (_this$_layerStyle$sho = (_this$_layerStyle = this._layerStyle) === null || _this$_layerStyle === void 0 ? void 0 : _this$_layerStyle.show) !== null && _this$_layerStyle$sho !== void 0 ? _this$_layerStyle$sho : true;
58
77
  this.sourceId = source === null || source === void 0 ? void 0 : source.id;
59
78
  this._renderClass = constant.GRAPHIC_LAYER_TYPE_TO_CLASS[options.type];
60
79
  if (entity) {
@@ -68,17 +87,7 @@ var BaseLayer = /*#__PURE__*/function () {
68
87
  } else if (options.type.endsWith('P')) {
69
88
  // Primitive类型
70
89
  this.isPrimitive = true;
71
- // 创建集合
72
- this._createPrimitiveCollection(options.type);
73
- // 实例的集合
74
- var primitiveInstance = [];
75
- source.source.forEach(function (t) {
76
- _this._createPrimitive(t, options, primitiveInstance);
77
- });
78
- if (!['pointP', 'billboardP', 'labelP'].includes(options.type)) {
79
- // 集合创建Primitive
80
- this.primitiveCollection.createPrimitive(options, primitiveInstance);
81
- }
90
+ this._initializePrimitiveLayers(source, options);
82
91
  } else {
83
92
  // entity类型
84
93
  this.isEntity = true;
@@ -93,6 +102,187 @@ var BaseLayer = /*#__PURE__*/function () {
93
102
  return this._mapContext && this._mapContext.getMap();
94
103
  }
95
104
 
105
+ // 是否是集合的Primitive类型
106
+ }, {
107
+ key: "_isCollectionPrimitiveType",
108
+ value: function _isCollectionPrimitiveType() {
109
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.type;
110
+ return COLLECTION_PRIMITIVE_TYPES.has(type);
111
+ }
112
+
113
+ // point/billboard/label 以 collection 形式直接管理 primitive,
114
+ // 其他 *P 类型本质上都是“一次收集 GeometryInstance -> 一次创建 Primitive”。
115
+ }, {
116
+ key: "_isBatchPrimitiveType",
117
+ value: function _isBatchPrimitiveType() {
118
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.type;
119
+ return !!type && type.endsWith('P') && !this._isCollectionPrimitiveType(type);
120
+ }
121
+
122
+ // 获取图层显示隐藏状态
123
+ }, {
124
+ key: "_getLayerVisibleState",
125
+ value: function _getLayerVisibleState() {
126
+ var _this$options$style$s, _this$options, _this$layers$0$entity, _this$layers$2;
127
+ var defaultShow = (_this$options$style$s = (_this$options = this.options) === null || _this$options === void 0 || (_this$options = _this$options.style) === null || _this$options === void 0 ? void 0 : _this$options.show) !== null && _this$options$style$s !== void 0 ? _this$options$style$s : true;
128
+ if (this.isPrimitive) {
129
+ var _this$primitiveCollec, _this$primitiveCollec2;
130
+ return (_this$primitiveCollec = (_this$primitiveCollec2 = this.primitiveCollection) === null || _this$primitiveCollec2 === void 0 ? void 0 : _this$primitiveCollec2.show) !== null && _this$primitiveCollec !== void 0 ? _this$primitiveCollec : defaultShow;
131
+ }
132
+ if (!this.layers.length) {
133
+ return defaultShow;
134
+ }
135
+ if (this.type === 'html') {
136
+ var _this$layers$;
137
+ return ((_this$layers$ = this.layers[0]) === null || _this$layers$ === void 0 || (_this$layers$ = _this$layers$.container) === null || _this$layers$ === void 0 || (_this$layers$ = _this$layers$.style) === null || _this$layers$ === void 0 ? void 0 : _this$layers$.display) !== 'none';
138
+ }
139
+ return (_this$layers$0$entity = (_this$layers$2 = this.layers[0]) === null || _this$layers$2 === void 0 || (_this$layers$2 = _this$layers$2.entity) === null || _this$layers$2 === void 0 ? void 0 : _this$layers$2.show) !== null && _this$layers$0$entity !== void 0 ? _this$layers$0$entity : defaultShow;
140
+ }
141
+
142
+ // 设置图层显示隐藏
143
+ }, {
144
+ key: "_setEntityVisible",
145
+ value: function _setEntityVisible(layer, isShow) {
146
+ if (this.type === 'html') {
147
+ layer.show(isShow);
148
+ } else if (layer.entity) {
149
+ layer.entity.show = isShow;
150
+ }
151
+ }
152
+
153
+ // 解析数据源
154
+ }, {
155
+ key: "_resolveSource",
156
+ value: function _resolveSource(data) {
157
+ var source = null;
158
+ var sourceType = BaseSource.analysisSourceType(data);
159
+ if (sourceType === 'sourceInstance') {
160
+ source = data;
161
+ } else if (sourceType === 'sourceId') {
162
+ source = this.getMap().graphicLayerCollection.graphicSources.get(data);
163
+ } else {
164
+ source = this.getMap().graphicLayerCollection.addSource(uuidv4(), data);
165
+ }
166
+ if (!source) {
167
+ utils.warn('未找到对应的数据源');
168
+ return null;
169
+ }
170
+ return source;
171
+ }
172
+
173
+ // 获取当前数据源
174
+ }, {
175
+ key: "_getCurrentSource",
176
+ value: function _getCurrentSource() {
177
+ return {
178
+ id: this.sourceId,
179
+ source: this.layers.map(function (t) {
180
+ return t.source;
181
+ })
182
+ };
183
+ }
184
+
185
+ // 合并图层样式
186
+ }, {
187
+ key: "_mergeLayerStyle",
188
+ value: function _mergeLayerStyle(style) {
189
+ this._layerStyle = merge(cloneDeep(this._layerStyle || {}), cloneDeep(style || {}));
190
+ this.options.style = cloneDeep(this._layerStyle);
191
+ }
192
+
193
+ // 获取样式模板
194
+ }, {
195
+ key: "_getStyleTemplate",
196
+ value: function _getStyleTemplate(layerIndex) {
197
+ var styleTemplate = cloneDeep(this._layerStyle || {});
198
+ if (this._isBatchPrimitiveType() && layerIndex !== undefined) {
199
+ var overrideStyle = this._styleOverridesByIndex.get(layerIndex);
200
+ if (overrideStyle) {
201
+ merge(styleTemplate, cloneDeep(overrideStyle));
202
+ }
203
+ }
204
+ return styleTemplate;
205
+ }
206
+
207
+ // 获取原始样式
208
+ }, {
209
+ key: "_getOriginStyle",
210
+ value: function _getOriginStyle(data, layerIndex) {
211
+ return utils.styleFun(this._getStyleTemplate(layerIndex), data.properties || {});
212
+ }
213
+
214
+ // 裁剪局部样式
215
+ }, {
216
+ key: "_trimStyleOverridesByLength",
217
+ value: function _trimStyleOverridesByLength(length) {
218
+ if (!this._styleOverridesByIndex.size) {
219
+ return;
220
+ }
221
+ var nextOverrides = new Map();
222
+ var _iterator = _createForOfIteratorHelper(this._styleOverridesByIndex.entries()),
223
+ _step;
224
+ try {
225
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
226
+ var _step$value = _slicedToArray(_step.value, 2),
227
+ _index = _step$value[0],
228
+ style = _step$value[1];
229
+ if (_index < length) {
230
+ nextOverrides.set(_index, style);
231
+ }
232
+ }
233
+ } catch (err) {
234
+ _iterator.e(err);
235
+ } finally {
236
+ _iterator.f();
237
+ }
238
+ this._styleOverridesByIndex = nextOverrides;
239
+ }
240
+
241
+ // 删除后调整局部样式索引
242
+ }, {
243
+ key: "_shiftStyleOverridesAfterRemove",
244
+ value: function _shiftStyleOverridesAfterRemove(removeIndex) {
245
+ if (!this._styleOverridesByIndex.size || removeIndex < 0) {
246
+ return;
247
+ }
248
+ var nextOverrides = new Map();
249
+ var _iterator2 = _createForOfIteratorHelper(this._styleOverridesByIndex.entries()),
250
+ _step2;
251
+ try {
252
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
253
+ var _step2$value = _slicedToArray(_step2.value, 2),
254
+ _index2 = _step2$value[0],
255
+ style = _step2$value[1];
256
+ if (_index2 < removeIndex) {
257
+ nextOverrides.set(_index2, style);
258
+ } else if (_index2 > removeIndex) {
259
+ nextOverrides.set(_index2 - 1, style);
260
+ }
261
+ }
262
+ } catch (err) {
263
+ _iterator2.e(err);
264
+ } finally {
265
+ _iterator2.f();
266
+ }
267
+ this._styleOverridesByIndex = nextOverrides;
268
+ }
269
+
270
+ // 设置局部样式
271
+ }, {
272
+ key: "_setStyleOverrideByIndex",
273
+ value: function _setStyleOverrideByIndex(layerIndex, style) {
274
+ var currentStyle = this._styleOverridesByIndex.get(layerIndex) || {};
275
+ this._styleOverridesByIndex.set(layerIndex, merge(cloneDeep(currentStyle), cloneDeep(style || {})));
276
+ }
277
+
278
+ // 批量Primitive样式是否支持热更新
279
+ }, {
280
+ key: "_canHotUpdateBatchPrimitiveStyle",
281
+ value: function _canHotUpdateBatchPrimitiveStyle(style) {
282
+ var keys = Object.keys(style || {});
283
+ return keys.length === 1 && keys[0] === 'show' && !isFunction(style.show);
284
+ }
285
+
96
286
  // 根据类型创建不同的集合
97
287
  }, {
98
288
  key: "_createPrimitiveCollection",
@@ -156,17 +346,66 @@ var BaseLayer = /*#__PURE__*/function () {
156
346
  };
157
347
  (_createType$type = createType[type]) === null || _createType$type === void 0 || _createType$type.call(createType);
158
348
  }
349
+ }, {
350
+ key: "_initializePrimitiveLayers",
351
+ value: function _initializePrimitiveLayers(source) {
352
+ var _this3 = this;
353
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.options;
354
+ this._createPrimitiveCollection(options.type);
355
+ var primitiveInstance = [];
356
+ source.source.forEach(function (t, index) {
357
+ _this3._createPrimitive(t, options, primitiveInstance, index);
358
+ });
359
+ if (this._isBatchPrimitiveType(options.type)) {
360
+ this.primitiveCollection.createPrimitive(_objectSpread(_objectSpread({}, options), {}, {
361
+ style: cloneDeep(this._layerStyle || {})
362
+ }), primitiveInstance);
363
+ }
364
+ }
365
+ }, {
366
+ key: "_mountPrimitiveCollection",
367
+ value: function _mountPrimitiveCollection() {
368
+ var _this$getMap;
369
+ if (!this.primitiveCollection) {
370
+ return;
371
+ }
372
+ var primitives = (_this$getMap = this.getMap()) === null || _this$getMap === void 0 || (_this$getMap = _this$getMap.scene) === null || _this$getMap === void 0 ? void 0 : _this$getMap.primitives;
373
+ if (!primitives) {
374
+ return;
375
+ }
376
+ if (this._isCollectionPrimitiveType()) {
377
+ primitives.add(this.primitiveCollection);
378
+ } else if (this.primitiveCollection.primitive) {
379
+ primitives.add(this.primitiveCollection.primitive);
380
+ }
381
+ }
382
+ }, {
383
+ key: "_disposePrimitiveCollection",
384
+ value: function _disposePrimitiveCollection() {
385
+ if (!this.primitiveCollection) {
386
+ return;
387
+ }
388
+ if (this._isCollectionPrimitiveType()) {
389
+ var _this$primitiveCollec3, _this$primitiveCollec4, _this$getMap2;
390
+ (_this$primitiveCollec3 = (_this$primitiveCollec4 = this.primitiveCollection).removeAll) === null || _this$primitiveCollec3 === void 0 || _this$primitiveCollec3.call(_this$primitiveCollec4);
391
+ (_this$getMap2 = this.getMap()) === null || _this$getMap2 === void 0 || (_this$getMap2 = _this$getMap2.scene) === null || _this$getMap2 === void 0 || (_this$getMap2 = _this$getMap2.primitives) === null || _this$getMap2 === void 0 || _this$getMap2.remove(this.primitiveCollection);
392
+ } else {
393
+ this.primitiveCollection.removeAll();
394
+ }
395
+ this.primitiveCollection = null;
396
+ }
159
397
 
160
398
  // 创建相应的entity
161
399
  }, {
162
400
  key: "_createEntity",
163
401
  value: function _createEntity(data, options) {
402
+ var originStyle = this._getOriginStyle(data);
164
403
  var layer = new this._renderClass(_objectSpread(_objectSpread(_objectSpread({
165
404
  map: this.getMap()
166
405
  }, data), options), {}, {
167
406
  html: isFunction(options.html) ? options.html(data.properties) : options.html,
168
407
  source: data,
169
- style: utils.styleFun(cloneDeep(options.style || {}), data.properties)
408
+ style: originStyle
170
409
  }));
171
410
  this.layers.push(layer);
172
411
  return layer;
@@ -175,10 +414,11 @@ var BaseLayer = /*#__PURE__*/function () {
175
414
  // 创建相应的primitive
176
415
  }, {
177
416
  key: "_createPrimitive",
178
- value: function _createPrimitive(data, options, primitiveInstance) {
417
+ value: function _createPrimitive(data, options, primitiveInstance, layerIndex) {
418
+ var originStyle = this._getOriginStyle(data, layerIndex);
179
419
  var layer = new this._renderClass(_objectSpread(_objectSpread(_objectSpread({}, data), options), {}, {
180
420
  source: data,
181
- style: utils.styleFun(cloneDeep(options.style || {}), data.properties),
421
+ style: originStyle,
182
422
  primitiveInstance: primitiveInstance,
183
423
  primitiveCollection: this.primitiveCollection,
184
424
  layerId: this.id,
@@ -187,6 +427,62 @@ var BaseLayer = /*#__PURE__*/function () {
187
427
  this.layers.push(layer);
188
428
  }
189
429
 
430
+ // 同步增量数据
431
+ }, {
432
+ key: "_syncIncrementalData",
433
+ value: function _syncIncrementalData(source, createLayer) {
434
+ if (source.source.length < this.layers.length) {
435
+ var startIndex = this.layers.length - 1;
436
+ for (var i = startIndex; i >= source.source.length; i--) {
437
+ this.removeOne(this.layers[i]);
438
+ }
439
+ }
440
+ for (var _i = 0; _i < source.source.length; _i++) {
441
+ var sourceData = source.source[_i];
442
+ if (this.layers[_i]) {
443
+ this.layers[_i].updateData(sourceData);
444
+ } else {
445
+ createLayer(sourceData, _i);
446
+ }
447
+ }
448
+ }
449
+
450
+ // 设置entity数据
451
+ }, {
452
+ key: "_setEntityData",
453
+ value: function _setEntityData(source) {
454
+ var _this4 = this;
455
+ var isShow = this._layerVisible;
456
+ this._syncIncrementalData(source, function (sourceData) {
457
+ var layer = _this4._createEntity(sourceData, _this4.options);
458
+ layer.entity && _this4.getMap().entities.add(layer.entity);
459
+ _this4._setEntityVisible(layer, isShow);
460
+ });
461
+ }
462
+
463
+ // 设置集合的Primitive数据
464
+ }, {
465
+ key: "_setCollectionPrimitiveData",
466
+ value: function _setCollectionPrimitiveData(source) {
467
+ var _this5 = this;
468
+ this._syncIncrementalData(source, function (sourceData, index) {
469
+ _this5._createPrimitive(sourceData, _this5.options, [], index);
470
+ });
471
+ }
472
+
473
+ // batch primitive 不再依赖实例级 updateData/updateStyle,
474
+ // 数据和样式变化统一通过整层重建保持一致性。
475
+ }, {
476
+ key: "_rebuildBatchPrimitiveData",
477
+ value: function _rebuildBatchPrimitiveData(source) {
478
+ var isShow = this._layerVisible;
479
+ this._disposePrimitiveCollection();
480
+ this.layers = [];
481
+ this._initializePrimitiveLayers(source, this.options);
482
+ this._mountPrimitiveCollection();
483
+ this.show(isShow);
484
+ }
485
+
190
486
  // 是否能进行操作
191
487
  }, {
192
488
  key: "_canOperate",
@@ -205,6 +501,7 @@ var BaseLayer = /*#__PURE__*/function () {
205
501
  if (!this._canOperate()) {
206
502
  return;
207
503
  }
504
+ this._layerVisible = isShow;
208
505
  if (this.isEntity) {
209
506
  if (this.type === 'html') {
210
507
  this.layers.forEach(function (t) {
@@ -233,13 +530,23 @@ var BaseLayer = /*#__PURE__*/function () {
233
530
  }, {
234
531
  key: "setStyle",
235
532
  value: function setStyle(style) {
236
- var _this3 = this;
533
+ var _this6 = this;
237
534
  if (!this._canOperate()) {
238
535
  return;
239
536
  }
537
+ this._mergeLayerStyle(style);
538
+ if (this._isBatchPrimitiveType()) {
539
+ if (this._canHotUpdateBatchPrimitiveStyle(style)) {
540
+ this.show(!!style.show);
541
+ return;
542
+ }
543
+ this._trimStyleOverridesByLength(this.layers.length);
544
+ this._rebuildBatchPrimitiveData(this._getCurrentSource());
545
+ return;
546
+ }
240
547
  this.layers.forEach(function (t) {
241
- var originStyle = utils.styleFun(style, t.source.properties);
242
- var handleStyle = _this3._renderClass.handleOptions(originStyle);
548
+ var originStyle = _this6._getOriginStyle(t.source);
549
+ var handleStyle = _this6._renderClass.handleOptions(originStyle);
243
550
  t.updateStyle(originStyle, handleStyle);
244
551
  });
245
552
  }
@@ -253,6 +560,18 @@ var BaseLayer = /*#__PURE__*/function () {
253
560
  }
254
561
  var currLayer = this._getOne(layer);
255
562
  if (currLayer) {
563
+ if (this._isBatchPrimitiveType()) {
564
+ // batch primitive 无法可靠地只改单个实例,这里记录局部样式后整层重建。
565
+ var layerIndex = this.layers.findIndex(function (t) {
566
+ return t.id === currLayer.id;
567
+ });
568
+ if (layerIndex === -1) {
569
+ return;
570
+ }
571
+ this._setStyleOverrideByIndex(layerIndex, style);
572
+ this._rebuildBatchPrimitiveData(this._getCurrentSource());
573
+ return;
574
+ }
256
575
  var originStyle = utils.styleFun(style, currLayer.source.properties);
257
576
  var handleStyle = this._renderClass.handleOptions(originStyle);
258
577
  currLayer.updateStyle(originStyle, handleStyle);
@@ -266,40 +585,22 @@ var BaseLayer = /*#__PURE__*/function () {
266
585
  if (!this._canOperate()) {
267
586
  return;
268
587
  }
269
- // 获取数据源
270
- var source = null;
271
- var sourceType = BaseSource.analysisSourceType(data);
272
- if (sourceType === 'sourceInstance') {
273
- source = data;
274
- } else if (sourceType === 'sourceId') {
275
- source = this.getMap().graphicLayerCollection.graphicSources.get(data);
276
- } else {
277
- source = this.getMap().graphicLayerCollection.addSource(uuidv4(), data);
588
+ var source = this._resolveSource(data);
589
+ if (!source) {
590
+ return;
278
591
  }
279
592
  this.sourceId = source.id;
280
- // 移除多余的
281
- if (source.source.length < this.layers.length) {
282
- var startIndex = this.layers.length - 1;
283
- for (var i = startIndex; i >= source.source.length; i--) {
284
- this.removeOne(this.layers[i]);
285
- }
593
+ if (this.isEntity) {
594
+ this._setEntityData(source);
595
+ return;
286
596
  }
287
- // 实例的集合
288
- var primitiveInstance = [];
289
- for (var _i = 0; _i < source.source.length; _i++) {
290
- var sourceData = source.source[_i];
291
- if (this.layers[_i]) {
292
- // 更新数据
293
- this.layers[_i].updateData(sourceData);
294
- } else {
295
- // 创建数据
296
- if (this.isEntity) {
297
- var layer = this._createEntity(sourceData, this.options);
298
- layer.entity && this.getMap().entities.add(layer.entity);
299
- } else {
300
- this._createPrimitive(sourceData, this.options, primitiveInstance);
301
- }
302
- }
597
+ if (this._isCollectionPrimitiveType()) {
598
+ this._setCollectionPrimitiveData(source);
599
+ return;
600
+ }
601
+ if (this.isPrimitive) {
602
+ this._trimStyleOverridesByLength(source.source.length);
603
+ this._rebuildBatchPrimitiveData(source);
303
604
  }
304
605
  }
305
606
 
@@ -307,7 +608,7 @@ var BaseLayer = /*#__PURE__*/function () {
307
608
  }, {
308
609
  key: "remove",
309
610
  value: function remove() {
310
- var _this4 = this;
611
+ var _this7 = this;
311
612
  if (!this._canOperate()) {
312
613
  return;
313
614
  }
@@ -319,12 +620,11 @@ var BaseLayer = /*#__PURE__*/function () {
319
620
  });
320
621
  } else {
321
622
  this.layers.forEach(function (t) {
322
- _this4.getMap().entities.remove(t.entity);
623
+ _this7.getMap().entities.remove(t.entity);
323
624
  });
324
625
  }
325
626
  } else {
326
- this.primitiveCollection.removeAll();
327
- this.getMap().scene.primitives.remove(this.primitiveCollection);
627
+ this._disposePrimitiveCollection();
328
628
  }
329
629
  this.layers = [];
330
630
  // 移除相应的graphicLayers上的数据
@@ -349,20 +649,42 @@ var BaseLayer = /*#__PURE__*/function () {
349
649
  return;
350
650
  }
351
651
  var currLayer = this._getOne(layer);
352
- if (currLayer) {
353
- if (this.isEntity) {
354
- if (this.type === 'html') {
355
- currLayer.remove();
356
- } else {
357
- this.getMap().entities.remove(currLayer.entity);
358
- }
652
+ if (!currLayer) {
653
+ return;
654
+ }
655
+ var layerIndex = this.layers.findIndex(function (t) {
656
+ return t.id === currLayer.id;
657
+ });
658
+ if (this.isEntity) {
659
+ if (this.type === 'html') {
660
+ currLayer.remove();
359
661
  } else {
360
- this.primitiveCollection.remove(currLayer.primitive);
662
+ this.getMap().entities.remove(currLayer.entity);
361
663
  }
362
664
  this.layers = this.layers.filter(function (t) {
363
665
  return t.id !== currLayer.id;
364
666
  });
667
+ return;
365
668
  }
669
+ if (this._isCollectionPrimitiveType()) {
670
+ var _currLayer$getPrimiti;
671
+ var primitive = (_currLayer$getPrimiti = currLayer.getPrimitive) === null || _currLayer$getPrimiti === void 0 ? void 0 : _currLayer$getPrimiti.call(currLayer);
672
+ primitive && this.primitiveCollection.remove(primitive);
673
+ this.layers = this.layers.filter(function (t) {
674
+ return t.id !== currLayer.id;
675
+ });
676
+ return;
677
+ }
678
+ this._shiftStyleOverridesAfterRemove(layerIndex);
679
+ var nextSource = {
680
+ id: this.sourceId,
681
+ source: this.layers.filter(function (t) {
682
+ return t.id !== currLayer.id;
683
+ }).map(function (t) {
684
+ return t.source;
685
+ })
686
+ };
687
+ this._rebuildBatchPrimitiveData(nextSource);
366
688
  }
367
689
 
368
690
  // 飞行至矢量数据图层位置
@@ -393,9 +715,9 @@ var BaseLayer = /*#__PURE__*/function () {
393
715
  key: "_toDestroy",
394
716
  value: function _toDestroy() {
395
717
  this.isDestroyed = true;
718
+ this._styleOverridesByIndex.clear();
396
719
  this.layers = [];
397
- this.primitiveCollection && this.primitiveCollection.removeAll();
398
- this.primitiveCollection = null;
720
+ this._disposePrimitiveCollection();
399
721
  }
400
722
  }, {
401
723
  key: "destroy",
@@ -7,5 +7,4 @@ export default class BasePrimitiveInstance {
7
7
  readonly isPrimitive: boolean;
8
8
  constructor(options: any);
9
9
  getMap(): any;
10
- updateStyle(): void;
11
10
  }