mars3d-supermap 3.5.13 → 3.5.15

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.
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Mars3D平台插件,结合supermap超图库使用的功能插件 mars3d-supermap
3
3
  *
4
- * 版本信息:v3.5.13
5
- * 编译日期:2023-06-26 22:15:57
4
+ * 版本信息:v3.5.15
5
+ * 编译日期:2023-07-10 19:14:37
6
6
  * 版权所有:Copyright by 火星科技 http://mars3d.cn
7
7
  * 使用单位:免费公开版 ,2023-03-17
8
8
  */
@@ -34,6 +34,7 @@
34
34
 
35
35
  const Cesium$2 = mars3d__namespace.Cesium;
36
36
  const BaseLayer$1 = mars3d__namespace.layer.BaseLayer;
37
+
37
38
  /**
38
39
  * 超图S3M三维模型图层,
39
40
  * 【需要引入 mars3d-supermap 插件库】
@@ -63,7 +64,6 @@
63
64
  * @class S3MLayer
64
65
  * @extends {BaseLayer}
65
66
  */
66
-
67
67
  class S3MLayer extends BaseLayer$1 {
68
68
  /**
69
69
  * 模型对应的Cesium.S3MTilesLayer图层组
@@ -74,66 +74,55 @@
74
74
  get layer() {
75
75
  return this._layerArr;
76
76
  }
77
+
77
78
  /**
78
79
  * 设置S3M图层本身支持的参数
79
80
  * @type {object}
80
81
  * @see [S3M支持的参数]{@link http://support.supermap.com.cn:8090/webgl/docs/Documentation/S3MTilesLayer.html?classFilter=S3MTilesLayer}
81
82
  */
82
-
83
-
84
83
  get s3mOptions() {
85
84
  return this.options.s3mOptions;
86
85
  }
87
-
88
86
  set s3mOptions(value) {
89
87
  for (const key in value) {
90
88
  let val = value[key];
91
89
  this.options.s3mOptions[key] = val;
92
-
93
90
  if (key === "transparentBackColor") {
94
91
  // 去黑边,与offset互斥,注意别配置offset
95
92
  val = Cesium$2.Color.fromCssColorString(val);
96
93
  } else if (key === "transparentBackColorTolerance") {
97
94
  val = Number(val);
98
95
  }
99
-
100
96
  for (let i = 0; i < this._layerArr.length; i++) {
101
97
  const layer = this._layerArr[i];
102
-
103
98
  if (layer == null) {
104
99
  continue;
105
100
  }
106
-
107
101
  layer[key] = val;
108
102
  }
109
103
  }
110
104
  }
111
-
112
105
  _showHook(show) {
113
106
  this.eachLayer(layer => {
114
107
  layer.visible = show; // 不同超图版本,有的是visible,有的是show
115
-
116
108
  layer.show = show;
117
109
  }, this);
118
110
  }
111
+
119
112
  /**
120
113
  * 对象添加到地图前创建一些对象的钩子方法,
121
114
  * 只会调用一次
122
115
  * @return {void} 无
123
116
  * @private
124
117
  */
125
-
126
-
127
118
  _mountedHook() {
128
119
  if (!this._map.scene.open) {
129
120
  throw new Error("请引入 超图版本Cesium库 或 超图S3M插件 ");
130
121
  }
122
+ const centerOld = this._map.getCameraView();
131
123
 
132
- const centerOld = this._map.getCameraView(); // 场景添加S3M图层服务
133
-
134
-
124
+ // 场景添加S3M图层服务
135
125
  let promise;
136
-
137
126
  if (this.options.layername) {
138
127
  promise = this._map.scene.addS3MTilesLayerByScp(this.options.url, {
139
128
  name: this.options.layername,
@@ -145,30 +134,24 @@
145
134
  autoSetView: this.options.flyTo
146
135
  });
147
136
  }
148
-
149
137
  promise.then(smLayer => {
150
138
  if (Array.isArray(smLayer)) {
151
139
  this._layerArr = smLayer;
152
140
  } else {
153
141
  this._layerArr = [smLayer];
154
142
  }
155
-
156
143
  for (let i = 0; i < this._layerArr.length; i++) {
157
144
  const layer = this._layerArr[i];
158
-
159
145
  if (!layer) {
160
146
  continue;
161
147
  }
162
-
163
148
  try {
164
149
  this._initModelItem(layer);
165
150
  } catch (e) {
166
151
  mars3d__namespace.Log.logError("s3m图层初始化出错", e);
167
152
  }
168
153
  }
169
-
170
154
  this._showHook(this.show);
171
-
172
155
  if (this.options.flyTo) {
173
156
  this.flyToByAnimationEnd();
174
157
  } else if (this.options.flyTo === false) {
@@ -176,32 +159,29 @@
176
159
  duration: 0
177
160
  });
178
161
  }
179
-
180
162
  this._readyPromise.resolve(this);
181
-
182
163
  this.fire(mars3d__namespace.EventType.load, {
183
164
  layers: this._layerArr
184
165
  });
185
166
  }, error => {
186
167
  var _this$_readyPromise;
187
-
188
168
  if ((_this$_readyPromise = this._readyPromise) !== null && _this$_readyPromise !== void 0 && _this$_readyPromise.reject) {
189
169
  this._readyPromise.reject(error);
190
170
  }
191
- }); // this._map.viewer.pickEvent.addEventListener(function (feature) {
171
+ });
172
+
173
+ // this._map.viewer.pickEvent.addEventListener(function (feature) {
192
174
  // debugger;
