bbl-mapbox-react 0.0.17 → 0.0.18

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.
package/dist/index.mjs CHANGED
@@ -408,7 +408,34 @@ var BaseCanvasRenderer = class {
408
408
  destroy() {
409
409
  this.isDestroyed = !0, this.map.getLayer(this.areaLayerId) && this.map.removeLayer(this.areaLayerId), this.map.getSource(this.areaSourceId) && this.map.removeSource(this.areaSourceId), this.map.getLayer(this.labelLayerId) && this.map.removeLayer(this.labelLayerId), this.map.getSource(this.labelSourceId) && this.map.removeSource(this.labelSourceId), this.map.getLayer(this.layerId) && this.map.removeLayer(this.layerId), this.map.getSource(this.sourceId) && this.map.removeSource(this.sourceId);
410
410
  }
411
- };
411
+ }, move_default = "data:image/svg+xml,%3c?xml%20version='1.0'%20standalone='no'?%3e%3c!DOCTYPE%20svg%20PUBLIC%20'-//W3C//DTD%20SVG%201.1//EN'%20'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3e%3csvg%20t='1775030039452'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='24839'%20data-spm-anchor-id='a313x.search_index.0.i1.78953a81FCkAe0'%20width='64'%20height='64'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M512%20938.666667l-170.666667-170.666667h341.333334l-170.666667%20170.666667z%20m0-853.333334l170.666667%20170.666667H341.333333l170.666667-170.666667z%20m0%20512a85.333333%2085.333333%200%201%201%200-170.666666%2085.333333%2085.333333%200%200%201%200%20170.666666zM85.333333%20512l170.666667-170.666667v341.333334l-170.666667-170.666667z%20m853.333334%200l-170.666667%20170.666667V341.333333l170.666667%20170.666667z'%20fill='%23ffffff'%20p-id='24840'%3e%3c/path%3e%3c/svg%3e";
412
+ const MOVE_ICON_ID = "__edit-move-icon__";
413
+ var _moveIconLoading = !1;
414
+ function ensureMoveIcon(e) {
415
+ if (e.hasImage("__edit-move-icon__") || _moveIconLoading) return;
416
+ _moveIconLoading = !0;
417
+ let t = new Image();
418
+ t.onload = () => {
419
+ if (e.hasImage("__edit-move-icon__")) {
420
+ _moveIconLoading = !1;
421
+ return;
422
+ }
423
+ let n = document.createElement("canvas");
424
+ n.width = 28, n.height = 28;
425
+ let r = n.getContext("2d");
426
+ r.beginPath(), r.arc(28 / 2, 28 / 2, 28 / 2, 0, Math.PI * 2), r.fillStyle = "rgba(51,136,255,0.9)", r.fill();
427
+ let i = 28 * .6, a = (28 - i) / 2;
428
+ r.drawImage(t, a, a, i, i);
429
+ let o = r.getImageData(0, 0, 28, 28);
430
+ e.addImage(MOVE_ICON_ID, {
431
+ width: 28,
432
+ height: 28,
433
+ data: new Uint8Array(o.data.buffer)
434
+ }), _moveIconLoading = !1;
435
+ }, t.onerror = () => {
436
+ _moveIconLoading = !1;
437
+ }, t.src = move_default;
438
+ }
412
439
  function calculateRadarBounds(e, t) {
413
440
  let n = destinationPoint(e, t, 0), r = destinationPoint(e, t, 90), i = destinationPoint(e, t, 180), a = destinationPoint(e, t, 270)[0], o = r[0], s = i[1], c = n[1];
414
441
  return [
@@ -420,7 +447,7 @@ function calculateRadarBounds(e, t) {
420
447
  }
421
448
  var CanvasRadarRenderer = class extends BaseCanvasRenderer {
422
449
  constructor(e, t, n, r) {
423
- super(e, t, "radar", n, r), this.animationFrameId = null, this.currentRotation = t.initialRotation ?? RADAR_DEFAULTS.initialRotation;
450
+ super(e, t, "radar", n, r), this.animationFrameId = null, this.isEditing = !1, this.editSourceId = "", this.editMoveLayerId = "", this.editSourceId = `radar-edit-source-${t.id}`, this.editMoveLayerId = `radar-edit-move-${t.id}`, this.currentRotation = t.initialRotation ?? RADAR_DEFAULTS.initialRotation;
424
451
  let i = calculateRadarBounds(t.center, t.radius);
425
452
  this.init(i), t.isAnimating && this.startAnimation();
426
453
  }
@@ -480,7 +507,84 @@ var CanvasRadarRenderer = class extends BaseCanvasRenderer {
480
507
  return Math.sqrt((r * a) ** 2 + (i * 110540) ** 2) <= n;
481
508
  }
482
509
  destroy() {
483
- this.stopAnimation(), super.destroy();
510
+ this.removeEditLayers(), this.stopAnimation(), super.destroy();
511
+ }
512
+ getEditHandleGeoJSON(e) {
513
+ return {
514
+ type: "FeatureCollection",
515
+ features: [{
516
+ type: "Feature",
517
+ geometry: {
518
+ type: "Point",
519
+ coordinates: e ?? this.entity.center
520
+ },
521
+ properties: {
522
+ handleType: "move",
523
+ index: 0
524
+ }
525
+ }]
526
+ };
527
+ }
528
+ createEditLayers() {
529
+ this.map.getSource(this.editSourceId) || (ensureMoveIcon(this.map), this.map.addSource(this.editSourceId, {
530
+ type: "geojson",
531
+ data: this.getEditHandleGeoJSON()
532
+ }), this.map.addLayer({
533
+ id: this.editMoveLayerId,
534
+ type: "symbol",
535
+ source: this.editSourceId,
536
+ filter: [
537
+ "==",
538
+ ["get", "handleType"],
539
+ "move"
540
+ ],
541
+ layout: {
542
+ "icon-image": MOVE_ICON_ID,
543
+ "icon-allow-overlap": !0,
544
+ "icon-ignore-placement": !0
545
+ }
546
+ }));
547
+ }
548
+ removeEditLayers() {
549
+ this.map.getLayer(this.editMoveLayerId) && this.map.removeLayer(this.editMoveLayerId), this.map.getSource(this.editSourceId) && this.map.removeSource(this.editSourceId);
550
+ }
551
+ refreshEditHandles(e) {
552
+ let t = this.map.getSource(this.editSourceId);
553
+ t && t.setData(this.getEditHandleGeoJSON(e));
554
+ }
555
+ setEditing(e) {
556
+ this.isEditing !== e && (this.isEditing = e, e ? this.createEditLayers() : this.removeEditLayers());
557
+ }
558
+ getEditHandleAt(e, t) {
559
+ if (!this.isEditing) return null;
560
+ let n = this.entity.center, r = this.map.project(e), i = this.map.project(n), a = r.x - i.x, o = r.y - i.y;
561
+ return a * a + o * o <= 144 ? {
562
+ type: "move",
563
+ index: 0,
564
+ position: n
565
+ } : null;
566
+ }
567
+ applyHandleMove(e, t) {
568
+ let n = t[0] - e.position[0], r = t[1] - e.position[1], i = [this.entity.center[0] + n, this.entity.center[1] + r], a = {
569
+ ...this.entity,
570
+ center: i
571
+ };
572
+ this.entity = a;
573
+ let o = calculateRadarBounds(i, this.entity.radius);
574
+ return this.updateSourceCoordinates(o), this.updateLabel(), this.refreshEditHandles(), a;
575
+ }
576
+ updateEditPreview(e, t) {
577
+ let n = t[0] - e.position[0], r = t[1] - e.position[1], i = [this.entity.center[0] + n, this.entity.center[1] + r], a = calculateRadarBounds(i, this.entity.radius);
578
+ this.updateSourceCoordinates(a);
579
+ let o = this.entity;
580
+ this.entity = {
581
+ ...this.entity,
582
+ center: i
583
+ }, this.updateLabel(), this.entity = o, this.refreshEditHandles(i);
584
+ }
585
+ cancelEditPreview() {
586
+ let e = calculateRadarBounds(this.entity.center, this.entity.radius);
587
+ this.updateSourceCoordinates(e), this.updateLabel(), this.refreshEditHandles();
484
588
  }
485
589
  };
486
590
  function calculateImageBounds(e, t, n) {
@@ -494,7 +598,7 @@ function calculateImageBounds(e, t, n) {
494
598
  }
495
599
  var CanvasImageRenderer = class extends BaseCanvasRenderer {
496
600
  constructor(e, t, n, r) {
497
- super(e, t, "image", n, r), this.loadedImage = null, this.imageLoaded = !1, this.currentSrc = "", this.imageAspectRatio = 1, this.loadImage(t.src, !0);
601
+ super(e, t, "image", n, r), this.loadedImage = null, this.imageLoaded = !1, this.currentSrc = "", this.imageAspectRatio = 1, this.isEditing = !1, this.editSourceId = "", this.editMoveLayerId = "", this.editSourceId = `image-edit-source-${t.id}`, this.editMoveLayerId = `image-edit-move-${t.id}`, this.loadImage(t.src, !0);
498
602
  }
499
603
  getSize() {
500
604
  let { width: e } = this.entity, t = e / this.imageAspectRatio;
@@ -600,9 +704,89 @@ var CanvasImageRenderer = class extends BaseCanvasRenderer {
600
704
  let { center: t } = this.entity, [n, r] = this.getSize(), i = e[0] - t[0], a = e[1] - t[1], o = 111320 * Math.cos(t[1] * Math.PI / 180), s = Math.abs(i * o), c = Math.abs(a * 110540);
601
705
  return s <= n / 2 && c <= r / 2;
602
706
  }
707
+ getEditHandleGeoJSON(e) {
708
+ return {
709
+ type: "FeatureCollection",
710
+ features: [{
711
+ type: "Feature",
712
+ geometry: {
713
+ type: "Point",
714
+ coordinates: e ?? this.entity.center
715
+ },
716
+ properties: {
717
+ handleType: "move",
718
+ index: 0
719
+ }
720
+ }]
721
+ };
722
+ }
723
+ createEditLayers() {
724
+ this.map.getSource(this.editSourceId) || (ensureMoveIcon(this.map), this.map.addSource(this.editSourceId, {
725
+ type: "geojson",
726
+ data: this.getEditHandleGeoJSON()
727
+ }), this.map.addLayer({
728
+ id: this.editMoveLayerId,
729
+ type: "symbol",
730
+ source: this.editSourceId,
731
+ filter: [
732
+ "==",
733
+ ["get", "handleType"],
734
+ "move"
735
+ ],
736
+ layout: {
737
+ "icon-image": MOVE_ICON_ID,
738
+ "icon-allow-overlap": !0,
739
+ "icon-ignore-placement": !0
740
+ }
741
+ }));
742
+ }
743
+ removeEditLayers() {
744
+ this.map.getLayer(this.editMoveLayerId) && this.map.removeLayer(this.editMoveLayerId), this.map.getSource(this.editSourceId) && this.map.removeSource(this.editSourceId);
745
+ }
746
+ refreshEditHandles(e) {
747
+ let t = this.map.getSource(this.editSourceId);
748
+ t && t.setData(this.getEditHandleGeoJSON(e));
749
+ }
750
+ setEditing(e) {
751
+ this.isEditing !== e && (this.isEditing = e, e ? this.createEditLayers() : this.removeEditLayers());
752
+ }
753
+ getEditHandleAt(e, t) {
754
+ if (!this.isEditing) return null;
755
+ let n = this.entity.center, r = this.map.project(e), i = this.map.project(n), a = r.x - i.x, o = r.y - i.y;
756
+ return a * a + o * o <= 144 ? {
757
+ type: "move",
758
+ index: 0,
759
+ position: n
760
+ } : null;
761
+ }
762
+ applyHandleMove(e, t) {
763
+ let n = t[0] - e.position[0], r = t[1] - e.position[1], i = [this.entity.center[0] + n, this.entity.center[1] + r], a = {
764
+ ...this.entity,
765
+ center: i
766
+ };
767
+ this.entity = a;
768
+ let [o, s] = this.getSize(), c = calculateImageBounds(i, o, s);
769
+ return this.updateSourceCoordinates(c), this.updateLabel(), this.refreshEditHandles(), a;
770
+ }
771
+ updateEditPreview(e, t) {
772
+ let n = t[0] - e.position[0], r = t[1] - e.position[1], i = [this.entity.center[0] + n, this.entity.center[1] + r], [a, o] = this.getSize(), s = calculateImageBounds(i, a, o);
773
+ this.updateSourceCoordinates(s);
774
+ let c = this.entity;
775
+ this.entity = {
776
+ ...this.entity,
777
+ center: i
778
+ }, this.updateLabel(), this.entity = c, this.refreshEditHandles(i);
779
+ }
780
+ cancelEditPreview() {
781
+ let [e, t] = this.getSize(), n = calculateImageBounds(this.entity.center, e, t);
782
+ this.updateSourceCoordinates(n), this.updateLabel(), this.refreshEditHandles();
783
+ }
784
+ destroy() {
785
+ this.removeEditLayers(), super.destroy();
786
+ }
603
787
  }, MarkerRenderer = class {
604
788
  constructor(e, t, n, r) {
605
- this.marker = null, this.markerElement = null, this.imageElement = null, this.labelElement = null, this.placeholderElement = null, this.isSelected = !1, this.imageAspectRatio = 1, this.imageLoaded = !1, this.destroyed = !1, this.map = e, this.entity = t, this.globalNameConfig = n, this.globalSelectNameConfig = r, this.loadImageAndCreateMarker(t.src);
789
+ this.marker = null, this.markerElement = null, this.imageElement = null, this.labelElement = null, this.placeholderElement = null, this.isSelected = !1, this.imageAspectRatio = 1, this.imageLoaded = !1, this.destroyed = !1, this.isEditing = !1, this.moveIconElement = null, this.map = e, this.entity = t, this.globalNameConfig = n, this.globalSelectNameConfig = r, this.loadImageAndCreateMarker(t.src);
606
790
  }
607
791
  loadImageAndCreateMarker(e) {
608
792
  if (!e) {
@@ -674,7 +858,47 @@ var CanvasImageRenderer = class extends BaseCanvasRenderer {
674
858
  (t.width !== e.width || t.rotation !== e.rotation || t.confidence !== e.confidence) && (this.imageElement.style.width = `${e.width}px`, this.imageElement.style.height = `${n}px`, this.imageElement.style.transform = `rotate(${r}deg)`, this.imageElement.style.opacity = `${i}`), t.name !== e.name && (e.name && !this.labelElement ? (this.labelElement = document.createElement("div"), this.labelElement.className = "mapbox-marker-label", this.labelElement.textContent = e.name, this.updateLabelStyle(), this.markerElement?.appendChild(this.labelElement), this.placeholderElement = document.createElement("div"), this.placeholderElement.className = "mapbox-marker-placeholder", this.placeholderElement.textContent = e.name, this.markerElement?.insertBefore(this.placeholderElement, this.markerElement.firstChild)) : !e.name && this.labelElement ? (this.labelElement.remove(), this.labelElement = null, this.placeholderElement?.remove(), this.placeholderElement = null) : this.labelElement && (this.labelElement.textContent = e.name || "", this.placeholderElement && (this.placeholderElement.textContent = e.name || ""))), t.confidence !== e.confidence && this.updateLabelStyle();
675
859
  }
676
860
  destroy() {
677
- this.destroyed = !0, this.marker &&= (this.marker.remove(), null), this.markerElement = null, this.imageElement = null, this.labelElement = null, this.placeholderElement = null;
861
+ this.removeMoveIcon(), this.destroyed = !0, this.marker &&= (this.marker.remove(), null), this.markerElement = null, this.imageElement = null, this.labelElement = null, this.placeholderElement = null;
862
+ }
863
+ createMoveIcon() {
864
+ if (this.moveIconElement || !this.markerElement) return;
865
+ let e = document.createElement("div");
866
+ e.className = "mapbox-marker-move-icon", e.style.cssText = "width:28px;height:28px;border-radius:50%;background:rgba(51,136,255,0.9);display:flex;align-items:center;justify-content:center;cursor:move;position:absolute;left:50%;bottom:0;transform:translate(-50%,100%);pointer-events:none;";
867
+ let t = document.createElement("img");
868
+ t.src = move_default, t.style.cssText = "width:60%;height:60%;", e.appendChild(t), this.markerElement.appendChild(e), this.moveIconElement = e;
869
+ }
870
+ removeMoveIcon() {
871
+ this.moveIconElement &&= (this.moveIconElement.remove(), null);
872
+ }
873
+ setEditing(e) {
874
+ this.isEditing !== e && (this.isEditing = e, e ? this.createMoveIcon() : this.removeMoveIcon());
875
+ }
876
+ getEditHandleAt(e, t) {
877
+ if (!this.isEditing) return null;
878
+ let n = this.map.project(e);
879
+ if (this.moveIconElement) {
880
+ let t = this.moveIconElement.getBoundingClientRect(), r = this.map.getContainer().getBoundingClientRect(), i = t.left + t.width / 2 - r.left, a = t.top + t.height / 2 - r.top, o = n.x - i, s = n.y - a;
881
+ if (o * o + s * s <= 256) return {
882
+ type: "move",
883
+ index: 0,
884
+ position: e
885
+ };
886
+ }
887
+ return null;
888
+ }
889
+ applyHandleMove(e, t) {
890
+ let n = t[0] - e.position[0], r = t[1] - e.position[1], i = [this.entity.center[0] + n, this.entity.center[1] + r], a = {
891
+ ...this.entity,
892
+ center: i
893
+ };
894
+ return this.entity = a, this.marker && this.marker.setLngLat(i), a;
895
+ }
896
+ updateEditPreview(e, t) {
897
+ let n = t[0] - e.position[0], r = t[1] - e.position[1], i = [this.entity.center[0] + n, this.entity.center[1] + r];
898
+ this.marker && this.marker.setLngLat(i);
899
+ }
900
+ cancelEditPreview() {
901
+ this.marker && this.marker.setLngLat(this.entity.center);
678
902
  }
679
903
  }, UnitRenderer = class extends MarkerRenderer {
680
904
  constructor(e, t, n, r) {
@@ -840,7 +1064,7 @@ var CanvasImageRenderer = class extends BaseCanvasRenderer {
840
1064
  };
841
1065
  }
842
1066
  constructor(e, t, n, r, i, a) {
843
- this.isSelected = !1, this.initialized = !1, this.map = e, this.entity = t, this.globalNameConfig = n, this.globalSelectNameConfig = r, this.globalAreaConfig = i, this.globalLengthConfig = a, this.sourceId = `polygon-source-${t.id}`, this.fillLayerId = `polygon-fill-${t.id}`, this.strokeLayerId = `polygon-stroke-${t.id}`, this.labelLayerId = `polygon-label-${t.id}`, this.areaLayerId = `polygon-area-${t.id}`, this.lengthLayerId = `polygon-length-${t.id}`, this.initLayers();
1067
+ this.isSelected = !1, this.initialized = !1, this.isEditing = !1, this.map = e, this.entity = t, this.globalNameConfig = n, this.globalSelectNameConfig = r, this.globalAreaConfig = i, this.globalLengthConfig = a, this.sourceId = `polygon-source-${t.id}`, this.fillLayerId = `polygon-fill-${t.id}`, this.strokeLayerId = `polygon-stroke-${t.id}`, this.labelLayerId = `polygon-label-${t.id}`, this.areaLayerId = `polygon-area-${t.id}`, this.lengthLayerId = `polygon-length-${t.id}`, this.editSourceId = `polygon-edit-source-${t.id}`, this.editHandleLayerId = `polygon-edit-handles-${t.id}`, this.editMidpointLayerId = `polygon-edit-midpoints-${t.id}`, this.editMoveLayerId = `polygon-edit-move-${t.id}`, this.initLayers();
844
1068
  }
845
1069
  get nameStyle() {
846
1070
  return resolveNameConfig(this.entity.nameConfig, this.globalNameConfig, DEFAULT_NAME_CONFIG);
@@ -1162,8 +1386,201 @@ var CanvasImageRenderer = class extends BaseCanvasRenderer {
1162
1386
  }
1163
1387
  (n.fillColor !== t.fillColor || n.fillOpacity !== t.fillOpacity || n.confidence !== t.confidence) && this.map.getLayer(this.fillLayerId) && (this.map.setPaintProperty(this.fillLayerId, "fill-color", t.fillColor ?? e.DEFAULTS.fillColor), this.map.setPaintProperty(this.fillLayerId, "fill-opacity", (t.fillOpacity ?? e.DEFAULTS.fillOpacity) * i)), (n.strokeColor !== t.strokeColor || n.strokeWidth !== t.strokeWidth || n.strokeOpacity !== t.strokeOpacity || n.confidence !== t.confidence) && this.map.getLayer(this.strokeLayerId) && (this.isSelected || this.map.setPaintProperty(this.strokeLayerId, "line-color", t.strokeColor ?? e.DEFAULTS.strokeColor), this.map.setPaintProperty(this.strokeLayerId, "line-width", t.strokeWidth ?? e.DEFAULTS.strokeWidth), this.map.setPaintProperty(this.strokeLayerId, "line-opacity", (t.strokeOpacity ?? e.DEFAULTS.strokeOpacity) * i)), n.confidence !== t.confidence && (this.map.getLayer(this.labelLayerId) && this.map.setPaintProperty(this.labelLayerId, "text-opacity", i), this.map.getLayer(this.areaLayerId) && this.map.setPaintProperty(this.areaLayerId, "text-opacity", i), this.map.getLayer(this.lengthLayerId) && this.map.setPaintProperty(this.lengthLayerId, "text-opacity", i));
1164
1388
  }
1389
+ getEditHandleGeoJSON(e) {
1390
+ let t = e ?? this.entity.coordinates;
1391
+ if (!t || t.length < 3) return {
1392
+ type: "FeatureCollection",
1393
+ features: []
1394
+ };
1395
+ let n = [];
1396
+ for (let e = 0; e < t.length; e++) n.push({
1397
+ type: "Feature",
1398
+ geometry: {
1399
+ type: "Point",
1400
+ coordinates: t[e]
1401
+ },
1402
+ properties: {
1403
+ handleType: "vertex",
1404
+ index: e
1405
+ }
1406
+ });
1407
+ for (let e = 0; e < t.length; e++) {
1408
+ let r = t[e], i = t[(e + 1) % t.length];
1409
+ n.push({
1410
+ type: "Feature",
1411
+ geometry: {
1412
+ type: "Point",
1413
+ coordinates: [(r[0] + i[0]) / 2, (r[1] + i[1]) / 2]
1414
+ },
1415
+ properties: {
1416
+ handleType: "midpoint",
1417
+ index: e
1418
+ }
1419
+ });
1420
+ }
1421
+ let r = 0, i = 0;
1422
+ for (let e of t) r += e[0], i += e[1];
1423
+ return r /= t.length, i /= t.length, n.push({
1424
+ type: "Feature",
1425
+ geometry: {
1426
+ type: "Point",
1427
+ coordinates: [r, i]
1428
+ },
1429
+ properties: {
1430
+ handleType: "move",
1431
+ index: 0
1432
+ }
1433
+ }), {
1434
+ type: "FeatureCollection",
1435
+ features: n
1436
+ };
1437
+ }
1438
+ createEditLayers() {
1439
+ this.map.getSource(this.editSourceId) || (ensureMoveIcon(this.map), this.map.addSource(this.editSourceId, {
1440
+ type: "geojson",
1441
+ data: this.getEditHandleGeoJSON()
1442
+ }), this.map.addLayer({
1443
+ id: this.editMidpointLayerId,
1444
+ type: "circle",
1445
+ source: this.editSourceId,
1446
+ filter: [
1447
+ "==",
1448
+ ["get", "handleType"],
1449
+ "midpoint"
1450
+ ],
1451
+ paint: {
1452
+ "circle-radius": 4,
1453
+ "circle-color": "#3388ff",
1454
+ "circle-opacity": .5,
1455
+ "circle-stroke-color": "#3388ff",
1456
+ "circle-stroke-width": 1
1457
+ }
1458
+ }), this.map.addLayer({
1459
+ id: this.editHandleLayerId,
1460
+ type: "circle",
1461
+ source: this.editSourceId,
1462
+ filter: [
1463
+ "==",
1464
+ ["get", "handleType"],
1465
+ "vertex"
1466
+ ],
1467
+ paint: {
1468
+ "circle-radius": 6,
1469
+ "circle-color": "#ffffff",
1470
+ "circle-stroke-color": "#3388ff",
1471
+ "circle-stroke-width": 2
1472
+ }
1473
+ }), this.map.addLayer({
1474
+ id: this.editMoveLayerId,
1475
+ type: "symbol",
1476
+ source: this.editSourceId,
1477
+ filter: [
1478
+ "==",
1479
+ ["get", "handleType"],
1480
+ "move"
1481
+ ],
1482
+ layout: {
1483
+ "icon-image": MOVE_ICON_ID,
1484
+ "icon-allow-overlap": !0,
1485
+ "icon-ignore-placement": !0
1486
+ }
1487
+ }));
1488
+ }
1489
+ removeEditLayers() {
1490
+ this.map.getLayer(this.editMoveLayerId) && this.map.removeLayer(this.editMoveLayerId), this.map.getLayer(this.editHandleLayerId) && this.map.removeLayer(this.editHandleLayerId), this.map.getLayer(this.editMidpointLayerId) && this.map.removeLayer(this.editMidpointLayerId), this.map.getSource(this.editSourceId) && this.map.removeSource(this.editSourceId);
1491
+ }
1492
+ refreshEditHandles(e) {
1493
+ let t = this.map.getSource(this.editSourceId);
1494
+ t && t.setData(this.getEditHandleGeoJSON(e));
1495
+ }
1496
+ setEditing(e) {
1497
+ this.isEditing !== e && (this.isEditing = e, this.initialized && (e ? this.createEditLayers() : this.removeEditLayers()));
1498
+ }
1499
+ getEditHandleAt(e, t) {
1500
+ if (!this.isEditing) return null;
1501
+ let n = this.entity.coordinates;
1502
+ if (!n || n.length < 3) return null;
1503
+ let r = this.map.project(e), i = 0, a = 0;
1504
+ for (let e of n) i += e[0], a += e[1];
1505
+ i /= n.length, a /= n.length;
1506
+ let o = this.map.project([i, a]), s = r.x - o.x, c = r.y - o.y;
1507
+ if (s * s + c * c <= 144) return {
1508
+ type: "move",
1509
+ index: 0,
1510
+ position: [i, a]
1511
+ };
1512
+ for (let e = 0; e < n.length; e++) {
1513
+ let t = this.map.project(n[e]), i = r.x - t.x, a = r.y - t.y;
1514
+ if (i * i + a * a <= 100) return {
1515
+ type: "vertex",
1516
+ index: e,
1517
+ position: n[e]
1518
+ };
1519
+ }
1520
+ for (let e = 0; e < n.length; e++) {
1521
+ let t = n[e], i = n[(e + 1) % n.length], a = [(t[0] + i[0]) / 2, (t[1] + i[1]) / 2], o = this.map.project(a), s = r.x - o.x, c = r.y - o.y;
1522
+ if (s * s + c * c <= 100) return {
1523
+ type: "midpoint",
1524
+ index: e,
1525
+ position: a
1526
+ };
1527
+ }
1528
+ return null;
1529
+ }
1530
+ offsetCoordinates(e, t, n) {
1531
+ let r = n[0] - t[0], i = n[1] - t[1];
1532
+ return e.map((e) => [e[0] + r, e[1] + i]);
1533
+ }
1534
+ applyHandleMove(e, t) {
1535
+ let n;
1536
+ e.type === "move" ? n = this.offsetCoordinates(this.entity.coordinates, e.position, t) : (n = [...this.entity.coordinates], n[e.index] = t);
1537
+ let r = {
1538
+ ...this.entity,
1539
+ coordinates: n
1540
+ };
1541
+ this.entity = r;
1542
+ let i = this.map.getSource(this.sourceId);
1543
+ return i && i.setData(this.getGeoJSON()), this.refreshEditHandles(), r;
1544
+ }
1545
+ updateEditPreview(e, t) {
1546
+ let n;
1547
+ e.type === "move" ? n = this.offsetCoordinates(this.entity.coordinates, e.position, t) : (n = [...this.entity.coordinates], n[e.index] = t);
1548
+ let r = this.entity;
1549
+ this.entity = {
1550
+ ...this.entity,
1551
+ coordinates: n
1552
+ };
1553
+ let i = this.map.getSource(this.sourceId);
1554
+ i && i.setData(this.getGeoJSON()), this.entity = r, this.refreshEditHandles(n);
1555
+ }
1556
+ cancelEditPreview() {
1557
+ let e = this.map.getSource(this.sourceId);
1558
+ e && e.setData(this.getGeoJSON()), this.refreshEditHandles();
1559
+ }
1560
+ deleteVertex(e) {
1561
+ let t = this.entity.coordinates;
1562
+ if (!t || t.length <= 3) return null;
1563
+ let n = t.filter((t, n) => n !== e), r = {
1564
+ ...this.entity,
1565
+ coordinates: n
1566
+ };
1567
+ this.entity = r;
1568
+ let i = this.map.getSource(this.sourceId);
1569
+ return i && i.setData(this.getGeoJSON()), this.refreshEditHandles(), r;
1570
+ }
1571
+ addVertex(e, t) {
1572
+ let n = [...this.entity.coordinates];
1573
+ n.splice(e + 1, 0, t);
1574
+ let r = {
1575
+ ...this.entity,
1576
+ coordinates: n
1577
+ };
1578
+ this.entity = r;
1579
+ let i = this.map.getSource(this.sourceId);
1580
+ return i && i.setData(this.getGeoJSON()), this.refreshEditHandles(), r;
1581
+ }
1165
1582
  destroy() {
1166
- this.initialized &&= (this.map.getLayer(this.lengthLayerId) && this.map.removeLayer(this.lengthLayerId), this.map.getLayer(this.areaLayerId) && this.map.removeLayer(this.areaLayerId), this.map.getLayer(this.labelLayerId) && this.map.removeLayer(this.labelLayerId), this.map.getLayer(this.strokeLayerId) && this.map.removeLayer(this.strokeLayerId), this.map.getLayer(this.fillLayerId) && this.map.removeLayer(this.fillLayerId), this.map.getSource(this.sourceId) && this.map.removeSource(this.sourceId), !1);
1583
+ this.initialized &&= (this.removeEditLayers(), this.map.getLayer(this.lengthLayerId) && this.map.removeLayer(this.lengthLayerId), this.map.getLayer(this.areaLayerId) && this.map.removeLayer(this.areaLayerId), this.map.getLayer(this.labelLayerId) && this.map.removeLayer(this.labelLayerId), this.map.getLayer(this.strokeLayerId) && this.map.removeLayer(this.strokeLayerId), this.map.getLayer(this.fillLayerId) && this.map.removeLayer(this.fillLayerId), this.map.getSource(this.sourceId) && this.map.removeSource(this.sourceId), !1);
1167
1584
  }
1168
1585
  }, PolylineRenderer = class e {
1169
1586
  static {
@@ -1176,7 +1593,7 @@ var CanvasImageRenderer = class extends BaseCanvasRenderer {
1176
1593
  };
1177
1594
  }
1178
1595
  constructor(e, t, n, r, i) {
1179
- this.isSelected = !1, this.initialized = !1, this.map = e, this.entity = t, this.globalNameConfig = n, this.globalSelectNameConfig = r, this.globalLengthConfig = i, this.sourceId = `polyline-source-${t.id}`, this.lineLayerId = `polyline-stroke-${t.id}`, this.labelLayerId = `polyline-label-${t.id}`, this.lengthLayerId = `polyline-length-${t.id}`, this.initLayers();
1596
+ this.isSelected = !1, this.initialized = !1, this.isEditing = !1, this.map = e, this.entity = t, this.globalNameConfig = n, this.globalSelectNameConfig = r, this.globalLengthConfig = i, this.sourceId = `polyline-source-${t.id}`, this.lineLayerId = `polyline-stroke-${t.id}`, this.labelLayerId = `polyline-label-${t.id}`, this.lengthLayerId = `polyline-length-${t.id}`, this.editSourceId = `polyline-edit-source-${t.id}`, this.editHandleLayerId = `polyline-edit-handles-${t.id}`, this.editMidpointLayerId = `polyline-edit-midpoints-${t.id}`, this.editMoveLayerId = `polyline-edit-move-${t.id}`, this.initLayers();
1180
1597
  }
1181
1598
  get nameStyle() {
1182
1599
  return resolveNameConfig(this.entity.nameConfig, this.globalNameConfig, DEFAULT_NAME_CONFIG);
@@ -1423,8 +1840,201 @@ var CanvasImageRenderer = class extends BaseCanvasRenderer {
1423
1840
  }
1424
1841
  (n.strokeColor !== t.strokeColor || n.strokeWidth !== t.strokeWidth || n.strokeOpacity !== t.strokeOpacity || n.confidence !== t.confidence || n.dashArray !== t.dashArray) && this.map.getLayer(this.lineLayerId) && (this.isSelected || this.map.setPaintProperty(this.lineLayerId, "line-color", t.strokeColor ?? e.DEFAULTS.strokeColor), this.map.setPaintProperty(this.lineLayerId, "line-width", t.strokeWidth ?? e.DEFAULTS.strokeWidth), this.map.setPaintProperty(this.lineLayerId, "line-opacity", (t.strokeOpacity ?? e.DEFAULTS.strokeOpacity) * i), t.dashArray && this.map.setPaintProperty(this.lineLayerId, "line-dasharray", t.dashArray)), (n.lineCap !== t.lineCap || n.lineJoin !== t.lineJoin) && this.map.getLayer(this.lineLayerId) && (this.map.setLayoutProperty(this.lineLayerId, "line-cap", t.lineCap ?? e.DEFAULTS.lineCap), this.map.setLayoutProperty(this.lineLayerId, "line-join", t.lineJoin ?? e.DEFAULTS.lineJoin)), n.confidence !== t.confidence && this.map.getLayer(this.labelLayerId) && this.map.setPaintProperty(this.labelLayerId, "text-opacity", i), n.confidence !== t.confidence && this.map.getLayer(this.lengthLayerId) && this.map.setPaintProperty(this.lengthLayerId, "text-opacity", i);
1425
1842
  }
1843
+ getEditHandleGeoJSON(e) {
1844
+ let t = e ?? this.entity.coordinates;
1845
+ if (!t || t.length < 2) return {
1846
+ type: "FeatureCollection",
1847
+ features: []
1848
+ };
1849
+ let n = [];
1850
+ for (let e = 0; e < t.length; e++) n.push({
1851
+ type: "Feature",
1852
+ geometry: {
1853
+ type: "Point",
1854
+ coordinates: t[e]
1855
+ },
1856
+ properties: {
1857
+ handleType: "vertex",
1858
+ index: e
1859
+ }
1860
+ });
1861
+ for (let e = 0; e < t.length - 1; e++) {
1862
+ let r = t[e], i = t[e + 1];
1863
+ n.push({
1864
+ type: "Feature",
1865
+ geometry: {
1866
+ type: "Point",
1867
+ coordinates: [(r[0] + i[0]) / 2, (r[1] + i[1]) / 2]
1868
+ },
1869
+ properties: {
1870
+ handleType: "midpoint",
1871
+ index: e
1872
+ }
1873
+ });
1874
+ }
1875
+ let r = 0, i = 0;
1876
+ for (let e of t) r += e[0], i += e[1];
1877
+ return r /= t.length, i /= t.length, n.push({
1878
+ type: "Feature",
1879
+ geometry: {
1880
+ type: "Point",
1881
+ coordinates: [r, i]
1882
+ },
1883
+ properties: {
1884
+ handleType: "move",
1885
+ index: 0
1886
+ }
1887
+ }), {
1888
+ type: "FeatureCollection",
1889
+ features: n
1890
+ };
1891
+ }
1892
+ createEditLayers() {
1893
+ this.map.getSource(this.editSourceId) || (ensureMoveIcon(this.map), this.map.addSource(this.editSourceId, {
1894
+ type: "geojson",
1895
+ data: this.getEditHandleGeoJSON()
1896
+ }), this.map.addLayer({
1897
+ id: this.editMidpointLayerId,
1898
+ type: "circle",
1899
+ source: this.editSourceId,
1900
+ filter: [
1901
+ "==",
1902
+ ["get", "handleType"],
1903
+ "midpoint"
1904
+ ],
1905
+ paint: {
1906
+ "circle-radius": 4,
1907
+ "circle-color": "#3388ff",
1908
+ "circle-opacity": .5,
1909
+ "circle-stroke-color": "#3388ff",
1910
+ "circle-stroke-width": 1
1911
+ }
1912
+ }), this.map.addLayer({
1913
+ id: this.editHandleLayerId,
1914
+ type: "circle",
1915
+ source: this.editSourceId,
1916
+ filter: [
1917
+ "==",
1918
+ ["get", "handleType"],
1919
+ "vertex"
1920
+ ],
1921
+ paint: {
1922
+ "circle-radius": 6,
1923
+ "circle-color": "#ffffff",
1924
+ "circle-stroke-color": "#3388ff",
1925
+ "circle-stroke-width": 2
1926
+ }
1927
+ }), this.map.addLayer({
1928
+ id: this.editMoveLayerId,
1929
+ type: "symbol",
1930
+ source: this.editSourceId,
1931
+ filter: [
1932
+ "==",
1933
+ ["get", "handleType"],
1934
+ "move"
1935
+ ],
1936
+ layout: {
1937
+ "icon-image": MOVE_ICON_ID,
1938
+ "icon-allow-overlap": !0,
1939
+ "icon-ignore-placement": !0
1940
+ }
1941
+ }));
1942
+ }
1943
+ removeEditLayers() {
1944
+ this.map.getLayer(this.editMoveLayerId) && this.map.removeLayer(this.editMoveLayerId), this.map.getLayer(this.editHandleLayerId) && this.map.removeLayer(this.editHandleLayerId), this.map.getLayer(this.editMidpointLayerId) && this.map.removeLayer(this.editMidpointLayerId), this.map.getSource(this.editSourceId) && this.map.removeSource(this.editSourceId);
1945
+ }
1946
+ refreshEditHandles(e) {
1947
+ let t = this.map.getSource(this.editSourceId);
1948
+ t && t.setData(this.getEditHandleGeoJSON(e));
1949
+ }
1950
+ setEditing(e) {
1951
+ this.isEditing !== e && (this.isEditing = e, this.initialized && (e ? this.createEditLayers() : this.removeEditLayers()));
1952
+ }
1953
+ getEditHandleAt(e, t) {
1954
+ if (!this.isEditing) return null;
1955
+ let n = this.entity.coordinates;
1956
+ if (!n || n.length < 2) return null;
1957
+ let r = this.map.project(e), i = 0, a = 0;
1958
+ for (let e of n) i += e[0], a += e[1];
1959
+ i /= n.length, a /= n.length;
1960
+ let o = this.map.project([i, a]), s = r.x - o.x, c = r.y - o.y;
1961
+ if (s * s + c * c <= 144) return {
1962
+ type: "move",
1963
+ index: 0,
1964
+ position: [i, a]
1965
+ };
1966
+ for (let e = 0; e < n.length; e++) {
1967
+ let t = this.map.project(n[e]), i = r.x - t.x, a = r.y - t.y;
1968
+ if (i * i + a * a <= 100) return {
1969
+ type: "vertex",
1970
+ index: e,
1971
+ position: n[e]
1972
+ };
1973
+ }
1974
+ for (let e = 0; e < n.length - 1; e++) {
1975
+ let t = n[e], i = n[e + 1], a = [(t[0] + i[0]) / 2, (t[1] + i[1]) / 2], o = this.map.project(a), s = r.x - o.x, c = r.y - o.y;
1976
+ if (s * s + c * c <= 100) return {
1977
+ type: "midpoint",
1978
+ index: e,
1979
+ position: a
1980
+ };
1981
+ }
1982
+ return null;
1983
+ }
1984
+ offsetCoordinates(e, t, n) {
1985
+ let r = n[0] - t[0], i = n[1] - t[1];
1986
+ return e.map((e) => [e[0] + r, e[1] + i]);
1987
+ }
1988
+ applyHandleMove(e, t) {
1989
+ let n;
1990
+ e.type === "move" ? n = this.offsetCoordinates(this.entity.coordinates, e.position, t) : (n = [...this.entity.coordinates], n[e.index] = t);
1991
+ let r = {
1992
+ ...this.entity,
1993
+ coordinates: n
1994
+ };
1995
+ this.entity = r;
1996
+ let i = this.map.getSource(this.sourceId);
1997
+ return i && i.setData(this.getGeoJSON()), this.refreshEditHandles(), r;
1998
+ }
1999
+ updateEditPreview(e, t) {
2000
+ let n;
2001
+ e.type === "move" ? n = this.offsetCoordinates(this.entity.coordinates, e.position, t) : (n = [...this.entity.coordinates], n[e.index] = t);
2002
+ let r = this.entity;
2003
+ this.entity = {
2004
+ ...this.entity,
2005
+ coordinates: n
2006
+ };
2007
+ let i = this.map.getSource(this.sourceId);
2008
+ i && i.setData(this.getGeoJSON()), this.entity = r, this.refreshEditHandles(n);
2009
+ }
2010
+ cancelEditPreview() {
2011
+ let e = this.map.getSource(this.sourceId);
2012
+ e && e.setData(this.getGeoJSON()), this.refreshEditHandles();
2013
+ }
2014
+ deleteVertex(e) {
2015
+ let t = this.entity.coordinates;
2016
+ if (!t || t.length <= 2) return null;
2017
+ let n = t.filter((t, n) => n !== e), r = {
2018
+ ...this.entity,
2019
+ coordinates: n
2020
+ };
2021
+ this.entity = r;
2022
+ let i = this.map.getSource(this.sourceId);
2023
+ return i && i.setData(this.getGeoJSON()), this.refreshEditHandles(), r;
2024
+ }
2025
+ addVertex(e, t) {
2026
+ let n = [...this.entity.coordinates];
2027
+ n.splice(e + 1, 0, t);
2028
+ let r = {
2029
+ ...this.entity,
2030
+ coordinates: n
2031
+ };
2032
+ this.entity = r;
2033
+ let i = this.map.getSource(this.sourceId);
2034
+ return i && i.setData(this.getGeoJSON()), this.refreshEditHandles(), r;
2035
+ }
1426
2036
  destroy() {
1427
- this.initialized &&= (this.map.getLayer(this.lengthLayerId) && this.map.removeLayer(this.lengthLayerId), this.map.getLayer(this.labelLayerId) && this.map.removeLayer(this.labelLayerId), this.map.getLayer(this.lineLayerId) && this.map.removeLayer(this.lineLayerId), this.map.getSource(this.sourceId) && this.map.removeSource(this.sourceId), !1);
2037
+ this.initialized &&= (this.removeEditLayers(), this.map.getLayer(this.lengthLayerId) && this.map.removeLayer(this.lengthLayerId), this.map.getLayer(this.labelLayerId) && this.map.removeLayer(this.labelLayerId), this.map.getLayer(this.lineLayerId) && this.map.removeLayer(this.lineLayerId), this.map.getSource(this.sourceId) && this.map.removeSource(this.sourceId), !1);
1428
2038
  }
1429
2039
  };
1430
2040
  function createCirclePolygon$1(e, t, n = 64) {
@@ -1452,7 +2062,7 @@ var CircleRenderer = class e {
1452
2062
  };
1453
2063
  }
1454
2064
  constructor(e, t, n, r, i, a) {
1455
- this.isSelected = !1, this.initialized = !1, this.gradientLayerIds = [], this.gradientSourceIds = [], this.map = e, this.entity = t, this.globalNameConfig = n, this.globalSelectNameConfig = r, this.globalAreaConfig = i, this.globalCircleConfig = a, this.sourceId = `circle-source-${t.id}`, this.fillLayerId = `circle-fill-${t.id}`, this.strokeLayerId = `circle-stroke-${t.id}`, this.centerPointLayerId = `circle-center-${t.id}`, this.labelLayerId = `circle-label-${t.id}`, this.areaLayerId = `circle-area-${t.id}`, this.radiusLineLayerId = `circle-radius-line-${t.id}`, this.radiusLabelLayerId = `circle-radius-label-${t.id}`, this.initLayers();
2065
+ this.isSelected = !1, this.initialized = !1, this.gradientLayerIds = [], this.gradientSourceIds = [], this.isEditing = !1, this.map = e, this.entity = t, this.globalNameConfig = n, this.globalSelectNameConfig = r, this.globalAreaConfig = i, this.globalCircleConfig = a, this.sourceId = `circle-source-${t.id}`, this.fillLayerId = `circle-fill-${t.id}`, this.strokeLayerId = `circle-stroke-${t.id}`, this.centerPointLayerId = `circle-center-${t.id}`, this.labelLayerId = `circle-label-${t.id}`, this.areaLayerId = `circle-area-${t.id}`, this.radiusLineLayerId = `circle-radius-line-${t.id}`, this.radiusLabelLayerId = `circle-radius-label-${t.id}`, this.editSourceId = `circle-edit-source-${t.id}`, this.editHandleLayerId = `circle-edit-handles-${t.id}`, this.editMoveLayerId = `circle-edit-move-${t.id}`, this.initLayers();
1456
2066
  }
1457
2067
  get nameStyle() {
1458
2068
  return resolveNameConfig(this.entity.nameConfig, this.globalNameConfig, DEFAULT_NAME_CONFIG);
@@ -1872,9 +2482,146 @@ var CircleRenderer = class e {
1872
2482
  this.map.getLayer(this.gradientLayerIds[n]) && (this.map.setPaintProperty(this.gradientLayerIds[n], "fill-color", `rgb(${i.r}, ${i.g}, ${i.b})`), this.map.setPaintProperty(this.gradientLayerIds[n], "fill-opacity", a));
1873
2483
  }
1874
2484
  }
2485
+ static {
2486
+ this.EDGE_BEARINGS = [
2487
+ 0,
2488
+ 90,
2489
+ 180,
2490
+ 270
2491
+ ];
2492
+ }
2493
+ getEditHandlePositions(t, n) {
2494
+ let r = t ?? this.entity.center, i = n ?? this.entity.radius, a = [];
2495
+ for (let t = 0; t < e.EDGE_BEARINGS.length; t++) a.push({
2496
+ type: "edge",
2497
+ index: t,
2498
+ position: destinationPoint(r, i, e.EDGE_BEARINGS[t])
2499
+ });
2500
+ return a.push({
2501
+ type: "move",
2502
+ index: 0,
2503
+ position: r
2504
+ }), a;
2505
+ }
2506
+ getEditHandleGeoJSON(e, t) {
2507
+ return {
2508
+ type: "FeatureCollection",
2509
+ features: this.getEditHandlePositions(e, t).map((e) => ({
2510
+ type: "Feature",
2511
+ geometry: {
2512
+ type: "Point",
2513
+ coordinates: e.position
2514
+ },
2515
+ properties: {
2516
+ handleType: e.type,
2517
+ index: e.index
2518
+ }
2519
+ }))
2520
+ };
2521
+ }
2522
+ createEditLayers() {
2523
+ this.map.getSource(this.editSourceId) || (ensureMoveIcon(this.map), this.map.addSource(this.editSourceId, {
2524
+ type: "geojson",
2525
+ data: this.getEditHandleGeoJSON()
2526
+ }), this.map.addLayer({
2527
+ id: this.editHandleLayerId,
2528
+ type: "circle",
2529
+ source: this.editSourceId,
2530
+ filter: [
2531
+ "==",
2532
+ ["get", "handleType"],
2533
+ "edge"
2534
+ ],
2535
+ paint: {
2536
+ "circle-radius": 6,
2537
+ "circle-color": "#ffffff",
2538
+ "circle-stroke-color": "#3388ff",
2539
+ "circle-stroke-width": 2
2540
+ }
2541
+ }), this.map.addLayer({
2542
+ id: this.editMoveLayerId,
2543
+ type: "symbol",
2544
+ source: this.editSourceId,
2545
+ filter: [
2546
+ "==",
2547
+ ["get", "handleType"],
2548
+ "move"
2549
+ ],
2550
+ layout: {
2551
+ "icon-image": MOVE_ICON_ID,
2552
+ "icon-allow-overlap": !0,
2553
+ "icon-ignore-placement": !0
2554
+ }
2555
+ }));
2556
+ }
2557
+ removeEditLayers() {
2558
+ this.map.getLayer(this.editMoveLayerId) && this.map.removeLayer(this.editMoveLayerId), this.map.getLayer(this.editHandleLayerId) && this.map.removeLayer(this.editHandleLayerId), this.map.getSource(this.editSourceId) && this.map.removeSource(this.editSourceId);
2559
+ }
2560
+ refreshEditHandles(e, t) {
2561
+ let n = this.map.getSource(this.editSourceId);
2562
+ n && n.setData(this.getEditHandleGeoJSON(e, t));
2563
+ }
2564
+ setEditing(e) {
2565
+ this.isEditing !== e && (this.isEditing = e, this.initialized && (e ? this.createEditLayers() : this.removeEditLayers()));
2566
+ }
2567
+ getEditHandleAt(e, t) {
2568
+ if (!this.isEditing) return null;
2569
+ let n = this.map.project(e), r = this.getEditHandlePositions(), i = r.find((e) => e.type === "move");
2570
+ if (i) {
2571
+ let e = this.map.project(i.position), t = n.x - e.x, r = n.y - e.y;
2572
+ if (t * t + r * r <= 144) return {
2573
+ type: "move",
2574
+ index: i.index,
2575
+ position: i.position
2576
+ };
2577
+ }
2578
+ for (let e of r) {
2579
+ if (e.type === "move") continue;
2580
+ let t = this.map.project(e.position), r = n.x - t.x, i = n.y - t.y;
2581
+ if (r * r + i * i <= 100) return {
2582
+ type: e.type,
2583
+ index: e.index,
2584
+ position: e.position
2585
+ };
2586
+ }
2587
+ return null;
2588
+ }
2589
+ applyHandleMove(e, t) {
2590
+ let n;
2591
+ if (e.type === "move") n = {
2592
+ ...this.entity,
2593
+ center: t
2594
+ };
2595
+ else {
2596
+ let e = this.calculateDistance(this.entity.center, t);
2597
+ n = {
2598
+ ...this.entity,
2599
+ radius: e
2600
+ };
2601
+ }
2602
+ this.entity = n;
2603
+ let r = this.map.getSource(this.sourceId);
2604
+ return r && r.setData(this.getGeoJSON()), this.refreshEditHandles(), n;
2605
+ }
2606
+ updateEditPreview(e, t) {
2607
+ let n, r;
2608
+ e.type === "move" ? (n = t, r = this.entity.radius) : (n = this.entity.center, r = this.calculateDistance(this.entity.center, t));
2609
+ let i = this.entity;
2610
+ this.entity = {
2611
+ ...this.entity,
2612
+ center: n,
2613
+ radius: r
2614
+ };
2615
+ let a = this.map.getSource(this.sourceId);
2616
+ a && a.setData(this.getGeoJSON()), this.entity = i, this.refreshEditHandles(n, r);
2617
+ }
2618
+ cancelEditPreview() {
2619
+ let e = this.map.getSource(this.sourceId);
2620
+ e && e.setData(this.getGeoJSON()), this.refreshEditHandles();
2621
+ }
1875
2622
  destroy() {
1876
2623
  if (this.initialized) {
1877
- this.map.getLayer(this.radiusLabelLayerId) && this.map.removeLayer(this.radiusLabelLayerId), this.map.getLayer(this.radiusLineLayerId) && this.map.removeLayer(this.radiusLineLayerId), this.map.getLayer(this.areaLayerId) && this.map.removeLayer(this.areaLayerId), this.map.getLayer(this.labelLayerId) && this.map.removeLayer(this.labelLayerId), this.map.getLayer(this.centerPointLayerId) && this.map.removeLayer(this.centerPointLayerId), this.map.getLayer(this.strokeLayerId) && this.map.removeLayer(this.strokeLayerId), this.map.getLayer(this.fillLayerId) && this.map.removeLayer(this.fillLayerId);
2624
+ this.removeEditLayers(), this.map.getLayer(this.radiusLabelLayerId) && this.map.removeLayer(this.radiusLabelLayerId), this.map.getLayer(this.radiusLineLayerId) && this.map.removeLayer(this.radiusLineLayerId), this.map.getLayer(this.areaLayerId) && this.map.removeLayer(this.areaLayerId), this.map.getLayer(this.labelLayerId) && this.map.removeLayer(this.labelLayerId), this.map.getLayer(this.centerPointLayerId) && this.map.removeLayer(this.centerPointLayerId), this.map.getLayer(this.strokeLayerId) && this.map.removeLayer(this.strokeLayerId), this.map.getLayer(this.fillLayerId) && this.map.removeLayer(this.fillLayerId);
1878
2625
  for (let e of this.gradientLayerIds) this.map.getLayer(e) && this.map.removeLayer(e);
1879
2626
  for (let e of this.gradientSourceIds) this.map.getSource(e) && this.map.removeSource(e);
1880
2627
  this.map.getSource(this.sourceId) && this.map.removeSource(this.sourceId), this.initialized = !1;
@@ -1901,9 +2648,17 @@ function calculateCircleBounds(e, t) {
1901
2648
  [a, s]
1902
2649
  ];
1903
2650
  }
1904
- var CanvasCircleRenderer = class extends BaseCanvasRenderer {
2651
+ var CanvasCircleRenderer = class e extends BaseCanvasRenderer {
2652
+ static {
2653
+ this.EDGE_BEARINGS = [
2654
+ 0,
2655
+ 90,
2656
+ 180,
2657
+ 270
2658
+ ];
2659
+ }
1905
2660
  constructor(e, t, n, r, i, a) {
1906
- super(e, t, "canvas-circle", n, r, i), this.animationFrameId = null, this.animationTime = 0, this.pulsePhase = 0, this.globalCircleConfig = a, this.radiusSourceId = `canvas-circle-radius-source-${String(t.id)}`, this.radiusLineLayerId = `canvas-circle-radius-line-${String(t.id)}`, this.radiusLabelLayerId = `canvas-circle-radius-label-${String(t.id)}`;
2661
+ super(e, t, "canvas-circle", n, r, i), this.animationFrameId = null, this.animationTime = 0, this.pulsePhase = 0, this.isEditing = !1, this.editSourceId = "", this.editHandleLayerId = "", this.editMoveLayerId = "", this.globalCircleConfig = a, this.radiusSourceId = `canvas-circle-radius-source-${String(t.id)}`, this.radiusLineLayerId = `canvas-circle-radius-line-${String(t.id)}`, this.radiusLabelLayerId = `canvas-circle-radius-label-${String(t.id)}`, this.editSourceId = `canvas-circle-edit-source-${String(t.id)}`, this.editHandleLayerId = `canvas-circle-edit-handles-${String(t.id)}`, this.editMoveLayerId = `canvas-circle-edit-move-${String(t.id)}`;
1907
2662
  let o = calculateCircleBounds(t.center, t.radius);
1908
2663
  this.init(o), this.initRadiusLayer(), t.isAnimating && this.startAnimation();
1909
2664
  }
@@ -2117,7 +2872,141 @@ var CanvasCircleRenderer = class extends BaseCanvasRenderer {
2117
2872
  return Math.sqrt((r * a) ** 2 + (i * 110540) ** 2) <= n;
2118
2873
  }
2119
2874
  destroy() {
2120
- this.stopAnimation(), this.map.getLayer(this.radiusLabelLayerId) && this.map.removeLayer(this.radiusLabelLayerId), this.map.getLayer(this.radiusLineLayerId) && this.map.removeLayer(this.radiusLineLayerId), this.map.getSource(this.radiusSourceId) && this.map.removeSource(this.radiusSourceId), super.destroy();
2875
+ this.removeEditLayers(), this.stopAnimation(), this.map.getLayer(this.radiusLabelLayerId) && this.map.removeLayer(this.radiusLabelLayerId), this.map.getLayer(this.radiusLineLayerId) && this.map.removeLayer(this.radiusLineLayerId), this.map.getSource(this.radiusSourceId) && this.map.removeSource(this.radiusSourceId), super.destroy();
2876
+ }
2877
+ getEditHandlePositions(t, n) {
2878
+ let r = t ?? this.entity.center, i = n ?? this.entity.radius, a = [];
2879
+ for (let t = 0; t < e.EDGE_BEARINGS.length; t++) a.push({
2880
+ type: "edge",
2881
+ index: t,
2882
+ position: destinationPoint(r, i, e.EDGE_BEARINGS[t])
2883
+ });
2884
+ return a.push({
2885
+ type: "move",
2886
+ index: 0,
2887
+ position: r
2888
+ }), a;
2889
+ }
2890
+ getEditHandleGeoJSON(e, t) {
2891
+ return {
2892
+ type: "FeatureCollection",
2893
+ features: this.getEditHandlePositions(e, t).map((e) => ({
2894
+ type: "Feature",
2895
+ geometry: {
2896
+ type: "Point",
2897
+ coordinates: e.position
2898
+ },
2899
+ properties: {
2900
+ handleType: e.type,
2901
+ index: e.index
2902
+ }
2903
+ }))
2904
+ };
2905
+ }
2906
+ createEditLayers() {
2907
+ this.map.getSource(this.editSourceId) || (ensureMoveIcon(this.map), this.map.addSource(this.editSourceId, {
2908
+ type: "geojson",
2909
+ data: this.getEditHandleGeoJSON()
2910
+ }), this.map.addLayer({
2911
+ id: this.editHandleLayerId,
2912
+ type: "circle",
2913
+ source: this.editSourceId,
2914
+ filter: [
2915
+ "==",
2916
+ ["get", "handleType"],
2917
+ "edge"
2918
+ ],
2919
+ paint: {
2920
+ "circle-radius": 6,
2921
+ "circle-color": "#ffffff",
2922
+ "circle-stroke-color": "#3388ff",
2923
+ "circle-stroke-width": 2
2924
+ }
2925
+ }), this.map.addLayer({
2926
+ id: this.editMoveLayerId,
2927
+ type: "symbol",
2928
+ source: this.editSourceId,
2929
+ filter: [
2930
+ "==",
2931
+ ["get", "handleType"],
2932
+ "move"
2933
+ ],
2934
+ layout: {
2935
+ "icon-image": MOVE_ICON_ID,
2936
+ "icon-allow-overlap": !0,
2937
+ "icon-ignore-placement": !0
2938
+ }
2939
+ }));
2940
+ }
2941
+ removeEditLayers() {
2942
+ this.map.getLayer(this.editMoveLayerId) && this.map.removeLayer(this.editMoveLayerId), this.map.getLayer(this.editHandleLayerId) && this.map.removeLayer(this.editHandleLayerId), this.map.getSource(this.editSourceId) && this.map.removeSource(this.editSourceId);
2943
+ }
2944
+ refreshEditHandles(e, t) {
2945
+ let n = this.map.getSource(this.editSourceId);
2946
+ n && n.setData(this.getEditHandleGeoJSON(e, t));
2947
+ }
2948
+ setEditing(e) {
2949
+ this.isEditing !== e && (this.isEditing = e, e ? this.createEditLayers() : this.removeEditLayers());
2950
+ }
2951
+ getEditHandleAt(e, t) {
2952
+ if (!this.isEditing) return null;
2953
+ let n = this.map.project(e), r = this.getEditHandlePositions(), i = r.find((e) => e.type === "move");
2954
+ if (i) {
2955
+ let e = this.map.project(i.position), t = n.x - e.x, r = n.y - e.y;
2956
+ if (t * t + r * r <= 144) return {
2957
+ type: "move",
2958
+ index: i.index,
2959
+ position: i.position
2960
+ };
2961
+ }
2962
+ for (let e of r) {
2963
+ if (e.type === "move") continue;
2964
+ let t = this.map.project(e.position), r = n.x - t.x, i = n.y - t.y;
2965
+ if (r * r + i * i <= 100) return {
2966
+ type: e.type,
2967
+ index: e.index,
2968
+ position: e.position
2969
+ };
2970
+ }
2971
+ return null;
2972
+ }
2973
+ applyHandleMove(e, t) {
2974
+ let n;
2975
+ if (e.type === "move") {
2976
+ let r = t[0] - e.position[0], i = t[1] - e.position[1], a = [this.entity.center[0] + r, this.entity.center[1] + i];
2977
+ n = {
2978
+ ...this.entity,
2979
+ center: a
2980
+ };
2981
+ } else {
2982
+ let e = distance(this.entity.center, t);
2983
+ n = {
2984
+ ...this.entity,
2985
+ radius: e
2986
+ };
2987
+ }
2988
+ this.entity = n;
2989
+ let r = calculateCircleBounds(n.center, n.radius);
2990
+ return this.updateSourceCoordinates(r), this.updateLabel(), this.updateAreaLabel(), this.updateRadiusLayer(), this.refreshEditHandles(), n;
2991
+ }
2992
+ updateEditPreview(e, t) {
2993
+ let n, r;
2994
+ if (e.type === "move") {
2995
+ let i = t[0] - e.position[0], a = t[1] - e.position[1];
2996
+ n = [this.entity.center[0] + i, this.entity.center[1] + a], r = this.entity.radius;
2997
+ } else n = this.entity.center, r = distance(this.entity.center, t);
2998
+ let i = calculateCircleBounds(n, r);
2999
+ this.updateSourceCoordinates(i);
3000
+ let a = this.entity;
3001
+ this.entity = {
3002
+ ...this.entity,
3003
+ center: n,
3004
+ radius: r
3005
+ }, this.updateLabel(), this.entity = a, this.refreshEditHandles(n, r);
3006
+ }
3007
+ cancelEditPreview() {
3008
+ let e = calculateCircleBounds(this.entity.center, this.entity.radius);
3009
+ this.updateSourceCoordinates(e), this.updateLabel(), this.refreshEditHandles();
2121
3010
  }
2122
3011
  };
2123
3012
  function createSquareCoordinates(e, t) {
@@ -2141,7 +3030,7 @@ var SquareRenderer = class e {
2141
3030
  };
2142
3031
  }
2143
3032
  constructor(e, t, n, r, i, a) {
2144
- this.isSelected = !1, this.initialized = !1, this.map = e, this.entity = t, this.globalNameConfig = n, this.globalSelectNameConfig = r, this.globalAreaConfig = i, this.globalLengthConfig = a, this.sourceId = `square-source-${t.id}`, this.fillLayerId = `square-fill-${t.id}`, this.strokeLayerId = `square-stroke-${t.id}`, this.labelLayerId = `square-label-${t.id}`, this.areaLayerId = `square-area-${t.id}`, this.lengthLayerId = `square-length-${t.id}`, this.initLayers();
3033
+ this.isSelected = !1, this.initialized = !1, this.isEditing = !1, this.map = e, this.entity = t, this.globalNameConfig = n, this.globalSelectNameConfig = r, this.globalAreaConfig = i, this.globalLengthConfig = a, this.sourceId = `square-source-${t.id}`, this.fillLayerId = `square-fill-${t.id}`, this.strokeLayerId = `square-stroke-${t.id}`, this.labelLayerId = `square-label-${t.id}`, this.areaLayerId = `square-area-${t.id}`, this.lengthLayerId = `square-length-${t.id}`, this.editSourceId = `square-edit-source-${t.id}`, this.editHandleLayerId = `square-edit-handles-${t.id}`, this.editMoveLayerId = `square-edit-move-${t.id}`, this.initLayers();
2145
3034
  }
2146
3035
  get nameStyle() {
2147
3036
  return resolveNameConfig(this.entity.nameConfig, this.globalNameConfig, DEFAULT_NAME_CONFIG);
@@ -2438,10 +3327,144 @@ var SquareRenderer = class e {
2438
3327
  }
2439
3328
  }) : n.showLength && !t.showLength && this.map.getLayer(this.lengthLayerId) && this.map.removeLayer(this.lengthLayerId);
2440
3329
  }
2441
- (n.fillColor !== t.fillColor || n.fillOpacity !== t.fillOpacity || n.confidence !== t.confidence) && this.map.getLayer(this.fillLayerId) && (this.map.setPaintProperty(this.fillLayerId, "fill-color", t.fillColor ?? e.DEFAULTS.fillColor), this.map.setPaintProperty(this.fillLayerId, "fill-opacity", (t.fillOpacity ?? e.DEFAULTS.fillOpacity) * i)), (n.strokeColor !== t.strokeColor || n.strokeWidth !== t.strokeWidth || n.strokeOpacity !== t.strokeOpacity || n.confidence !== t.confidence) && this.map.getLayer(this.strokeLayerId) && (this.isSelected || this.map.setPaintProperty(this.strokeLayerId, "line-color", t.strokeColor ?? e.DEFAULTS.strokeColor), this.map.setPaintProperty(this.strokeLayerId, "line-width", t.strokeWidth ?? e.DEFAULTS.strokeWidth), this.map.setPaintProperty(this.strokeLayerId, "line-opacity", (t.strokeOpacity ?? e.DEFAULTS.strokeOpacity) * i)), n.confidence !== t.confidence && (this.map.getLayer(this.labelLayerId) && this.map.setPaintProperty(this.labelLayerId, "text-opacity", i), this.map.getLayer(this.areaLayerId) && this.map.setPaintProperty(this.areaLayerId, "text-opacity", i), this.map.getLayer(this.lengthLayerId) && this.map.setPaintProperty(this.lengthLayerId, "text-opacity", i));
3330
+ (n.fillColor !== t.fillColor || n.fillOpacity !== t.fillOpacity || n.confidence !== t.confidence) && this.map.getLayer(this.fillLayerId) && (this.map.setPaintProperty(this.fillLayerId, "fill-color", t.fillColor ?? e.DEFAULTS.fillColor), this.map.setPaintProperty(this.fillLayerId, "fill-opacity", (t.fillOpacity ?? e.DEFAULTS.fillOpacity) * i)), (n.strokeColor !== t.strokeColor || n.strokeWidth !== t.strokeWidth || n.strokeOpacity !== t.strokeOpacity || n.confidence !== t.confidence) && this.map.getLayer(this.strokeLayerId) && (this.isSelected || this.map.setPaintProperty(this.strokeLayerId, "line-color", t.strokeColor ?? e.DEFAULTS.strokeColor), this.map.setPaintProperty(this.strokeLayerId, "line-width", t.strokeWidth ?? e.DEFAULTS.strokeWidth), this.map.setPaintProperty(this.strokeLayerId, "line-opacity", (t.strokeOpacity ?? e.DEFAULTS.strokeOpacity) * i)), n.confidence !== t.confidence && (this.map.getLayer(this.labelLayerId) && this.map.setPaintProperty(this.labelLayerId, "text-opacity", i), this.map.getLayer(this.areaLayerId) && this.map.setPaintProperty(this.areaLayerId, "text-opacity", i), this.map.getLayer(this.lengthLayerId) && this.map.setPaintProperty(this.lengthLayerId, "text-opacity", i));
3331
+ }
3332
+ getCorners(e, t) {
3333
+ return createSquareCoordinates(e ?? this.entity.center, t ?? this.entity.length).slice(0, 4);
3334
+ }
3335
+ getEditHandleGeoJSON(e, t) {
3336
+ let n = this.getCorners(e, t).map((e, t) => ({
3337
+ type: "Feature",
3338
+ geometry: {
3339
+ type: "Point",
3340
+ coordinates: e
3341
+ },
3342
+ properties: {
3343
+ handleType: "vertex",
3344
+ index: t
3345
+ }
3346
+ })), r = e ?? this.entity.center;
3347
+ return n.push({
3348
+ type: "Feature",
3349
+ geometry: {
3350
+ type: "Point",
3351
+ coordinates: r
3352
+ },
3353
+ properties: {
3354
+ handleType: "move",
3355
+ index: 0
3356
+ }
3357
+ }), {
3358
+ type: "FeatureCollection",
3359
+ features: n
3360
+ };
3361
+ }
3362
+ createEditLayers() {
3363
+ this.map.getSource(this.editSourceId) || (ensureMoveIcon(this.map), this.map.addSource(this.editSourceId, {
3364
+ type: "geojson",
3365
+ data: this.getEditHandleGeoJSON()
3366
+ }), this.map.addLayer({
3367
+ id: this.editHandleLayerId,
3368
+ type: "circle",
3369
+ source: this.editSourceId,
3370
+ filter: [
3371
+ "==",
3372
+ ["get", "handleType"],
3373
+ "vertex"
3374
+ ],
3375
+ paint: {
3376
+ "circle-radius": 6,
3377
+ "circle-color": "#ffffff",
3378
+ "circle-stroke-color": "#3388ff",
3379
+ "circle-stroke-width": 2
3380
+ }
3381
+ }), this.map.addLayer({
3382
+ id: this.editMoveLayerId,
3383
+ type: "symbol",
3384
+ source: this.editSourceId,
3385
+ filter: [
3386
+ "==",
3387
+ ["get", "handleType"],
3388
+ "move"
3389
+ ],
3390
+ layout: {
3391
+ "icon-image": MOVE_ICON_ID,
3392
+ "icon-allow-overlap": !0,
3393
+ "icon-ignore-placement": !0
3394
+ }
3395
+ }));
3396
+ }
3397
+ removeEditLayers() {
3398
+ this.map.getLayer(this.editMoveLayerId) && this.map.removeLayer(this.editMoveLayerId), this.map.getLayer(this.editHandleLayerId) && this.map.removeLayer(this.editHandleLayerId), this.map.getSource(this.editSourceId) && this.map.removeSource(this.editSourceId);
3399
+ }
3400
+ refreshEditHandles(e, t) {
3401
+ let n = this.map.getSource(this.editSourceId);
3402
+ n && n.setData(this.getEditHandleGeoJSON(e, t));
3403
+ }
3404
+ setEditing(e) {
3405
+ this.isEditing !== e && (this.isEditing = e, this.initialized && (e ? this.createEditLayers() : this.removeEditLayers()));
3406
+ }
3407
+ getEditHandleAt(e, t) {
3408
+ if (!this.isEditing) return null;
3409
+ let n = this.getCorners(), r = this.map.project(e), i = this.entity.center, a = this.map.project(i), o = r.x - a.x, s = r.y - a.y;
3410
+ if (o * o + s * s <= 144) return {
3411
+ type: "move",
3412
+ index: 0,
3413
+ position: i
3414
+ };
3415
+ for (let e = 0; e < n.length; e++) {
3416
+ let t = this.map.project(n[e]), i = r.x - t.x, a = r.y - t.y;
3417
+ if (i * i + a * a <= 100) return {
3418
+ type: "vertex",
3419
+ index: e,
3420
+ position: n[e]
3421
+ };
3422
+ }
3423
+ return null;
3424
+ }
3425
+ computeNewLength(e) {
3426
+ return distance(this.entity.center, e) * Math.SQRT2;
3427
+ }
3428
+ applyHandleMove(e, t) {
3429
+ let n;
3430
+ if (e.type === "move") {
3431
+ let r = t[0] - e.position[0], i = t[1] - e.position[1], a = [this.entity.center[0] + r, this.entity.center[1] + i];
3432
+ n = {
3433
+ ...this.entity,
3434
+ center: a
3435
+ };
3436
+ } else {
3437
+ let e = this.computeNewLength(t);
3438
+ n = {
3439
+ ...this.entity,
3440
+ length: e
3441
+ };
3442
+ }
3443
+ this.entity = n;
3444
+ let r = this.map.getSource(this.sourceId);
3445
+ return r && r.setData(this.getGeoJSON()), this.refreshEditHandles(), n;
3446
+ }
3447
+ updateEditPreview(e, t) {
3448
+ let n, r;
3449
+ if (e.type === "move") {
3450
+ let i = t[0] - e.position[0], a = t[1] - e.position[1];
3451
+ n = [this.entity.center[0] + i, this.entity.center[1] + a], r = this.entity.length;
3452
+ } else n = this.entity.center, r = this.computeNewLength(t);
3453
+ let i = this.entity;
3454
+ this.entity = {
3455
+ ...this.entity,
3456
+ center: n,
3457
+ length: r
3458
+ };
3459
+ let a = this.map.getSource(this.sourceId);
3460
+ a && a.setData(this.getGeoJSON()), this.entity = i, this.refreshEditHandles(n, r);
3461
+ }
3462
+ cancelEditPreview() {
3463
+ let e = this.map.getSource(this.sourceId);
3464
+ e && e.setData(this.getGeoJSON()), this.refreshEditHandles();
2442
3465
  }
2443
3466
  destroy() {
2444
- this.initialized &&= (this.map.getLayer(this.lengthLayerId) && this.map.removeLayer(this.lengthLayerId), this.map.getLayer(this.areaLayerId) && this.map.removeLayer(this.areaLayerId), this.map.getLayer(this.labelLayerId) && this.map.removeLayer(this.labelLayerId), this.map.getLayer(this.strokeLayerId) && this.map.removeLayer(this.strokeLayerId), this.map.getLayer(this.fillLayerId) && this.map.removeLayer(this.fillLayerId), this.map.getSource(this.sourceId) && this.map.removeSource(this.sourceId), !1);
3467
+ this.initialized &&= (this.removeEditLayers(), this.map.getLayer(this.lengthLayerId) && this.map.removeLayer(this.lengthLayerId), this.map.getLayer(this.areaLayerId) && this.map.removeLayer(this.areaLayerId), this.map.getLayer(this.labelLayerId) && this.map.removeLayer(this.labelLayerId), this.map.getLayer(this.strokeLayerId) && this.map.removeLayer(this.strokeLayerId), this.map.getLayer(this.fillLayerId) && this.map.removeLayer(this.fillLayerId), this.map.getSource(this.sourceId) && this.map.removeSource(this.sourceId), !1);
2445
3468
  }
2446
3469
  };
2447
3470
  function createRectangleCoordinates(e) {
@@ -2465,7 +3488,7 @@ var RectangleRenderer = class e {
2465
3488
  };
2466
3489
  }
2467
3490
  constructor(e, t, n, r, i, a) {
2468
- this.isSelected = !1, this.initialized = !1, this.map = e, this.entity = t, this.globalNameConfig = n, this.globalSelectNameConfig = r, this.globalAreaConfig = i, this.globalLengthConfig = a, this.sourceId = `rectangle-source-${t.id}`, this.fillLayerId = `rectangle-fill-${t.id}`, this.strokeLayerId = `rectangle-stroke-${t.id}`, this.labelLayerId = `rectangle-label-${t.id}`, this.areaLayerId = `rectangle-area-${t.id}`, this.lengthLayerId = `rectangle-length-${t.id}`, this.initLayers();
3491
+ this.isSelected = !1, this.initialized = !1, this.isEditing = !1, this.map = e, this.entity = t, this.globalNameConfig = n, this.globalSelectNameConfig = r, this.globalAreaConfig = i, this.globalLengthConfig = a, this.sourceId = `rectangle-source-${t.id}`, this.fillLayerId = `rectangle-fill-${t.id}`, this.strokeLayerId = `rectangle-stroke-${t.id}`, this.labelLayerId = `rectangle-label-${t.id}`, this.areaLayerId = `rectangle-area-${t.id}`, this.lengthLayerId = `rectangle-length-${t.id}`, this.editSourceId = `rectangle-edit-source-${t.id}`, this.editHandleLayerId = `rectangle-edit-handles-${t.id}`, this.editMoveLayerId = `rectangle-edit-move-${t.id}`, this.initLayers();
2469
3492
  }
2470
3493
  get nameStyle() {
2471
3494
  return resolveNameConfig(this.entity.nameConfig, this.globalNameConfig, DEFAULT_NAME_CONFIG);
@@ -2777,8 +3800,135 @@ var RectangleRenderer = class e {
2777
3800
  }
2778
3801
  (n.fillColor !== t.fillColor || n.fillOpacity !== t.fillOpacity || n.confidence !== t.confidence) && this.map.getLayer(this.fillLayerId) && (this.map.setPaintProperty(this.fillLayerId, "fill-color", t.fillColor ?? e.DEFAULTS.fillColor), this.map.setPaintProperty(this.fillLayerId, "fill-opacity", (t.fillOpacity ?? e.DEFAULTS.fillOpacity) * i)), (n.strokeColor !== t.strokeColor || n.strokeWidth !== t.strokeWidth || n.strokeOpacity !== t.strokeOpacity || n.confidence !== t.confidence) && this.map.getLayer(this.strokeLayerId) && (this.isSelected || this.map.setPaintProperty(this.strokeLayerId, "line-color", t.strokeColor ?? e.DEFAULTS.strokeColor), this.map.setPaintProperty(this.strokeLayerId, "line-width", t.strokeWidth ?? e.DEFAULTS.strokeWidth), this.map.setPaintProperty(this.strokeLayerId, "line-opacity", (t.strokeOpacity ?? e.DEFAULTS.strokeOpacity) * i)), n.confidence !== t.confidence && (this.map.getLayer(this.labelLayerId) && this.map.setPaintProperty(this.labelLayerId, "text-opacity", i), this.map.getLayer(this.areaLayerId) && this.map.setPaintProperty(this.areaLayerId, "text-opacity", i), this.map.getLayer(this.lengthLayerId) && this.map.setPaintProperty(this.lengthLayerId, "text-opacity", i));
2779
3802
  }
3803
+ getCorners(e) {
3804
+ return createRectangleCoordinates(e ?? this.entity.bounds).slice(0, 4);
3805
+ }
3806
+ getEditHandleGeoJSON(e) {
3807
+ let t = this.getCorners(e).map((e, t) => ({
3808
+ type: "Feature",
3809
+ geometry: {
3810
+ type: "Point",
3811
+ coordinates: e
3812
+ },
3813
+ properties: {
3814
+ handleType: "vertex",
3815
+ index: t
3816
+ }
3817
+ })), n = e ?? this.entity.bounds, r = (n[0][0] + n[1][0]) / 2, i = (n[0][1] + n[1][1]) / 2;
3818
+ return t.push({
3819
+ type: "Feature",
3820
+ geometry: {
3821
+ type: "Point",
3822
+ coordinates: [r, i]
3823
+ },
3824
+ properties: {
3825
+ handleType: "move",
3826
+ index: 0
3827
+ }
3828
+ }), {
3829
+ type: "FeatureCollection",
3830
+ features: t
3831
+ };
3832
+ }
3833
+ createEditLayers() {
3834
+ this.map.getSource(this.editSourceId) || (ensureMoveIcon(this.map), this.map.addSource(this.editSourceId, {
3835
+ type: "geojson",
3836
+ data: this.getEditHandleGeoJSON()
3837
+ }), this.map.addLayer({
3838
+ id: this.editHandleLayerId,
3839
+ type: "circle",
3840
+ source: this.editSourceId,
3841
+ filter: [
3842
+ "==",
3843
+ ["get", "handleType"],
3844
+ "vertex"
3845
+ ],
3846
+ paint: {
3847
+ "circle-radius": 6,
3848
+ "circle-color": "#ffffff",
3849
+ "circle-stroke-color": "#3388ff",
3850
+ "circle-stroke-width": 2
3851
+ }
3852
+ }), this.map.addLayer({
3853
+ id: this.editMoveLayerId,
3854
+ type: "symbol",
3855
+ source: this.editSourceId,
3856
+ filter: [
3857
+ "==",
3858
+ ["get", "handleType"],
3859
+ "move"
3860
+ ],
3861
+ layout: {
3862
+ "icon-image": MOVE_ICON_ID,
3863
+ "icon-allow-overlap": !0,
3864
+ "icon-ignore-placement": !0
3865
+ }
3866
+ }));
3867
+ }
3868
+ removeEditLayers() {
3869
+ this.map.getLayer(this.editMoveLayerId) && this.map.removeLayer(this.editMoveLayerId), this.map.getLayer(this.editHandleLayerId) && this.map.removeLayer(this.editHandleLayerId), this.map.getSource(this.editSourceId) && this.map.removeSource(this.editSourceId);
3870
+ }
3871
+ refreshEditHandles(e) {
3872
+ let t = this.map.getSource(this.editSourceId);
3873
+ t && t.setData(this.getEditHandleGeoJSON(e));
3874
+ }
3875
+ setEditing(e) {
3876
+ this.isEditing !== e && (this.isEditing = e, this.initialized && (e ? this.createEditLayers() : this.removeEditLayers()));
3877
+ }
3878
+ getEditHandleAt(e, t) {
3879
+ if (!this.isEditing) return null;
3880
+ let n = this.getCorners(), r = this.map.project(e), i = this.calculateRectangleCenter(), a = this.map.project(i), o = r.x - a.x, s = r.y - a.y;
3881
+ if (o * o + s * s <= 144) return {
3882
+ type: "move",
3883
+ index: 0,
3884
+ position: i
3885
+ };
3886
+ for (let e = 0; e < n.length; e++) {
3887
+ let t = this.map.project(n[e]), i = r.x - t.x, a = r.y - t.y;
3888
+ if (i * i + a * a <= 100) return {
3889
+ type: "vertex",
3890
+ index: e,
3891
+ position: n[e]
3892
+ };
3893
+ }
3894
+ return null;
3895
+ }
3896
+ computeNewBounds(e, t) {
3897
+ let n = this.getCorners(), r = (e + 2) % 4, i = n[r];
3898
+ return [[Math.min(t[0], i[0]), Math.min(t[1], i[1])], [Math.max(t[0], i[0]), Math.max(t[1], i[1])]];
3899
+ }
3900
+ offsetBounds(e, t, n) {
3901
+ let r = n[0] - t[0], i = n[1] - t[1];
3902
+ return [[e[0][0] + r, e[0][1] + i], [e[1][0] + r, e[1][1] + i]];
3903
+ }
3904
+ applyHandleMove(e, t) {
3905
+ let n;
3906
+ n = e.type === "move" ? this.offsetBounds(this.entity.bounds, e.position, t) : this.computeNewBounds(e.index, t);
3907
+ let r = {
3908
+ ...this.entity,
3909
+ bounds: n
3910
+ };
3911
+ this.entity = r;
3912
+ let i = this.map.getSource(this.sourceId);
3913
+ return i && i.setData(this.getGeoJSON()), this.refreshEditHandles(), r;
3914
+ }
3915
+ updateEditPreview(e, t) {
3916
+ let n;
3917
+ n = e.type === "move" ? this.offsetBounds(this.entity.bounds, e.position, t) : this.computeNewBounds(e.index, t);
3918
+ let r = this.entity;
3919
+ this.entity = {
3920
+ ...this.entity,
3921
+ bounds: n
3922
+ };
3923
+ let i = this.map.getSource(this.sourceId);
3924
+ i && i.setData(this.getGeoJSON()), this.entity = r, this.refreshEditHandles(n);
3925
+ }
3926
+ cancelEditPreview() {
3927
+ let e = this.map.getSource(this.sourceId);
3928
+ e && e.setData(this.getGeoJSON()), this.refreshEditHandles();
3929
+ }
2780
3930
  destroy() {
2781
- this.initialized &&= (this.map.getLayer(this.lengthLayerId) && this.map.removeLayer(this.lengthLayerId), this.map.getLayer(this.areaLayerId) && this.map.removeLayer(this.areaLayerId), this.map.getLayer(this.labelLayerId) && this.map.removeLayer(this.labelLayerId), this.map.getLayer(this.strokeLayerId) && this.map.removeLayer(this.strokeLayerId), this.map.getLayer(this.fillLayerId) && this.map.removeLayer(this.fillLayerId), this.map.getSource(this.sourceId) && this.map.removeSource(this.sourceId), !1);
3931
+ this.initialized &&= (this.removeEditLayers(), this.map.getLayer(this.lengthLayerId) && this.map.removeLayer(this.lengthLayerId), this.map.getLayer(this.areaLayerId) && this.map.removeLayer(this.areaLayerId), this.map.getLayer(this.labelLayerId) && this.map.removeLayer(this.labelLayerId), this.map.getLayer(this.strokeLayerId) && this.map.removeLayer(this.strokeLayerId), this.map.getLayer(this.fillLayerId) && this.map.removeLayer(this.fillLayerId), this.map.getSource(this.sourceId) && this.map.removeSource(this.sourceId), !1);
2782
3932
  }
2783
3933
  };
2784
3934
  const EntityPopup = ({ popupState: e, onClose: r, portalContainer: i, popupRef: s }) => {
@@ -3505,61 +4655,65 @@ function clearAllPreviewSources(e) {
3505
4655
  "polyline-vertices-source"
3506
4656
  ]) clearPreviewSource(e, `${PREVIEW_PREFIX}${t}`);
3507
4657
  }
3508
- function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, className: s = "", style: c }) {
3509
- let [l, u] = useState(!1), [d, f] = useState(null), [g, _] = useState({
4658
+ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, onDrawModeChange: s, className: c = "", style: l }) {
4659
+ let [u, d] = useState(!1), [f, g] = useState(null), [_, v] = useState({
3510
4660
  showArea: !0,
3511
4661
  showLength: !0,
3512
4662
  showRadius: !0
3513
- }), v = r !== void 0, y = v ? {
4663
+ }), y = r !== void 0, b = y ? {
3514
4664
  showArea: r.showArea ?? !0,
3515
4665
  showLength: r.showLength ?? !0,
3516
4666
  showRadius: r.showRadius ?? !0
3517
- } : g, [b, x] = useState([]), S = useRef(/* @__PURE__ */ new Map()), C = useRef(0), T = useRef(null), E = useRef(null), D = useRef(null), O = useRef(null), k = useRef(null), A = useRef([]), j = useRef([]), M = useRef(y);
3518
- M.current = y;
3519
- let N = useRef(d);
3520
- N.current = d;
3521
- let be = useCallback(() => `measure-${++C.current}`, []), xe = useRef(!1), Se = useCallback(() => {
3522
- !e || !e.isStyleLoaded() || (initAllPreviewLayers(e), xe.current = !0);
4667
+ } : _, [x, S] = useState([]), C = useRef(/* @__PURE__ */ new Map()), T = useRef(0), E = useRef(null), D = useRef(null), O = useRef(null), k = useRef(null), A = useRef(null), j = useRef([]), M = useRef([]), N = useRef(b);
4668
+ N.current = b;
4669
+ let Ce = useRef(f);
4670
+ Ce.current = f;
4671
+ let P = useCallback(() => `measure-${++T.current}`, []);
4672
+ useEffect(() => {
4673
+ s?.(f !== null);
4674
+ }, [f, s]);
4675
+ let we = useRef(!1), Te = useCallback(() => {
4676
+ !e || !e.isStyleLoaded() || (initAllPreviewLayers(e), we.current = !0);
3523
4677
  }, [e]);
3524
4678
  useEffect(() => {
3525
4679
  if (!e) return;
3526
4680
  let t = () => {
3527
- initAllPreviewLayers(e), xe.current = !0;
4681
+ initAllPreviewLayers(e), we.current = !0;
3528
4682
  };
3529
4683
  e.isStyleLoaded() ? t() : e.once("load", t);
3530
4684
  let n = () => {
3531
- xe.current = !1;
4685
+ we.current = !1;
3532
4686
  };
3533
4687
  return e.on("style.load", n), () => {
3534
4688
  e.off("style.load", n);
3535
4689
  };
3536
4690
  }, [e]), useEffect(() => {
3537
4691
  let e = (e) => {
3538
- T.current && !T.current.contains(e.target) && E.current && !E.current.contains(e.target) && u(!1);
4692
+ E.current && !E.current.contains(e.target) && D.current && !D.current.contains(e.target) && d(!1);
3539
4693
  };
3540
4694
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
3541
4695
  }, []);
3542
- let Ce = useCallback((t) => {
4696
+ let F = useCallback((t) => {
3543
4697
  if (!e) return;
3544
- let n = applyEntityConfig(t, M.current), r = null;
4698
+ let n = applyEntityConfig(t, N.current), r = null;
3545
4699
  if (n.type === "circle" ? r = new CircleRenderer(e, n) : n.type === "square" ? r = new SquareRenderer(e, n) : n.type === "rectangle" ? r = new RectangleRenderer(e, n) : n.type === "polygon" ? r = new PolygonRenderer(e, n) : n.type === "polyline" && (r = new PolylineRenderer(e, n)), r) {
3546
- S.current.set(n.id, r);
4700
+ C.current.set(n.id, r);
3547
4701
  let e = {
3548
4702
  entity: n,
3549
4703
  shapeLabel: SHAPE_LABELS[n.type] || n.type,
3550
4704
  area: computeEntityArea(n),
3551
4705
  lengthOrRadius: computeEntityLengthOrRadius(n)
3552
4706
  };
3553
- x((t) => [...t, e]);
3554
- }
3555
- }, [e]), we = useCallback((e) => {
3556
- let t = S.current.get(e);
3557
- t && (t.destroy(), S.current.delete(e)), x((t) => t.filter((t) => t.entity.id !== e));
3558
- }, []), Te = useCallback(() => {
3559
- S.current.forEach((e) => e.destroy()), S.current.clear(), x([]);
3560
- }, []), Ee = useCallback((t) => {
4707
+ S((t) => [...t, e]);
4708
+ }
4709
+ }, [e]), Ee = useCallback((e) => {
4710
+ let t = C.current.get(e);
4711
+ t && (t.destroy(), C.current.delete(e)), S((t) => t.filter((t) => t.entity.id !== e));
4712
+ }, []), De = useCallback(() => {
4713
+ C.current.forEach((e) => e.destroy()), C.current.clear(), S([]);
4714
+ }, []), Oe = useCallback((t) => {
3561
4715
  if (!e) return;
3562
- let n = S.current.get(t);
4716
+ let n = C.current.get(t);
3563
4717
  if (!n) return;
3564
4718
  let r = n.getBounds();
3565
4719
  e.fitBounds(r, {
@@ -3567,21 +4721,21 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3567
4721
  maxZoom: 18,
3568
4722
  duration: 1e3
3569
4723
  });
3570
- }, [e]), De = useCallback((e, t) => {
4724
+ }, [e]), ke = useCallback((e, t) => {
3571
4725
  let n = {
3572
- ...M.current,
4726
+ ...N.current,
3573
4727
  [e]: t
3574
4728
  };
3575
- v ? i?.({ ...n }) : _(n), x((t) => t.map((t) => {
4729
+ y ? i?.({ ...n }) : v(n), S((t) => t.map((t) => {
3576
4730
  let r = { ...t.entity };
3577
4731
  r[e] = void 0;
3578
- let i = applyEntityConfig(r, n), a = S.current.get(t.entity.id);
4732
+ let i = applyEntityConfig(r, n), a = C.current.get(t.entity.id);
3579
4733
  return a && a.update(i), {
3580
4734
  ...t,
3581
4735
  entity: i
3582
4736
  };
3583
4737
  }));
3584
- }, [v, i]), Oe = useCallback((t, n) => {
4738
+ }, [y, i]), Ae = useCallback((t, n) => {
3585
4739
  if (!e) return;
3586
4740
  let [r, i] = t, [a, o] = n, s = [
3587
4741
  [Math.min(r, a), Math.max(i, o)],
@@ -3600,7 +4754,7 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3600
4754
  });
3601
4755
  let l = e.getSource(`${PREVIEW_PREFIX}rect-preview-measure-source`);
3602
4756
  if (l) {
3603
- let e = M.current, t = [], n = s[0], r = s[1], i = s[2];
4757
+ let e = N.current, t = [], n = s[0], r = s[1], i = s[2];
3604
4758
  if (e?.showArea) {
3605
4759
  let e = distance(n, r), a = distance(r, i);
3606
4760
  t.push({
@@ -3631,7 +4785,7 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3631
4785
  features: t
3632
4786
  });
3633
4787
  }
3634
- }, [e]), ke = useCallback((t, n) => {
4788
+ }, [e]), je = useCallback((t, n) => {
3635
4789
  if (!e) return;
3636
4790
  let r = calculateDistance(t, n), i = createCirclePolygon(t, r), a = e.getSource(`${PREVIEW_PREFIX}circle-preview-source`);
3637
4791
  a && a.setData({
@@ -3642,7 +4796,7 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3642
4796
  },
3643
4797
  properties: {}
3644
4798
  });
3645
- let o = M.current, s = [], c = [];
4799
+ let o = N.current, s = [], c = [];
3646
4800
  if (o?.showArea && s.push({
3647
4801
  type: "Feature",
3648
4802
  geometry: {
@@ -3678,7 +4832,7 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3678
4832
  type: "FeatureCollection",
3679
4833
  features: c
3680
4834
  });
3681
- }, [e]), Ae = useCallback((t, n) => {
4835
+ }, [e]), Me = useCallback((t, n) => {
3682
4836
  if (!e) return;
3683
4837
  let r = calculateDistance(t, n) * 2, i = createSquareCoords(t, r), a = e.getSource(`${PREVIEW_PREFIX}square-preview-source`);
3684
4838
  a && a.setData({
@@ -3691,7 +4845,7 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3691
4845
  });
3692
4846
  let o = e.getSource(`${PREVIEW_PREFIX}square-preview-measure-source`);
3693
4847
  if (o) {
3694
- let e = M.current, n = [];
4848
+ let e = N.current, n = [];
3695
4849
  if (e?.showArea && n.push({
3696
4850
  type: "Feature",
3697
4851
  geometry: {
@@ -3715,7 +4869,7 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3715
4869
  features: n
3716
4870
  });
3717
4871
  }
3718
- }, [e]), je = useCallback((t, n) => {
4872
+ }, [e]), Ne = useCallback((t, n) => {
3719
4873
  if (!e) return;
3720
4874
  let r = [...t, n], i = e.getSource(`${PREVIEW_PREFIX}polygon-preview-source`);
3721
4875
  i && (r.length >= 3 ? i.setData({
@@ -3750,7 +4904,7 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3750
4904
  });
3751
4905
  let o = e.getSource(`${PREVIEW_PREFIX}polygon-preview-measure-source`);
3752
4906
  if (o) {
3753
- let e = M.current, t = [];
4907
+ let e = N.current, t = [];
3754
4908
  if (e?.showArea && r.length >= 3) {
3755
4909
  let e = polygonArea([...r, r[0]]), n = 0, i = 0;
3756
4910
  for (let e of r) n += e[0], i += e[1];
@@ -3792,7 +4946,7 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3792
4946
  features: t
3793
4947
  });
3794
4948
  }
3795
- }, [e]), Me = useCallback((t, n) => {
4949
+ }, [e]), I = useCallback((t, n) => {
3796
4950
  if (!e) return;
3797
4951
  let r = [...t, n], i = e.getSource(`${PREVIEW_PREFIX}polyline-preview-source`);
3798
4952
  i && (r.length >= 2 ? i.setData({
@@ -3820,7 +4974,7 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3820
4974
  });
3821
4975
  let o = e.getSource(`${PREVIEW_PREFIX}polyline-preview-measure-source`);
3822
4976
  if (o) {
3823
- let e = M.current, t = [];
4977
+ let e = N.current, t = [];
3824
4978
  if (e?.showLength && r.length >= 2) for (let e = 0; e < r.length - 1; e++) {
3825
4979
  let n = r[e], i = r[e + 1];
3826
4980
  t.push({
@@ -3839,118 +4993,118 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3839
4993
  }
3840
4994
  }, [e]);
3841
4995
  useEffect(() => {
3842
- if (!e || !d) return;
3843
- Se(), e.getCanvas().style.cursor = "crosshair";
4996
+ if (!e || !f) return;
4997
+ Te(), e.getCanvas().style.cursor = "crosshair";
3844
4998
  let t = (t) => {
3845
- let n = [t.lngLat.lng, t.lngLat.lat], r = N.current;
4999
+ let n = [t.lngLat.lng, t.lngLat.lat], r = Ce.current;
3846
5000
  if (r === "rectangle") {
3847
- let t = D.current;
3848
- if (!t) D.current = n;
5001
+ let t = O.current;
5002
+ if (!t) O.current = n;
3849
5003
  else {
3850
5004
  let r = {
3851
- id: be(),
5005
+ id: P(),
3852
5006
  type: "rectangle",
3853
5007
  bounds: [t, n]
3854
5008
  };
3855
- Ce(r), D.current = null, clearAllPreviewSources(e), f(null);
5009
+ F(r), O.current = null, clearAllPreviewSources(e), g(null);
3856
5010
  }
3857
5011
  } else if (r === "circle") {
3858
- let t = O.current;
3859
- if (!t) O.current = { center: n };
5012
+ let t = k.current;
5013
+ if (!t) k.current = { center: n };
3860
5014
  else {
3861
5015
  let r = calculateDistance(t.center, n), i = {
3862
- id: be(),
5016
+ id: P(),
3863
5017
  type: "circle",
3864
5018
  center: t.center,
3865
5019
  radius: r
3866
5020
  };
3867
- Ce(i), O.current = null, clearAllPreviewSources(e), f(null);
5021
+ F(i), k.current = null, clearAllPreviewSources(e), g(null);
3868
5022
  }
3869
5023
  } else if (r === "square") {
3870
- let t = k.current;
3871
- if (!t) k.current = { center: n };
5024
+ let t = A.current;
5025
+ if (!t) A.current = { center: n };
3872
5026
  else {
3873
5027
  let r = calculateDistance(t.center, n) * 2, i = {
3874
- id: be(),
5028
+ id: P(),
3875
5029
  type: "square",
3876
5030
  center: t.center,
3877
5031
  length: r
3878
5032
  };
3879
- Ce(i), k.current = null, clearAllPreviewSources(e), f(null);
5033
+ F(i), A.current = null, clearAllPreviewSources(e), g(null);
3880
5034
  }
3881
5035
  } else if (r === "polygon") {
3882
- let t = A.current;
5036
+ let t = j.current;
3883
5037
  if (t.length >= 3 && calculateDistance(t[0], n) < 20) {
3884
5038
  let n = {
3885
- id: be(),
5039
+ id: P(),
3886
5040
  type: "polygon",
3887
5041
  coordinates: [...t]
3888
5042
  };
3889
- Ce(n), A.current = [], clearAllPreviewSources(e), f(null);
5043
+ F(n), j.current = [], clearAllPreviewSources(e), g(null);
3890
5044
  return;
3891
5045
  }
3892
- A.current = [...t, n];
3893
- } else r === "polyline" && (j.current = [...j.current, n]);
5046
+ j.current = [...t, n];
5047
+ } else r === "polyline" && (M.current = [...M.current, n]);
3894
5048
  }, n = (e) => {
3895
- let t = [e.lngLat.lng, e.lngLat.lat], n = N.current;
3896
- if (n === "rectangle" && D.current) Oe(D.current, t);
3897
- else if (n === "circle" && O.current) ke(O.current.center, t);
3898
- else if (n === "square" && k.current) Ae(k.current.center, t);
5049
+ let t = [e.lngLat.lng, e.lngLat.lat], n = Ce.current;
5050
+ if (n === "rectangle" && O.current) Ae(O.current, t);
5051
+ else if (n === "circle" && k.current) je(k.current.center, t);
5052
+ else if (n === "square" && A.current) Me(A.current.center, t);
3899
5053
  else if (n === "polygon") {
3900
- let e = A.current;
3901
- e.length > 0 && je(e, t);
3902
- } else if (n === "polyline") {
3903
5054
  let e = j.current;
3904
- e.length > 0 && Me(e, t);
5055
+ e.length > 0 && Ne(e, t);
5056
+ } else if (n === "polyline") {
5057
+ let e = M.current;
5058
+ e.length > 0 && I(e, t);
3905
5059
  }
3906
5060
  }, r = (t) => {
3907
5061
  t.preventDefault();
3908
- let n = N.current;
5062
+ let n = Ce.current;
3909
5063
  if (n === "polygon") {
3910
- let t = A.current;
5064
+ let t = j.current;
3911
5065
  if (t.length >= 3) {
3912
5066
  let n = {
3913
- id: be(),
5067
+ id: P(),
3914
5068
  type: "polygon",
3915
5069
  coordinates: [...t]
3916
5070
  };
3917
- Ce(n), A.current = [], clearAllPreviewSources(e), f(null);
3918
- } else A.current = [], clearAllPreviewSources(e);
5071
+ F(n), j.current = [], clearAllPreviewSources(e), g(null);
5072
+ } else j.current = [], clearAllPreviewSources(e);
3919
5073
  } else if (n === "polyline") {
3920
- let t = j.current;
5074
+ let t = M.current;
3921
5075
  if (t.length >= 2) {
3922
5076
  let n = {
3923
- id: be(),
5077
+ id: P(),
3924
5078
  type: "polyline",
3925
5079
  coordinates: [...t]
3926
5080
  };
3927
- Ce(n), j.current = [], clearAllPreviewSources(e), f(null);
3928
- } else j.current = [], clearAllPreviewSources(e);
5081
+ F(n), M.current = [], clearAllPreviewSources(e), g(null);
5082
+ } else M.current = [], clearAllPreviewSources(e);
3929
5083
  }
3930
5084
  }, i = (t) => {
3931
- t.key === "Escape" && (D.current = null, O.current = null, k.current = null, A.current = [], j.current = [], clearAllPreviewSources(e), f(null));
5085
+ t.key === "Escape" && (O.current = null, k.current = null, A.current = null, j.current = [], M.current = [], clearAllPreviewSources(e), g(null));
3932
5086
  }, a = (t) => {
3933
5087
  t.preventDefault();
3934
- let n = N.current;
5088
+ let n = Ce.current;
3935
5089
  if (n === "polygon") {
3936
- let t = A.current;
5090
+ let t = j.current;
3937
5091
  if (t.length >= 3) {
3938
5092
  let n = {
3939
- id: be(),
5093
+ id: P(),
3940
5094
  type: "polygon",
3941
5095
  coordinates: [...t]
3942
5096
  };
3943
- Ce(n), A.current = [], clearAllPreviewSources(e), f(null);
5097
+ F(n), j.current = [], clearAllPreviewSources(e), g(null);
3944
5098
  }
3945
5099
  } else if (n === "polyline") {
3946
- let t = j.current;
5100
+ let t = M.current;
3947
5101
  if (t.length >= 2) {
3948
5102
  let n = {
3949
- id: be(),
5103
+ id: P(),
3950
5104
  type: "polyline",
3951
5105
  coordinates: [...t]
3952
5106
  };
3953
- Ce(n), j.current = [], clearAllPreviewSources(e), f(null);
5107
+ F(n), M.current = [], clearAllPreviewSources(e), g(null);
3954
5108
  }
3955
5109
  }
3956
5110
  };
@@ -3959,28 +5113,28 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3959
5113
  };
3960
5114
  }, [
3961
5115
  e,
3962
- d,
3963
- be,
3964
- Ce,
3965
- Se,
3966
- Oe,
3967
- ke,
5116
+ f,
5117
+ P,
5118
+ F,
5119
+ Te,
3968
5120
  Ae,
3969
5121
  je,
3970
- Me
5122
+ Me,
5123
+ Ne,
5124
+ I
3971
5125
  ]), useEffect(() => () => {
3972
- S.current.forEach((e) => e.destroy()), S.current.clear();
5126
+ C.current.forEach((e) => e.destroy()), C.current.clear();
3973
5127
  }, []);
3974
- let Ne = useCallback((t) => {
3975
- f((e) => e === t ? null : t), D.current = null, O.current = null, k.current = null, A.current = [], j.current = [], e && clearAllPreviewSources(e);
5128
+ let Pe = useCallback((t) => {
5129
+ g((e) => e === t ? null : t), O.current = null, k.current = null, A.current = null, j.current = [], M.current = [], e && clearAllPreviewSources(e);
3976
5130
  }, [e]);
3977
5131
  return e ? /* @__PURE__ */ jsxs("div", {
3978
- className: `mapbox-measure-control ${s}`,
3979
- style: c,
5132
+ className: `mapbox-measure-control ${c}`,
5133
+ style: l,
3980
5134
  children: [/* @__PURE__ */ jsxs("button", {
3981
- ref: E,
3982
- className: `mapbox-control-btn mapbox-measure-control__btn ${l ? "mapbox-measure-control__btn--active" : ""}`,
3983
- onClick: () => u(!l),
5135
+ ref: D,
5136
+ className: `mapbox-control-btn mapbox-measure-control__btn ${u ? "mapbox-measure-control__btn--active" : ""}`,
5137
+ onClick: () => d(!u),
3984
5138
  title: "测量",
3985
5139
  children: [
3986
5140
  /* @__PURE__ */ jsx("img", {
@@ -3989,14 +5143,14 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
3989
5143
  className: "mapbox-measure-control__btn-icon"
3990
5144
  }),
3991
5145
  /* @__PURE__ */ jsx("span", { children: "测量" }),
3992
- b.length > 0 && /* @__PURE__ */ jsxs("span", { children: [
5146
+ x.length > 0 && /* @__PURE__ */ jsxs("span", { children: [
3993
5147
  "(",
3994
- b.length,
5148
+ x.length,
3995
5149
  ")"
3996
5150
  ] })
3997
5151
  ]
3998
- }), l && /* @__PURE__ */ jsxs("div", {
3999
- ref: T,
5152
+ }), u && /* @__PURE__ */ jsxs("div", {
5153
+ ref: E,
4000
5154
  className: "mapbox-measure-control__panel",
4001
5155
  children: [
4002
5156
  /* @__PURE__ */ jsx("div", {
@@ -4007,18 +5161,18 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
4007
5161
  className: "mapbox-measure-control__settings",
4008
5162
  children: [
4009
5163
  /* @__PURE__ */ jsx(Checkbox, {
4010
- checked: y.showArea,
4011
- onChange: (e) => De("showArea", e),
5164
+ checked: b.showArea,
5165
+ onChange: (e) => ke("showArea", e),
4012
5166
  children: "面积"
4013
5167
  }),
4014
5168
  /* @__PURE__ */ jsx(Checkbox, {
4015
- checked: y.showLength,
4016
- onChange: (e) => De("showLength", e),
5169
+ checked: b.showLength,
5170
+ onChange: (e) => ke("showLength", e),
4017
5171
  children: "长度"
4018
5172
  }),
4019
5173
  /* @__PURE__ */ jsx(Checkbox, {
4020
- checked: y.showRadius,
4021
- onChange: (e) => De("showRadius", e),
5174
+ checked: b.showRadius,
5175
+ onChange: (e) => ke("showRadius", e),
4022
5176
  children: "半径"
4023
5177
  })
4024
5178
  ]
@@ -4030,16 +5184,16 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
4030
5184
  /* @__PURE__ */ jsxs("div", {
4031
5185
  className: "mapbox-measure-control__tools",
4032
5186
  children: [DRAW_TOOLS.map((e) => /* @__PURE__ */ jsx("button", {
4033
- className: `mapbox-measure-control__tool-btn ${d === e.mode ? "mapbox-measure-control__tool-btn--active" : ""}`,
4034
- onClick: () => Ne(e.mode),
5187
+ className: `mapbox-measure-control__tool-btn ${f === e.mode ? "mapbox-measure-control__tool-btn--active" : ""}`,
5188
+ onClick: () => Pe(e.mode),
4035
5189
  title: e.label,
4036
5190
  children: /* @__PURE__ */ jsx("img", {
4037
5191
  src: e.icon,
4038
5192
  alt: e.label
4039
5193
  })
4040
- }, e.mode)), b.length > 0 && /* @__PURE__ */ jsx("button", {
5194
+ }, e.mode)), x.length > 0 && /* @__PURE__ */ jsx("button", {
4041
5195
  className: "mapbox-measure-control__tool-btn mapbox-measure-control__tool-btn--danger",
4042
- onClick: Te,
5196
+ onClick: De,
4043
5197
  title: "清除全部",
4044
5198
  children: /* @__PURE__ */ jsx("img", {
4045
5199
  src: "data:image/svg+xml,%3c?xml%20version='1.0'%20standalone='no'?%3e%3c!DOCTYPE%20svg%20PUBLIC%20'-//W3C//DTD%20SVG%201.1//EN'%20'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3e%3csvg%20t='1769394652565'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='6483'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='128'%20height='128'%3e%3cpath%20d='M841.385637%20288.639098a36.479886%2036.479886%200%200%201%2072.74644%207.679976l6.613312%20629.544699A109.866323%20109.866323%200%200%201%20810.665733%201023.9968H222.507571a109.652991%20109.652991%200%200%201-109.012992-98.133027l-3.626656-629.544699a36.479886%2036.479886%200%200%201%2072.74644-7.679976L186.241018%20917.330467a36.479886%2036.479886%200%200%200%2036.266553%2032.639898H810.665733A36.479886%2036.479886%200%200%200%20847.99895%20917.330467z%20m-219.732646%20113.706311a36.479886%2036.479886%200%200%201%2036.693218%2036.479886v255.9992a36.693219%2036.693219%200%201%201-73.173104%200v-255.9992a36.479886%2036.479886%200%200%201%2036.479886-36.479886z%20m-219.305982%200a36.479886%2036.479886%200%200%201%2036.479886%2036.479886v255.9992a36.693219%2036.693219%200%201%201-73.173104%200v-255.9992a36.479886%2036.479886%200%200%201%2036.693218-36.479886z%20m-36.693218-255.9992h292.692418V91.519714a18.346609%2018.346609%200%200%200-18.346609-18.346609H384.0004a18.346609%2018.346609%200%200%200-18.346609%2018.346609z%20m-73.173105%200V73.173105A73.173105%2073.173105%200%200%201%20365.653791%200h292.692418a73.386437%2073.386437%200%200%201%2073.173105%2073.173105v73.173104h255.9992a36.693219%2036.693219%200%200%201%200%2073.173105H36.481486a36.693219%2036.693219%200%200%201%200-73.173105z'%20fill='%23EB6865'%20p-id='6484'%3e%3c/path%3e%3c/svg%3e",
@@ -4047,7 +5201,7 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
4047
5201
  })
4048
5202
  })]
4049
5203
  }),
4050
- b.length > 0 ? /* @__PURE__ */ jsx("div", {
5204
+ x.length > 0 ? /* @__PURE__ */ jsx("div", {
4051
5205
  className: "mapbox-measure-control__list",
4052
5206
  children: /* @__PURE__ */ jsxs("table", {
4053
5207
  className: "mapbox-measure-control__table",
@@ -4057,9 +5211,9 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
4057
5211
  /* @__PURE__ */ jsx("th", { children: "面积" }),
4058
5212
  /* @__PURE__ */ jsx("th", { children: "长度/半径" }),
4059
5213
  /* @__PURE__ */ jsx("th", {})
4060
- ] }) }), /* @__PURE__ */ jsx("tbody", { children: b.map((e) => /* @__PURE__ */ jsxs("tr", {
5214
+ ] }) }), /* @__PURE__ */ jsx("tbody", { children: x.map((e) => /* @__PURE__ */ jsxs("tr", {
4061
5215
  className: "mapbox-measure-control__table-row",
4062
- onClick: () => Ee(e.entity.id),
5216
+ onClick: () => Oe(e.entity.id),
4063
5217
  children: [
4064
5218
  /* @__PURE__ */ jsx("td", { children: e.shapeLabel }),
4065
5219
  /* @__PURE__ */ jsx("td", { children: String(e.entity.id) }),
@@ -4068,7 +5222,7 @@ function MeasureControl({ map: e, entityConfig: r, onEntityConfigChange: i, clas
4068
5222
  /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsx("button", {
4069
5223
  className: "mapbox-measure-control__delete-btn",
4070
5224
  onClick: (t) => {
4071
- t.stopPropagation(), we(e.entity.id);
5225
+ t.stopPropagation(), Ee(e.entity.id);
4072
5226
  },
4073
5227
  title: "删除",
4074
5228
  children: /* @__PURE__ */ jsx("img", {
@@ -4403,6 +5557,220 @@ const EditControl = ({ markerTemplates: e, selectedTemplate: t, onTemplateSelect
4403
5557
  });
4404
5558
  return createPortal(d, i);
4405
5559
  };
5560
+ var route_planning_default = "data:image/svg+xml,%3c?xml%20version='1.0'%20standalone='no'?%3e%3c!DOCTYPE%20svg%20PUBLIC%20'-//W3C//DTD%20SVG%201.1//EN'%20'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3e%3csvg%20t='1775031767174'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='30653'%20data-spm-anchor-id='a313x.search_index.0.i6.78953a81FCkAe0'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='64'%20height='64'%3e%3cpath%20d='M322.24%20479.210667l-42.453333-42.432%20198.826666-198.826667c53.397333-53.376%20139.306667-53.568%20191.914667-0.981333%2052.608%2052.608%2052.416%20138.517333-0.981333%20191.914666L455.722667%20642.709333l-42.432-42.453333%20213.824-213.802667a74.773333%2074.773333%200%200%200-0.341334-105.728%2074.773333%2074.773333%200%200%200-105.728-0.341333l-198.826666%20198.826667z'%20fill='%23ffffff'%20p-id='30654'%3e%3c/path%3e%3cpath%20d='M699.093333%20613.333333l42.453334%2042.432-169.429334%20169.408c-48.341333%2048.341333-129.28%2042.282667-181.248-9.664-51.968-51.968-58.026667-132.906667-9.664-181.248l234.346667-234.346666%2042.432%2042.410666L423.616%20676.693333c-22.250667%2022.250667-19.050667%2065.024%2011.008%2095.061334%2030.037333%2030.058667%2072.810667%2033.258667%2095.061333%2010.986666l169.429334-169.408zM187.989333%20571.029333c-38.933333-38.933333-38.805333-102.613333%200.853334-142.293333%2039.68-39.68%20103.381333-39.808%20142.293333-0.853333%2038.954667%2038.912%2038.826667%20102.613333-0.853333%20142.293333-39.68%2039.658667-103.381333%2039.786667-142.293334%200.853333z%20m43.733334-43.733333c15.744%2015.744%2040.874667%2015.68%2056.128%200.426667%2015.253333-15.232%2015.296-40.362667-0.426667-56.106667-15.765333-15.744-40.896-15.701333-56.149333-0.448-15.232%2015.232-15.296%2040.384%200.448%2056.106667z'%20fill='%23ffffff'%20p-id='30655'%3e%3c/path%3e%3cpath%20d='M846.144%20489.728l-31.466667%20198.784-56.96-101.461333-104.042666-38.506667z'%20fill='%23ffffff'%20p-id='30656'%3e%3c/path%3e%3c/svg%3e", SOURCE_ID = "route-planning-temp-line", LINE_LAYER_ID = "route-planning-temp-line-layer", POINT_LAYER_ID = "route-planning-temp-point-layer";
5561
+ const RoutePlanningControl = forwardRef(({ map: e, pointCount: i = 2, showPointCountInput: c = !1, visualType: l = "marker", onSelectFinished: u, showButton: d = !0 }, f) => {
5562
+ let [h, g] = useState("idle"), [_, v] = useState(0), [y, b] = useState(i), [x, S] = useState(!1), C = useRef(null), w = useRef(null), T = useRef([]), E = useRef([]), D = useRef("idle"), O = useRef(null), ve = useRef("");
5563
+ useEffect(() => {
5564
+ D.current = h;
5565
+ }, [h]), useEffect(() => {
5566
+ b(i);
5567
+ }, [i]), useEffect(() => {
5568
+ if (!x) return;
5569
+ let e = (e) => {
5570
+ w.current && !w.current.contains(e.target) && C.current && !C.current.contains(e.target) && S(!1);
5571
+ }, t = setTimeout(() => {
5572
+ document.addEventListener("mousedown", e);
5573
+ }, 0);
5574
+ return () => {
5575
+ clearTimeout(t), document.removeEventListener("mousedown", e);
5576
+ };
5577
+ }, [x]);
5578
+ let ye = useCallback(() => {
5579
+ for (let e of E.current) e.remove();
5580
+ E.current = [], e && (e.getLayer(LINE_LAYER_ID) && e.removeLayer(LINE_LAYER_ID), e.getLayer(POINT_LAYER_ID) && e.removeLayer(POINT_LAYER_ID), e.getSource(SOURCE_ID) && e.removeSource(SOURCE_ID));
5581
+ }, [e]), k = useCallback(() => {
5582
+ if (!e) return;
5583
+ let t = T.current, n = {
5584
+ type: "FeatureCollection",
5585
+ features: [{
5586
+ type: "Feature",
5587
+ properties: {},
5588
+ geometry: {
5589
+ type: "LineString",
5590
+ coordinates: t.length >= 2 ? t : []
5591
+ }
5592
+ }, ...t.map((e, t) => ({
5593
+ type: "Feature",
5594
+ properties: { index: t },
5595
+ geometry: {
5596
+ type: "Point",
5597
+ coordinates: e
5598
+ }
5599
+ }))]
5600
+ }, r = e.getSource(SOURCE_ID);
5601
+ r ? r.setData(n) : (e.addSource(SOURCE_ID, {
5602
+ type: "geojson",
5603
+ data: n
5604
+ }), e.addLayer({
5605
+ id: LINE_LAYER_ID,
5606
+ type: "line",
5607
+ source: SOURCE_ID,
5608
+ filter: [
5609
+ "==",
5610
+ "$type",
5611
+ "LineString"
5612
+ ],
5613
+ paint: {
5614
+ "line-color": "#4A90D9",
5615
+ "line-width": 3,
5616
+ "line-dasharray": [2, 2]
5617
+ }
5618
+ }), e.addLayer({
5619
+ id: POINT_LAYER_ID,
5620
+ type: "circle",
5621
+ source: SOURCE_ID,
5622
+ filter: [
5623
+ "==",
5624
+ "$type",
5625
+ "Point"
5626
+ ],
5627
+ paint: {
5628
+ "circle-radius": 6,
5629
+ "circle-color": "#4A90D9",
5630
+ "circle-stroke-width": 2,
5631
+ "circle-stroke-color": "#fff"
5632
+ }
5633
+ }));
5634
+ }, [e]), be = useCallback((t) => {
5635
+ if (!e || !O.current) return;
5636
+ let { visualType: n } = O.current;
5637
+ if (n === "marker") {
5638
+ let n = document.createElement("div");
5639
+ n.className = "route-planning-temp-marker", n.textContent = String(T.current.length);
5640
+ let r = new mapboxgl.Marker({ element: n }).setLngLat(t).addTo(e);
5641
+ E.current.push(r);
5642
+ } else k();
5643
+ }, [e, k]), xe = useCallback(() => {
5644
+ ye(), T.current = [], O.current = null, v(0), g("idle"), e && (e.getCanvas().style.cursor = ve.current);
5645
+ }, [ye, e]), Se = useCallback(async () => {
5646
+ let e = O.current, t = [...T.current];
5647
+ if (!e || t.length < 2) {
5648
+ xe();
5649
+ return;
5650
+ }
5651
+ g("planning");
5652
+ try {
5653
+ await e.onSelectFinished(t);
5654
+ } catch (e) {
5655
+ console.error("Route planning onSelectFinished failed:", e);
5656
+ } finally {
5657
+ xe();
5658
+ }
5659
+ }, [xe]), A = useCallback((e) => {
5660
+ if (D.current !== "selecting" || !O.current) return;
5661
+ let t = [e.lngLat.lng, e.lngLat.lat];
5662
+ T.current.push(t);
5663
+ let n = T.current.length;
5664
+ v(n), be(t), n >= O.current.pointCount && Se();
5665
+ }, [be, Se]), j = useCallback((e) => {
5666
+ D.current === "selecting" && (e.preventDefault(), xe());
5667
+ }, [xe]);
5668
+ useEffect(() => {
5669
+ if (e && h === "selecting") return e.on("click", A), e.on("contextmenu", j), () => {
5670
+ e.off("click", A), e.off("contextmenu", j);
5671
+ };
5672
+ }, [
5673
+ e,
5674
+ h,
5675
+ A,
5676
+ j
5677
+ ]);
5678
+ let M = useCallback((t) => {
5679
+ if (!e) return;
5680
+ D.current !== "idle" && xe();
5681
+ let n = Math.max(2, t.pointCount ?? i), r = t.visualType ?? l;
5682
+ O.current = {
5683
+ pointCount: n,
5684
+ visualType: r,
5685
+ onSelectFinished: t.onSelectFinished
5686
+ }, T.current = [], v(0), b(n), S(!1), ve.current = e.getCanvas().style.cursor, e.getCanvas().style.cursor = "crosshair", g("selecting");
5687
+ }, [
5688
+ e,
5689
+ i,
5690
+ l,
5691
+ xe
5692
+ ]);
5693
+ useImperativeHandle(f, () => ({ startPlanning: M }), [M]);
5694
+ let N = () => {
5695
+ h === "idle" ? S((e) => !e) : h === "selecting" && xe();
5696
+ }, Ce = () => {
5697
+ u && M({
5698
+ pointCount: Math.max(2, y),
5699
+ visualType: l,
5700
+ onSelectFinished: u
5701
+ });
5702
+ }, P = (e) => {
5703
+ let t = parseInt(e.target.value, 10);
5704
+ !isNaN(t) && t >= 2 ? b(t) : e.target.value === "" && b(2);
5705
+ }, we = () => {
5706
+ if (h === "planning") return /* @__PURE__ */ jsx("span", { children: "规划中..." });
5707
+ if (h === "selecting") {
5708
+ let e = O.current?.pointCount ?? y;
5709
+ return /* @__PURE__ */ jsxs("span", { children: [
5710
+ _,
5711
+ "/",
5712
+ e
5713
+ ] });
5714
+ }
5715
+ return "路径规划";
5716
+ }, Te = h === "selecting", F = h === "planning";
5717
+ return !d && h === "idle" ? null : /* @__PURE__ */ jsxs("div", {
5718
+ className: `mapbox-route-planning-control${d ? "" : " mapbox-route-planning-control--floating"}`,
5719
+ children: [/* @__PURE__ */ jsxs("button", {
5720
+ ref: C,
5721
+ className: `mapbox-control-btn mapbox-route-planning-control__btn${Te ? " mapbox-route-planning-control__btn--active" : ""}${F ? " mapbox-route-planning-control__btn--planning" : ""}${x ? " mapbox-route-planning-control__btn--active" : ""}`,
5722
+ onClick: N,
5723
+ disabled: F,
5724
+ title: h === "idle" ? "路径规划" : h === "selecting" ? "取消选点" : "规划中...",
5725
+ children: [/* @__PURE__ */ jsx("img", {
5726
+ src: route_planning_default,
5727
+ alt: "route",
5728
+ className: "mapbox-route-planning-control__btn-icon"
5729
+ }), we()]
5730
+ }), x && h === "idle" && /* @__PURE__ */ jsxs("div", {
5731
+ ref: w,
5732
+ className: "mapbox-route-planning-control__panel",
5733
+ children: [/* @__PURE__ */ jsx("div", {
5734
+ className: "mapbox-route-planning-control__panel-header",
5735
+ children: /* @__PURE__ */ jsx("span", {
5736
+ className: "mapbox-route-planning-control__panel-title",
5737
+ children: "路径规划"
5738
+ })
5739
+ }), /* @__PURE__ */ jsxs("div", {
5740
+ className: "mapbox-route-planning-control__panel-body",
5741
+ children: [
5742
+ /* @__PURE__ */ jsxs("div", {
5743
+ className: "mapbox-route-planning-control__panel-row",
5744
+ children: [/* @__PURE__ */ jsx("span", {
5745
+ className: "mapbox-route-planning-control__panel-label",
5746
+ children: "选点数量"
5747
+ }), c ? /* @__PURE__ */ jsx("input", {
5748
+ type: "number",
5749
+ className: "mapbox-route-planning-control__panel-input",
5750
+ value: y,
5751
+ min: 2,
5752
+ onChange: P
5753
+ }) : /* @__PURE__ */ jsx("span", {
5754
+ className: "mapbox-route-planning-control__panel-value",
5755
+ children: y
5756
+ })]
5757
+ }),
5758
+ /* @__PURE__ */ jsx("div", {
5759
+ className: "mapbox-route-planning-control__panel-tip",
5760
+ children: "左键点击地图选点,右键取消"
5761
+ }),
5762
+ /* @__PURE__ */ jsx("button", {
5763
+ className: "mapbox-route-planning-control__panel-start",
5764
+ onClick: Ce,
5765
+ disabled: !u,
5766
+ children: "开始规划"
5767
+ })
5768
+ ]
5769
+ })]
5770
+ })]
5771
+ });
5772
+ });
5773
+ RoutePlanningControl.displayName = "RoutePlanningControl";
4406
5774
  function mergePopupConfig(e, t, n) {
4407
5775
  return {
4408
5776
  content: e.content ?? n ?? null,
@@ -4550,51 +5918,53 @@ function adjustPopupForBounds(e, t) {
4550
5918
  return r.x + t.width + 10 > n.width && (r.x = n.width - t.width - 10), r.x < 10 && (r.x = 10), r.y + t.height + 10 > n.height && (r.y = n.height - t.height - 10), r.y < 10 && (r.y = 10), r;
4551
5919
  }
4552
5920
  const Mapbox = forwardRef((e, c) => {
4553
- let { center: l = [116.4074, 39.9042], zoom: u = 12, pitch: d = 0, bearing: f = 0, style: h = "mapbox://styles/mapbox/dark-v11", maxBounds: g, mode: _ = "display", editConfig: v = {}, pickerConfig: y = {}, onPick: b, interactive: x = {}, layers: S = [], rasterPaint: T, entities: E = [], selectedIds: D = [], entityConfig: O, nameConfig: k, selectNameConfig: A, areaConfig: j, circleConfig: M, lengthConfig: N, showCoordinates: xe = !0, showScale: Te = !0, showResetView: Ee = !0, showRoadHighlight: De = !1, showMeasure: ke = !1, showRasterPaint: Ae = !1, onRasterPaintChange: Me, popupDefaults: P, renderPopup: Pe, onMapLoad: Fe, onEntityClick: Ie, onPopupOpen: Le, onPopupClose: Re, className: ze = "", containerStyle: Be } = e, Ve = useRef(null), F = useRef(null), I = useRef(/* @__PURE__ */ new Map()), L = useRef(/* @__PURE__ */ new Map()), He = useRef(/* @__PURE__ */ new Set()), [R, Ue] = useState(null), We = useRef(null), Ge = useRef(null), Ke = useRef(null), [qe, Je] = useState(null), Ye = useRef(null), Xe = useRef(null), [Ze, Qe] = useState(null), [z, $e] = useState(_), [et, tt] = useState(null), nt = useRef(null), [rt, B] = useState(null), [it, V] = useState(null), [at, ot] = useState(null), H = useRef(!1), U = useRef(null), W = useRef(null), G = useRef(null), st = useRef(null), K = useRef(null), ct = useRef([]), q = useRef(null), lt = useRef(null), J = useRef(null), ut = useRef([]), dt = useRef(null);
5921
+ let { center: l = [116.4074, 39.9042], zoom: u = 12, pitch: d = 0, bearing: f = 0, style: h = "mapbox://styles/mapbox/dark-v11", maxBounds: g, mode: _ = "display", editConfig: v = {}, pickerConfig: y = {}, onPick: b, interactive: x = {}, layers: S = [], rasterPaint: T, entities: E = [], selectedIds: D = [], entityConfig: O, nameConfig: k, selectNameConfig: A, areaConfig: j, circleConfig: M, lengthConfig: N, showCoordinates: Ce = !0, showScale: P = !0, showResetView: we = !0, showRoadHighlight: Te = !1, showMeasure: Ee = !1, showRasterPaint: Ae = !1, showRoutePlanning: je, onRasterPaintChange: Me, popupDefaults: I, renderPopup: Pe, onMapLoad: Fe, onEntityClick: Ie, onPopupOpen: Le, onPopupClose: Re, className: ze = "", containerStyle: Be } = e, Ve = useRef(null), He = useRef(null), L = useRef(null), R = useRef(/* @__PURE__ */ new Map()), z = useRef(/* @__PURE__ */ new Map()), Ue = useRef(/* @__PURE__ */ new Set()), [B, We] = useState(null), Ge = useRef(null), Ke = useRef(null), qe = useRef(null), [Je, Ye] = useState(null), Xe = useRef(null), Ze = useRef(null), [V, Qe] = useState(null), [$e, et] = useState(_), [tt, nt] = useState(null), rt = useRef(null), [it, H] = useState(null), [at, U] = useState(null), [ot, st] = useState(null), W = useRef(!1), G = useRef(null), ct = useRef(null), K = useRef(null), lt = useRef(null), q = useRef(null), ut = useRef([]), J = useRef(null), dt = useRef(null), ft = useRef(null), pt = useRef([]), mt = useRef(null), ht = useRef(!1), [gt, _t] = useState([]), vt = useRef([]);
5922
+ vt.current = gt;
5923
+ let Y = useRef(null);
4554
5924
  useEffect(() => {
4555
- $e(_);
5925
+ et(_);
4556
5926
  }, [_]);
4557
- let ft = useCallback((e) => {
4558
- let t = I.current.get(e), n = L.current.get(e);
5927
+ let yt = useCallback((e) => {
5928
+ let t = R.current.get(e), n = z.current.get(e);
4559
5929
  if (t && n) {
4560
5930
  if (n.type === "radar" && t instanceof CanvasRadarRenderer) {
4561
5931
  let r = {
4562
5932
  ...n,
4563
5933
  isAnimating: !0
4564
5934
  };
4565
- L.current.set(e, r), t.startAnimation();
5935
+ z.current.set(e, r), t.startAnimation();
4566
5936
  } else if (n.type === "circle" && t instanceof CanvasCircleRenderer) {
4567
5937
  let r = {
4568
5938
  ...n,
4569
5939
  isAnimating: !0
4570
5940
  };
4571
- L.current.set(e, r), t.startAnimation();
5941
+ z.current.set(e, r), t.startAnimation();
4572
5942
  }
4573
5943
  }
4574
- }, []), pt = useCallback((e) => {
4575
- let t = I.current.get(e), n = L.current.get(e);
5944
+ }, []), bt = useCallback((e) => {
5945
+ let t = R.current.get(e), n = z.current.get(e);
4576
5946
  if (t && n) {
4577
5947
  if (n.type === "radar" && t instanceof CanvasRadarRenderer) {
4578
5948
  let r = {
4579
5949
  ...n,
4580
5950
  isAnimating: !1
4581
5951
  };
4582
- L.current.set(e, r), t.stopAnimation();
5952
+ z.current.set(e, r), t.stopAnimation();
4583
5953
  } else if (n.type === "circle" && t instanceof CanvasCircleRenderer) {
4584
5954
  let r = {
4585
5955
  ...n,
4586
5956
  isAnimating: !1
4587
5957
  };
4588
- L.current.set(e, r), t.stopAnimation();
5958
+ z.current.set(e, r), t.stopAnimation();
4589
5959
  }
4590
5960
  }
4591
- }, []), mt = useCallback((e) => {
4592
- let t = L.current.get(e);
4593
- t && (t.type === "radar" || t.type === "circle") && (t.type, t.isAnimating ? pt(e) : ft(e));
4594
- }, [ft, pt]), ht = useCallback((e) => {
5961
+ }, []), xt = useCallback((e) => {
5962
+ let t = z.current.get(e);
5963
+ t && (t.type === "radar" || t.type === "circle") && (t.type, t.isAnimating ? bt(e) : yt(e));
5964
+ }, [yt, bt]), St = useCallback((e) => {
4595
5965
  if (e === void 0) {
4596
5966
  let e = !1;
4597
- for (let [, t] of I.current) if (t instanceof UnitRenderer) {
5967
+ for (let [, t] of R.current) if (t instanceof UnitRenderer) {
4598
5968
  let n = t.getShowTrajectory();
4599
5969
  if (n === "all" || typeof n == "number" && n > 0) {
4600
5970
  e = !0;
@@ -4602,18 +5972,18 @@ const Mapbox = forwardRef((e, c) => {
4602
5972
  }
4603
5973
  }
4604
5974
  let t = e ? 0 : "all";
4605
- for (let [, e] of I.current) e instanceof UnitRenderer && e.setShowTrajectory(t);
5975
+ for (let [, e] of R.current) e instanceof UnitRenderer && e.setShowTrajectory(t);
4606
5976
  } else {
4607
5977
  let t = new Set(e.map(String));
4608
- for (let [e, n] of I.current) n instanceof UnitRenderer && n.setShowTrajectory(t.has(String(e)) ? "all" : 0);
5978
+ for (let [e, n] of R.current) n instanceof UnitRenderer && n.setShowTrajectory(t.has(String(e)) ? "all" : 0);
4609
5979
  }
4610
- }, []), gt = useCallback((e, t, n) => {
5980
+ }, []), Ct = useCallback((e, t, n) => {
4611
5981
  let r = E.find((t) => String(t.id) === String(e));
4612
- if (!r?.popup || !F.current) return;
5982
+ if (!r?.popup || !L.current) return;
4613
5983
  let i = r.popup.content ?? Pe?.(r);
4614
5984
  if (!i) return;
4615
- let a = mergePopupConfig(r.popup, P, i), { position: o, actualPosition: s } = calculatePopupPosition(r, a, F.current, n);
4616
- Ue({
5985
+ let a = mergePopupConfig(r.popup, I, i), { position: o, actualPosition: s } = calculatePopupPosition(r, a, L.current, n);
5986
+ We({
4617
5987
  entityId: e,
4618
5988
  position: o,
4619
5989
  config: a,
@@ -4622,26 +5992,26 @@ const Mapbox = forwardRef((e, c) => {
4622
5992
  }), Le?.(e);
4623
5993
  }, [
4624
5994
  E,
4625
- P,
5995
+ I,
4626
5996
  Pe,
4627
5997
  Le
4628
- ]), _t = useCallback((e) => {
4629
- R?.entityId === e && (Ue(null), Re?.(e));
4630
- }, [R, Re]), vt = useCallback(() => {
4631
- Ue((e) => (e && Re?.(e.entityId), null));
4632
- }, [Re]), yt = useCallback((e) => R?.entityId === e, [R]), bt = useCallback((e, t, n) => {
4633
- let r = F.current;
5998
+ ]), wt = useCallback((e) => {
5999
+ B?.entityId === e && (We(null), Re?.(e));
6000
+ }, [B, Re]), Tt = useCallback(() => {
6001
+ We((e) => (e && Re?.(e.entityId), null));
6002
+ }, [Re]), Et = useCallback((e) => B?.entityId === e, [B]), Dt = useCallback((e, t, n) => {
6003
+ let r = L.current;
4634
6004
  r && r.flyTo({
4635
6005
  center: e,
4636
6006
  zoom: t ?? r.getZoom(),
4637
6007
  ...n
4638
6008
  });
4639
- }, []), xt = useCallback((e, t, n) => {
4640
- let r = F.current;
6009
+ }, []), Ot = useCallback((e, t, n) => {
6010
+ let r = L.current;
4641
6011
  if (!r || e.length === 0) return;
4642
6012
  let i = [];
4643
6013
  for (let t of e) {
4644
- let e = I.current.get(t);
6014
+ let e = R.current.get(t);
4645
6015
  e && i.push(e.getBounds());
4646
6016
  }
4647
6017
  if (i.length === 0) return;
@@ -4663,17 +6033,17 @@ const Mapbox = forwardRef((e, c) => {
4663
6033
  pitch: n?.pitch ?? r.getPitch()
4664
6034
  };
4665
6035
  t !== void 0 && (p.maxZoom = t), n?.essential !== void 0 && (p.essential = n.essential), r.fitBounds(f, p);
4666
- }, []), St = useCallback((e) => {
4667
- let t = F.current;
6036
+ }, []), kt = useCallback((e) => {
6037
+ let t = L.current;
4668
6038
  if (!t || !t.getContainer()) return;
4669
6039
  let { showMarker: n = !0, markerColor: r = "#3388ff", name: i, nameConfig: a } = y;
4670
6040
  if (!n) {
4671
- nt.current &&= (nt.current.remove(), null);
6041
+ rt.current &&= (rt.current.remove(), null);
4672
6042
  return;
4673
6043
  }
4674
- if (nt.current) {
4675
- nt.current.setLngLat(e);
4676
- let t = nt.current.getElement(), n = t.querySelector(".marker-label");
6044
+ if (rt.current) {
6045
+ rt.current.setLngLat(e);
6046
+ let t = rt.current.getElement(), n = t.querySelector(".marker-label");
4677
6047
  if (i) {
4678
6048
  let e = resolveNameConfig(a, k);
4679
6049
  if (n) n.textContent = i, n.style.color = e.fillColor, n.style.opacity = String(e.fillOpacity), n.style.webkitTextStrokeColor = e.strokeColor, n.style.webkitTextStrokeWidth = `${e.strokeWidth}px`;
@@ -4690,38 +6060,38 @@ const Mapbox = forwardRef((e, c) => {
4690
6060
  let e = resolveNameConfig(a, k), t = document.createElement("div");
4691
6061
  t.className = "marker-label", t.textContent = i, t.style.color = e.fillColor, t.style.opacity = String(e.fillOpacity), t.style.webkitTextStrokeColor = e.strokeColor, t.style.webkitTextStrokeWidth = `${e.strokeWidth}px`, n.appendChild(t);
4692
6062
  }
4693
- nt.current = new mapboxgl.Marker({
6063
+ rt.current = new mapboxgl.Marker({
4694
6064
  element: n,
4695
6065
  anchor: "bottom"
4696
6066
  }).setLngLat(e).addTo(t);
4697
6067
  }
4698
- }, [y, k]), Ct = useCallback(() => {
4699
- nt.current &&= (nt.current.remove(), null);
4700
- }, []), wt = useCallback(() => `marker-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`, []), Tt = useCallback((e) => {
4701
- let t = F.current;
4702
- if (Ve.current) if (dt.current &&= (dt.current.remove(), null), e && t) {
6068
+ }, [y, k]), At = useCallback(() => {
6069
+ rt.current &&= (rt.current.remove(), null);
6070
+ }, []), jt = useCallback(() => `marker-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`, []), Mt = useCallback((e) => {
6071
+ let t = L.current;
6072
+ if (Ve.current) if (mt.current &&= (mt.current.remove(), null), e && t) {
4703
6073
  t.getCanvas().style.cursor = "none";
4704
6074
  let n = document.createElement("div");
4705
6075
  n.className = "mapbox-custom-cursor";
4706
6076
  let r = e.size || e.width || 32;
4707
6077
  n.style.cssText = "\n position: fixed;\n pointer-events: none;\n z-index: 9999;\n transform: translate(-50%, -50%);\n opacity: 0.8;\n ";
4708
6078
  let i = document.createElement("img");
4709
- i.src = e.icon, i.style.width = `${r}px`, i.style.height = `${e.size || e.height || r}px`, i.style.objectFit = "contain", n.appendChild(i), document.body.appendChild(n), dt.current = n;
6079
+ i.src = e.icon, i.style.width = `${r}px`, i.style.height = `${e.size || e.height || r}px`, i.style.objectFit = "contain", n.appendChild(i), document.body.appendChild(n), mt.current = n;
4710
6080
  let a = (e) => {
4711
- dt.current && (dt.current.style.left = `${e.clientX}px`, dt.current.style.top = `${e.clientY}px`);
6081
+ mt.current && (mt.current.style.left = `${e.clientX}px`, mt.current.style.top = `${e.clientY}px`);
4712
6082
  };
4713
6083
  document.addEventListener("mousemove", a), n.dataset.cleanup = "true", n._cleanup = () => {
4714
6084
  document.removeEventListener("mousemove", a);
4715
6085
  };
4716
6086
  } else t && (t.getCanvas().style.cursor = "");
4717
- }, []), Y = useCallback(() => {
4718
- if (dt.current) {
4719
- let e = dt.current._cleanup;
4720
- e && e(), dt.current.remove(), dt.current = null;
6087
+ }, []), X = useCallback(() => {
6088
+ if (mt.current) {
6089
+ let e = mt.current._cleanup;
6090
+ e && e(), mt.current.remove(), mt.current = null;
4721
6091
  }
4722
- let e = F.current;
6092
+ let e = L.current;
4723
6093
  e && (e.getCanvas().style.cursor = "");
4724
- }, []), Et = useCallback((e, t, n) => {
6094
+ }, []), Nt = useCallback((e, t, n) => {
4725
6095
  if (!e.getSource(t)) {
4726
6096
  if (!e.getStyle().glyphs) {
4727
6097
  let t = e.style, n = "/gis-fonts/{fontstack}/{range}.pbf";
@@ -4757,8 +6127,8 @@ const Mapbox = forwardRef((e, c) => {
4757
6127
  }
4758
6128
  });
4759
6129
  }
4760
- }, []), Dt = useCallback(() => {
4761
- let e = F.current;
6130
+ }, []), Pt = useCallback(() => {
6131
+ let e = L.current;
4762
6132
  e && (e.getSource("rect-preview-source") || (e.addSource("rect-preview-source", {
4763
6133
  type: "geojson",
4764
6134
  data: {
@@ -4782,9 +6152,9 @@ const Mapbox = forwardRef((e, c) => {
4782
6152
  "line-width": 2,
4783
6153
  "line-dasharray": [4, 4]
4784
6154
  }
4785
- }), Et(e, "rect-preview-measure-source", "rect-preview-measure-label")));
4786
- }, [Et]), Ot = useCallback((e, t) => {
4787
- let n = F.current;
6155
+ }), Nt(e, "rect-preview-measure-source", "rect-preview-measure-label")));
6156
+ }, [Nt]), Ft = useCallback((e, t) => {
6157
+ let n = L.current;
4788
6158
  if (!n) return;
4789
6159
  let r = n.getSource("rect-preview-source");
4790
6160
  if (!r) return;
@@ -4803,11 +6173,11 @@ const Mapbox = forwardRef((e, c) => {
4803
6173
  },
4804
6174
  properties: {}
4805
6175
  });
4806
- let l = U.current, u = l?.strokeColor ?? "#3388ff", d = l?.strokeWidth ?? 2, f = l?.fillColor ?? "#3388ff", p = l?.fillOpacity ?? .1;
6176
+ let l = G.current, u = l?.strokeColor ?? "#3388ff", d = l?.strokeWidth ?? 2, f = l?.fillColor ?? "#3388ff", p = l?.fillOpacity ?? .1;
4807
6177
  n.getLayer("rect-preview-line") && (n.setPaintProperty("rect-preview-line", "line-color", u), n.setPaintProperty("rect-preview-line", "line-width", d)), n.getLayer("rect-preview-fill") && (n.setPaintProperty("rect-preview-fill", "fill-color", f), n.setPaintProperty("rect-preview-fill", "fill-opacity", p));
4808
6178
  let m = n.getSource("rect-preview-measure-source");
4809
6179
  if (m) {
4810
- let e = En.current, t = [], n = c[0], r = c[1], i = c[2];
6180
+ let e = Nn.current, t = [], n = c[0], r = c[1], i = c[2];
4811
6181
  if (e?.showArea) {
4812
6182
  let e = [(n[0] + i[0]) / 2, (n[1] + i[1]) / 2], a = distance(n, r), o = distance(r, i);
4813
6183
  t.push({
@@ -4844,8 +6214,8 @@ const Mapbox = forwardRef((e, c) => {
4844
6214
  features: t
4845
6215
  });
4846
6216
  }
4847
- }, []), kt = useCallback(() => {
4848
- let e = F.current;
6217
+ }, []), It = useCallback(() => {
6218
+ let e = L.current;
4849
6219
  if (!e) return;
4850
6220
  let t = e.getSource("rect-preview-source");
4851
6221
  t && t.setData({
@@ -4857,10 +6227,10 @@ const Mapbox = forwardRef((e, c) => {
4857
6227
  type: "FeatureCollection",
4858
6228
  features: []
4859
6229
  });
4860
- }, []), X = useCallback(() => {
4861
- ot(null), kt();
4862
- }, [kt]), At = useCallback(() => {
4863
- let e = F.current;
6230
+ }, []), Z = useCallback(() => {
6231
+ st(null), It();
6232
+ }, [It]), Lt = useCallback(() => {
6233
+ let e = L.current;
4864
6234
  e && (e.getSource("circle-preview-source") || (e.addSource("circle-preview-source", {
4865
6235
  type: "geojson",
4866
6236
  data: {
@@ -4884,7 +6254,7 @@ const Mapbox = forwardRef((e, c) => {
4884
6254
  "line-width": 2,
4885
6255
  "line-dasharray": [4, 4]
4886
6256
  }
4887
- }), Et(e, "circle-preview-measure-source", "circle-preview-measure-label"), e.getSource("circle-preview-radius-source") || (e.addSource("circle-preview-radius-source", {
6257
+ }), Nt(e, "circle-preview-measure-source", "circle-preview-measure-label"), e.getSource("circle-preview-radius-source") || (e.addSource("circle-preview-radius-source", {
4888
6258
  type: "geojson",
4889
6259
  data: {
4890
6260
  type: "FeatureCollection",
@@ -4901,22 +6271,22 @@ const Mapbox = forwardRef((e, c) => {
4901
6271
  "line-dasharray": [4, 4]
4902
6272
  }
4903
6273
  }))));
4904
- }, [Et]), jt = useCallback((e, t, n = 64) => {
6274
+ }, [Nt]), Rt = useCallback((e, t, n = 64) => {
4905
6275
  let [r, i] = e, a = [], o = t / 6371e3, s = i * Math.PI / 180;
4906
6276
  for (let e = 0; e <= n; e++) {
4907
6277
  let t = e / n * 2 * Math.PI, c = o * Math.cos(t), l = o * Math.sin(t) / Math.cos(s), u = i + c * 180 / Math.PI, d = r + l * 180 / Math.PI;
4908
6278
  a.push([d, u]);
4909
6279
  }
4910
6280
  return a;
4911
- }, []), Mt = useCallback((e, t) => {
6281
+ }, []), zt = useCallback((e, t) => {
4912
6282
  let [n, r] = e, [i, a] = t, o = (a - r) * Math.PI / 180, s = (i - n) * Math.PI / 180, c = Math.sin(o / 2) * Math.sin(o / 2) + Math.cos(r * Math.PI / 180) * Math.cos(a * Math.PI / 180) * Math.sin(s / 2) * Math.sin(s / 2);
4913
6283
  return 6371e3 * (2 * Math.atan2(Math.sqrt(c), Math.sqrt(1 - c)));
4914
- }, []), Nt = useCallback((e, t) => {
4915
- let n = F.current;
6284
+ }, []), Bt = useCallback((e, t) => {
6285
+ let n = L.current;
4916
6286
  if (!n) return;
4917
6287
  let r = n.getSource("circle-preview-source");
4918
6288
  if (!r) return;
4919
- let i = Mt(e, t), a = jt(e, i);
6289
+ let i = zt(e, t), a = Rt(e, i);
4920
6290
  r.setData({
4921
6291
  type: "Feature",
4922
6292
  geometry: {
@@ -4925,9 +6295,9 @@ const Mapbox = forwardRef((e, c) => {
4925
6295
  },
4926
6296
  properties: {}
4927
6297
  });
4928
- let o = G.current, s = o?.strokeColor ?? "#3388ff", c = o?.strokeWidth ?? 2, l = o?.fillColor ?? "#3388ff", u = o?.fillOpacity ?? .1;
6298
+ let o = K.current, s = o?.strokeColor ?? "#3388ff", c = o?.strokeWidth ?? 2, l = o?.fillColor ?? "#3388ff", u = o?.fillOpacity ?? .1;
4929
6299
  n.getLayer("circle-preview-line") && (n.setPaintProperty("circle-preview-line", "line-color", s), n.setPaintProperty("circle-preview-line", "line-width", c)), n.getLayer("circle-preview-fill") && (n.setPaintProperty("circle-preview-fill", "fill-color", l), n.setPaintProperty("circle-preview-fill", "fill-opacity", u));
4930
- let d = En.current, f = [], p = [];
6300
+ let d = Nn.current, f = [], p = [];
4931
6301
  if (d?.showArea) {
4932
6302
  let t = Math.PI * i * i;
4933
6303
  f.push({
@@ -4940,7 +6310,7 @@ const Mapbox = forwardRef((e, c) => {
4940
6310
  });
4941
6311
  }
4942
6312
  if (d?.showRadius) {
4943
- let t = G.current?.radiusAngle ?? 90, n = destinationPoint(e, i, t), r = [(e[0] + n[0]) / 2, (e[1] + n[1]) / 2];
6313
+ let t = K.current?.radiusAngle ?? 90, n = destinationPoint(e, i, t), r = [(e[0] + n[0]) / 2, (e[1] + n[1]) / 2];
4944
6314
  p.push({
4945
6315
  type: "Feature",
4946
6316
  geometry: {
@@ -4967,8 +6337,8 @@ const Mapbox = forwardRef((e, c) => {
4967
6337
  type: "FeatureCollection",
4968
6338
  features: p
4969
6339
  });
4970
- }, [Mt, jt]), Pt = useCallback(() => {
4971
- let e = F.current;
6340
+ }, [zt, Rt]), Vt = useCallback(() => {
6341
+ let e = L.current;
4972
6342
  if (!e) return;
4973
6343
  let t = e.getSource("circle-preview-source");
4974
6344
  t && t.setData({
@@ -4985,10 +6355,10 @@ const Mapbox = forwardRef((e, c) => {
4985
6355
  type: "FeatureCollection",
4986
6356
  features: []
4987
6357
  });
4988
- }, []), Ft = useCallback(() => {
4989
- st.current = null, Pt();
4990
- }, [Pt]), It = useCallback(() => {
4991
- let e = F.current;
6358
+ }, []), Ht = useCallback(() => {
6359
+ lt.current = null, Vt();
6360
+ }, [Vt]), Ut = useCallback(() => {
6361
+ let e = L.current;
4992
6362
  e && (e.getSource("polygon-preview-source") || (e.addSource("polygon-preview-source", {
4993
6363
  type: "geojson",
4994
6364
  data: {
@@ -5028,9 +6398,9 @@ const Mapbox = forwardRef((e, c) => {
5028
6398
  "circle-stroke-color": "#ffffff",
5029
6399
  "circle-stroke-width": 2
5030
6400
  }
5031
- }), Et(e, "polygon-preview-measure-source", "polygon-preview-measure-label")));
5032
- }, [Et]), Lt = useCallback((e, t) => {
5033
- let n = F.current;
6401
+ }), Nt(e, "polygon-preview-measure-source", "polygon-preview-measure-label")));
6402
+ }, [Nt]), Wt = useCallback((e, t) => {
6403
+ let n = L.current;
5034
6404
  if (!n) return;
5035
6405
  let r = n.getSource("polygon-preview-source"), i = n.getSource("polygon-vertices-source");
5036
6406
  if (!r || !i) return;
@@ -5067,11 +6437,11 @@ const Mapbox = forwardRef((e, c) => {
5067
6437
  properties: {}
5068
6438
  }))
5069
6439
  });
5070
- let o = K.current, s = o?.strokeColor ?? "#3388ff", c = o?.strokeWidth ?? 2, l = o?.fillColor ?? "#3388ff", u = o?.fillOpacity ?? .1;
6440
+ let o = q.current, s = o?.strokeColor ?? "#3388ff", c = o?.strokeWidth ?? 2, l = o?.fillColor ?? "#3388ff", u = o?.fillOpacity ?? .1;
5071
6441
  n.getLayer("polygon-preview-line") && (n.setPaintProperty("polygon-preview-line", "line-color", s), n.setPaintProperty("polygon-preview-line", "line-width", c)), n.getLayer("polygon-preview-fill") && (n.setPaintProperty("polygon-preview-fill", "fill-color", l), n.setPaintProperty("polygon-preview-fill", "fill-opacity", u)), n.getLayer("polygon-vertices") && n.setPaintProperty("polygon-vertices", "circle-color", s);
5072
6442
  let d = n.getSource("polygon-preview-measure-source");
5073
6443
  if (d) {
5074
- let e = En.current, t = [];
6444
+ let e = Nn.current, t = [];
5075
6445
  if (e?.showArea && a.length >= 3) {
5076
6446
  let e = [...a, a[0]], n = polygonArea(e), r = 0, i = 0;
5077
6447
  for (let e of a) r += e[0], i += e[1];
@@ -5113,8 +6483,8 @@ const Mapbox = forwardRef((e, c) => {
5113
6483
  features: t
5114
6484
  });
5115
6485
  }
5116
- }, []), Rt = useCallback(() => {
5117
- let e = F.current;
6486
+ }, []), Gt = useCallback(() => {
6487
+ let e = L.current;
5118
6488
  if (!e) return;
5119
6489
  let t = e.getSource("polygon-preview-source");
5120
6490
  t && t.setData({
@@ -5131,10 +6501,10 @@ const Mapbox = forwardRef((e, c) => {
5131
6501
  type: "FeatureCollection",
5132
6502
  features: []
5133
6503
  });
5134
- }, []), zt = useCallback(() => {
5135
- ct.current = [], Rt();
5136
- }, [Rt]), Bt = useCallback(() => {
5137
- let e = F.current;
6504
+ }, []), Kt = useCallback(() => {
6505
+ ut.current = [], Gt();
6506
+ }, [Gt]), qt = useCallback(() => {
6507
+ let e = L.current;
5138
6508
  e && (e.getSource("square-preview-source") || (e.addSource("square-preview-source", {
5139
6509
  type: "geojson",
5140
6510
  data: {
@@ -5158,8 +6528,8 @@ const Mapbox = forwardRef((e, c) => {
5158
6528
  "line-width": 2,
5159
6529
  "line-dasharray": [4, 4]
5160
6530
  }
5161
- }), Et(e, "square-preview-measure-source", "square-preview-measure-label")));
5162
- }, [Et]), Vt = useCallback((e, t) => {
6531
+ }), Nt(e, "square-preview-measure-source", "square-preview-measure-label")));
6532
+ }, [Nt]), Jt = useCallback((e, t) => {
5163
6533
  let [n, r] = e, i = t / 2 / 6371e3, a = r * Math.PI / 180, o = i * 180 / Math.PI, s = i * 180 / Math.PI / Math.cos(a);
5164
6534
  return [
5165
6535
  [n - s, r + o],
@@ -5168,12 +6538,12 @@ const Mapbox = forwardRef((e, c) => {
5168
6538
  [n - s, r - o],
5169
6539
  [n - s, r + o]
5170
6540
  ];
5171
- }, []), Ht = useCallback((e, t) => {
5172
- let n = F.current;
6541
+ }, []), Yt = useCallback((e, t) => {
6542
+ let n = L.current;
5173
6543
  if (!n) return;
5174
6544
  let r = n.getSource("square-preview-source");
5175
6545
  if (!r) return;
5176
- let i = Mt(e, t) * 2, a = Vt(e, i);
6546
+ let i = zt(e, t) * 2, a = Jt(e, i);
5177
6547
  r.setData({
5178
6548
  type: "Feature",
5179
6549
  geometry: {
@@ -5182,11 +6552,11 @@ const Mapbox = forwardRef((e, c) => {
5182
6552
  },
5183
6553
  properties: {}
5184
6554
  });
5185
- let o = q.current, s = o?.strokeColor ?? "#3388ff", c = o?.strokeWidth ?? 2, l = o?.fillColor ?? "#3388ff", u = o?.fillOpacity ?? .1;
6555
+ let o = J.current, s = o?.strokeColor ?? "#3388ff", c = o?.strokeWidth ?? 2, l = o?.fillColor ?? "#3388ff", u = o?.fillOpacity ?? .1;
5186
6556
  n.getLayer("square-preview-line") && (n.setPaintProperty("square-preview-line", "line-color", s), n.setPaintProperty("square-preview-line", "line-width", c)), n.getLayer("square-preview-fill") && (n.setPaintProperty("square-preview-fill", "fill-color", l), n.setPaintProperty("square-preview-fill", "fill-opacity", u));
5187
6557
  let d = n.getSource("square-preview-measure-source");
5188
6558
  if (d) {
5189
- let t = En.current, n = [];
6559
+ let t = Nn.current, n = [];
5190
6560
  if (t?.showArea && n.push({
5191
6561
  type: "Feature",
5192
6562
  geometry: {
@@ -5210,8 +6580,8 @@ const Mapbox = forwardRef((e, c) => {
5210
6580
  features: n
5211
6581
  });
5212
6582
  }
5213
- }, [Mt, Vt]), Ut = useCallback(() => {
5214
- let e = F.current;
6583
+ }, [zt, Jt]), Xt = useCallback(() => {
6584
+ let e = L.current;
5215
6585
  if (!e) return;
5216
6586
  let t = e.getSource("square-preview-source");
5217
6587
  t && t.setData({
@@ -5223,10 +6593,10 @@ const Mapbox = forwardRef((e, c) => {
5223
6593
  type: "FeatureCollection",
5224
6594
  features: []
5225
6595
  });
5226
- }, []), Wt = useCallback(() => {
5227
- lt.current = null, Ut();
5228
- }, [Ut]), Gt = useCallback(() => {
5229
- let e = F.current;
6596
+ }, []), Zt = useCallback(() => {
6597
+ dt.current = null, Xt();
6598
+ }, [Xt]), Qt = useCallback(() => {
6599
+ let e = L.current;
5230
6600
  e && (e.getSource("polyline-preview-source") || (e.addSource("polyline-preview-source", {
5231
6601
  type: "geojson",
5232
6602
  data: {
@@ -5258,9 +6628,9 @@ const Mapbox = forwardRef((e, c) => {
5258
6628
  "circle-stroke-color": "#ffffff",
5259
6629
  "circle-stroke-width": 2
5260
6630
  }
5261
- }), Et(e, "polyline-preview-measure-source", "polyline-preview-measure-label")));
5262
- }, [Et]), Kt = useCallback((e, t) => {
5263
- let n = F.current;
6631
+ }), Nt(e, "polyline-preview-measure-source", "polyline-preview-measure-label")));
6632
+ }, [Nt]), $t = useCallback((e, t) => {
6633
+ let n = L.current;
5264
6634
  if (!n) return;
5265
6635
  let r = n.getSource("polyline-preview-source"), i = n.getSource("polyline-vertices-source");
5266
6636
  if (!r || !i) return;
@@ -5286,11 +6656,11 @@ const Mapbox = forwardRef((e, c) => {
5286
6656
  properties: {}
5287
6657
  }))
5288
6658
  });
5289
- let o = J.current, s = o?.strokeColor ?? "#3388ff", c = o?.strokeWidth ?? 2;
6659
+ let o = ft.current, s = o?.strokeColor ?? "#3388ff", c = o?.strokeWidth ?? 2;
5290
6660
  n.getLayer("polyline-preview-line") && (n.setPaintProperty("polyline-preview-line", "line-color", s), n.setPaintProperty("polyline-preview-line", "line-width", c)), n.getLayer("polyline-vertices") && n.setPaintProperty("polyline-vertices", "circle-color", s);
5291
6661
  let l = n.getSource("polyline-preview-measure-source");
5292
6662
  if (l) {
5293
- let e = En.current, t = [];
6663
+ let e = Nn.current, t = [];
5294
6664
  if (e?.showLength && a.length >= 2) for (let e = 0; e < a.length - 1; e++) {
5295
6665
  let n = a[e], r = a[e + 1], i = [(n[0] + r[0]) / 2, (n[1] + r[1]) / 2];
5296
6666
  t.push({
@@ -5307,8 +6677,8 @@ const Mapbox = forwardRef((e, c) => {
5307
6677
  features: t
5308
6678
  });
5309
6679
  }
5310
- }, []), qt = useCallback(() => {
5311
- let e = F.current;
6680
+ }, []), en = useCallback(() => {
6681
+ let e = L.current;
5312
6682
  if (!e) return;
5313
6683
  let t = e.getSource("polyline-preview-source");
5314
6684
  t && t.setData({
@@ -5325,150 +6695,159 @@ const Mapbox = forwardRef((e, c) => {
5325
6695
  type: "FeatureCollection",
5326
6696
  features: []
5327
6697
  });
5328
- }, []), Z = useCallback(() => {
5329
- ut.current = [], qt();
5330
- }, [qt]), Jt = useCallback((e) => {
5331
- B(e), Tt(e), e ? (V("marker"), X(), Ft(), zt(), Wt(), Z()) : V(null);
6698
+ }, []), Q = useCallback(() => {
6699
+ pt.current = [], en();
6700
+ }, [en]), tn = useCallback((e) => {
6701
+ H(e), Mt(e), e ? (U("marker"), Z(), Ht(), Kt(), Zt(), Q()) : U(null);
5332
6702
  }, [
5333
- Tt,
5334
- X,
5335
- Ft,
5336
- zt,
5337
- Wt,
5338
- Z
5339
- ]), Yt = useCallback((e) => {
5340
- if (V(e), e === "rectangle") {
5341
- B(null), Y(), Ft(), zt(), Wt(), Z();
5342
- let e = F.current;
6703
+ Mt,
6704
+ Z,
6705
+ Ht,
6706
+ Kt,
6707
+ Zt,
6708
+ Q
6709
+ ]), nn = useCallback((e) => {
6710
+ if (U(e), e === "rectangle") {
6711
+ H(null), X(), Ht(), Kt(), Zt(), Q();
6712
+ let e = L.current;
5343
6713
  e && (e.getCanvas().style.cursor = "crosshair");
5344
6714
  } else if (e === "circle") {
5345
- B(null), Y(), X(), zt(), Wt(), Z();
5346
- let e = F.current;
6715
+ H(null), X(), Z(), Kt(), Zt(), Q();
6716
+ let e = L.current;
5347
6717
  e && (e.getCanvas().style.cursor = "crosshair");
5348
6718
  } else if (e === "polygon") {
5349
- B(null), Y(), X(), Ft(), Wt(), Z();
5350
- let e = F.current;
6719
+ H(null), X(), Z(), Ht(), Zt(), Q();
6720
+ let e = L.current;
5351
6721
  e && (e.getCanvas().style.cursor = "crosshair");
5352
6722
  } else if (e === "square") {
5353
- B(null), Y(), X(), Ft(), zt(), Z();
5354
- let e = F.current;
6723
+ H(null), X(), Z(), Ht(), Kt(), Q();
6724
+ let e = L.current;
5355
6725
  e && (e.getCanvas().style.cursor = "crosshair");
5356
6726
  } else if (e === "polyline") {
5357
- B(null), Y(), X(), Ft(), zt(), Wt();
5358
- let e = F.current;
6727
+ H(null), X(), Z(), Ht(), Kt(), Zt();
6728
+ let e = L.current;
5359
6729
  e && (e.getCanvas().style.cursor = "crosshair");
5360
- } else e === "marker" ? (X(), Ft(), zt(), Wt(), Z()) : (B(null), Y(), X(), Ft(), zt(), Wt(), Z());
6730
+ } else e === "marker" ? (Z(), Ht(), Kt(), Zt(), Q()) : (H(null), X(), Z(), Ht(), Kt(), Zt(), Q());
5361
6731
  }, [
5362
- Y,
5363
6732
  X,
5364
- Ft,
5365
- zt,
5366
- Wt,
5367
- Z
5368
- ]), Xt = useCallback((e) => {
6733
+ Z,
6734
+ Ht,
6735
+ Kt,
6736
+ Zt,
6737
+ Q
6738
+ ]), rn = useCallback((e) => {
5369
6739
  if (e !== "picker") {
5370
6740
  let e = y.value && isFinite(y.value.lng) && isFinite(y.value.lat), t = y.showMarker !== !1;
5371
- (!e || !t) && Ct(), tt(null);
6741
+ (!e || !t) && At(), nt(null);
5372
6742
  }
5373
- e !== "edit" && (B(null), V(null), X(), Z(), Y()), $e(e);
6743
+ e !== "edit" && (H(null), U(null), Z(), Q(), X()), et(e);
5374
6744
  }, [
5375
- Ct,
5376
- Y,
6745
+ At,
5377
6746
  X,
5378
- Z
5379
- ]), Zt = useCallback(() => z, [z]), Qt = useCallback(() => et, [et]), $t = useCallback(() => {
5380
- Ct(), tt(null);
5381
- }, [Ct]);
6747
+ Z,
6748
+ Q
6749
+ ]), an = useCallback(() => $e, [$e]), on = useCallback(() => tt, [tt]), sn = useCallback(() => {
6750
+ At(), nt(null);
6751
+ }, [At]);
5382
6752
  useEffect(() => {
5383
- if (!Ze) return;
6753
+ if (!V) return;
5384
6754
  let e = y.value;
5385
6755
  if (e && isFinite(e.lng) && isFinite(e.lat)) {
5386
6756
  let t = [e.lng, e.lat];
5387
- tt(e), St(t);
6757
+ nt(e), kt(t);
5388
6758
  }
5389
6759
  }, [
5390
6760
  y.value,
5391
- St,
5392
- Ze
6761
+ kt,
6762
+ V
5393
6763
  ]);
5394
- let en = (e) => "mode" in e, tn = useCallback((e) => {
5395
- if ($e("edit"), Ct(), tt(null), H.current = !0, en(e)) {
5396
- if (e.mode === "marker") e.markerStyle ? (W.current = e.markerStyle, U.current = null, G.current = null, K.current = null, q.current = null, J.current = null, B(null), V("marker"), e.markerStyle.src && e.markerStyle.width ? Tt({
6764
+ let cn = (e) => "mode" in e, ln = useCallback((e) => {
6765
+ if (et("edit"), At(), nt(null), W.current = !0, cn(e)) {
6766
+ if (e.mode === "marker") e.markerStyle ? (ct.current = e.markerStyle, G.current = null, K.current = null, q.current = null, J.current = null, ft.current = null, H(null), U("marker"), e.markerStyle.src && e.markerStyle.width ? Mt({
5397
6767
  id: "custom",
5398
6768
  name: e.markerStyle.name || "Marker",
5399
6769
  icon: e.markerStyle.src,
5400
6770
  width: e.markerStyle.width
5401
- }) : Y()) : e.template && (W.current = null, U.current = null, G.current = null, K.current = null, q.current = null, J.current = null, B(e.template), V("marker"), Tt(e.template));
6771
+ }) : X()) : e.template && (ct.current = null, G.current = null, K.current = null, q.current = null, J.current = null, ft.current = null, H(e.template), U("marker"), Mt(e.template));
5402
6772
  else if (e.mode === "rectangle") {
5403
- U.current = e.rectangleStyle || null, W.current = null, G.current = null, K.current = null, q.current = null, J.current = null, B(null), V("rectangle"), Y();
5404
- let t = F.current;
6773
+ G.current = e.rectangleStyle || null, ct.current = null, K.current = null, q.current = null, J.current = null, ft.current = null, H(null), U("rectangle"), X();
6774
+ let t = L.current;
5405
6775
  t && (t.getCanvas().style.cursor = "crosshair");
5406
6776
  } else if (e.mode === "circle") {
5407
- G.current = e.circleStyle || null, U.current = null, W.current = null, K.current = null, q.current = null, J.current = null, B(null), V("circle"), Y();
5408
- let t = F.current;
6777
+ K.current = e.circleStyle || null, G.current = null, ct.current = null, q.current = null, J.current = null, ft.current = null, H(null), U("circle"), X();
6778
+ let t = L.current;
5409
6779
  t && (t.getCanvas().style.cursor = "crosshair");
5410
6780
  } else if (e.mode === "polygon") {
5411
- K.current = e.polygonStyle || null, U.current = null, W.current = null, G.current = null, q.current = null, J.current = null, B(null), V("polygon"), Y();
5412
- let t = F.current;
6781
+ q.current = e.polygonStyle || null, G.current = null, ct.current = null, K.current = null, J.current = null, ft.current = null, H(null), U("polygon"), X();
6782
+ let t = L.current;
5413
6783
  t && (t.getCanvas().style.cursor = "crosshair");
5414
6784
  } else if (e.mode === "square") {
5415
- q.current = e.squareStyle || null, U.current = null, W.current = null, G.current = null, K.current = null, J.current = null, B(null), V("square"), Y();
5416
- let t = F.current;
6785
+ J.current = e.squareStyle || null, G.current = null, ct.current = null, K.current = null, q.current = null, ft.current = null, H(null), U("square"), X();
6786
+ let t = L.current;
5417
6787
  t && (t.getCanvas().style.cursor = "crosshair");
5418
6788
  } else if (e.mode === "polyline") {
5419
- J.current = e.polylineStyle || null, U.current = null, W.current = null, G.current = null, K.current = null, q.current = null, B(null), V("polyline"), Y();
5420
- let t = F.current;
6789
+ ft.current = e.polylineStyle || null, G.current = null, ct.current = null, K.current = null, q.current = null, J.current = null, H(null), U("polyline"), X();
6790
+ let t = L.current;
5421
6791
  t && (t.getCanvas().style.cursor = "crosshair");
5422
6792
  }
5423
- } else B(e), V("marker"), Tt(e), U.current = null, W.current = null, G.current = null, K.current = null, q.current = null, J.current = null;
6793
+ } else H(e), U("marker"), Mt(e), G.current = null, ct.current = null, K.current = null, q.current = null, J.current = null, ft.current = null;
5424
6794
  }, [
5425
- Ct,
5426
- Tt,
5427
- Y
6795
+ At,
6796
+ Mt,
6797
+ X
5428
6798
  ]);
5429
6799
  useImperativeHandle(c, () => ({
5430
- startAnimation: ft,
5431
- stopAnimation: pt,
5432
- toggleAnimation: mt,
5433
- getMap: () => F.current,
5434
- openPopup: (e) => gt(e, "programmatic"),
5435
- closePopup: _t,
5436
- closeAllPopups: vt,
5437
- isPopupOpen: yt,
5438
- toggleUnitTrajectory: ht,
5439
- flyTo: bt,
5440
- flyToEntities: xt,
5441
- getMode: Zt,
5442
- setMode: Xt,
5443
- getPickedLocation: Qt,
5444
- clearPickedLocation: $t,
5445
- startDrawing: tn,
5446
- getRenderer: (e) => I.current.get(e)
6800
+ startAnimation: yt,
6801
+ stopAnimation: bt,
6802
+ toggleAnimation: xt,
6803
+ getMap: () => L.current,
6804
+ openPopup: (e) => Ct(e, "programmatic"),
6805
+ closePopup: wt,
6806
+ closeAllPopups: Tt,
6807
+ isPopupOpen: Et,
6808
+ toggleUnitTrajectory: St,
6809
+ flyTo: Dt,
6810
+ flyToEntities: Ot,
6811
+ getMode: an,
6812
+ setMode: rn,
6813
+ getPickedLocation: on,
6814
+ clearPickedLocation: sn,
6815
+ startDrawing: ln,
6816
+ getRenderer: (e) => R.current.get(e),
6817
+ setEditingEntities: (e) => {
6818
+ for (let t of vt.current) e.map(String).includes(String(t)) || R.current.get(t)?.setEditing?.(!1);
6819
+ for (let t of e) R.current.get(t)?.setEditing?.(!0);
6820
+ Y.current &&= (R.current.get(Y.current.entityId)?.cancelEditPreview?.(), null), _t(e);
6821
+ },
6822
+ getEditingEntities: () => vt.current,
6823
+ startRoutePlanning: (e) => {
6824
+ He.current?.startPlanning(e);
6825
+ }
5447
6826
  }), [
5448
- ft,
5449
- pt,
5450
- mt,
5451
- gt,
5452
- _t,
5453
- vt,
5454
6827
  yt,
5455
- ht,
5456
6828
  bt,
5457
6829
  xt,
5458
- Zt,
5459
- Xt,
5460
- Qt,
5461
- $t,
5462
- tn
6830
+ Ct,
6831
+ wt,
6832
+ Tt,
6833
+ Et,
6834
+ St,
6835
+ Dt,
6836
+ Ot,
6837
+ an,
6838
+ rn,
6839
+ on,
6840
+ sn,
6841
+ ln
5463
6842
  ]);
5464
- let nn = useCallback(() => {
5465
- let e = F.current;
6843
+ let un = useCallback(() => {
6844
+ let e = L.current;
5466
6845
  if (!e) return;
5467
- let t = new Set(E.map((e) => e.id)), n = new Set(I.current.keys());
5468
- for (let e of n) t.has(e) || (I.current.get(e)?.destroy(), I.current.delete(e));
6846
+ let t = new Set(E.map((e) => e.id)), n = new Set(R.current.keys());
6847
+ for (let e of n) t.has(e) || (R.current.get(e)?.destroy(), R.current.delete(e));
5469
6848
  let r = new Set(D.map(String));
5470
6849
  for (let t of E) {
5471
- let n = applyEntityConfig(t, O), i = I.current.get(n.id);
6850
+ let n = applyEntityConfig(t, O), i = R.current.get(n.id);
5472
6851
  if (i) if (n.type === "radar" && i instanceof CanvasRadarRenderer) i.update(n);
5473
6852
  else if (n.type === "image" && i instanceof CanvasImageRenderer) i.update(n);
5474
6853
  else if (n.type === "marker" && i instanceof MarkerRenderer) i.update(n);
@@ -5478,20 +6857,24 @@ const Mapbox = forwardRef((e, c) => {
5478
6857
  else {
5479
6858
  i.destroy();
5480
6859
  let t = new CanvasCircleRenderer(e, n, k, A, j, M);
5481
- I.current.set(n.id, t), t.setSelected(r.has(String(n.id)));
6860
+ R.current.set(n.id, t), t.setSelected(r.has(String(n.id)));
5482
6861
  }
5483
6862
  else if (i instanceof CircleRenderer) i.update(n);
5484
6863
  else {
5485
6864
  i.destroy();
5486
6865
  let t = new CircleRenderer(e, n, k, A, j, M);
5487
- I.current.set(n.id, t), t.setSelected(r.has(String(n.id)));
6866
+ R.current.set(n.id, t), t.setSelected(r.has(String(n.id)));
5488
6867
  }
5489
6868
  else (n.type === "square" && i instanceof SquareRenderer || n.type === "rectangle" && i instanceof RectangleRenderer || n.type === "polyline" && i instanceof PolylineRenderer) && i.update(n);
5490
6869
  else {
5491
6870
  let t = null;
5492
- n.type === "radar" ? t = new CanvasRadarRenderer(e, n, k, A) : n.type === "image" ? t = new CanvasImageRenderer(e, n, k, A) : n.type === "marker" ? t = new MarkerRenderer(e, n, k, A) : n.type === "unit" ? t = new UnitRenderer(e, n, k, A) : n.type === "polygon" ? t = new PolygonRenderer(e, n, k, A, j, N) : n.type === "circle" ? t = n.fillType === "radial-gradient" ? new CanvasCircleRenderer(e, n, k, A, j, M) : new CircleRenderer(e, n, k, A, j, M) : n.type === "square" ? t = new SquareRenderer(e, n, k, A, j, N) : n.type === "rectangle" ? t = new RectangleRenderer(e, n, k, A, j, N) : n.type === "polyline" && (t = new PolylineRenderer(e, n, k, A, N)), t && (I.current.set(n.id, t), t.setSelected(r.has(String(n.id))));
6871
+ n.type === "radar" ? t = new CanvasRadarRenderer(e, n, k, A) : n.type === "image" ? t = new CanvasImageRenderer(e, n, k, A) : n.type === "marker" ? t = new MarkerRenderer(e, n, k, A) : n.type === "unit" ? t = new UnitRenderer(e, n, k, A) : n.type === "polygon" ? t = new PolygonRenderer(e, n, k, A, j, N) : n.type === "circle" ? t = n.fillType === "radial-gradient" ? new CanvasCircleRenderer(e, n, k, A, j, M) : new CircleRenderer(e, n, k, A, j, M) : n.type === "square" ? t = new SquareRenderer(e, n, k, A, j, N) : n.type === "rectangle" ? t = new RectangleRenderer(e, n, k, A, j, N) : n.type === "polyline" && (t = new PolylineRenderer(e, n, k, A, N)), t && (R.current.set(n.id, t), t.setSelected(r.has(String(n.id))), vt.current.map(String).includes(String(n.id)) && t.setEditing?.(!0));
5493
6872
  }
5494
6873
  }
6874
+ for (let e of vt.current) {
6875
+ let t = R.current.get(e);
6876
+ t && t.setEditing?.(!0);
6877
+ }
5495
6878
  }, [
5496
6879
  E,
5497
6880
  D,
@@ -5501,10 +6884,10 @@ const Mapbox = forwardRef((e, c) => {
5501
6884
  j,
5502
6885
  M,
5503
6886
  N
5504
- ]), rn = useCallback(() => {
5505
- for (let e of I.current.values()) e.destroy();
5506
- I.current.clear();
5507
- }, []), an = useCallback((e) => {
6887
+ ]), dn = useCallback(() => {
6888
+ for (let e of R.current.values()) e.destroy();
6889
+ R.current.clear();
6890
+ }, []), fn = useCallback((e) => {
5508
6891
  let t = e.getStyle();
5509
6892
  if (!t?.layers) return;
5510
6893
  let n = [
@@ -5519,10 +6902,10 @@ const Mapbox = forwardRef((e, c) => {
5519
6902
  "marker-"
5520
6903
  ];
5521
6904
  for (let e of t.layers) if (n.some((t) => e.id.startsWith(t))) return e.id;
5522
- }, []), on = useCallback((e) => {
6905
+ }, []), pn = useCallback((e) => {
5523
6906
  let t = T, n = { "raster-opacity": e.opacity ?? 1 }, r = e.brightness ?? t?.brightness, i = e.saturation ?? t?.saturation, a = e.contrast ?? t?.contrast, o = e.hueRotate ?? t?.hueRotate;
5524
6907
  return r !== void 0 && (n["raster-brightness-min"] = 0, n["raster-brightness-max"] = r), i !== void 0 && (n["raster-saturation"] = i), a !== void 0 && (n["raster-contrast"] = a), o !== void 0 && (n["raster-hue-rotate"] = o), n;
5525
- }, [T]), sn = useCallback((e, t) => {
6908
+ }, [T]), mn = useCallback((e, t) => {
5526
6909
  let n = `base-layer-source-${t.id}`, r = `base-layer-${t.id}`, i = {
5527
6910
  type: "raster",
5528
6911
  tiles: [t.url],
@@ -5532,19 +6915,19 @@ const Mapbox = forwardRef((e, c) => {
5532
6915
  scheme: t.scheme ?? "xyz"
5533
6916
  };
5534
6917
  t.bounds && (i.bounds = t.bounds), t.attribution && (i.attribution = t.attribution), e.addSource(n, i);
5535
- let a = an(e);
6918
+ let a = fn(e);
5536
6919
  e.addLayer({
5537
6920
  id: r,
5538
6921
  type: "raster",
5539
6922
  source: n,
5540
- paint: on(t),
6923
+ paint: pn(t),
5541
6924
  layout: { visibility: t.visible === !1 ? "none" : "visible" }
5542
6925
  }, a);
5543
- }, [an, on]), cn = useCallback(async (e, t) => {
6926
+ }, [fn, pn]), hn = useCallback(async (e, t) => {
5544
6927
  try {
5545
6928
  let n = await (await fetch(t.url)).json(), r = `base-layer-source-${t.id}`, i = `base-layer-${t.id}`;
5546
- if (!He.current.has(t.id)) return;
5547
- let a = n.format === "pbf" || n.vector_layers, o = an(e);
6929
+ if (!Ue.current.has(t.id)) return;
6930
+ let a = n.format === "pbf" || n.vector_layers, o = fn(e);
5548
6931
  a ? (e.addSource(r, {
5549
6932
  type: "vector",
5550
6933
  tiles: n.tiles,
@@ -5564,21 +6947,21 @@ const Mapbox = forwardRef((e, c) => {
5564
6947
  id: i,
5565
6948
  type: "raster",
5566
6949
  source: r,
5567
- paint: on(t),
6950
+ paint: pn(t),
5568
6951
  layout: { visibility: t.visible === !1 ? "none" : "visible" }
5569
6952
  }, o));
5570
6953
  } catch (e) {
5571
6954
  console.error(`Failed to load TileJSON from ${t.url}:`, e);
5572
6955
  }
5573
- }, [an, on]), ln = useCallback(async (e, t) => {
6956
+ }, [fn, pn]), gn = useCallback(async (e, t) => {
5574
6957
  try {
5575
6958
  let n = await (await fetch(t.url)).json();
5576
- if (!He.current.has(t.id)) return;
6959
+ if (!Ue.current.has(t.id)) return;
5577
6960
  if (n.sources) for (let [r, i] of Object.entries(n.sources)) {
5578
6961
  let n = `base-layer-source-${t.id}-${r}`;
5579
6962
  e.getSource(n) || e.addSource(n, i);
5580
6963
  }
5581
- let r = an(e);
6964
+ let r = fn(e);
5582
6965
  if (n.layers) for (let i of n.layers) {
5583
6966
  let n = `base-layer-${t.id}-${i.id}`;
5584
6967
  if (e.getLayer(n)) continue;
@@ -5589,7 +6972,7 @@ const Mapbox = forwardRef((e, c) => {
5589
6972
  };
5590
6973
  i.type === "raster" && (a.paint = {
5591
6974
  ...a.paint,
5592
- ...on(t)
6975
+ ...pn(t)
5593
6976
  }), t.visible === !1 && (a.layout = {
5594
6977
  ...a.layout,
5595
6978
  visibility: "none"
@@ -5602,50 +6985,50 @@ const Mapbox = forwardRef((e, c) => {
5602
6985
  } catch (e) {
5603
6986
  console.error(`Failed to load Style JSON from ${t.url}:`, e);
5604
6987
  }
5605
- }, [an, on]), un = useCallback((e, t) => {
6988
+ }, [fn, pn]), _n = useCallback((e, t) => {
5606
6989
  let n = e.getStyle();
5607
6990
  if (!n) return;
5608
6991
  let r = `base-layer-${t}`, i = n.layers?.filter((e) => e.id.startsWith(r)) ?? [];
5609
6992
  for (let t of i) e.getLayer(t.id) && e.removeLayer(t.id);
5610
6993
  let a = `base-layer-source-${t}`, o = n.sources ?? {};
5611
6994
  for (let t of Object.keys(o)) t.startsWith(a) && e.getSource(t) && e.removeSource(t);
5612
- }, []), dn = useCallback((e) => {
5613
- let t = F.current;
6995
+ }, []), vn = useCallback((e) => {
6996
+ let t = L.current;
5614
6997
  if (!t) return;
5615
- let n = new Set(e.map((e) => e.id)), r = He.current;
5616
- for (let e of r) n.has(e) || (un(t, e), r.delete(e));
6998
+ let n = new Set(e.map((e) => e.id)), r = Ue.current;
6999
+ for (let e of r) n.has(e) || (_n(t, e), r.delete(e));
5617
7000
  for (let n of e) if (r.has(n.id)) {
5618
7001
  let e = `base-layer-${n.id}`;
5619
7002
  if (t.getLayer(e)) {
5620
- let r = on(n);
7003
+ let r = pn(n);
5621
7004
  for (let [n, i] of Object.entries(r)) t.setPaintProperty(e, n, i);
5622
7005
  t.setLayoutProperty(e, "visibility", n.visible === !1 ? "none" : "visible");
5623
7006
  }
5624
7007
  } else switch (r.add(n.id), n.type) {
5625
7008
  case "raster":
5626
- sn(t, n);
7009
+ mn(t, n);
5627
7010
  break;
5628
7011
  case "tilejson":
5629
- cn(t, n);
7012
+ hn(t, n);
5630
7013
  break;
5631
7014
  case "style":
5632
- ln(t, n);
7015
+ gn(t, n);
5633
7016
  break;
5634
7017
  default: {
5635
7018
  let e = n;
5636
- e.url && sn(t, {
7019
+ e.url && mn(t, {
5637
7020
  ...e,
5638
7021
  type: "raster"
5639
7022
  });
5640
7023
  }
5641
7024
  }
5642
7025
  }, [
5643
- sn,
5644
- cn,
5645
- ln,
5646
- un,
5647
- on
5648
- ]), fn = useCallback((e) => {
7026
+ mn,
7027
+ hn,
7028
+ gn,
7029
+ _n,
7030
+ pn
7031
+ ]), yn = useCallback((e) => {
5649
7032
  let t = e;
5650
7033
  for (; t;) {
5651
7034
  let e = t.getAttribute?.("data-entity-id");
@@ -5653,293 +7036,353 @@ const Mapbox = forwardRef((e, c) => {
5653
7036
  t = t.parentElement;
5654
7037
  }
5655
7038
  return null;
5656
- }, []), pn = useCallback((e) => {
7039
+ }, []), bn = useCallback((e) => {
5657
7040
  let t = [e.lngLat.lng, e.lngLat.lat], n = {
5658
7041
  x: e.point.x,
5659
7042
  y: e.point.y
5660
- }, r = xn.current;
7043
+ }, r = On.current;
5661
7044
  if (r === "picker") {
5662
7045
  let e = {
5663
7046
  lng: t[0],
5664
7047
  lat: t[1]
5665
7048
  };
5666
- tt(e), St(t), Sn.current?.(e);
7049
+ nt(e), kt(t), kn.current?.(e);
5667
7050
  return;
5668
7051
  }
7052
+ if (ht.current) return;
5669
7053
  if (r === "edit") {
5670
- let e = wn.current;
7054
+ let e = jn.current;
5671
7055
  if (e === "rectangle") {
5672
- let e = Tn.current;
5673
- if (!e) ot(t);
7056
+ let e = Mn.current;
7057
+ if (!e) st(t);
5674
7058
  else {
5675
- let n = U.current, r = applyEntityConfig({
7059
+ let n = G.current, r = applyEntityConfig({
5676
7060
  ...n,
5677
- id: n?.id ?? wt(),
7061
+ id: n?.id ?? jt(),
5678
7062
  type: "rectangle",
5679
7063
  bounds: [e, t]
5680
7064
  }, O);
5681
- kt();
5682
- let i = F.current;
5683
- if (i && !I.current.has(r.id)) {
7065
+ It();
7066
+ let i = L.current;
7067
+ if (i && !R.current.has(r.id)) {
5684
7068
  let e = new RectangleRenderer(i, r, k, A, j, N);
5685
- I.current.set(r.id, e);
7069
+ R.current.set(r.id, e);
5686
7070
  }
5687
- Q.current.onRectangleAdd?.(r), ot(null), U.current = null, H.current && (H.current = !1, V(null), i && (i.getCanvas().style.cursor = ""));
7071
+ $.current.onRectangleAdd?.(r), st(null), G.current = null, W.current && (W.current = !1, U(null), i && (i.getCanvas().style.cursor = ""));
5688
7072
  }
5689
7073
  return;
5690
7074
  }
5691
7075
  if (e === "circle") {
5692
- let e = st.current;
5693
- if (!e) st.current = { center: t };
7076
+ let e = lt.current;
7077
+ if (!e) lt.current = { center: t };
5694
7078
  else {
5695
- let n = Mt(e.center, t), r = G.current, i = applyEntityConfig({
7079
+ let n = zt(e.center, t), r = K.current, i = applyEntityConfig({
5696
7080
  ...r,
5697
- id: r?.id ?? wt(),
7081
+ id: r?.id ?? jt(),
5698
7082
  type: "circle",
5699
7083
  center: e.center,
5700
7084
  radius: n
5701
7085
  }, O);
5702
- Pt();
5703
- let a = F.current;
5704
- if (a && !I.current.has(i.id)) {
7086
+ Vt();
7087
+ let a = L.current;
7088
+ if (a && !R.current.has(i.id)) {
5705
7089
  let e = new CircleRenderer(a, i, k, A, j, M);
5706
- I.current.set(i.id, e);
7090
+ R.current.set(i.id, e);
5707
7091
  }
5708
- Q.current.onCircleAdd?.(i), st.current = null, G.current = null, H.current && (H.current = !1, V(null), a && (a.getCanvas().style.cursor = ""));
7092
+ $.current.onCircleAdd?.(i), lt.current = null, K.current = null, W.current && (W.current = !1, U(null), a && (a.getCanvas().style.cursor = ""));
5709
7093
  }
5710
7094
  return;
5711
7095
  }
5712
7096
  if (e === "polygon") {
5713
- let e = ct.current;
7097
+ let e = ut.current;
5714
7098
  if (e.length >= 3) {
5715
7099
  let n = e[0];
5716
- if (Mt(n, t) < 20) {
5717
- let t = K.current, n = applyEntityConfig({
7100
+ if (zt(n, t) < 20) {
7101
+ let t = q.current, n = applyEntityConfig({
5718
7102
  ...t,
5719
- id: t?.id ?? wt(),
7103
+ id: t?.id ?? jt(),
5720
7104
  type: "polygon",
5721
7105
  coordinates: [...e]
5722
7106
  }, O);
5723
- Rt();
5724
- let r = F.current;
5725
- if (r && !I.current.has(n.id)) {
7107
+ Gt();
7108
+ let r = L.current;
7109
+ if (r && !R.current.has(n.id)) {
5726
7110
  let e = new PolygonRenderer(r, n, k, A, j, N);
5727
- I.current.set(n.id, e);
7111
+ R.current.set(n.id, e);
5728
7112
  }
5729
- Q.current.onPolygonAdd?.(n), ct.current = [], K.current = null, H.current && (H.current = !1, V(null), r && (r.getCanvas().style.cursor = ""));
7113
+ $.current.onPolygonAdd?.(n), ut.current = [], q.current = null, W.current && (W.current = !1, U(null), r && (r.getCanvas().style.cursor = ""));
5730
7114
  return;
5731
7115
  }
5732
7116
  }
5733
- ct.current = [...e, t];
7117
+ ut.current = [...e, t];
5734
7118
  return;
5735
7119
  }
5736
7120
  if (e === "square") {
5737
- let e = lt.current;
5738
- if (!e) lt.current = { center: t };
7121
+ let e = dt.current;
7122
+ if (!e) dt.current = { center: t };
5739
7123
  else {
5740
- let n = Mt(e.center, t) * 2, r = q.current, i = applyEntityConfig({
7124
+ let n = zt(e.center, t) * 2, r = J.current, i = applyEntityConfig({
5741
7125
  ...r,
5742
- id: r?.id ?? wt(),
7126
+ id: r?.id ?? jt(),
5743
7127
  type: "square",
5744
7128
  center: e.center,
5745
7129
  length: n
5746
7130
  }, O);
5747
- Ut();
5748
- let a = F.current;
5749
- if (a && !I.current.has(i.id)) {
7131
+ Xt();
7132
+ let a = L.current;
7133
+ if (a && !R.current.has(i.id)) {
5750
7134
  let e = new SquareRenderer(a, i, k, A, j, N);
5751
- I.current.set(i.id, e);
7135
+ R.current.set(i.id, e);
5752
7136
  }
5753
- Q.current.onSquareAdd?.(i), lt.current = null, q.current = null, H.current && (H.current = !1, V(null), a && (a.getCanvas().style.cursor = ""));
7137
+ $.current.onSquareAdd?.(i), dt.current = null, J.current = null, W.current && (W.current = !1, U(null), a && (a.getCanvas().style.cursor = ""));
5754
7138
  }
5755
7139
  return;
5756
7140
  }
5757
7141
  if (e === "polyline") {
5758
- ut.current = [...ut.current, t];
7142
+ pt.current = [...pt.current, t];
5759
7143
  return;
5760
7144
  }
5761
- let n = W.current;
7145
+ let n = ct.current;
5762
7146
  if (n && n.src && n.width) {
5763
7147
  let e = {
5764
7148
  ...n,
5765
- id: n.id ?? wt(),
7149
+ id: n.id ?? jt(),
5766
7150
  type: "marker",
5767
7151
  center: t,
5768
7152
  src: n.src,
5769
7153
  width: n.width
5770
7154
  };
5771
- Q.current.onMarkerAdd?.(e), B(null), V(null), Y(), W.current = null, H.current = !1;
7155
+ $.current.onMarkerAdd?.(e), H(null), U(null), X(), ct.current = null, W.current = !1;
5772
7156
  return;
5773
7157
  }
5774
- let r = Cn.current;
7158
+ let r = An.current;
5775
7159
  if (r) {
5776
7160
  let e = {
5777
- id: wt(),
7161
+ id: jt(),
5778
7162
  type: "marker",
5779
7163
  name: r.name,
5780
7164
  center: t,
5781
7165
  src: r.icon,
5782
7166
  width: r.size || r.width || 32
5783
7167
  };
5784
- r.customData !== void 0 && (e.customData = r.customData), Q.current.onMarkerAdd?.(e), B(null), V(null), Y(), H.current = !1;
7168
+ r.customData !== void 0 && (e.customData = r.customData), $.current.onMarkerAdd?.(e), H(null), U(null), X(), W.current = !1;
7169
+ return;
7170
+ }
7171
+ }
7172
+ if (vt.current.length > 0) {
7173
+ let e = L.current?.getZoom() ?? 12;
7174
+ if (Y.current) {
7175
+ let { entityId: e, activeHandle: n } = Y.current, r = R.current.get(e);
7176
+ if (r?.applyHandleMove) {
7177
+ let e = r.applyHandleMove(n, t);
7178
+ $.current.onEntityEdit?.(e);
7179
+ }
7180
+ Y.current = null;
5785
7181
  return;
5786
7182
  }
7183
+ for (let n of vt.current) {
7184
+ let r = R.current.get(n);
7185
+ if (!r?.getEditHandleAt) continue;
7186
+ let i = r.getEditHandleAt(t, e);
7187
+ if (i) {
7188
+ if (i.type === "midpoint" && r.addVertex) {
7189
+ let e = r.addVertex(i.index, i.position);
7190
+ $.current.onEntityEdit?.(e), Y.current = {
7191
+ entityId: n,
7192
+ activeHandle: {
7193
+ type: "vertex",
7194
+ index: i.index + 1,
7195
+ position: i.position
7196
+ }
7197
+ };
7198
+ } else Y.current = {
7199
+ entityId: n,
7200
+ activeHandle: i
7201
+ };
7202
+ return;
7203
+ }
7204
+ }
5787
7205
  }
5788
- let i = vn.current, a = yn.current, o = bn.current, s = fn(e.originalEvent.target);
7206
+ let i = Tn.current, a = En.current, o = Dn.current, s = yn(e.originalEvent.target);
5789
7207
  if (s) {
5790
7208
  let e = i.find((e) => String(e.id) === s);
5791
7209
  if (e) {
5792
7210
  if (a?.(e), e.popup) {
5793
7211
  let t = e.popup.content ?? Pe?.(e);
5794
- t && mergePopupConfig(e.popup, P, t).trigger === "click" && o(s, "click", n);
7212
+ t && mergePopupConfig(e.popup, I, t).trigger === "click" && o(s, "click", n);
5795
7213
  }
5796
7214
  return;
5797
7215
  }
5798
7216
  }
5799
- for (let [t, r] of I.current) {
7217
+ for (let [t, r] of R.current) {
5800
7218
  let s = r.getLabelLayerId();
5801
- if (s && F.current?.getLayer(s) && F.current.queryRenderedFeatures(e.point, { layers: [s] }).length > 0) {
7219
+ if (s && L.current?.getLayer(s) && L.current.queryRenderedFeatures(e.point, { layers: [s] }).length > 0) {
5802
7220
  let e = i.find((e) => e.id === t);
5803
7221
  if (e) {
5804
7222
  if (a?.(e), e.popup) {
5805
7223
  let r = e.popup.content ?? Pe?.(e);
5806
- r && mergePopupConfig(e.popup, P, r).trigger === "click" && o(t, "click", n);
7224
+ r && mergePopupConfig(e.popup, I, r).trigger === "click" && o(t, "click", n);
5807
7225
  }
5808
7226
  return;
5809
7227
  }
5810
7228
  }
5811
7229
  }
5812
- for (let [e, r] of I.current) if (r.isPointInEntity(t)) {
7230
+ for (let [e, r] of R.current) if (r.isPointInEntity(t)) {
5813
7231
  let t = i.find((t) => t.id === e);
5814
7232
  if (t) {
5815
7233
  if (a?.(t), t.popup) {
5816
7234
  let r = t.popup.content ?? Pe?.(t);
5817
- r && mergePopupConfig(t.popup, P, r).trigger === "click" && o(e, "click", n);
7235
+ r && mergePopupConfig(t.popup, I, r).trigger === "click" && o(e, "click", n);
5818
7236
  }
5819
7237
  return;
5820
7238
  }
5821
7239
  }
5822
7240
  }, [
5823
- P,
7241
+ I,
5824
7242
  Pe,
5825
- fn
5826
- ]), mn = useCallback((e) => {
5827
- let t = [e.lngLat.lng, e.lngLat.lat], n = wn.current, r = Tn.current;
5828
- n === "rectangle" && r && Ot(r, t);
5829
- let i = st.current;
5830
- n === "circle" && i && Nt(i.center, t);
5831
- let a = ct.current;
5832
- n === "polygon" && a.length > 0 && Lt(a, t);
5833
- let o = lt.current;
5834
- n === "square" && o && Ht(o.center, t);
5835
- let s = ut.current;
5836
- n === "polyline" && s.length > 0 && Kt(s, t);
5837
- let c = vn.current, l = bn.current;
5838
- for (let [e, n] of I.current) if (n.isPointInEntity(t)) {
7243
+ yn
7244
+ ]), xn = useCallback((e) => {
7245
+ let t = [e.lngLat.lng, e.lngLat.lat];
7246
+ if (Y.current) {
7247
+ let { entityId: e, activeHandle: n } = Y.current;
7248
+ R.current.get(e)?.updateEditPreview?.(n, t);
7249
+ return;
7250
+ }
7251
+ let n = jn.current, r = Mn.current;
7252
+ n === "rectangle" && r && Ft(r, t);
7253
+ let i = lt.current;
7254
+ n === "circle" && i && Bt(i.center, t);
7255
+ let a = ut.current;
7256
+ n === "polygon" && a.length > 0 && Wt(a, t);
7257
+ let o = dt.current;
7258
+ n === "square" && o && Yt(o.center, t);
7259
+ let s = pt.current;
7260
+ n === "polyline" && s.length > 0 && $t(s, t);
7261
+ let c = Tn.current, l = Dn.current;
7262
+ for (let [e, n] of R.current) if (n.isPointInEntity(t)) {
5839
7263
  let t = c.find((t) => t.id === e);
5840
7264
  if (!t?.popup) continue;
5841
7265
  let n = t.popup.content ?? Pe?.(t);
5842
7266
  if (!n) continue;
5843
- let r = mergePopupConfig(t.popup, P, n);
7267
+ let r = mergePopupConfig(t.popup, I, n);
5844
7268
  if (r.trigger === "hover") {
5845
- Ke.current && clearTimeout(Ke.current), Ke.current = window.setTimeout(() => {
7269
+ qe.current && clearTimeout(qe.current), qe.current = window.setTimeout(() => {
5846
7270
  l(e, "hover");
5847
7271
  }, r.hoverDelay);
5848
7272
  return;
5849
7273
  }
5850
7274
  }
5851
- if (Ke.current &&= (clearTimeout(Ke.current), null), R?.openedBy === "hover") {
5852
- let e = I.current.get(R.entityId);
5853
- e && !e.isPointInEntity(t) && _t(R.entityId);
7275
+ if (qe.current &&= (clearTimeout(qe.current), null), B?.openedBy === "hover") {
7276
+ let e = R.current.get(B.entityId);
7277
+ e && !e.isPointInEntity(t) && wt(B.entityId);
5854
7278
  }
5855
7279
  }, [
5856
- P,
7280
+ I,
5857
7281
  Pe,
5858
- R,
5859
- _t,
5860
- Ot,
5861
- Nt,
5862
- Lt,
5863
- Ht,
5864
- Kt
5865
- ]), hn = useCallback((e) => {
5866
- if (e.preventDefault(), xn.current !== "edit") return;
5867
- if (Cn.current) {
5868
- B(null), V(null), Y();
7282
+ B,
7283
+ wt,
7284
+ Ft,
7285
+ Bt,
7286
+ Wt,
7287
+ Yt,
7288
+ $t
7289
+ ]), Sn = useCallback((e) => {
7290
+ if (e.preventDefault(), ht.current) return;
7291
+ if (vt.current.length > 0) {
7292
+ let t = [e.lngLat.lng, e.lngLat.lat];
7293
+ if (Y.current) {
7294
+ R.current.get(Y.current.entityId)?.cancelEditPreview?.(), Y.current = null;
7295
+ return;
7296
+ }
7297
+ let n = L.current?.getZoom() ?? 12;
7298
+ for (let e of vt.current) {
7299
+ let r = R.current.get(e);
7300
+ if (!r?.getEditHandleAt || !r.deleteVertex) continue;
7301
+ let i = r.getEditHandleAt(t, n);
7302
+ if (i && i.type === "vertex") {
7303
+ let e = r.deleteVertex(i.index);
7304
+ e && $.current.onEntityEdit?.(e);
7305
+ return;
7306
+ }
7307
+ }
7308
+ }
7309
+ if (On.current !== "edit") return;
7310
+ if (An.current) {
7311
+ H(null), U(null), X();
5869
7312
  return;
5870
7313
  }
5871
- let t = wn.current;
7314
+ let t = jn.current;
5872
7315
  if (t === "rectangle") {
5873
- if (Tn.current) ot(null), kt();
7316
+ if (Mn.current) st(null), It();
5874
7317
  else {
5875
- V(null);
5876
- let e = F.current;
7318
+ U(null);
7319
+ let e = L.current;
5877
7320
  e && (e.getCanvas().style.cursor = "");
5878
7321
  }
5879
7322
  return;
5880
7323
  }
5881
7324
  if (t === "circle") {
5882
- if (st.current) st.current = null, Pt();
7325
+ if (lt.current) lt.current = null, Vt();
5883
7326
  else {
5884
- V(null);
5885
- let e = F.current;
7327
+ U(null);
7328
+ let e = L.current;
5886
7329
  e && (e.getCanvas().style.cursor = "");
5887
7330
  }
5888
7331
  return;
5889
7332
  }
5890
7333
  if (t === "polygon") {
5891
- let e = ct.current;
7334
+ let e = ut.current;
5892
7335
  if (e.length >= 3) {
5893
- let t = K.current, n = applyEntityConfig({
7336
+ let t = q.current, n = applyEntityConfig({
5894
7337
  ...t,
5895
- id: t?.id ?? wt(),
7338
+ id: t?.id ?? jt(),
5896
7339
  type: "polygon",
5897
7340
  coordinates: [...e]
5898
7341
  }, O);
5899
- Rt();
5900
- let r = F.current;
5901
- if (r && !I.current.has(n.id)) {
7342
+ Gt();
7343
+ let r = L.current;
7344
+ if (r && !R.current.has(n.id)) {
5902
7345
  let e = new PolygonRenderer(r, n, k, A, j, N);
5903
- I.current.set(n.id, e);
7346
+ R.current.set(n.id, e);
5904
7347
  }
5905
- Q.current.onPolygonAdd?.(n), ct.current = [], K.current = null, H.current && (H.current = !1, V(null), r && (r.getCanvas().style.cursor = ""));
5906
- } else if (e.length > 0) ct.current = [], Rt();
7348
+ $.current.onPolygonAdd?.(n), ut.current = [], q.current = null, W.current && (W.current = !1, U(null), r && (r.getCanvas().style.cursor = ""));
7349
+ } else if (e.length > 0) ut.current = [], Gt();
5907
7350
  else {
5908
- V(null);
5909
- let e = F.current;
7351
+ U(null);
7352
+ let e = L.current;
5910
7353
  e && (e.getCanvas().style.cursor = "");
5911
7354
  }
5912
7355
  return;
5913
7356
  }
5914
7357
  if (t === "square") {
5915
- if (lt.current) lt.current = null, Ut();
7358
+ if (dt.current) dt.current = null, Xt();
5916
7359
  else {
5917
- V(null);
5918
- let e = F.current;
7360
+ U(null);
7361
+ let e = L.current;
5919
7362
  e && (e.getCanvas().style.cursor = "");
5920
7363
  }
5921
7364
  return;
5922
7365
  }
5923
7366
  if (t === "polyline") {
5924
- let e = ut.current;
7367
+ let e = pt.current;
5925
7368
  if (e.length >= 2) {
5926
- let t = J.current, n = applyEntityConfig({
7369
+ let t = ft.current, n = applyEntityConfig({
5927
7370
  ...t,
5928
- id: t?.id ?? wt(),
7371
+ id: t?.id ?? jt(),
5929
7372
  type: "polyline",
5930
7373
  coordinates: [...e]
5931
7374
  }, O);
5932
- qt();
5933
- let r = F.current;
5934
- if (r && !I.current.has(n.id)) {
7375
+ en();
7376
+ let r = L.current;
7377
+ if (r && !R.current.has(n.id)) {
5935
7378
  let e = new PolylineRenderer(r, n, k, A, N);
5936
- I.current.set(n.id, e);
7379
+ R.current.set(n.id, e);
5937
7380
  }
5938
- Q.current.onPolylineAdd?.(n), ut.current = [], J.current = null, H.current && (H.current = !1, V(null), r && (r.getCanvas().style.cursor = ""));
5939
- } else if (e.length > 0) ut.current = [], qt();
7381
+ $.current.onPolylineAdd?.(n), pt.current = [], ft.current = null, W.current && (W.current = !1, U(null), r && (r.getCanvas().style.cursor = ""));
7382
+ } else if (e.length > 0) pt.current = [], en();
5940
7383
  else {
5941
- V(null);
5942
- let e = F.current;
7384
+ U(null);
7385
+ let e = L.current;
5943
7386
  e && (e.getCanvas().style.cursor = "");
5944
7387
  }
5945
7388
  return;
@@ -5947,45 +7390,45 @@ const Mapbox = forwardRef((e, c) => {
5947
7390
  let n = [e.lngLat.lng, e.lngLat.lat], r = {
5948
7391
  x: e.point.x,
5949
7392
  y: e.point.y
5950
- }, i = vn.current, a = fn(e.originalEvent.target);
7393
+ }, i = Tn.current, a = yn(e.originalEvent.target);
5951
7394
  if (a) {
5952
7395
  let e = i.find((e) => String(e.id) === a);
5953
7396
  if (e) {
5954
- gn(e, r, n);
7397
+ Cn(e, r, n);
5955
7398
  return;
5956
7399
  }
5957
7400
  }
5958
- for (let [t, a] of I.current) {
7401
+ for (let [t, a] of R.current) {
5959
7402
  let o = a.getLabelLayerId();
5960
- if (o && F.current?.getLayer(o) && F.current.queryRenderedFeatures(e.point, { layers: [o] }).length > 0) {
7403
+ if (o && L.current?.getLayer(o) && L.current.queryRenderedFeatures(e.point, { layers: [o] }).length > 0) {
5961
7404
  let e = i.find((e) => e.id === t);
5962
7405
  if (e) {
5963
- gn(e, r, n);
7406
+ Cn(e, r, n);
5964
7407
  return;
5965
7408
  }
5966
7409
  }
5967
7410
  }
5968
- for (let [e, t] of I.current) if (t.isPointInEntity(n)) {
7411
+ for (let [e, t] of R.current) if (t.isPointInEntity(n)) {
5969
7412
  let t = i.find((t) => t.id === e);
5970
7413
  if (t) {
5971
- gn(t, r, n);
7414
+ Cn(t, r, n);
5972
7415
  return;
5973
7416
  }
5974
7417
  }
5975
7418
  }, [
5976
- fn,
5977
- Y,
5978
- kt,
5979
- Pt,
5980
- Rt,
5981
- Ut,
5982
- qt
5983
- ]), gn = useCallback((e, t, n) => {
7419
+ yn,
7420
+ X,
7421
+ It,
7422
+ Vt,
7423
+ Gt,
7424
+ Xt,
7425
+ en
7426
+ ]), Cn = useCallback((e, t, n) => {
5984
7427
  let r = Ve.current?.getBoundingClientRect(), i = r ? {
5985
7428
  x: t.x + r.left,
5986
7429
  y: t.y + r.top
5987
7430
  } : t;
5988
- Je({
7431
+ Ye({
5989
7432
  position: i,
5990
7433
  lngLat: n,
5991
7434
  items: [{
@@ -6001,12 +7444,12 @@ const Mapbox = forwardRef((e, c) => {
6001
7444
  }),
6002
7445
  danger: !0,
6003
7446
  onClick: () => {
6004
- Q.current.onEntityDelete?.(e);
7447
+ $.current.onEntityDelete?.(e);
6005
7448
  }
6006
7449
  }]
6007
7450
  });
6008
- }, []), _n = useCallback(() => {
6009
- Je(null);
7451
+ }, []), wn = useCallback(() => {
7452
+ Ye(null);
6010
7453
  }, []);
6011
7454
  useEffect(() => {
6012
7455
  let e = document.createElement("div");
@@ -6017,11 +7460,11 @@ const Mapbox = forwardRef((e, c) => {
6017
7460
  width: 100%;
6018
7461
  pointer-events: none;
6019
7462
  height: 100%;
6020
- z-index: ${P?.zIndex ?? 1e3};
6021
- `, document.body.appendChild(e), We.current = e, () => {
7463
+ z-index: ${I?.zIndex ?? 1e3};
7464
+ `, document.body.appendChild(e), Ge.current = e, () => {
6022
7465
  document.body.contains(e) && document.body.removeChild(e);
6023
7466
  };
6024
- }, [P?.zIndex]), useEffect(() => {
7467
+ }, [I?.zIndex]), useEffect(() => {
6025
7468
  let e = document.createElement("div");
6026
7469
  return e.id = `mapbox-context-menu-container-${Date.now()}`, e.style.cssText = `
6027
7470
  position: fixed;
@@ -6030,61 +7473,65 @@ const Mapbox = forwardRef((e, c) => {
6030
7473
  width: 100%;
6031
7474
  pointer-events: none;
6032
7475
  height: 100%;
6033
- z-index: ${(P?.zIndex ?? 1e3) + 100};
6034
- `, document.body.appendChild(e), Ye.current = e, () => {
7476
+ z-index: ${(I?.zIndex ?? 1e3) + 100};
7477
+ `, document.body.appendChild(e), Xe.current = e, () => {
6035
7478
  document.body.contains(e) && document.body.removeChild(e);
6036
7479
  };
6037
- }, [P?.zIndex]);
6038
- let vn = useRef(E);
6039
- vn.current = E;
6040
- let yn = useRef(Ie);
6041
- yn.current = Ie;
6042
- let bn = useRef(gt);
6043
- bn.current = gt;
6044
- let xn = useRef(z);
6045
- xn.current = z;
6046
- let Sn = useRef(b);
6047
- Sn.current = b;
6048
- let Cn = useRef(rt);
6049
- Cn.current = rt;
6050
- let wn = useRef(it);
6051
- wn.current = it;
6052
- let Tn = useRef(at);
6053
- Tn.current = at;
6054
- let Q = useRef(v);
6055
- Q.current = v;
6056
- let En = useRef(O);
6057
- En.current = O, useEffect(() => {
7480
+ }, [I?.zIndex]);
7481
+ let Tn = useRef(E);
7482
+ Tn.current = E;
7483
+ let En = useRef(Ie);
7484
+ En.current = Ie;
7485
+ let Dn = useRef(Ct);
7486
+ Dn.current = Ct;
7487
+ let On = useRef($e);
7488
+ On.current = $e;
7489
+ let kn = useRef(b);
7490
+ kn.current = b;
7491
+ let An = useRef(it);
7492
+ An.current = it;
7493
+ let jn = useRef(at);
7494
+ jn.current = at;
7495
+ let Mn = useRef(ot);
7496
+ Mn.current = ot;
7497
+ let $ = useRef(v);
7498
+ $.current = v;
7499
+ let Nn = useRef(O);
7500
+ Nn.current = O, useEffect(() => {
6058
7501
  let e = (e) => {
6059
- if (e.key === "Escape" && z === "edit") {
6060
- if (rt && (B(null), V(null), Y()), it === "rectangle") if (at) ot(null), kt();
7502
+ if (e.key === "Escape" && Y.current) {
7503
+ R.current.get(Y.current.entityId)?.cancelEditPreview?.(), Y.current = null;
7504
+ return;
7505
+ }
7506
+ if (e.key === "Escape" && $e === "edit") {
7507
+ if (it && (H(null), U(null), X()), at === "rectangle") if (ot) st(null), It();
6061
7508
  else {
6062
- V(null);
6063
- let e = F.current;
7509
+ U(null);
7510
+ let e = L.current;
6064
7511
  e && (e.getCanvas().style.cursor = "");
6065
7512
  }
6066
- if (it === "circle") if (st.current) st.current = null, Pt();
7513
+ if (at === "circle") if (lt.current) lt.current = null, Vt();
6067
7514
  else {
6068
- V(null);
6069
- let e = F.current;
7515
+ U(null);
7516
+ let e = L.current;
6070
7517
  e && (e.getCanvas().style.cursor = "");
6071
7518
  }
6072
- if (it === "polygon") if (ct.current.length > 0) ct.current = [], Rt();
7519
+ if (at === "polygon") if (ut.current.length > 0) ut.current = [], Gt();
6073
7520
  else {
6074
- V(null);
6075
- let e = F.current;
7521
+ U(null);
7522
+ let e = L.current;
6076
7523
  e && (e.getCanvas().style.cursor = "");
6077
7524
  }
6078
- if (it === "square") if (lt.current) lt.current = null, Ut();
7525
+ if (at === "square") if (dt.current) dt.current = null, Xt();
6079
7526
  else {
6080
- V(null);
6081
- let e = F.current;
7527
+ U(null);
7528
+ let e = L.current;
6082
7529
  e && (e.getCanvas().style.cursor = "");
6083
7530
  }
6084
- if (it === "polyline") if (ut.current.length > 0) ut.current = [], qt();
7531
+ if (at === "polyline") if (pt.current.length > 0) pt.current = [], en();
6085
7532
  else {
6086
- V(null);
6087
- let e = F.current;
7533
+ U(null);
7534
+ let e = L.current;
6088
7535
  e && (e.getCanvas().style.cursor = "");
6089
7536
  }
6090
7537
  }
@@ -6093,49 +7540,49 @@ const Mapbox = forwardRef((e, c) => {
6093
7540
  document.removeEventListener("keydown", e);
6094
7541
  };
6095
7542
  }, [
6096
- z,
6097
- rt,
7543
+ $e,
6098
7544
  it,
6099
7545
  at,
6100
- Y,
6101
- kt,
6102
- Pt,
6103
- Rt,
6104
- Ut,
6105
- qt
7546
+ ot,
7547
+ X,
7548
+ It,
7549
+ Vt,
7550
+ Gt,
7551
+ Xt,
7552
+ en
6106
7553
  ]), useEffect(() => {
6107
- let e = F.current;
6108
- if (!e || !R) return;
6109
- let t = R.entityId, n = R.config, r = () => {
6110
- let r = vn.current.find((e) => e.id === t);
7554
+ let e = L.current;
7555
+ if (!e || !B) return;
7556
+ let t = B.entityId, n = B.config, r = () => {
7557
+ let r = Tn.current.find((e) => e.id === t);
6111
7558
  if (!r) {
6112
- vt();
7559
+ Tt();
6113
7560
  return;
6114
7561
  }
6115
- let { position: i } = calculatePopupPosition(r, n, e, void 0, Ge.current);
6116
- Ge.current && (Ge.current.style.left = `${i.x}px`, Ge.current.style.top = `${i.y}px`);
7562
+ let { position: i } = calculatePopupPosition(r, n, e, void 0, Ke.current);
7563
+ Ke.current && (Ke.current.style.left = `${i.x}px`, Ke.current.style.top = `${i.y}px`);
6117
7564
  }, i = setTimeout(() => {
6118
7565
  r();
6119
7566
  }, 50);
6120
7567
  return e.on("move", r), e.on("zoom", r), e.on("rotate", r), e.on("pitch", r), () => {
6121
7568
  clearTimeout(i), e.off("move", r), e.off("zoom", r), e.off("rotate", r), e.off("pitch", r);
6122
7569
  };
6123
- }, [R?.entityId, vt]), useEffect(() => {
6124
- let e = F.current, t = Ve.current;
6125
- if (!e || !qe || !t) return;
6126
- let n = qe.lngLat, r = () => {
7570
+ }, [B?.entityId, Tt]), useEffect(() => {
7571
+ let e = L.current, t = Ve.current;
7572
+ if (!e || !Je || !t) return;
7573
+ let n = Je.lngLat, r = () => {
6127
7574
  let r = e.project(n), i = t.clientWidth, a = t.clientHeight;
6128
7575
  if (r.x < 0 || r.x > i || r.y < 0 || r.y > a) {
6129
- _n();
7576
+ wn();
6130
7577
  return;
6131
7578
  }
6132
7579
  let o = t.getBoundingClientRect(), s = r.x + o.left, c = r.y + o.top;
6133
- Xe.current && (Xe.current.style.left = `${s}px`, Xe.current.style.top = `${c}px`);
7580
+ Ze.current && (Ze.current.style.left = `${s}px`, Ze.current.style.top = `${c}px`);
6134
7581
  };
6135
7582
  return e.on("move", r), e.on("zoom", r), e.on("rotate", r), e.on("pitch", r), () => {
6136
7583
  e.off("move", r), e.off("zoom", r), e.off("rotate", r), e.off("pitch", r);
6137
7584
  };
6138
- }, [qe?.lngLat, _n]), useEffect(() => {
7585
+ }, [Je?.lngLat, wn]), useEffect(() => {
6139
7586
  if (!Ve.current) return;
6140
7587
  let e = {
6141
7588
  version: 8,
@@ -6169,98 +7616,98 @@ const Mapbox = forwardRef((e, c) => {
6169
7616
  return { url: e };
6170
7617
  }
6171
7618
  });
6172
- return F.current = _, _.on("load", () => {
7619
+ return L.current = _, _.on("load", () => {
6173
7620
  if (!_.getStyle().glyphs) {
6174
7621
  let e = _.style, t = "/gis-fonts/{fontstack}/{range}.pbf";
6175
7622
  e.glyphs = t, e.stylesheet && (e.stylesheet.glyphs = t);
6176
7623
  }
6177
- L.current.clear(), E.forEach((e) => {
6178
- L.current.set(e.id, e);
6179
- }), dn(S), nn(), Dt(), At(), It(), Bt(), Gt(), Qe(_), Fe?.(_);
6180
- }), _.on("click", pn), _.on("mousemove", mn), _.on("contextmenu", hn), () => {
6181
- _.off("click", pn), _.off("mousemove", mn), _.off("contextmenu", hn), rn(), Ct(), Y(), X(), Z(), _.remove(), F.current = null;
7624
+ z.current.clear(), E.forEach((e) => {
7625
+ z.current.set(e.id, e);
7626
+ }), vn(S), un(), Pt(), Lt(), Ut(), qt(), Qt(), Qe(_), Fe?.(_);
7627
+ }), _.on("click", bn), _.on("mousemove", xn), _.on("contextmenu", Sn), () => {
7628
+ _.off("click", bn), _.off("mousemove", xn), _.off("contextmenu", Sn), dn(), At(), X(), Z(), Q(), _.remove(), L.current = null;
6182
7629
  };
6183
7630
  }, []), useEffect(() => {
6184
- if (F.current) {
6185
- if (!F.current.isStyleLoaded()) {
6186
- F.current.once("load", () => {
6187
- L.current.clear(), E.forEach((e) => {
6188
- L.current.set(e.id, e);
6189
- }), nn();
7631
+ if (L.current) {
7632
+ if (!L.current.isStyleLoaded()) {
7633
+ L.current.once("load", () => {
7634
+ z.current.clear(), E.forEach((e) => {
7635
+ z.current.set(e.id, e);
7636
+ }), un();
6190
7637
  });
6191
7638
  return;
6192
7639
  }
6193
- L.current.clear(), E.forEach((e) => {
6194
- L.current.set(e.id, e);
6195
- }), nn();
7640
+ z.current.clear(), E.forEach((e) => {
7641
+ z.current.set(e.id, e);
7642
+ }), un();
6196
7643
  }
6197
- }, [E, nn]), useEffect(() => {
6198
- !F.current || !F.current.isStyleLoaded() || (rn(), nn());
7644
+ }, [E, un]), useEffect(() => {
7645
+ !L.current || !L.current.isStyleLoaded() || (dn(), un());
6199
7646
  }, [
6200
7647
  k,
6201
7648
  A,
6202
7649
  j,
6203
7650
  M,
6204
7651
  N,
6205
- rn,
6206
- nn
7652
+ dn,
7653
+ un
6207
7654
  ]), useEffect(() => {
6208
- if (F.current) {
6209
- if (!F.current.isStyleLoaded()) {
6210
- F.current.once("load", () => {
6211
- dn(S);
7655
+ if (L.current) {
7656
+ if (!L.current.isStyleLoaded()) {
7657
+ L.current.once("load", () => {
7658
+ vn(S);
6212
7659
  });
6213
7660
  return;
6214
7661
  }
6215
- dn(S);
6216
- }
6217
- }, [S, dn]);
6218
- let Dn = useRef(void 0), On = useRef(!0), kn = useRef(S);
6219
- kn.current = S;
6220
- let An = useRef(dn);
6221
- An.current = dn;
6222
- let jn = useRef(rn);
6223
- jn.current = rn;
6224
- let Mn = useRef(nn);
6225
- Mn.current = nn;
6226
- let Nn = useRef(Dt);
6227
- Nn.current = Dt;
6228
- let Pn = useRef(At);
6229
- Pn.current = At;
6230
- let Fn = useRef(It);
6231
- Fn.current = It;
6232
- let In = useRef(Bt);
6233
- In.current = Bt;
6234
- let Ln = useRef(Gt);
6235
- Ln.current = Gt, useEffect(() => {
6236
- let e = F.current;
7662
+ vn(S);
7663
+ }
7664
+ }, [S, vn]);
7665
+ let Pn = useRef(void 0), Fn = useRef(!0), In = useRef(S);
7666
+ In.current = S;
7667
+ let Ln = useRef(vn);
7668
+ Ln.current = vn;
7669
+ let Rn = useRef(dn);
7670
+ Rn.current = dn;
7671
+ let zn = useRef(un);
7672
+ zn.current = un;
7673
+ let Bn = useRef(Pt);
7674
+ Bn.current = Pt;
7675
+ let Vn = useRef(Lt);
7676
+ Vn.current = Lt;
7677
+ let Hn = useRef(Ut);
7678
+ Hn.current = Ut;
7679
+ let Un = useRef(qt);
7680
+ Un.current = qt;
7681
+ let Wn = useRef(Qt);
7682
+ Wn.current = Qt, useEffect(() => {
7683
+ let e = L.current;
6237
7684
  if (!e) return;
6238
7685
  let t = h || {
6239
7686
  version: 8,
6240
7687
  sources: {},
6241
7688
  layers: []
6242
7689
  };
6243
- if (On.current) {
6244
- On.current = !1, Dn.current = h;
7690
+ if (Fn.current) {
7691
+ Fn.current = !1, Pn.current = h;
6245
7692
  return;
6246
7693
  }
6247
- Dn.current !== h && (Dn.current = h, e.setStyle(t), e.once("style.load", () => {
7694
+ Pn.current !== h && (Pn.current = h, e.setStyle(t), e.once("style.load", () => {
6248
7695
  if (!e.getStyle().glyphs) {
6249
7696
  let t = e.style, n = "/gis-fonts/{fontstack}/{range}.pbf";
6250
7697
  t.glyphs = n, t.stylesheet && (t.stylesheet.glyphs = n);
6251
7698
  }
6252
- He.current.clear(), An.current(kn.current), jn.current(), Mn.current(), Nn.current(), Pn.current(), Fn.current(), In.current(), Ln.current();
7699
+ Ue.current.clear(), Ln.current(In.current), Rn.current(), zn.current(), Bn.current(), Vn.current(), Hn.current(), Un.current(), Wn.current();
6253
7700
  }));
6254
7701
  }, [h]), useEffect(() => {
6255
7702
  let e = new Set(D.map(String));
6256
- for (let [t, n] of I.current) n.setSelected(e.has(String(t)));
7703
+ for (let [t, n] of R.current) n.setSelected(e.has(String(t)));
6257
7704
  }, [D]);
6258
- let Rn = useRef({});
7705
+ let Gn = useRef({});
6259
7706
  useEffect(() => {
6260
- let e = F.current;
7707
+ let e = L.current;
6261
7708
  if (!e) return;
6262
- let t = Rn.current, n = l && (t.center?.[0] !== l[0] || t.center?.[1] !== l[1]), r = t.zoom !== u, i = t.pitch !== d, a = t.bearing !== f;
6263
- !n && !r && !i && !a || (Rn.current = {
7709
+ let t = Gn.current, n = l && (t.center?.[0] !== l[0] || t.center?.[1] !== l[1]), r = t.zoom !== u, i = t.pitch !== d, a = t.bearing !== f;
7710
+ !n && !r && !i && !a || (Gn.current = {
6264
7711
  center: l,
6265
7712
  zoom: u,
6266
7713
  pitch: d,
@@ -6277,13 +7724,13 @@ const Mapbox = forwardRef((e, c) => {
6277
7724
  d,
6278
7725
  f
6279
7726
  ]);
6280
- let zn = (() => xe === !1 ? null : xe === !0 ? { enabled: !0 } : xe)(), Bn = (() => Te === !1 ? null : Te === !0 ? { enabled: !0 } : Te)(), Vn = (() => Ee === !1 ? null : Ee === !0 ? { enabled: !0 } : Ee)(), $ = (() => {
6281
- if (De === !1) return null;
7727
+ let Kn = (() => Ce === !1 ? null : Ce === !0 ? { enabled: !0 } : Ce)(), qn = (() => P === !1 ? null : P === !0 ? { enabled: !0 } : P)(), Jn = (() => we === !1 ? null : we === !0 ? { enabled: !0 } : we)(), Yn = (() => {
7728
+ if (Te === !1) return null;
6282
7729
  let e, t;
6283
7730
  if (S && S.length > 0) {
6284
7731
  let n = S.find((e) => e.hasRoadNetwork === !0) || S[0];
6285
7732
  if (n.type === "style") {
6286
- let t = F.current?.getStyle();
7733
+ let t = L.current?.getStyle();
6287
7734
  if (t?.sources) {
6288
7735
  let r = `base-layer-source-${n.id}-`, i = Object.keys(t.sources).find((e) => e.startsWith(r));
6289
7736
  i && (e = i);
@@ -6291,35 +7738,35 @@ const Mapbox = forwardRef((e, c) => {
6291
7738
  } else e = `base-layer-source-${n.id}`;
6292
7739
  t = n.roadNetworkSourceLayer || "road";
6293
7740
  }
6294
- return De === !0 ? {
7741
+ return Te === !0 ? {
6295
7742
  enabled: !0,
6296
7743
  source: e,
6297
7744
  sourceLayer: t
6298
7745
  } : {
6299
- ...De,
6300
- source: De.source || e,
6301
- sourceLayer: De.sourceLayer || t
7746
+ ...Te,
7747
+ source: Te.source || e,
7748
+ sourceLayer: Te.sourceLayer || t
6302
7749
  };
6303
- })(), Hn = (() => ke ? ke === !0 ? { enabled: !0 } : ke : null)(), Un = (() => Ae ? Ae === !0 ? { enabled: !0 } : Ae : null)(), Wn = useMemo(() => {
7750
+ })(), Xn = (() => Ee ? Ee === !0 ? { enabled: !0 } : Ee : null)(), Zn = (() => Ae ? Ae === !0 ? { enabled: !0 } : Ae : null)(), Qn = (() => je || null)(), $n = useMemo(() => {
6304
7751
  let e = [];
6305
7752
  for (let t of S) if (t.applyRasterPaint) if (t.type === "style") {
6306
- let n = F.current;
7753
+ let n = L.current;
6307
7754
  if (n) {
6308
7755
  let r = `base-layer-${t.id}-`, i = n.getStyle();
6309
7756
  if (i?.layers) for (let t of i.layers) t.id.startsWith(r) && t.type === "raster" && e.push(t.id);
6310
7757
  }
6311
7758
  } else e.push(`base-layer-${t.id}`);
6312
7759
  return e;
6313
- }, [S, Ze]);
7760
+ }, [S, V]);
6314
7761
  return /* @__PURE__ */ jsxs("div", {
6315
- className: `comp-mapbox ${z === "picker" ? "comp-mapbox--picker-mode" : ""} ${ze}`,
7762
+ className: `comp-mapbox ${$e === "picker" ? "comp-mapbox--picker-mode" : ""} ${ze}`,
6316
7763
  style: Be,
6317
7764
  children: [
6318
7765
  /* @__PURE__ */ jsx("div", {
6319
7766
  ref: Ve,
6320
7767
  className: "comp-mapbox__map"
6321
7768
  }),
6322
- z === "picker" && y.showCrosshair === !0 && /* @__PURE__ */ jsxs("div", {
7769
+ $e === "picker" && y.showCrosshair === !0 && /* @__PURE__ */ jsxs("div", {
6323
7770
  className: "comp-mapbox__crosshair",
6324
7771
  children: [/* @__PURE__ */ jsx("div", {
6325
7772
  className: "comp-mapbox__crosshair-h",
@@ -6329,83 +7776,102 @@ const Mapbox = forwardRef((e, c) => {
6329
7776
  style: y.crosshairColor ? { backgroundColor: y.crosshairColor } : void 0
6330
7777
  })]
6331
7778
  }),
6332
- z === "edit" && v.showEditTools !== !1 && (v.markerTemplates && v.markerTemplates.length > 0 || v.showRectangleTool || v.showCircleTool || v.showPolygonTool || v.showSquareTool || v.showPolylineTool) || $ && $.enabled !== !1 ? /* @__PURE__ */ jsxs("div", {
7779
+ $e === "edit" && v.showEditTools !== !1 && (v.markerTemplates && v.markerTemplates.length > 0 || v.showRectangleTool || v.showCircleTool || v.showPolygonTool || v.showSquareTool || v.showPolylineTool) || Yn && Yn.enabled !== !1 || Qn && Qn.enabled !== !1 ? /* @__PURE__ */ jsxs("div", {
6333
7780
  className: "comp-mapbox__edit-controls",
6334
- children: [z === "edit" && v.showEditTools !== !1 && (v.markerTemplates && v.markerTemplates.length > 0 || v.showRectangleTool || v.showCircleTool || v.showPolygonTool || v.showSquareTool || v.showPolylineTool) && /* @__PURE__ */ jsx(EditControl, {
6335
- markerTemplates: v.markerTemplates || [],
6336
- selectedTemplate: rt,
6337
- onTemplateSelect: Jt,
6338
- drawMode: it,
6339
- onDrawModeChange: Yt,
6340
- showRectangleTool: v.showRectangleTool,
6341
- showCircleTool: v.showCircleTool,
6342
- showPolygonTool: v.showPolygonTool,
6343
- showSquareTool: v.showSquareTool,
6344
- showPolylineTool: v.showPolylineTool
6345
- }), $ && $.enabled !== !1 && /* @__PURE__ */ jsx(RoadHighlightControl, {
6346
- map: Ze,
6347
- highlightWidth: $.highlightWidth,
6348
- defaultRoadTypes: $.defaultRoadTypes,
6349
- defaultMinWidth: $.defaultMinWidth,
6350
- source: $.source,
6351
- sourceLayer: $.sourceLayer,
6352
- className: $.className,
6353
- style: $.style
6354
- })]
7781
+ children: [
7782
+ $e === "edit" && v.showEditTools !== !1 && (v.markerTemplates && v.markerTemplates.length > 0 || v.showRectangleTool || v.showCircleTool || v.showPolygonTool || v.showSquareTool || v.showPolylineTool) && /* @__PURE__ */ jsx(EditControl, {
7783
+ markerTemplates: v.markerTemplates || [],
7784
+ selectedTemplate: it,
7785
+ onTemplateSelect: tn,
7786
+ drawMode: at,
7787
+ onDrawModeChange: nn,
7788
+ showRectangleTool: v.showRectangleTool,
7789
+ showCircleTool: v.showCircleTool,
7790
+ showPolygonTool: v.showPolygonTool,
7791
+ showSquareTool: v.showSquareTool,
7792
+ showPolylineTool: v.showPolylineTool
7793
+ }),
7794
+ Yn && Yn.enabled !== !1 && /* @__PURE__ */ jsx(RoadHighlightControl, {
7795
+ map: V,
7796
+ highlightWidth: Yn.highlightWidth,
7797
+ defaultRoadTypes: Yn.defaultRoadTypes,
7798
+ defaultMinWidth: Yn.defaultMinWidth,
7799
+ source: Yn.source,
7800
+ sourceLayer: Yn.sourceLayer,
7801
+ className: Yn.className,
7802
+ style: Yn.style
7803
+ }),
7804
+ Qn && Qn.enabled !== !1 && /* @__PURE__ */ jsx(RoutePlanningControl, {
7805
+ ref: He,
7806
+ map: V,
7807
+ pointCount: Qn.pointCount,
7808
+ showPointCountInput: Qn.showPointCountInput,
7809
+ visualType: Qn.visualType,
7810
+ onSelectFinished: Qn.onSelectFinished
7811
+ })
7812
+ ]
6355
7813
  }) : null,
6356
- (zn?.enabled !== !1 || Bn?.enabled !== !1 || Vn?.enabled !== !1 || Hn && Hn.enabled !== !1 || Un && Un.enabled !== !1) && /* @__PURE__ */ jsxs("div", {
7814
+ (Kn?.enabled !== !1 || qn?.enabled !== !1 || Jn?.enabled !== !1 || Xn && Xn.enabled !== !1 || Zn && Zn.enabled !== !1) && /* @__PURE__ */ jsxs("div", {
6357
7815
  className: "comp-mapbox__controls",
6358
7816
  children: [
6359
- zn && zn.enabled !== !1 && /* @__PURE__ */ jsx(CoordinateDisplay, {
6360
- map: Ze,
6361
- precision: zn.precision,
6362
- className: zn.className,
6363
- style: zn.style
7817
+ Kn && Kn.enabled !== !1 && /* @__PURE__ */ jsx(CoordinateDisplay, {
7818
+ map: V,
7819
+ precision: Kn.precision,
7820
+ className: Kn.className,
7821
+ style: Kn.style
6364
7822
  }),
6365
- Bn && Bn.enabled !== !1 && /* @__PURE__ */ jsx(ScaleControl, {
6366
- map: Ze,
6367
- maxWidth: Bn.maxWidth,
6368
- unit: Bn.unit,
6369
- className: Bn.className,
6370
- style: Bn.style
7823
+ qn && qn.enabled !== !1 && /* @__PURE__ */ jsx(ScaleControl, {
7824
+ map: V,
7825
+ maxWidth: qn.maxWidth,
7826
+ unit: qn.unit,
7827
+ className: qn.className,
7828
+ style: qn.style
6371
7829
  }),
6372
- Hn && Hn.enabled !== !1 && /* @__PURE__ */ jsx(MeasureControl, {
6373
- map: Ze,
7830
+ Xn && Xn.enabled !== !1 && /* @__PURE__ */ jsx(MeasureControl, {
7831
+ map: V,
6374
7832
  entityConfig: O,
6375
- className: Hn.className,
6376
- style: Hn.style
7833
+ onDrawModeChange: (e) => {
7834
+ ht.current = e;
7835
+ },
7836
+ className: Xn.className,
7837
+ style: Xn.style
6377
7838
  }),
6378
- Un && Un.enabled !== !1 && /* @__PURE__ */ jsx(RasterPaintControl, {
6379
- map: Ze,
7839
+ Zn && Zn.enabled !== !1 && /* @__PURE__ */ jsx(RasterPaintControl, {
7840
+ map: V,
6380
7841
  value: T,
6381
7842
  onChange: Me,
6382
- rasterPaintLayerIds: Wn,
6383
- className: Un.className,
6384
- style: Un.style
7843
+ rasterPaintLayerIds: $n,
7844
+ className: Zn.className,
7845
+ style: Zn.style
6385
7846
  }),
6386
- Vn && Vn.enabled !== !1 && /* @__PURE__ */ jsx(ResetViewControl, {
6387
- map: Ze,
7847
+ Jn && Jn.enabled !== !1 && /* @__PURE__ */ jsx(ResetViewControl, {
7848
+ map: V,
6388
7849
  initialCenter: l,
6389
7850
  initialZoom: u,
6390
7851
  initialPitch: d,
6391
7852
  initialBearing: f,
6392
- duration: Vn.duration,
6393
- className: Vn.className,
6394
- style: Vn.style
7853
+ duration: Jn.duration,
7854
+ className: Jn.className,
7855
+ style: Jn.style
6395
7856
  })
6396
7857
  ]
6397
7858
  }),
6398
- R && We.current && /* @__PURE__ */ jsx(EntityPopup, {
6399
- popupState: R,
6400
- onClose: () => _t(R.entityId),
6401
- portalContainer: We.current,
6402
- popupRef: Ge
7859
+ !(Qn && Qn.enabled !== !1) && /* @__PURE__ */ jsx(RoutePlanningControl, {
7860
+ ref: He,
7861
+ map: V,
7862
+ showButton: !1
7863
+ }),
7864
+ B && Ge.current && /* @__PURE__ */ jsx(EntityPopup, {
7865
+ popupState: B,
7866
+ onClose: () => wt(B.entityId),
7867
+ portalContainer: Ge.current,
7868
+ popupRef: Ke
6403
7869
  }),
6404
- qe && Ye.current && /* @__PURE__ */ jsx(ContextMenu, {
6405
- menuState: qe,
6406
- onClose: _n,
6407
- portalContainer: Ye.current,
6408
- menuRef: Xe
7870
+ Je && Xe.current && /* @__PURE__ */ jsx(ContextMenu, {
7871
+ menuState: Je,
7872
+ onClose: wn,
7873
+ portalContainer: Xe.current,
7874
+ menuRef: Ze
6409
7875
  })
6410
7876
  ]
6411
7877
  });