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.
@@ -143,6 +143,7 @@ const useAppMapWrapper = (hy) => {
143
143
  maxZoom: mapConfig.maxZoom || 18,
144
144
  center: { lat: userInfo?.lat || 22.553681, lng: userInfo?.lng || 113.931936 },
145
145
  zoom: mapConfig.zoom || 14,
146
+ satelliteMap: mapConfig.satelliteMap,
146
147
  completeCallbacks: () => {
147
148
  nextTick(() => {
148
149
  emits("complete", hy.hyMap.value, hy.map.value);
@@ -1,7 +1,7 @@
1
1
  import L from 'leaflet';
2
2
  import { EventEmitter } from 'events';
3
3
  import { importCoordinate, exportCoordinate } from '../js/webgis.mjs';
4
- import { createMapProxy, createWrappedHandlerStore } from '../js/mapProxy.mjs';
4
+ import { createWrappedHandlerStore, createNativeMapProxy } from '../js/mapProxy.mjs';
5
5
 
6
6
  var __defProp = Object.defineProperty;
7
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -49,53 +49,17 @@ function circleToPolygonPoints(center, radius, asObject = false) {
49
49
  }
50
50
  const generalMapMethods = {
51
51
  // 导入到地图里面
52
- getBounds: function(target) {
53
- const bounds = target.getBounds();
54
- let southWest = bounds.getSouthWest();
55
- let northEast = bounds.getNorthEast();
56
- let center = bounds.getCenter();
57
- bounds.getSouthWest = function() {
58
- const { lat, lng } = latAndLngCheck(southWest);
59
- return { lat, lng };
60
- };
61
- bounds.getNorthEast = function() {
62
- const { lat, lng } = latAndLngCheck(northEast);
63
- return { lat, lng };
64
- };
65
- bounds.getCenter = function() {
66
- const { lat, lng } = latAndLngCheck(center);
67
- return { lat, lng };
68
- };
69
- return bounds;
52
+ getBounds: function(target, BM2) {
53
+ const bounds = target.getBounds ? target.getBounds() : target;
54
+ return BM2.latLngBounds(latAndLngCheck(bounds.getSouthWest()), latAndLngCheck(bounds.getNorthEast()));
70
55
  },
71
56
  getMap: function(map) {
72
- return createMapProxy(map, {
73
- getCenter: function(target) {
74
- const center = target.getCenter();
75
- const { lng, lat } = latAndLngCheck(center);
76
- return { lat, lng };
77
- }
78
- });
57
+ return map.getRawMap ? map.getRawMap() : map;
79
58
  },
80
59
  // 导出到外面
81
- getBoundsExport: function(target) {
60
+ getBoundsExport: function(target, BM2) {
82
61
  const bounds = target.getBounds();
83
- let southWest = bounds.getSouthWest();
84
- let northEast = bounds.getNorthEast();
85
- let center = bounds.getCenter();
86
- bounds.getSouthWest = function() {
87
- const { lat, lng } = latAndLngCheckExport(southWest);
88
- return { lat, lng };
89
- };
90
- bounds.getNorthEast = function() {
91
- const { lat, lng } = latAndLngCheckExport(northEast);
92
- return { lat, lng };
93
- };
94
- bounds.getCenter = function() {
95
- const { lat, lng } = latAndLngCheckExport(center);
96
- return { lat, lng };
97
- };
98
- return bounds;
62
+ return BM2.latLngBounds(latAndLngCheckExport(bounds.getSouthWest()), latAndLngCheckExport(bounds.getNorthEast()));
99
63
  }
100
64
  };
101
65
  function latAndLngCheck(item) {
@@ -131,6 +95,10 @@ function latLngListCheck(dataList = []) {
131
95
  for (let i = 0; i < dataList.length; i++) {
132
96
  const item = dataList[i];
133
97
  const type = Array.isArray(item);
98
+ if (type && (item.length === 0 || typeof item[0] === "object")) {
99
+ newDataList.push(latLngListCheck(item));
100
+ continue;
101
+ }
134
102
  let { lat, lng } = latAndLngCheck(item);
135
103
  if (type) {
136
104
  newDataList.push([lat, lng]);
@@ -149,6 +117,10 @@ function latLngListCheckExport(dataList = []) {
149
117
  for (let i = 0; i < dataList.length; i++) {
150
118
  const item = dataList[i];
151
119
  const type = Array.isArray(item);
120
+ if (type && (item.length === 0 || typeof item[0] === "object")) {
121
+ newDataList.push(latLngListCheckExport(item));
122
+ continue;
123
+ }
152
124
  let { lat, lng } = latAndLngCheckExport(item);
153
125
  if (type) {
154
126
  newDataList.push([lat, lng]);
@@ -167,10 +139,11 @@ class bigMap extends EventEmitter {
167
139
  super();
168
140
  // 绘画多边形覆盖物
169
141
  __publicField(this, "Polygon", (pathList = [], option) => {
142
+ const BM2 = this.BM;
170
143
  if (pathList && pathList.length !== 0) {
171
144
  pathList = latLngListCheck(pathList);
172
145
  }
173
- const polygon = new this.BM.Polygon([pathList], option);
146
+ const polygon = new this.BM.Polygon(pathList, option);
174
147
  const wrappedHandlers = createWrappedHandlerStore();
175
148
  const handlers = {
176
149
  addTo: function(target, map) {
@@ -178,12 +151,16 @@ class bigMap extends EventEmitter {
178
151
  },
179
152
  // 修改位置
180
153
  getBounds: function(target) {
181
- return generalMapMethods.getBoundsExport(target);
154
+ return generalMapMethods.getBoundsExport(target, BM2);
182
155
  },
183
156
  getLatLngs: function(target) {
184
- const latLngList = target.getLatLngs();
185
- const item = JSON.parse(JSON.stringify(latLngList[0]));
186
- return [latLngListCheckExport([...item])];
157
+ return latLngListCheckExport(target.getLatLngs());
158
+ },
159
+ setLatLngs: function(target, points) {
160
+ return target.setLatLngs(latLngListCheck(points));
161
+ },
162
+ addLatLng: function(target, point) {
163
+ return target.addLatLng(latAndLngCheck(point));
187
164
  },
188
165
  on: function(target, types, fn, context) {
189
166
  if (types === "click") {
@@ -203,13 +180,14 @@ class bigMap extends EventEmitter {
203
180
  return target.off(types, wrappedFn || fn, context);
204
181
  }
205
182
  };
206
- return createMapProxy(polygon, handlers);
183
+ return createNativeMapProxy(polygon, handlers);
207
184
  });
208
185
  this.initParams = request;
209
186
  }
210
187
  // 初始化地图
211
188
  InitMap(domId, option) {
212
189
  this.BM = this.initParams.BM;
190
+ const BM2 = this.BM;
213
191
  this.BM.Config.HTTP_URL = this.initParams.bmHttpsUrl;
214
192
  this.BM.Config.HTTPS_URL = this.initParams.bmHttpsUrl;
215
193
  const { center } = option;
@@ -246,16 +224,22 @@ class bigMap extends EventEmitter {
246
224
  target.off();
247
225
  }
248
226
  },
249
- fitBounds: function(target, params) {
250
- if (!Array.isArray(params)) {
251
- params = [params];
252
- }
253
- const fitBoundsList = params.map(
254
- (item) => createMapProxy(item, {
255
- getBounds: (boundsTarget) => generalMapMethods.getBounds(boundsTarget)
256
- })
257
- );
258
- return target.fitBounds(fitBoundsList);
227
+ fitBounds: function(target, params, options) {
228
+ const bounds = BM2.latLngBounds();
229
+ const extend = (item) => {
230
+ if (item?.getBounds) {
231
+ const layer = item.getInitLayer ? item.getInitLayer() : item;
232
+ bounds.extend(layer.getBounds());
233
+ } else if (item?.getSouthWest) {
234
+ bounds.extend(generalMapMethods.getBounds(item, BM2));
235
+ } else if (Array.isArray(item) && (item.length === 0 || typeof item[0] === "object")) {
236
+ item.forEach(extend);
237
+ } else {
238
+ bounds.extend(latAndLngCheck(item));
239
+ }
240
+ };
241
+ extend(params);
242
+ return target.fitBounds(bounds, options);
259
243
  },
260
244
  // 获取中心点
261
245
  getCenter: function(target) {
@@ -268,16 +252,7 @@ class bigMap extends EventEmitter {
268
252
  },
269
253
  // 四个角
270
254
  getBounds: function(target) {
271
- const bounds = target.getBounds();
272
- let southWest = bounds.getSouthWest();
273
- let northEast = bounds.getNorthEast();
274
- bounds.getSouthWest = function() {
275
- return latAndLngCheckExport(southWest);
276
- };
277
- bounds.getNorthEast = function() {
278
- return latAndLngCheckExport(northEast);
279
- };
280
- return bounds;
255
+ return generalMapMethods.getBoundsExport(target, BM2);
281
256
  },
282
257
  // 移动至目标位置
283
258
  panTo: function(target, center2, options) {
@@ -302,31 +277,12 @@ class bigMap extends EventEmitter {
302
277
  } else if (types === "pm:create") {
303
278
  const customClickHandler = (e) => {
304
279
  const newEvent = { ...e };
305
- const bounds = newEvent.layer.getBounds();
306
- if (!newEvent.layer.getLatLngs) {
307
- newEvent.layer.getLatLngs = () => {
308
- const circle = newEvent.layer;
309
- const points = circleToPolygonPoints(circle.getLatLng(), circle.getRadius() / 1e3, true);
310
- return [latLngListCheckExport(points)];
311
- };
312
- } else {
313
- const latLngList = newEvent.layer.getLatLngs();
314
- newEvent.layer.getLatLngs = () => {
315
- const item = JSON.parse(JSON.stringify(latLngList[0]));
316
- return [latLngListCheckExport([...item])];
317
- };
318
- }
319
- newEvent.layer.getBounds = () => {
320
- let southWest = bounds.getSouthWest();
321
- let northEast = bounds.getNorthEast();
322
- bounds.getSouthWest = function() {
323
- return latAndLngCheckExport(southWest);
324
- };
325
- bounds.getNorthEast = function() {
326
- return latAndLngCheckExport(northEast);
327
- };
328
- return bounds;
329
- };
280
+ newEvent.layer = createNativeMapProxy(e.layer, {
281
+ getLatLngs: (layer) => latLngListCheckExport(
282
+ layer.getLatLngs ? layer.getLatLngs() : [circleToPolygonPoints(layer.getLatLng(), layer.getRadius() / 1e3, true)]
283
+ ),
284
+ getBounds: (layer) => generalMapMethods.getBoundsExport(layer, BM2)
285
+ });
330
286
  fn.call(context || target, newEvent);
331
287
  };
332
288
  wrappedHandlers.remember(types, fn, customClickHandler);
@@ -341,21 +297,23 @@ class bigMap extends EventEmitter {
341
297
  satelliteMapFn: function() {
342
298
  }
343
299
  };
344
- return createMapProxy(newMap, handlers);
300
+ return createNativeMapProxy(newMap, handlers);
345
301
  }
346
302
  // 地图图层
347
303
  layerGroup(map, markers = []) {
348
- const layerGroup = this.BM.layerGroup(markers);
349
- layerGroup.addTo(map);
304
+ const layerGroup = this.BM.layerGroup(
305
+ markers.map((marker) => marker.getInitLayer ? marker.getInitLayer() : marker)
306
+ );
307
+ layerGroup.addTo(generalMapMethods.getMap(map));
350
308
  const handlers = {
351
309
  addLayer: function(target, addItem) {
352
- return target.addLayer(addItem);
310
+ return target.addLayer(addItem.getInitLayer ? addItem.getInitLayer() : addItem);
353
311
  },
354
312
  clearLayers: function(target) {
355
313
  return target.clearLayers();
356
314
  }
357
315
  };
358
- return createMapProxy(layerGroup, handlers);
316
+ return createNativeMapProxy(layerGroup, handlers);
359
317
  }
360
318
  // 自定义图标
361
319
  DivIcon(option) {
@@ -396,7 +354,7 @@ class bigMap extends EventEmitter {
396
354
  // 更改标记位置。
397
355
  setLatLng: function(target, lngAndLat) {
398
356
  const { lat, lng } = latAndLngCheck(lngAndLat);
399
- target.setLatLng([lat, lng]);
357
+ return target.setLatLng([lat, lng]);
400
358
  },
401
359
  // 更改标记图标。
402
360
  setIcon: function(target, iconParams) {
@@ -420,7 +378,7 @@ class bigMap extends EventEmitter {
420
378
  return target.off(types, wrappedFn || fn, context);
421
379
  }
422
380
  };
423
- return createMapProxy(marker, handlers);
381
+ return createNativeMapProxy(marker, handlers);
424
382
  }
425
383
  // 生成 聚合点
426
384
  MarkerClusterGroup(map, markerList, option) {
@@ -436,7 +394,7 @@ class bigMap extends EventEmitter {
436
394
  maxClusterRadius: option.maxClusterRadius
437
395
  };
438
396
  const displayCluster = new this.BM.MarkerClusterGroup(option);
439
- map.addLayer(displayCluster);
397
+ generalMapMethods.getMap(map).addLayer(displayCluster);
440
398
  const toNativeMarkers = (list = []) => {
441
399
  const markers = Array.isArray(list) ? list : [list];
442
400
  return markers.map((marker) => marker?.getInitMarker ? marker.getInitMarker() : marker).filter(Boolean);
@@ -448,16 +406,20 @@ class bigMap extends EventEmitter {
448
406
  removeLayers: function(target, markerList2 = []) {
449
407
  target.removeLayers(toNativeMarkers(markerList2));
450
408
  },
409
+ clearLayers: function(target) {
410
+ target.clearLayers();
411
+ },
451
412
  addLayers: function(target, markerList2 = []) {
452
413
  target.addLayers(toNativeMarkers(markerList2));
453
414
  }
454
415
  };
455
- const newDisplayCluster = createMapProxy(displayCluster, handlers);
416
+ const newDisplayCluster = createNativeMapProxy(displayCluster, handlers);
456
417
  newDisplayCluster.addLayers(markerList);
457
418
  return newDisplayCluster;
458
419
  }
459
420
  // 绘画圆
460
421
  Circle(latLngList = {}, option = {}) {
422
+ const BM2 = this.BM;
461
423
  option = {
462
424
  ...option,
463
425
  radius: option.radius,
@@ -471,13 +433,19 @@ class bigMap extends EventEmitter {
471
433
  latLngList = [lat, lng];
472
434
  const circle = new this.BM.Circle(latLngList, option);
473
435
  const handlers = {
436
+ getLatLng: function(target) {
437
+ return latAndLngCheckExport(target.getLatLng());
438
+ },
439
+ setLatLng: function(target, center) {
440
+ return target.setLatLng(latAndLngCheck(center));
441
+ },
474
442
  // 添加到地图
475
443
  addTo: function(target, map) {
476
444
  return target.addTo(generalMapMethods.getMap(map));
477
445
  },
478
446
  // 修改位置
479
447
  getBounds: function(target) {
480
- return generalMapMethods.getBoundsExport(target);
448
+ return generalMapMethods.getBoundsExport(target, BM2);
481
449
  },
482
450
  // 圆形转多边形坐标
483
451
  getLatLngs: function(target) {
@@ -485,22 +453,27 @@ class bigMap extends EventEmitter {
485
453
  return [latLngListCheckExport(points)];
486
454
  }
487
455
  };
488
- return createMapProxy(circle, handlers);
456
+ return createNativeMapProxy(circle, handlers);
489
457
  }
490
458
  // 自定义 popup
491
459
  Popup(option) {
460
+ const BM2 = this.BM;
492
461
  option = {
493
462
  closeButton: false,
494
463
  ...option
495
464
  };
496
465
  const popup = new this.BM.Popup(option);
497
466
  const handlers = {
467
+ getLatLng: function(target) {
468
+ const point = target.getLatLng();
469
+ return point ? latAndLngCheckExport(point) : point;
470
+ },
498
471
  addTo: function(target, map) {
499
472
  return target.addTo(generalMapMethods.getMap(map));
500
473
  },
501
474
  // 修改位置
502
475
  getBounds: function(target) {
503
- return generalMapMethods.getBoundsExport(target);
476
+ return generalMapMethods.getBoundsExport(target, BM2);
504
477
  },
505
478
  // 修改位置
506
479
  setLatLng: function(target, latLngList) {
@@ -510,22 +483,32 @@ class bigMap extends EventEmitter {
510
483
  return target.setLatLng(latLngList);
511
484
  }
512
485
  };
513
- return createMapProxy(popup, handlers);
486
+ return createNativeMapProxy(popup, handlers);
514
487
  }
515
488
  // 自定义 线条
516
489
  Polyline(latLngList = [], option = {}) {
490
+ const BM2 = this.BM;
517
491
  if (latLngList && latLngList.length !== 0) {
518
492
  latLngList = latLngListCheck(latLngList);
519
493
  }
520
494
  const polyline = this.BM.polyline(latLngList, option);
521
495
  const wrappedHandlers = createWrappedHandlerStore();
522
496
  const handlers = {
497
+ getLatLngs: function(target) {
498
+ return latLngListCheckExport(target.getLatLngs());
499
+ },
500
+ setLatLngs: function(target, points) {
501
+ return target.setLatLngs(latLngListCheck(points));
502
+ },
503
+ addLatLng: function(target, point) {
504
+ return target.addLatLng(latAndLngCheck(point));
505
+ },
523
506
  addTo: function(target, map) {
524
507
  return target.addTo(generalMapMethods.getMap(map));
525
508
  },
526
509
  // 修改位置
527
510
  getBounds: function(target) {
528
- return generalMapMethods.getBoundsExport(target);
511
+ return generalMapMethods.getBoundsExport(target, BM2);
529
512
  },
530
513
  on: function(target, types, fn, context) {
531
514
  if (types === "click") {
@@ -545,12 +528,13 @@ class bigMap extends EventEmitter {
545
528
  return target.off(types, wrappedFn || fn, context);
546
529
  }
547
530
  };
548
- return createMapProxy(polyline, handlers);
531
+ return createNativeMapProxy(polyline, handlers);
549
532
  }
550
533
  // 轨迹回放
551
534
  TrackPlayer(latLngList = [], option = {}, map = null) {
552
535
  let monitorTrack = null;
553
536
  let speed = option.speed;
537
+ const nativePath = latLngListCheck(latLngList);
554
538
  let polyline = this.Polyline(latLngList, {
555
539
  color: option.notPassedLineColor || "#FF1875",
556
540
  // 线颜色
@@ -571,7 +555,7 @@ class bigMap extends EventEmitter {
571
555
  })
572
556
  }).addTo(map);
573
557
  marker.on("update_position", (e) => {
574
- passedPolyline.setLatLngs(e.path);
558
+ passedPolyline.getInitLayer().setLatLngs(e.path);
575
559
  if (monitorTrack) {
576
560
  clearTimeout(monitorTrack);
577
561
  }
@@ -582,7 +566,7 @@ class bigMap extends EventEmitter {
582
566
  map.setView(latLngList[0], 18);
583
567
  const moveAlong = () => {
584
568
  if (!marker) return;
585
- marker.moveAlong(latLngList, speed / 3.6, {
569
+ marker.moveAlong(nativePath, speed / 3.6, {
586
570
  replay: false
587
571
  });
588
572
  };
@@ -625,7 +609,7 @@ class bigMap extends EventEmitter {
625
609
  }
626
610
  }
627
611
  };
628
- return createMapProxy(marker, handlers);
612
+ return createNativeMapProxy(marker, handlers);
629
613
  }
630
614
  /**
631
615
  *
@@ -650,15 +634,10 @@ class bigMap extends EventEmitter {
650
634
  rawMap.on(this.BM.Draw.Event.CREATED, (e) => {
651
635
  isEnd = true;
652
636
  layer = e.layer;
653
- if (!layer._latlngs) {
654
- const center = latAndLngCheckExport(layer.getLatLng());
655
- layer._latlngs = [circleToPolygonPoints(center, layer.getRadius() / 1e3, true)];
656
- } else {
657
- layer._latlngs[0] = latLngListCheckExport(layer._latlngs[0]);
658
- }
637
+ const points = layer.getLatLngs ? layer.getLatLngs()[0] : circleToPolygonPoints(layer.getLatLng(), layer.getRadius() / 1e3, true);
659
638
  layer.addTo(rawMap);
660
639
  if (options.onChange) {
661
- options.onChange(layer._latlngs[0]);
640
+ options.onChange(latLngListCheckExport(points));
662
641
  }
663
642
  });
664
643
  const mapClick = () => {
@@ -704,7 +683,7 @@ class bigMap extends EventEmitter {
704
683
  });
705
684
  }
706
685
  };
707
- return createMapProxy({}, handlers);
686
+ return createNativeMapProxy({}, handlers);
708
687
  }
709
688
  // 电子围栏
710
689
  CreateFence(pmType = "rectangle", options = {}, map) {
@@ -733,7 +712,7 @@ class bigMap extends EventEmitter {
733
712
  pm.close();
734
713
  };
735
714
  const onChange = (pointList) => {
736
- setPolygon(latLngListCheck(pointList));
715
+ setPolygon(pointList);
737
716
  };
738
717
  const pm = this.CreatePm(
739
718
  pmType,
@@ -754,7 +733,7 @@ class bigMap extends EventEmitter {
754
733
  setPolygon(circleToPolygonPoints(lnglat, radius / 2e3));
755
734
  },
756
735
  setPolygon: function(target, pointList) {
757
- setPolygon(latLngListCheck(pointList));
736
+ setPolygon(pointList);
758
737
  },
759
738
  startDraw: function(target, toolType = "rectangle") {
760
739
  clearPolygon();
@@ -775,7 +754,7 @@ class bigMap extends EventEmitter {
775
754
  target.setMouseTool(toolType);
776
755
  }
777
756
  };
778
- return createMapProxy(pm, handlers);
757
+ return createNativeMapProxy(pm, handlers);
779
758
  }
780
759
  // 测距工具 labelColor labelFillColor lineColor
781
760
  RangingTool(options = {}, map) {
@@ -1105,7 +1084,7 @@ class bigMap extends EventEmitter {
1105
1084
  rangingPointsEnd = null;
1106
1085
  }
1107
1086
  };
1108
- return createMapProxy({}, handlers);
1087
+ return createNativeMapProxy({}, handlers);
1109
1088
  }
1110
1089
  }
1111
1090
 
@@ -325,6 +325,9 @@ class Google extends EventEmitter {
325
325
  // 添加多个个 【marker】
326
326
  addLayers: function(target, markerArray = []) {
327
327
  target.addMarkers(markerArray);
328
+ },
329
+ clearLayers: function(target) {
330
+ target.clearMarkers();
328
331
  }
329
332
  };
330
333
  return createMapProxy(displayCluster, handlers);