hy-dispatch-ui-v3 0.2.83 → 0.2.84

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.
@@ -53,53 +53,17 @@ function circleToPolygonPoints(center, radius, asObject = false) {
53
53
  }
54
54
  const generalMapMethods = {
55
55
  // 导入到地图里面
56
- getBounds: function(target) {
57
- const bounds = target.getBounds();
58
- let southWest = bounds.getSouthWest();
59
- let northEast = bounds.getNorthEast();
60
- let center = bounds.getCenter();
61
- bounds.getSouthWest = function() {
62
- const { lat, lng } = latAndLngCheck(southWest);
63
- return { lat, lng };
64
- };
65
- bounds.getNorthEast = function() {
66
- const { lat, lng } = latAndLngCheck(northEast);
67
- return { lat, lng };
68
- };
69
- bounds.getCenter = function() {
70
- const { lat, lng } = latAndLngCheck(center);
71
- return { lat, lng };
72
- };
73
- return bounds;
56
+ getBounds: function(target, BM2) {
57
+ const bounds = target.getBounds ? target.getBounds() : target;
58
+ return BM2.latLngBounds(latAndLngCheck(bounds.getSouthWest()), latAndLngCheck(bounds.getNorthEast()));
74
59
  },
75
60
  getMap: function(map) {
76
- return mapProxy.createMapProxy(map, {
77
- getCenter: function(target) {
78
- const center = target.getCenter();
79
- const { lng, lat } = latAndLngCheck(center);
80
- return { lat, lng };
81
- }
82
- });
61
+ return map.getRawMap ? map.getRawMap() : map;
83
62
  },
84
63
  // 导出到外面
85
- getBoundsExport: function(target) {
64
+ getBoundsExport: function(target, BM2) {
86
65
  const bounds = target.getBounds();
87
- let southWest = bounds.getSouthWest();
88
- let northEast = bounds.getNorthEast();
89
- let center = bounds.getCenter();
90
- bounds.getSouthWest = function() {
91
- const { lat, lng } = latAndLngCheckExport(southWest);
92
- return { lat, lng };
93
- };
94
- bounds.getNorthEast = function() {
95
- const { lat, lng } = latAndLngCheckExport(northEast);
96
- return { lat, lng };
97
- };
98
- bounds.getCenter = function() {
99
- const { lat, lng } = latAndLngCheckExport(center);
100
- return { lat, lng };
101
- };
102
- return bounds;
66
+ return BM2.latLngBounds(latAndLngCheckExport(bounds.getSouthWest()), latAndLngCheckExport(bounds.getNorthEast()));
103
67
  }
104
68
  };
105
69
  function latAndLngCheck(item) {
@@ -135,6 +99,10 @@ function latLngListCheck(dataList = []) {
135
99
  for (let i = 0; i < dataList.length; i++) {
136
100
  const item = dataList[i];
137
101
  const type = Array.isArray(item);
102
+ if (type && (item.length === 0 || typeof item[0] === "object")) {
103
+ newDataList.push(latLngListCheck(item));
104
+ continue;
105
+ }
138
106
  let { lat, lng } = latAndLngCheck(item);
139
107
  if (type) {
140
108
  newDataList.push([lat, lng]);
@@ -153,6 +121,10 @@ function latLngListCheckExport(dataList = []) {
153
121
  for (let i = 0; i < dataList.length; i++) {
154
122
  const item = dataList[i];
155
123
  const type = Array.isArray(item);
124
+ if (type && (item.length === 0 || typeof item[0] === "object")) {
125
+ newDataList.push(latLngListCheckExport(item));
126
+ continue;
127
+ }
156
128
  let { lat, lng } = latAndLngCheckExport(item);
157
129
  if (type) {
158
130
  newDataList.push([lat, lng]);
@@ -171,10 +143,11 @@ class bigMap extends events.EventEmitter {
171
143
  super();
172
144
  // 绘画多边形覆盖物
173
145
  __publicField(this, "Polygon", (pathList = [], option) => {
146
+ const BM2 = this.BM;
174
147
  if (pathList && pathList.length !== 0) {
175
148
  pathList = latLngListCheck(pathList);
176
149
  }
177
- const polygon = new this.BM.Polygon([pathList], option);
150
+ const polygon = new this.BM.Polygon(pathList, option);
178
151
  const wrappedHandlers = mapProxy.createWrappedHandlerStore();
179
152
  const handlers = {
180
153
  addTo: function(target, map) {
@@ -182,12 +155,16 @@ class bigMap extends events.EventEmitter {
182
155
  },
183
156
  // 修改位置
184
157
  getBounds: function(target) {
185
- return generalMapMethods.getBoundsExport(target);
158
+ return generalMapMethods.getBoundsExport(target, BM2);
186
159
  },
187
160
  getLatLngs: function(target) {
188
- const latLngList = target.getLatLngs();
189
- const item = JSON.parse(JSON.stringify(latLngList[0]));
190
- return [latLngListCheckExport([...item])];
161
+ return latLngListCheckExport(target.getLatLngs());
162
+ },
163
+ setLatLngs: function(target, points) {
164
+ return target.setLatLngs(latLngListCheck(points));
165
+ },
166
+ addLatLng: function(target, point) {
167
+ return target.addLatLng(latAndLngCheck(point));
191
168
  },
192
169
  on: function(target, types, fn, context) {
193
170
  if (types === "click") {
@@ -207,13 +184,14 @@ class bigMap extends events.EventEmitter {
207
184
  return target.off(types, wrappedFn || fn, context);
208
185
  }
209
186
  };
210
- return mapProxy.createMapProxy(polygon, handlers);
187
+ return mapProxy.createNativeMapProxy(polygon, handlers);
211
188
  });
212
189
  this.initParams = request;
213
190
  }
214
191
  // 初始化地图
215
192
  InitMap(domId, option) {
216
193
  this.BM = this.initParams.BM;
194
+ const BM2 = this.BM;
217
195
  this.BM.Config.HTTP_URL = this.initParams.bmHttpsUrl;
218
196
  this.BM.Config.HTTPS_URL = this.initParams.bmHttpsUrl;
219
197
  const { center } = option;
@@ -250,16 +228,22 @@ class bigMap extends events.EventEmitter {
250
228
  target.off();
251
229
  }
252
230
  },
253
- fitBounds: function(target, params) {
254
- if (!Array.isArray(params)) {
255
- params = [params];
256
- }
257
- const fitBoundsList = params.map(
258
- (item) => mapProxy.createMapProxy(item, {
259
- getBounds: (boundsTarget) => generalMapMethods.getBounds(boundsTarget)
260
- })
261
- );
262
- return target.fitBounds(fitBoundsList);
231
+ fitBounds: function(target, params, options) {
232
+ const bounds = BM2.latLngBounds();
233
+ const extend = (item) => {
234
+ if (item?.getBounds) {
235
+ const layer = item.getInitLayer ? item.getInitLayer() : item;
236
+ bounds.extend(layer.getBounds());
237
+ } else if (item?.getSouthWest) {
238
+ bounds.extend(generalMapMethods.getBounds(item, BM2));
239
+ } else if (Array.isArray(item) && (item.length === 0 || typeof item[0] === "object")) {
240
+ item.forEach(extend);
241
+ } else {
242
+ bounds.extend(latAndLngCheck(item));
243
+ }
244
+ };
245
+ extend(params);
246
+ return target.fitBounds(bounds, options);
263
247
  },
264
248
  // 获取中心点
265
249
  getCenter: function(target) {
@@ -272,16 +256,7 @@ class bigMap extends events.EventEmitter {
272
256
  },
273
257
  // 四个角
274
258
  getBounds: function(target) {
275
- const bounds = target.getBounds();
276
- let southWest = bounds.getSouthWest();
277
- let northEast = bounds.getNorthEast();
278
- bounds.getSouthWest = function() {
279
- return latAndLngCheckExport(southWest);
280
- };
281
- bounds.getNorthEast = function() {
282
- return latAndLngCheckExport(northEast);
283
- };
284
- return bounds;
259
+ return generalMapMethods.getBoundsExport(target, BM2);
285
260
  },
286
261
  // 移动至目标位置
287
262
  panTo: function(target, center2, options) {
@@ -306,31 +281,12 @@ class bigMap extends events.EventEmitter {
306
281
  } else if (types === "pm:create") {
307
282
  const customClickHandler = (e) => {
308
283
  const newEvent = { ...e };
309
- const bounds = newEvent.layer.getBounds();
310
- if (!newEvent.layer.getLatLngs) {
311
- newEvent.layer.getLatLngs = () => {
312
- const circle = newEvent.layer;
313
- const points = circleToPolygonPoints(circle.getLatLng(), circle.getRadius() / 1e3, true);
314
- return [latLngListCheckExport(points)];
315
- };
316
- } else {
317
- const latLngList = newEvent.layer.getLatLngs();
318
- newEvent.layer.getLatLngs = () => {
319
- const item = JSON.parse(JSON.stringify(latLngList[0]));
320
- return [latLngListCheckExport([...item])];
321
- };
322
- }
323
- newEvent.layer.getBounds = () => {
324
- let southWest = bounds.getSouthWest();
325
- let northEast = bounds.getNorthEast();
326
- bounds.getSouthWest = function() {
327
- return latAndLngCheckExport(southWest);
328
- };
329
- bounds.getNorthEast = function() {
330
- return latAndLngCheckExport(northEast);
331
- };
332
- return bounds;
333
- };
284
+ newEvent.layer = mapProxy.createNativeMapProxy(e.layer, {
285
+ getLatLngs: (layer) => latLngListCheckExport(
286
+ layer.getLatLngs ? layer.getLatLngs() : [circleToPolygonPoints(layer.getLatLng(), layer.getRadius() / 1e3, true)]
287
+ ),
288
+ getBounds: (layer) => generalMapMethods.getBoundsExport(layer, BM2)
289
+ });
334
290
  fn.call(context || target, newEvent);
335
291
  };
336
292
  wrappedHandlers.remember(types, fn, customClickHandler);
@@ -345,21 +301,23 @@ class bigMap extends events.EventEmitter {
345
301
  satelliteMapFn: function() {
346
302
  }
347
303
  };
348
- return mapProxy.createMapProxy(newMap, handlers);
304
+ return mapProxy.createNativeMapProxy(newMap, handlers);
349
305
  }
350
306
  // 地图图层
351
307
  layerGroup(map, markers = []) {
352
- const layerGroup = this.BM.layerGroup(markers);
353
- layerGroup.addTo(map);
308
+ const layerGroup = this.BM.layerGroup(
309
+ markers.map((marker) => marker.getInitLayer ? marker.getInitLayer() : marker)
310
+ );
311
+ layerGroup.addTo(generalMapMethods.getMap(map));
354
312
  const handlers = {
355
313
  addLayer: function(target, addItem) {
356
- return target.addLayer(addItem);
314
+ return target.addLayer(addItem.getInitLayer ? addItem.getInitLayer() : addItem);
357
315
  },
358
316
  clearLayers: function(target) {
359
317
  return target.clearLayers();
360
318
  }
361
319
  };
362
- return mapProxy.createMapProxy(layerGroup, handlers);
320
+ return mapProxy.createNativeMapProxy(layerGroup, handlers);
363
321
  }
364
322
  // 自定义图标
365
323
  DivIcon(option) {
@@ -400,7 +358,7 @@ class bigMap extends events.EventEmitter {
400
358
  // 更改标记位置。
401
359
  setLatLng: function(target, lngAndLat) {
402
360
  const { lat, lng } = latAndLngCheck(lngAndLat);
403
- target.setLatLng([lat, lng]);
361
+ return target.setLatLng([lat, lng]);
404
362
  },
405
363
  // 更改标记图标。
406
364
  setIcon: function(target, iconParams) {
@@ -424,7 +382,7 @@ class bigMap extends events.EventEmitter {
424
382
  return target.off(types, wrappedFn || fn, context);
425
383
  }
426
384
  };
427
- return mapProxy.createMapProxy(marker, handlers);
385
+ return mapProxy.createNativeMapProxy(marker, handlers);
428
386
  }
429
387
  // 生成 聚合点
430
388
  MarkerClusterGroup(map, markerList, option) {
@@ -440,7 +398,7 @@ class bigMap extends events.EventEmitter {
440
398
  maxClusterRadius: option.maxClusterRadius
441
399
  };
442
400
  const displayCluster = new this.BM.MarkerClusterGroup(option);
443
- map.addLayer(displayCluster);
401
+ generalMapMethods.getMap(map).addLayer(displayCluster);
444
402
  const toNativeMarkers = (list = []) => {
445
403
  const markers = Array.isArray(list) ? list : [list];
446
404
  return markers.map((marker) => marker?.getInitMarker ? marker.getInitMarker() : marker).filter(Boolean);
@@ -452,16 +410,20 @@ class bigMap extends events.EventEmitter {
452
410
  removeLayers: function(target, markerList2 = []) {
453
411
  target.removeLayers(toNativeMarkers(markerList2));
454
412
  },
413
+ clearLayers: function(target) {
414
+ target.clearLayers();
415
+ },
455
416
  addLayers: function(target, markerList2 = []) {
456
417
  target.addLayers(toNativeMarkers(markerList2));
457
418
  }
458
419
  };
459
- const newDisplayCluster = mapProxy.createMapProxy(displayCluster, handlers);
420
+ const newDisplayCluster = mapProxy.createNativeMapProxy(displayCluster, handlers);
460
421
  newDisplayCluster.addLayers(markerList);
461
422
  return newDisplayCluster;
462
423
  }
463
424
  // 绘画圆
464
425
  Circle(latLngList = {}, option = {}) {
426
+ const BM2 = this.BM;
465
427
  option = {
466
428
  ...option,
467
429
  radius: option.radius,
@@ -475,13 +437,19 @@ class bigMap extends events.EventEmitter {
475
437
  latLngList = [lat, lng];
476
438
  const circle = new this.BM.Circle(latLngList, option);
477
439
  const handlers = {
440
+ getLatLng: function(target) {
441
+ return latAndLngCheckExport(target.getLatLng());
442
+ },
443
+ setLatLng: function(target, center) {
444
+ return target.setLatLng(latAndLngCheck(center));
445
+ },
478
446
  // 添加到地图
479
447
  addTo: function(target, map) {
480
448
  return target.addTo(generalMapMethods.getMap(map));
481
449
  },
482
450
  // 修改位置
483
451
  getBounds: function(target) {
484
- return generalMapMethods.getBoundsExport(target);
452
+ return generalMapMethods.getBoundsExport(target, BM2);
485
453
  },
486
454
  // 圆形转多边形坐标
487
455
  getLatLngs: function(target) {
@@ -489,22 +457,27 @@ class bigMap extends events.EventEmitter {
489
457
  return [latLngListCheckExport(points)];
490
458
  }
491
459
  };
492
- return mapProxy.createMapProxy(circle, handlers);
460
+ return mapProxy.createNativeMapProxy(circle, handlers);
493
461
  }
494
462
  // 自定义 popup
495
463
  Popup(option) {
464
+ const BM2 = this.BM;
496
465
  option = {
497
466
  closeButton: false,
498
467
  ...option
499
468
  };
500
469
  const popup = new this.BM.Popup(option);
501
470
  const handlers = {
471
+ getLatLng: function(target) {
472
+ const point = target.getLatLng();
473
+ return point ? latAndLngCheckExport(point) : point;
474
+ },
502
475
  addTo: function(target, map) {
503
476
  return target.addTo(generalMapMethods.getMap(map));
504
477
  },
505
478
  // 修改位置
506
479
  getBounds: function(target) {
507
- return generalMapMethods.getBoundsExport(target);
480
+ return generalMapMethods.getBoundsExport(target, BM2);
508
481
  },
509
482
  // 修改位置
510
483
  setLatLng: function(target, latLngList) {
@@ -514,22 +487,32 @@ class bigMap extends events.EventEmitter {
514
487
  return target.setLatLng(latLngList);
515
488
  }
516
489
  };
517
- return mapProxy.createMapProxy(popup, handlers);
490
+ return mapProxy.createNativeMapProxy(popup, handlers);
518
491
  }
519
492
  // 自定义 线条
520
493
  Polyline(latLngList = [], option = {}) {
494
+ const BM2 = this.BM;
521
495
  if (latLngList && latLngList.length !== 0) {
522
496
  latLngList = latLngListCheck(latLngList);
523
497
  }
524
498
  const polyline = this.BM.polyline(latLngList, option);
525
499
  const wrappedHandlers = mapProxy.createWrappedHandlerStore();
526
500
  const handlers = {
501
+ getLatLngs: function(target) {
502
+ return latLngListCheckExport(target.getLatLngs());
503
+ },
504
+ setLatLngs: function(target, points) {
505
+ return target.setLatLngs(latLngListCheck(points));
506
+ },
507
+ addLatLng: function(target, point) {
508
+ return target.addLatLng(latAndLngCheck(point));
509
+ },
527
510
  addTo: function(target, map) {
528
511
  return target.addTo(generalMapMethods.getMap(map));
529
512
  },
530
513
  // 修改位置
531
514
  getBounds: function(target) {
532
- return generalMapMethods.getBoundsExport(target);
515
+ return generalMapMethods.getBoundsExport(target, BM2);
533
516
  },
534
517
  on: function(target, types, fn, context) {
535
518
  if (types === "click") {
@@ -549,12 +532,13 @@ class bigMap extends events.EventEmitter {
549
532
  return target.off(types, wrappedFn || fn, context);
550
533
  }
551
534
  };
552
- return mapProxy.createMapProxy(polyline, handlers);
535
+ return mapProxy.createNativeMapProxy(polyline, handlers);
553
536
  }
554
537
  // 轨迹回放
555
538
  TrackPlayer(latLngList = [], option = {}, map = null) {
556
539
  let monitorTrack = null;
557
540
  let speed = option.speed;
541
+ const nativePath = latLngListCheck(latLngList);
558
542
  let polyline = this.Polyline(latLngList, {
559
543
  color: option.notPassedLineColor || "#FF1875",
560
544
  // 线颜色
@@ -575,7 +559,7 @@ class bigMap extends events.EventEmitter {
575
559
  })
576
560
  }).addTo(map);
577
561
  marker.on("update_position", (e) => {
578
- passedPolyline.setLatLngs(e.path);
562
+ passedPolyline.getInitLayer().setLatLngs(e.path);
579
563
  if (monitorTrack) {
580
564
  clearTimeout(monitorTrack);
581
565
  }
@@ -586,7 +570,7 @@ class bigMap extends events.EventEmitter {
586
570
  map.setView(latLngList[0], 18);
587
571
  const moveAlong = () => {
588
572
  if (!marker) return;
589
- marker.moveAlong(latLngList, speed / 3.6, {
573
+ marker.moveAlong(nativePath, speed / 3.6, {
590
574
  replay: false
591
575
  });
592
576
  };
@@ -629,7 +613,7 @@ class bigMap extends events.EventEmitter {
629
613
  }
630
614
  }
631
615
  };
632
- return mapProxy.createMapProxy(marker, handlers);
616
+ return mapProxy.createNativeMapProxy(marker, handlers);
633
617
  }
634
618
  /**
635
619
  *
@@ -654,15 +638,10 @@ class bigMap extends events.EventEmitter {
654
638
  rawMap.on(this.BM.Draw.Event.CREATED, (e) => {
655
639
  isEnd = true;
656
640
  layer = e.layer;
657
- if (!layer._latlngs) {
658
- const center = latAndLngCheckExport(layer.getLatLng());
659
- layer._latlngs = [circleToPolygonPoints(center, layer.getRadius() / 1e3, true)];
660
- } else {
661
- layer._latlngs[0] = latLngListCheckExport(layer._latlngs[0]);
662
- }
641
+ const points = layer.getLatLngs ? layer.getLatLngs()[0] : circleToPolygonPoints(layer.getLatLng(), layer.getRadius() / 1e3, true);
663
642
  layer.addTo(rawMap);
664
643
  if (options.onChange) {
665
- options.onChange(layer._latlngs[0]);
644
+ options.onChange(latLngListCheckExport(points));
666
645
  }
667
646
  });
668
647
  const mapClick = () => {
@@ -708,7 +687,7 @@ class bigMap extends events.EventEmitter {
708
687
  });
709
688
  }
710
689
  };
711
- return mapProxy.createMapProxy({}, handlers);
690
+ return mapProxy.createNativeMapProxy({}, handlers);
712
691
  }
713
692
  // 电子围栏
714
693
  CreateFence(pmType = "rectangle", options = {}, map) {
@@ -737,7 +716,7 @@ class bigMap extends events.EventEmitter {
737
716
  pm.close();
738
717
  };
739
718
  const onChange = (pointList) => {
740
- setPolygon(latLngListCheck(pointList));
719
+ setPolygon(pointList);
741
720
  };
742
721
  const pm = this.CreatePm(
743
722
  pmType,
@@ -758,7 +737,7 @@ class bigMap extends events.EventEmitter {
758
737
  setPolygon(circleToPolygonPoints(lnglat, radius / 2e3));
759
738
  },
760
739
  setPolygon: function(target, pointList) {
761
- setPolygon(latLngListCheck(pointList));
740
+ setPolygon(pointList);
762
741
  },
763
742
  startDraw: function(target, toolType = "rectangle") {
764
743
  clearPolygon();
@@ -779,7 +758,7 @@ class bigMap extends events.EventEmitter {
779
758
  target.setMouseTool(toolType);
780
759
  }
781
760
  };
782
- return mapProxy.createMapProxy(pm, handlers);
761
+ return mapProxy.createNativeMapProxy(pm, handlers);
783
762
  }
784
763
  // 测距工具 labelColor labelFillColor lineColor
785
764
  RangingTool(options = {}, map) {
@@ -1109,7 +1088,7 @@ class bigMap extends events.EventEmitter {
1109
1088
  rangingPointsEnd = null;
1110
1089
  }
1111
1090
  };
1112
- return mapProxy.createMapProxy({}, handlers);
1091
+ return mapProxy.createNativeMapProxy({}, handlers);
1113
1092
  }
1114
1093
  }
1115
1094
 
@@ -329,6 +329,9 @@ class Google extends events.EventEmitter {
329
329
  // 添加多个个 【marker】
330
330
  addLayers: function(target, markerArray = []) {
331
331
  target.addMarkers(markerArray);
332
+ },
333
+ clearLayers: function(target) {
334
+ target.clearMarkers();
332
335
  }
333
336
  };
334
337
  return mapProxy.createMapProxy(displayCluster, handlers);