193
175
  // });
194
- } // 对单个s3m图层处理
195
-
176
+ }
196
177
 
178
+ // 对单个s3m图层处理
197
179
  _initModelItem(layer) {
198
- var _this$options, _this$options$positio;
199
-
180
+ var _this$options;
200
181
  // 图层参数合并
201
182
  if (this.options.s3mOptions) {
202
183
  for (const key in this.options.s3mOptions) {
203
184
  const val = this.options.s3mOptions[key];
204
-
205
185
  if (key === "transparentBackColor") {
206
186
  layer[key] = Cesium$2.Color.fromCssColorString(val); // 去黑边
207
187
  } else if (key === "transparentBackColorTolerance") {
@@ -210,45 +190,43 @@
210
190
  layer[key] = val;
211
191
  }
212
192
  }
213
- } // 选中颜色
214
-
193
+ }
215
194
 
195
+ // 选中颜色
216
196
  if (this.options.highlight) {
217
197
  layer.selectedColor = mars3d__namespace.Util.getColorByStyle(this.options.highlight);
218
- } // 高度调整
219
-
198
+ }
220
199
 
221
- if ((_this$options = this.options) !== null && _this$options !== void 0 && (_this$options$positio = _this$options.position) !== null && _this$options$positio !== void 0 && _this$options$positio.alt) {
200
+ // 高度调整
201
+ if ((_this$options = this.options) !== null && _this$options !== void 0 && (_this$options = _this$options.position) !== null && _this$options !== void 0 && _this$options.alt) {
222
202
  layer.style3D.altitudeMode = Cesium$2.HeightReference.NONE;
223
203
  layer.style3D.bottomAltitude = this.options.position.alt;
224
-
225
204
  if (layer.refresh) {
226
205
  layer.refresh(); // 设置风格后需刷新
227
206
  }
228
207
  }
229
208
  }
209
+
230
210
  /**
231
211
  * 对象添加到地图上的创建钩子方法,
232
212
  * 每次add时都会调用
233
213
  * @return {void} 无
234
214
  * @private
235
215
  */
236
-
237
-
238
216
  _addedHook() {
239
217
  this._showHook(this.show);
240
218
  }
219
+
241
220
  /**
242
221
  * 对象从地图上移除的创建钩子方法,
243
222
  * 每次remove时都会调用
244
223
  * @return {void} 无
245
224
  * @private
246
225
  */
247
-
248
-
249
226
  _removedHook() {
250
227
  this._showHook(false);
251
228
  }
229
+
252
230
  /**
253
231
  * 遍历每一个子图层并将其作为参数传递给回调函数
254
232
  *
@@ -256,33 +234,28 @@
256
234
  * @param {object} [context] 侦听器的上下文(this关键字将指向的对象)。
257
235
  * @return {GroupLayer} 当前对象本身,可以链式调用
258
236
  */
259
-
260
-
261
237
  eachLayer(method, context) {
262
238
  if (!this._layerArr) {
263
239
  return;
264
240
  }
265
-
266
241
  this._layerArr.forEach(layer => {
267
242
  method.call(context, layer);
268
243
  });
269
-
270
244
  return this;
271
245
  }
246
+
272
247
  /**
273
248
  * 设置透明度
274
249
  * @param {number} value 透明度
275
250
  * @return {void} 无
276
251
  */
277
-
278
-
279
252
  setOpacity(value) {
280
253
  this.eachLayer(layer => {
281
254
  layer.style3D.fillForeColor.alpha = value;
282
255
  }, this);
283
- } // 定位至数据区域
284
-
256
+ }
285
257
 
