leaflet-polydraw 2.0.0 → 2.0.2

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.
@@ -15606,9 +15606,11 @@ class PolygonInteractionManager {
15606
15606
  __publicField(this, "_boundDragEndListener", null);
15607
15607
  __publicField(this, "dragUsesPointerEvents", false);
15608
15608
  __publicField(this, "polygonTouchStartListeners", /* @__PURE__ */ new WeakMap());
15609
+ __publicField(this, "polygonNativeStartListeners", /* @__PURE__ */ new WeakMap());
15609
15610
  __publicField(this, "_openMenuPopup", null);
15610
15611
  __publicField(this, "transformModeActive", false);
15611
15612
  __publicField(this, "transformControllers", /* @__PURE__ */ new WeakMap());
15613
+ __publicField(this, "transformAuxiliaryDisplayValues", /* @__PURE__ */ new WeakMap());
15612
15614
  __publicField(this, "deleteMarkerSuppressUntil", 0);
15613
15615
  __publicField(this, "onModeChange", () => {
15614
15616
  if (this.currentCloneGhost || this.isPolygonDragActive()) {
@@ -15759,7 +15761,6 @@ class PolygonInteractionManager {
15759
15761
  switch (operation2) {
15760
15762
  case "addVertex":
15761
15763
  case "removeVertex":
15762
- case "removeHole":
15763
15764
  case "toggleOptimization":
15764
15765
  return operation2;
15765
15766
  case "modifierSubtract":
@@ -16347,6 +16348,9 @@ class PolygonInteractionManager {
16347
16348
  const { level: optimizationLevel, original: originalOptimizationLevel } = this.getOptimizationMetadataFromFeatureGroup(featureGroup);
16348
16349
  const featureMetadataState = this.getFeatureMetadataState(featureGroup);
16349
16350
  const newPolygon = this.turfHelper.getMultiPolygon([coords]);
16351
+ if (this.saveHistoryState) {
16352
+ this.saveHistoryState("removeHole");
16353
+ }
16350
16354
  this.cleanupFeatureGroup(featureGroup);
16351
16355
  this.removeFeatureGroup(featureGroup);
16352
16356
  this.emitPolygonUpdated({
@@ -16420,6 +16424,7 @@ class PolygonInteractionManager {
16420
16424
  interactive: true
16421
16425
  }
16422
16426
  );
16427
+ edgePolyline._polydrawAuxiliaryLayer = true;
16423
16428
  edgePolyline._polydrawEdgeInfo = {
16424
16429
  ringIndex,
16425
16430
  edgeIndex: i,
@@ -16476,6 +16481,92 @@ class PolygonInteractionManager {
16476
16481
  if (!this.layerManager) return true;
16477
16482
  return this.layerManager.isInActiveLayer(fg) && this.layerManager.isFeatureGroupEditable(fg);
16478
16483
  }
16484
+ beginPolygonDrag(polygon2, startLatLng, originalEvent, options = {}) {
16485
+ var _a2, _b2;
16486
+ if (this.transformModeActive) return false;
16487
+ if (!this.isPolygonInActiveLayer(polygon2)) return false;
16488
+ if (!this.isPolygonDragModeActive()) return false;
16489
+ if (!this.modeManager.canPerformAction("polygonDrag")) return false;
16490
+ if (!startLatLng) return false;
16491
+ (_a2 = originalEvent.stopPropagation) == null ? void 0 : _a2.call(originalEvent);
16492
+ if (originalEvent.cancelable) {
16493
+ (_b2 = originalEvent.preventDefault) == null ? void 0 : _b2.call(originalEvent);
16494
+ }
16495
+ const existingDragData = polygon2._polydrawDragData;
16496
+ if (this.currentDragPolygon === polygon2 && (existingDragData == null ? void 0 : existingDragData.isDragging)) {
16497
+ return true;
16498
+ }
16499
+ const isCloneMode = this.modeManager.getCurrentMode() === DrawMode.Clone;
16500
+ const isModifierPressed = isCloneMode ? false : this.detectDragSubtractModifierKey(originalEvent);
16501
+ this.currentDragIsClone = isCloneMode;
16502
+ this.currentModifierDragMode = isModifierPressed;
16503
+ this.isModifierKeyHeld = isModifierPressed;
16504
+ if (this.saveHistoryState) {
16505
+ this.saveHistoryState(isCloneMode ? "polygonClone" : "polygonDrag");
16506
+ }
16507
+ polygon2._polydrawDragData = {
16508
+ ...polygon2._polydrawDragData ?? {
16509
+ originalOpacity: polygon2.options.fillOpacity
16510
+ },
16511
+ isDragging: true,
16512
+ startPosition: startLatLng,
16513
+ startLatLngs: polygon2.getLatLngs()
16514
+ };
16515
+ polygon2.setStyle({ fillOpacity: this.config.interaction.drag.opacity });
16516
+ if (isCloneMode) {
16517
+ this.showCloneGhost(polygon2._polydrawDragData.startLatLngs);
16518
+ } else {
16519
+ this.clearCloneGhost();
16520
+ }
16521
+ if (this.map.dragging) {
16522
+ this.map.dragging.disable();
16523
+ }
16524
+ this.setSubtractVisualMode(polygon2, isModifierPressed);
16525
+ this.setMarkerVisibility(polygon2, false);
16526
+ try {
16527
+ const container = this.map.getContainer();
16528
+ container.style.cursor = this.config.interaction.drag.dragCursor || "move";
16529
+ } catch {
16530
+ }
16531
+ if (options.attachTouchListeners) {
16532
+ this.attachDragTouchListeners();
16533
+ }
16534
+ this.attachDragDocumentListeners();
16535
+ this.attachDragCancelHandlers();
16536
+ this.currentDragPolygon = polygon2;
16537
+ return true;
16538
+ }
16539
+ attachPolygonNativeStartListeners(polygon2) {
16540
+ if (this.polygonNativeStartListeners.has(polygon2)) return;
16541
+ const startFromNativeEvent = (event) => {
16542
+ if (!this.isPolygonDragModeActive()) return;
16543
+ const latlng = EventAdapter.extractCoordinates(
16544
+ event,
16545
+ this.map
16546
+ );
16547
+ this.beginPolygonDrag(polygon2, latlng, event, {
16548
+ attachTouchListeners: event.type === "touchstart"
16549
+ });
16550
+ };
16551
+ const listeners = {
16552
+ mousedown: (event) => startFromNativeEvent(event),
16553
+ pointerdown: (event) => startFromNativeEvent(event),
16554
+ touchstart: (event) => startFromNativeEvent(event)
16555
+ };
16556
+ this.polygonNativeStartListeners.set(polygon2, listeners);
16557
+ const attach = () => {
16558
+ const el = polygon2._path;
16559
+ if (!el) return;
16560
+ el.addEventListener("mousedown", listeners.mousedown, { capture: true });
16561
+ el.addEventListener("pointerdown", listeners.pointerdown, { capture: true });
16562
+ el.addEventListener("touchstart", listeners.touchstart, { capture: true, passive: false });
16563
+ };
16564
+ if (polygon2._path) {
16565
+ attach();
16566
+ } else {
16567
+ polygon2.once("add", attach);
16568
+ }
16569
+ }
16479
16570
  /**
16480
16571
  * Enable polygon dragging functionality
16481
16572
  */
@@ -16489,151 +16580,34 @@ class PolygonInteractionManager {
16489
16580
  originalOpacity: polygon2.options.fillOpacity
16490
16581
  };
16491
16582
  polygon2.on("mousedown", (e) => {
16492
- if (this.transformModeActive) {
16493
- return;
16494
- }
16495
- if (!this.isPolygonInActiveLayer(polygon2)) {
16496
- return;
16497
- }
16498
16583
  if (!this.isPolygonDragModeActive()) {
16499
16584
  L.DomEvent.stopPropagation(e);
16500
16585
  this.map.fire("mousedown", e);
16501
16586
  return;
16502
16587
  }
16503
- if (!this.modeManager.canPerformAction("polygonDrag")) {
16504
- return;
16505
- }
16506
- L.DomEvent.stopPropagation(e.originalEvent);
16507
- L.DomEvent.preventDefault(e.originalEvent);
16508
- const isCloneMode = this.modeManager.getCurrentMode() === DrawMode.Clone;
16509
- const isModifierPressed = isCloneMode ? false : this.detectDragSubtractModifierKey(e.originalEvent);
16510
- this.currentDragIsClone = isCloneMode;
16511
- this.currentModifierDragMode = isModifierPressed;
16512
- this.isModifierKeyHeld = isModifierPressed;
16513
- if (this.saveHistoryState) {
16514
- this.saveHistoryState(isCloneMode ? "polygonClone" : "polygonDrag");
16515
- }
16516
- polygon2._polydrawDragData.isDragging = true;
16517
- polygon2._polydrawDragData.startPosition = e.latlng;
16518
- polygon2._polydrawDragData.startLatLngs = polygon2.getLatLngs();
16519
- polygon2.setStyle({ fillOpacity: this.config.interaction.drag.opacity });
16520
- if (isCloneMode) {
16521
- this.showCloneGhost(polygon2._polydrawDragData.startLatLngs);
16522
- } else {
16523
- this.clearCloneGhost();
16524
- }
16525
- if (this.map.dragging) {
16526
- this.map.dragging.disable();
16527
- }
16528
- this.setSubtractVisualMode(polygon2, isModifierPressed);
16529
- this.setMarkerVisibility(polygon2, false);
16530
- try {
16531
- const container = this.map.getContainer();
16532
- container.style.cursor = this.config.interaction.drag.dragCursor || "move";
16533
- } catch {
16534
- }
16535
- this.attachDragDocumentListeners();
16536
- this.attachDragCancelHandlers();
16537
- this.currentDragPolygon = polygon2;
16588
+ this.beginPolygonDrag(polygon2, e.latlng, e.originalEvent);
16538
16589
  });
16539
16590
  polygon2.on("pointerdown", ((event) => {
16540
16591
  const e = event;
16541
- if (this.transformModeActive) {
16542
- return;
16543
- }
16544
- if (!this.isPolygonInActiveLayer(polygon2)) {
16545
- return;
16546
- }
16547
16592
  if (!this.isPolygonDragModeActive()) {
16548
16593
  const originalEvent = e.originalEvent ?? e;
16549
16594
  L.DomEvent.stopPropagation(originalEvent);
16550
16595
  this.map.fire("pointerdown", e);
16551
16596
  return;
16552
16597
  }
16553
- if (!this.modeManager.canPerformAction("polygonDrag")) {
16554
- return;
16555
- }
16556
16598
  const orig = e.originalEvent ?? e;
16557
- L.DomEvent.stopPropagation(orig);
16558
- L.DomEvent.preventDefault(orig);
16559
- const isCloneMode = this.modeManager.getCurrentMode() === DrawMode.Clone;
16560
- const isModifierPressed = isCloneMode ? false : this.detectDragSubtractModifierKey(orig);
16561
- this.currentDragIsClone = isCloneMode;
16562
- this.currentModifierDragMode = isModifierPressed;
16563
- this.isModifierKeyHeld = isModifierPressed;
16564
- if (this.saveHistoryState) {
16565
- this.saveHistoryState(isCloneMode ? "polygonClone" : "polygonDrag");
16566
- }
16567
- polygon2._polydrawDragData.isDragging = true;
16568
- polygon2._polydrawDragData.startPosition = e.latlng;
16569
- polygon2._polydrawDragData.startLatLngs = polygon2.getLatLngs();
16570
- polygon2.setStyle({ fillOpacity: this.config.interaction.drag.opacity });
16571
- if (isCloneMode) {
16572
- this.showCloneGhost(polygon2._polydrawDragData.startLatLngs);
16573
- } else {
16574
- this.clearCloneGhost();
16575
- }
16576
- if (this.map.dragging) {
16577
- this.map.dragging.disable();
16578
- }
16579
- this.setSubtractVisualMode(polygon2, isModifierPressed);
16580
- this.setMarkerVisibility(polygon2, false);
16581
- try {
16582
- const container = this.map.getContainer();
16583
- container.style.cursor = this.config.interaction.drag.dragCursor || "move";
16584
- } catch {
16585
- }
16586
- this.attachDragDocumentListeners();
16587
- this.attachDragCancelHandlers();
16588
- this.currentDragPolygon = polygon2;
16599
+ this.beginPolygonDrag(polygon2, e.latlng, orig);
16589
16600
  }));
16590
16601
  if (LeafletVersionDetector.isV1()) {
16591
16602
  const onTouchStart = (e) => {
16592
- if (this.transformModeActive) return;
16593
- if (!this.isPolygonInActiveLayer(polygon2)) return;
16594
16603
  if (!this.isPolygonDragModeActive()) {
16595
16604
  return;
16596
16605
  }
16597
- if (!this.modeManager.canPerformAction("polygonDrag")) {
16598
- return;
16599
- }
16600
- e.stopPropagation();
16601
- e.preventDefault();
16602
16606
  const latlng = EventAdapter.extractCoordinates(
16603
16607
  e,
16604
16608
  this.map
16605
16609
  );
16606
- if (!latlng) return;
16607
- const isCloneMode = this.modeManager.getCurrentMode() === DrawMode.Clone;
16608
- this.currentDragIsClone = isCloneMode;
16609
- this.currentModifierDragMode = false;
16610
- this.isModifierKeyHeld = false;
16611
- if (this.saveHistoryState) {
16612
- this.saveHistoryState(isCloneMode ? "polygonClone" : "polygonDrag");
16613
- }
16614
- polygon2._polydrawDragData.isDragging = true;
16615
- polygon2._polydrawDragData.startPosition = latlng;
16616
- polygon2._polydrawDragData.startLatLngs = polygon2.getLatLngs();
16617
- polygon2.setStyle({ fillOpacity: this.config.interaction.drag.opacity });
16618
- if (isCloneMode) {
16619
- this.showCloneGhost(polygon2._polydrawDragData.startLatLngs);
16620
- } else {
16621
- this.clearCloneGhost();
16622
- }
16623
- if (this.map.dragging) {
16624
- this.map.dragging.disable();
16625
- }
16626
- this.setSubtractVisualMode(polygon2, false);
16627
- this.setMarkerVisibility(polygon2, false);
16628
- try {
16629
- const container = this.map.getContainer();
16630
- container.style.cursor = this.config.interaction.drag.dragCursor || "move";
16631
- } catch {
16632
- }
16633
- this.attachDragTouchListeners();
16634
- this.attachDragDocumentListeners();
16635
- this.attachDragCancelHandlers();
16636
- this.currentDragPolygon = polygon2;
16610
+ this.beginPolygonDrag(polygon2, latlng, e, { attachTouchListeners: true });
16637
16611
  };
16638
16612
  this.polygonTouchStartListeners.set(polygon2, onTouchStart);
16639
16613
  const attachTouch = () => {
@@ -16650,6 +16624,7 @@ class PolygonInteractionManager {
16650
16624
  polygon2.once("add", attachTouch);
16651
16625
  }
16652
16626
  }
16627
+ this.attachPolygonNativeStartListeners(polygon2);
16653
16628
  polygon2.on("mouseover", () => {
16654
16629
  if (!this.isPolygonInActiveLayer(polygon2)) return;
16655
16630
  if (!polygon2._polydrawDragData || !polygon2._polydrawDragData.isDragging) {
@@ -16675,6 +16650,7 @@ class PolygonInteractionManager {
16675
16650
  */
16676
16651
  updateMarkerDraggableState() {
16677
16652
  const shouldBeDraggable = this.modeManager.canPerformAction("markerDrag");
16653
+ const markersShouldCapturePointer = this.modeManager.getCurrentMode() !== DrawMode.Clone;
16678
16654
  this.getFeatureGroups().forEach((featureGroup) => {
16679
16655
  const isActiveLayer = this.isFeatureGroupInActiveLayer(featureGroup);
16680
16656
  const effectiveDraggable = shouldBeDraggable && isActiveLayer;
@@ -16683,6 +16659,10 @@ class PolygonInteractionManager {
16683
16659
  const marker = layer;
16684
16660
  try {
16685
16661
  marker.options.draggable = effectiveDraggable;
16662
+ const element = marker.getElement();
16663
+ if (element) {
16664
+ element.style.pointerEvents = markersShouldCapturePointer ? "auto" : "none";
16665
+ }
16686
16666
  if (marker.dragging) {
16687
16667
  if (effectiveDraggable) {
16688
16668
  marker.dragging.enable();
@@ -16777,6 +16757,7 @@ class PolygonInteractionManager {
16777
16757
  if (layer instanceof L.Marker) {
16778
16758
  this.cleanupMarker(layer);
16779
16759
  } else if (layer instanceof L.Polygon) {
16760
+ this.detachPolygonNativeStartListeners(layer);
16780
16761
  this.detachPolygonTouchStart(layer);
16781
16762
  this.polygonFeatureGroupMap.delete(layer);
16782
16763
  }
@@ -17279,7 +17260,6 @@ class PolygonInteractionManager {
17279
17260
  if (this.dragUsesPointerEvents) {
17280
17261
  document.addEventListener("pointermove", this._boundDragMoveListener);
17281
17262
  document.addEventListener("pointerup", this._boundDragEndListener);
17282
- return;
17283
17263
  }
17284
17264
  document.addEventListener("mousemove", this._boundDragMoveListener);
17285
17265
  document.addEventListener("mouseup", this._boundDragEndListener);
@@ -17288,17 +17268,15 @@ class PolygonInteractionManager {
17288
17268
  if (this._boundDragMoveListener) {
17289
17269
  if (this.dragUsesPointerEvents) {
17290
17270
  document.removeEventListener("pointermove", this._boundDragMoveListener);
17291
- } else {
17292
- document.removeEventListener("mousemove", this._boundDragMoveListener);
17293
17271
  }
17272
+ document.removeEventListener("mousemove", this._boundDragMoveListener);
17294
17273
  this._boundDragMoveListener = null;
17295
17274
  }
17296
17275
  if (this._boundDragEndListener) {
17297
17276
  if (this.dragUsesPointerEvents) {
17298
17277
  document.removeEventListener("pointerup", this._boundDragEndListener);
17299
- } else {
17300
- document.removeEventListener("mouseup", this._boundDragEndListener);
17301
17278
  }
17279
+ document.removeEventListener("mouseup", this._boundDragEndListener);
17302
17280
  this._boundDragEndListener = null;
17303
17281
  }
17304
17282
  this.dragUsesPointerEvents = false;
@@ -17331,6 +17309,17 @@ class PolygonInteractionManager {
17331
17309
  }
17332
17310
  this.polygonTouchStartListeners.delete(polygon2);
17333
17311
  }
17312
+ detachPolygonNativeStartListeners(polygon2) {
17313
+ const listeners = this.polygonNativeStartListeners.get(polygon2);
17314
+ if (!listeners) return;
17315
+ const el = polygon2._path;
17316
+ if (el) {
17317
+ el.removeEventListener("mousedown", listeners.mousedown, { capture: true });
17318
+ el.removeEventListener("pointerdown", listeners.pointerdown, { capture: true });
17319
+ el.removeEventListener("touchstart", listeners.touchstart, { capture: true });
17320
+ }
17321
+ this.polygonNativeStartListeners.delete(polygon2);
17322
+ }
17334
17323
  attachDragCancelHandlers() {
17335
17324
  if (this.dragCancelHandlersAttached) return;
17336
17325
  this.dragCancelHandlersAttached = true;
@@ -18033,6 +18022,36 @@ class PolygonInteractionManager {
18033
18022
  }
18034
18023
  });
18035
18024
  }
18025
+ setTransformAuxiliaryVisibility(featureGroup, visible) {
18026
+ const polygon2 = this.getPolygonLayer(featureGroup);
18027
+ if (polygon2) {
18028
+ this.setMarkerVisibility(polygon2, visible);
18029
+ }
18030
+ featureGroup.eachLayer((layer) => {
18031
+ var _a2;
18032
+ if (!this.isPolydrawAuxiliaryPolyline(layer)) {
18033
+ return;
18034
+ }
18035
+ const element = (_a2 = layer.getElement) == null ? void 0 : _a2.call(layer);
18036
+ if (!element) {
18037
+ return;
18038
+ }
18039
+ if (!visible) {
18040
+ if (!this.transformAuxiliaryDisplayValues.has(layer)) {
18041
+ this.transformAuxiliaryDisplayValues.set(layer, element.style.display);
18042
+ }
18043
+ element.style.display = "none";
18044
+ return;
18045
+ }
18046
+ if (this.transformAuxiliaryDisplayValues.has(layer)) {
18047
+ element.style.display = this.transformAuxiliaryDisplayValues.get(layer) ?? "";
18048
+ this.transformAuxiliaryDisplayValues.delete(layer);
18049
+ }
18050
+ });
18051
+ }
18052
+ isPolydrawAuxiliaryPolyline(layer) {
18053
+ return layer instanceof L.Polyline && !(layer instanceof L.Polygon) && layer._polydrawAuxiliaryLayer === true;
18054
+ }
18036
18055
  getBuiltInMenuButtonConfigs() {
18037
18056
  const menuOps = this.config.polygonTools;
18038
18057
  return [
@@ -18266,10 +18285,7 @@ class PolygonInteractionManager {
18266
18285
  (confirmed) => this.handleTransformControllerResult(controller, featureGroup, mode, confirmed)
18267
18286
  );
18268
18287
  this.transformControllers.set(featureGroup, controller);
18269
- const polygonLayer = this.getPolygonLayer(featureGroup);
18270
- if (polygonLayer) {
18271
- this.setMarkerVisibility(polygonLayer, false);
18272
- }
18288
+ this.setTransformAuxiliaryVisibility(featureGroup, false);
18273
18289
  this.transformModeActive = true;
18274
18290
  } catch {
18275
18291
  }
@@ -18284,7 +18300,7 @@ class PolygonInteractionManager {
18284
18300
  return;
18285
18301
  }
18286
18302
  if (!confirmed) {
18287
- this.setMarkerVisibility(polygonLayer, true);
18303
+ this.setTransformAuxiliaryVisibility(featureGroup, true);
18288
18304
  return;
18289
18305
  }
18290
18306
  const { level: optimizationLevel, original: originalOptimizationLevel } = this.getOptimizationMetadataFromFeatureGroup(featureGroup);
@@ -19126,6 +19142,7 @@ class PolygonMutationManager {
19126
19142
  fillColor: this.config.styles.hole.fillColor,
19127
19143
  fillOpacity: this.config.styles.hole.fillOpacity || 0.5
19128
19144
  });
19145
+ holePolyline._polydrawAuxiliaryLayer = true;
19129
19146
  featureGroup.addLayer(holePolyline);
19130
19147
  this.interactionManager.addHoleMarkers(latLngLiterals, featureGroup);
19131
19148
  }
@@ -21634,12 +21651,17 @@ class Polydraw extends L.Control {
21634
21651
  __publicField(this, "drawEventsAttached", false);
21635
21652
  __publicField(this, "controlEvents", /* @__PURE__ */ new WeakSet());
21636
21653
  __publicField(this, "lastControlPointerDown", null);
21654
+ __publicField(this, "_boundMouseMove");
21655
+ __publicField(this, "_boundMouseUp");
21637
21656
  __publicField(this, "_boundTouchMove");
21638
21657
  __publicField(this, "_boundTouchEnd");
21658
+ __publicField(this, "_boundTouchCancel");
21639
21659
  __publicField(this, "_boundTouchStart");
21640
21660
  __publicField(this, "_boundPointerDown");
21641
21661
  __publicField(this, "_boundPointerMove");
21642
21662
  __publicField(this, "_boundPointerUp");
21663
+ __publicField(this, "_boundPointerCancel");
21664
+ __publicField(this, "_boundContextMenu");
21643
21665
  __publicField(this, "_lastTapTime", 0);
21644
21666
  __publicField(this, "_lastTapLatLng", null);
21645
21667
  __publicField(this, "_tapTimeout", null);
@@ -21653,6 +21675,7 @@ class Polydraw extends L.Control {
21653
21675
  __publicField(this, "_initRequestId", 0);
21654
21676
  __publicField(this, "_historySuppressionDepth", 0);
21655
21677
  __publicField(this, "_lastAppliedVisibleMapOrder", []);
21678
+ __publicField(this, "originalMapTouchAction", null);
21656
21679
  /**
21657
21680
  * Updates map interactions based on the current drawing mode.
21658
21681
  */
@@ -21869,6 +21892,7 @@ class Polydraw extends L.Control {
21869
21892
  comprehensiveCleanup() {
21870
21893
  this.events(false);
21871
21894
  this.drawStartedEvents(false);
21895
+ this.setMapDrawingTouchLock(false);
21872
21896
  this.removeKeyboardHandlers();
21873
21897
  if (this.tracer) {
21874
21898
  try {
@@ -21907,12 +21931,21 @@ class Polydraw extends L.Control {
21907
21931
  if (this._boundKeyUpHandler) {
21908
21932
  this._boundKeyUpHandler = void 0;
21909
21933
  }
21934
+ if (this._boundMouseMove) {
21935
+ this._boundMouseMove = void 0;
21936
+ }
21937
+ if (this._boundMouseUp) {
21938
+ this._boundMouseUp = void 0;
21939
+ }
21910
21940
  if (this._boundTouchMove) {
21911
21941
  this._boundTouchMove = void 0;
21912
21942
  }
21913
21943
  if (this._boundTouchEnd) {
21914
21944
  this._boundTouchEnd = void 0;
21915
21945
  }
21946
+ if (this._boundTouchCancel) {
21947
+ this._boundTouchCancel = void 0;
21948
+ }
21916
21949
  if (this._boundTouchStart) {
21917
21950
  this._boundTouchStart = void 0;
21918
21951
  }
@@ -21925,6 +21958,12 @@ class Polydraw extends L.Control {
21925
21958
  if (this._boundPointerUp) {
21926
21959
  this._boundPointerUp = void 0;
21927
21960
  }
21961
+ if (this._boundPointerCancel) {
21962
+ this._boundPointerCancel = void 0;
21963
+ }
21964
+ if (this._boundContextMenu) {
21965
+ this._boundContextMenu = void 0;
21966
+ }
21928
21967
  if (this._tapTimeout) {
21929
21968
  clearTimeout(this._tapTimeout);
21930
21969
  this._tapTimeout = null;
@@ -23166,9 +23205,28 @@ class Polydraw extends L.Control {
23166
23205
  const mapDragEnabled = this.modeManager.canPerformAction("mapDrag");
23167
23206
  const mapZoomEnabled = this.modeManager.canPerformAction("mapZoom");
23168
23207
  const mapDoubleClickEnabled = this.modeManager.canPerformAction("mapDoubleClickZoom");
23169
- this.events(this.shouldEnableDrawEvents(this.drawMode));
23208
+ const drawEventsEnabled = this.shouldEnableDrawEvents(this.drawMode);
23209
+ this.events(drawEventsEnabled);
23210
+ this.setMapDrawingTouchLock(drawEventsEnabled);
23170
23211
  this.setLeafletMapEvents(mapDragEnabled, mapDoubleClickEnabled, mapZoomEnabled);
23171
23212
  }
23213
+ setMapDrawingTouchLock(enabled) {
23214
+ if (!this.map) {
23215
+ return;
23216
+ }
23217
+ const container = this.map.getContainer();
23218
+ if (enabled) {
23219
+ if (this.originalMapTouchAction === null) {
23220
+ this.originalMapTouchAction = container.style.touchAction || "";
23221
+ }
23222
+ container.style.touchAction = "none";
23223
+ return;
23224
+ }
23225
+ if (this.originalMapTouchAction !== null) {
23226
+ container.style.touchAction = this.originalMapTouchAction;
23227
+ this.originalMapTouchAction = null;
23228
+ }
23229
+ }
23172
23230
  /**
23173
23231
  * Restore the map state from a history snapshot
23174
23232
  */
@@ -23470,6 +23528,14 @@ class Polydraw extends L.Control {
23470
23528
  this.map[onoroff]("mouseup", this.mouseUpLeave, this);
23471
23529
  }
23472
23530
  if (onoff) {
23531
+ if (!this._boundMouseMove) {
23532
+ this._boundMouseMove = (e) => this.mouseMove(e);
23533
+ }
23534
+ if (!this._boundMouseUp) {
23535
+ this._boundMouseUp = (e) => this.mouseUpLeave(e);
23536
+ }
23537
+ document.addEventListener("mousemove", this._boundMouseMove);
23538
+ document.addEventListener("mouseup", this._boundMouseUp);
23473
23539
  if (!usePointerEvents) {
23474
23540
  if (!this._boundTouchMove) {
23475
23541
  this._boundTouchMove = (e) => this.mouseMove(e);
@@ -23477,8 +23543,12 @@ class Polydraw extends L.Control {
23477
23543
  if (!this._boundTouchEnd) {
23478
23544
  this._boundTouchEnd = (e) => this.mouseUpLeave(e);
23479
23545
  }
23480
- this.map.getContainer().addEventListener("touchmove", this._boundTouchMove, { passive: false });
23481
- this.map.getContainer().addEventListener("touchend", this._boundTouchEnd, { passive: false });
23546
+ if (!this._boundTouchCancel) {
23547
+ this._boundTouchCancel = (e) => this.mouseUpLeave(e);
23548
+ }
23549
+ document.addEventListener("touchmove", this._boundTouchMove, { passive: false });
23550
+ document.addEventListener("touchend", this._boundTouchEnd, { passive: false });
23551
+ document.addEventListener("touchcancel", this._boundTouchCancel, { passive: false });
23482
23552
  }
23483
23553
  if (usePointerEvents) {
23484
23554
  if (!this._boundPointerMove) {
@@ -23487,21 +23557,37 @@ class Polydraw extends L.Control {
23487
23557
  if (!this._boundPointerUp) {
23488
23558
  this._boundPointerUp = (e) => this.mouseUpLeave(e);
23489
23559
  }
23490
- this.map.getContainer().addEventListener("pointermove", this._boundPointerMove, { passive: false });
23491
- this.map.getContainer().addEventListener("pointerup", this._boundPointerUp, { passive: false });
23560
+ if (!this._boundPointerCancel) {
23561
+ this._boundPointerCancel = (e) => this.mouseUpLeave(e);
23562
+ }
23563
+ document.addEventListener("pointermove", this._boundPointerMove, { passive: false });
23564
+ document.addEventListener("pointerup", this._boundPointerUp, { passive: false });
23565
+ document.addEventListener("pointercancel", this._boundPointerCancel, { passive: false });
23492
23566
  }
23493
23567
  } else {
23568
+ if (this._boundMouseMove) {
23569
+ document.removeEventListener("mousemove", this._boundMouseMove);
23570
+ }
23571
+ if (this._boundMouseUp) {
23572
+ document.removeEventListener("mouseup", this._boundMouseUp);
23573
+ }
23494
23574
  if (this._boundTouchMove) {
23495
- this.map.getContainer().removeEventListener("touchmove", this._boundTouchMove);
23575
+ document.removeEventListener("touchmove", this._boundTouchMove);
23496
23576
  }
23497
23577
  if (this._boundTouchEnd) {
23498
- this.map.getContainer().removeEventListener("touchend", this._boundTouchEnd);
23578
+ document.removeEventListener("touchend", this._boundTouchEnd);
23579
+ }
23580
+ if (this._boundTouchCancel) {
23581
+ document.removeEventListener("touchcancel", this._boundTouchCancel);
23499
23582
  }
23500
23583
  if (this._boundPointerMove) {
23501
- this.map.getContainer().removeEventListener("pointermove", this._boundPointerMove);
23584
+ document.removeEventListener("pointermove", this._boundPointerMove);
23502
23585
  }
23503
23586
  if (this._boundPointerUp) {
23504
- this.map.getContainer().removeEventListener("pointerup", this._boundPointerUp);
23587
+ document.removeEventListener("pointerup", this._boundPointerUp);
23588
+ }
23589
+ if (this._boundPointerCancel) {
23590
+ document.removeEventListener("pointercancel", this._boundPointerCancel);
23505
23591
  }
23506
23592
  }
23507
23593
  }
@@ -23521,6 +23607,10 @@ class Polydraw extends L.Control {
23521
23607
  }
23522
23608
  this.map[onoroff]("dblclick", this.handleDoubleClick, this);
23523
23609
  if (onoff) {
23610
+ if (!this._boundContextMenu) {
23611
+ this._boundContextMenu = (e) => e.preventDefault();
23612
+ }
23613
+ this.map.getContainer().addEventListener("contextmenu", this._boundContextMenu);
23524
23614
  if (!usePointerEvents) {
23525
23615
  if (!this._boundTouchStart) {
23526
23616
  this._boundTouchStart = (e) => this.handleTouchStart(e);
@@ -23534,6 +23624,9 @@ class Polydraw extends L.Control {
23534
23624
  this.map.getContainer().addEventListener("pointerdown", this._boundPointerDown, { passive: false });
23535
23625
  }
23536
23626
  } else {
23627
+ if (this._boundContextMenu) {
23628
+ this.map.getContainer().removeEventListener("contextmenu", this._boundContextMenu);
23629
+ }
23537
23630
  if (this._boundTouchStart) {
23538
23631
  this.map.getContainer().removeEventListener("touchstart", this._boundTouchStart);
23539
23632
  }
@@ -23547,6 +23640,9 @@ class Polydraw extends L.Control {
23547
23640
  * @param event - The touch event
23548
23641
  */
23549
23642
  handleTouchStart(event) {
23643
+ if (EventAdapter.shouldPreventDefault(event)) {
23644
+ event.preventDefault();
23645
+ }
23550
23646
  const currentTime = Date.now();
23551
23647
  const timeDiff = currentTime - this._lastTapTime;
23552
23648
  const isPointToPointMode = this.modeManager.getCurrentMode() === DrawMode.PointToPoint || this.modeManager.getCurrentMode() === DrawMode.PointToPointSubtract;
@@ -23571,21 +23667,12 @@ class Polydraw extends L.Control {
23571
23667
  clearTimeout(this._tapTimeout);
23572
23668
  this._tapTimeout = null;
23573
23669
  }
23574
- if (timeDiff < 300 && timeDiff > 0) {
23575
- this.handleDoubleTap(event);
23576
- this._lastTapTime = 0;
23577
- } else {
23578
- this._lastTapTime = currentTime;
23579
- this._lastTapLatLng = EventAdapter.extractCoordinates(event, this.map);
23580
- if (!this.pointerEventsHandled) {
23581
- this._tapTimeout = window.setTimeout(() => {
23582
- this.mouseDown(event);
23583
- this._tapTimeout = null;
23584
- }, 300);
23585
- }
23586
- }
23670
+ this._lastTapTime = currentTime;
23671
+ this._lastTapLatLng = EventAdapter.extractCoordinates(event, this.map);
23672
+ this.mouseDown(event);
23587
23673
  }
23588
23674
  isP2PDoubleTapClose(tapLatLng, timeDiff) {
23675
+ if (!this.map) return false;
23589
23676
  if (!tapLatLng || !this._lastTapLatLng) return false;
23590
23677
  if (timeDiff <= 0 || timeDiff > 300) return false;
23591
23678
  const lastTapPoint = this.map.latLngToLayerPoint(this._lastTapLatLng);
@@ -23751,7 +23838,7 @@ class Polydraw extends L.Control {
23751
23838
  */
23752
23839
  mouseMove(event) {
23753
23840
  var _a2;
23754
- if (!this.isDrawingInProgress) {
23841
+ if (!this.map || !this.isDrawingInProgress) {
23755
23842
  return;
23756
23843
  }
23757
23844
  const normalizedEvent = EventAdapter.normalizeEvent(event);
@@ -23769,7 +23856,7 @@ class Polydraw extends L.Control {
23769
23856
  */
23770
23857
  async mouseUpLeave(event) {
23771
23858
  var _a2;
23772
- if (!this.isDrawingInProgress) {
23859
+ if (!this.map || !this.isDrawingInProgress) {
23773
23860
  return;
23774
23861
  }
23775
23862
  const normalizedEvent = EventAdapter.normalizeEvent(event);