258
+ // 定位至数据区域
286
259
  flyTo(options = {}) {
287
260
  if (this.options.center) {
288
261
  return this._map.setCameraView(this.options.center, options);
@@ -290,14 +263,15 @@
290
263
  return this._map.flyToExtent(this.options.extent, options);
291
264
  }
292
265
  }
293
-
294
266
  }
295
- mars3d__namespace.layer.S3MLayer = S3MLayer; // 注册下
267
+ mars3d__namespace.layer.S3MLayer = S3MLayer;
296
268
 
269
+ // 注册下
297
270
  mars3d__namespace.LayerUtil.register("supermap_s3m", S3MLayer);
298
271
 
299
272
  const Cesium$1 = mars3d__namespace.Cesium;
300
273
  const BaseTileLayer = mars3d__namespace.layer.BaseTileLayer;
274
+
301
275
  /**
302
276
  * 超图影像瓦片服务图层,
303
277
  * 【需要引入 mars3d-supermap 插件库】
@@ -370,39 +344,34 @@
370
344
  *
371
345
  * @see http://support.supermap.com.cn:8090/webgl/docs/Documentation/SuperMapImageryProvider.html?classFilter=SuperMapImageryProvider
372
346
  */
373
-
374
347
  class SmImgLayer extends BaseTileLayer {
375
348
  // 构建ImageryProvider
376
349
  async _createImageryProvider(options) {
377
350
  return await createImageryProvider(options);
378
- } // 添加时
379
-
351
+ }
380
352
 
353
+ // 添加时
381
354
  _addedHook() {
382
355
  super._addedHook();
383
-
384
356
  if (Cesium$1.defined(this.options.transparentBackColor)) {
385
357
  this._imageryLayer.transparentBackColor = mars3d__namespace.Util.getCesiumColor(this.options.transparentBackColor);
386
358
  this._imageryLayer.transparentBackColorTolerance = this.options.transparentBackColorTolerance; // 去黑边
387
359
  }
388
360
  }
389
-
390
361
  }
391
362
 
392
363
  async function createImageryProvider(options) {
393
364
  options = mars3d__namespace.LayerUtil.converOptions(options);
394
-
395
365
  if (options.url instanceof Cesium$1.Resource) {
396
366
  options.url = options.url.url;
397
367
  }
398
-
399
368
  if (Cesium$1.defined(options.transparentBackColor)) {
400
369
  delete options.transparentBackColor;
401
370
  delete options.transparentBackColorTolerance;
402
371
  }
403
-
404
372
  return new Cesium$1.SuperMapImageryProvider(options);
405
373
  }
374
+
406
375
  /**
407
376
  * 创建用于图层的 ImageryProvider对象
408
377
  *
@@ -410,17 +379,17 @@
410
379
  * @return {Cesium.ImageryProvider} ImageryProvider类
411
380
  * @function
412
381
  */
413
-
414
-
415
382
  SmImgLayer.createImageryProvider = createImageryProvider;
416
- mars3d__namespace.layer.SmImgLayer = SmImgLayer; // 注册下
383
+ mars3d__namespace.layer.SmImgLayer = SmImgLayer;
417
384
 
385
+ // 注册下
418
386
  const layerType = "supermap_img";
419
387
  mars3d__namespace.LayerUtil.register(layerType, SmImgLayer);
420
388
  mars3d__namespace.LayerUtil.registerImageryProvider(layerType, createImageryProvider);
421
389
 
422
390
  const Cesium = mars3d__namespace.Cesium;
423
391
  const BaseLayer = mars3d__namespace.layer.BaseLayer;
392
+
424
393
  /**
425
394
  * 超图MVT矢量瓦片图层,
426
395
  * 【需要引入 mars3d-supermap 插件库】
@@ -451,7 +420,6 @@
451
420
  * @class SmMvtLayer
452
421
  * @extends {BaseLayer}
453
422
  */
454
-
455
423
  class SmMvtLayer extends BaseLayer {
456
424
  /**
457
425
  * 对应的supermap图层 Cesium.VectorTilesLayer
@@ -462,21 +430,21 @@
462
430
  get layer() {
463
431
  return this._mvtLayer;
464
432
  }
433
+
465
434
  /**
466
435
  * 对象添加到地图前创建一些对象的钩子方法,
467
436
  * 只会调用一次
468
437
  * @return {void} 无
469
438
  * @private
470
439
  */
471
-
472
-
473
440
  _mountedHook() {
474
441
  // options参考API文档:http://support.supermap.com.cn:8090/webgl/docs/Documentation/Scene.html
475
442
  this._mvtLayer = this._map.scene.addVectorTilesMap({
476
443
  viewer: this._map.viewer,
477
444
  canvasWidth: 512,
478
445
  ...this.options
479
- }); // this._mvtLayer.readyPromise.then(function (data) {
446
+ });
447
+ // this._mvtLayer.readyPromise.then(function (data) {
480
448
  // // setPaintProperty(layerId, name, value, options)
481
449
  // // for(var layerId in that.options.style){
482
450
  // // that._mvtLayer.setPaintProperty(layerId, "fill-color", "rgba(255,0,0,0.8)");
@@ -489,87 +457,83 @@
489
457
  if (!this.show) {
490
458
  return;
491
459
  }
460
+ const position = mars3d__namespace.PointUtil.getCurrentMousePosition(scene, event.position);
492
461
 
493
- const position = mars3d__namespace.PointUtil.getCurrentMousePosition(scene, event.position); // 查询出相交图层的feature
494
-
495
- const features = this._mvtLayer.queryRenderedFeatures([position], {// layers: [selectLayer.id]
496
- }); // eslint-disable-next-line array-callback-return
497
-
462
+ // 查询出相交图层的feature
463
+ const features = this._mvtLayer.queryRenderedFeatures([position], {
464
+ // layers: [selectLayer.id]
465
+ });
498
466
 
467
+ // eslint-disable-next-line array-callback-return
499
468
  features.reduce((memo, result) => {
500
469
  const attr = result.feature.properties;
501
-
502
470
  if (!attr) {
503
471
  // eslint-disable-next-line array-callback-return
504
472
  return;
505
473
  }
506
-
507
474
  const content = mars3d__namespace.Util.getPopupForConfig(this.options, attr);
508
475
  const item = {
509
476
  data: attr,
510
477
  event: event
511
478
  };
512
-
513
479
  this._map.openPopup(position, content, item);
514
480
  });
515
481
  }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
516
482
  this.handler = handler;
517
483
  }
484
+
518
485
  /**
519
486
  * 对象添加到地图上的创建钩子方法,
520
487
  * 每次add时都会调用
521
488
  * @return {void} 无
522
489
  * @private
523
490
  */
524
-
525
-
526
491
  _addedHook() {
527
- this._mvtLayer.show = true; // this._mvtLayer.refresh();
492
+ this._mvtLayer.show = true;
493
+ // this._mvtLayer.refresh();
528
494
  }
495
+
529
496
  /**
530
497
  * 对象从地图上移除的创建钩子方法,
531
498
  * 每次remove时都会调用
532
499
  * @return {void} 无
533
500
  * @private
534
501
  */
535
-
536
-
537
502
  _removedHook() {
538
503
  if (this._mvtLayer) {
539
504
  this._mvtLayer.show = false;
540
505
  }
541
506
  }
507
+
542
508
  /**
543
509
  * 设置透明度
544
510
  * @param {number} value 透明度
545
511
  * @return {void} 无
546
512
  */
547
-
548
-
549
513
  setOpacity(value) {
550
514
  if (this._mvtLayer) {
551
515
  this._mvtLayer.alpha = parseFloat(value);
552
516
  }
553
- } // 定位至数据区域
554
-
517
+ }
555
518
 
519
+ // 定位至数据区域
556
520
  flyTo(options = {}) {
557
521
  if (this.options.center) {
558
522
  return this._map.setCameraView(this.options.center, options);
559
523
  } else if (this.options.extent) {
560
524
  return this._map.flyToExtent(this.options.extent, options);
561
525
  } else if (this._mvtLayer) {
562
- return this._map.camera.flyTo({ ...options,
526
+ return this._map.camera.flyTo({
527
+ ...options,
563
528
  destination: this._mvtLayer.rectangle
564
529
  });
565
530
  }
566
-
567
531
  return Promise.resolve(false);
568
532
  }
569
-
570
533
  }
571
- mars3d__namespace.layer.SmMvtLayer = SmMvtLayer; // 注册下
534
+ mars3d__namespace.layer.SmMvtLayer = SmMvtLayer;
572
535
 
536
+ // 注册下
573
537
  mars3d__namespace.LayerUtil.register("supermap_mvt", SmMvtLayer);
574
538
 
575
539
  exports.S3MLayer = S3MLayer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mars3d-supermap",
3
- "version": "3.5.13",
3
+ "version": "3.5.15",
4
4
  "description": "Mars3D平台插件,结合supermap超图库使用的功能插件",
5
5
  "main": "dist/mars3d-supermap.js",
6
6
  "files": [
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "peerDependencies": {},
10
10
  "devDependencies": {
11
- "mars3d": "~3.5.13"
11
+ "mars3d": "~3.5.15"
12
12
  },
13
13
  "scripts": {
14
14
  "lint": "eslint ./src/**/*.{js,ts} --fix"