leaflet-polydraw 2.0.1 → 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.
- package/dist/polydraw.es.js +113 -126
- package/dist/polydraw.es.js.map +1 -1
- package/dist/polydraw.umd.min.js +1 -1
- package/dist/polydraw.umd.min.js.map +1 -1
- package/dist/types/managers/polygon-interaction-manager.d.ts +4 -0
- package/dist/types/managers/polygon-interaction-manager.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/polydraw.es.js
CHANGED
|
@@ -15606,6 +15606,7 @@ 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());
|
|
@@ -15760,7 +15761,6 @@ class PolygonInteractionManager {
|
|
|
15760
15761
|
switch (operation2) {
|
|
15761
15762
|
case "addVertex":
|
|
15762
15763
|
case "removeVertex":
|
|
15763
|
-
case "removeHole":
|
|
15764
15764
|
case "toggleOptimization":
|
|
15765
15765
|
return operation2;
|
|
15766
15766
|
case "modifierSubtract":
|
|
@@ -16348,6 +16348,9 @@ class PolygonInteractionManager {
|
|
|
16348
16348
|
const { level: optimizationLevel, original: originalOptimizationLevel } = this.getOptimizationMetadataFromFeatureGroup(featureGroup);
|
|
16349
16349
|
const featureMetadataState = this.getFeatureMetadataState(featureGroup);
|
|
16350
16350
|
const newPolygon = this.turfHelper.getMultiPolygon([coords]);
|
|
16351
|
+
if (this.saveHistoryState) {
|
|
16352
|
+
this.saveHistoryState("removeHole");
|
|
16353
|
+
}
|
|
16351
16354
|
this.cleanupFeatureGroup(featureGroup);
|
|
16352
16355
|
this.removeFeatureGroup(featureGroup);
|
|
16353
16356
|
this.emitPolygonUpdated({
|
|
@@ -16478,6 +16481,92 @@ class PolygonInteractionManager {
|
|
|
16478
16481
|
if (!this.layerManager) return true;
|
|
16479
16482
|
return this.layerManager.isInActiveLayer(fg) && this.layerManager.isFeatureGroupEditable(fg);
|
|
16480
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
|
+
}
|
|
16481
16570
|
/**
|
|
16482
16571
|
* Enable polygon dragging functionality
|
|
16483
16572
|
*/
|
|
@@ -16491,151 +16580,34 @@ class PolygonInteractionManager {
|
|
|
16491
16580
|
originalOpacity: polygon2.options.fillOpacity
|
|
16492
16581
|
};
|
|
16493
16582
|
polygon2.on("mousedown", (e) => {
|
|
16494
|
-
if (this.transformModeActive) {
|
|
16495
|
-
return;
|
|
16496
|
-
}
|
|
16497
|
-
if (!this.isPolygonInActiveLayer(polygon2)) {
|
|
16498
|
-
return;
|
|
16499
|
-
}
|
|
16500
16583
|
if (!this.isPolygonDragModeActive()) {
|
|
16501
16584
|
L.DomEvent.stopPropagation(e);
|
|
16502
16585
|
this.map.fire("mousedown", e);
|
|
16503
16586
|
return;
|
|
16504
16587
|
}
|
|
16505
|
-
|
|
16506
|
-
return;
|
|
16507
|
-
}
|
|
16508
|
-
L.DomEvent.stopPropagation(e.originalEvent);
|
|
16509
|
-
L.DomEvent.preventDefault(e.originalEvent);
|
|
16510
|
-
const isCloneMode = this.modeManager.getCurrentMode() === DrawMode.Clone;
|
|
16511
|
-
const isModifierPressed = isCloneMode ? false : this.detectDragSubtractModifierKey(e.originalEvent);
|
|
16512
|
-
this.currentDragIsClone = isCloneMode;
|
|
16513
|
-
this.currentModifierDragMode = isModifierPressed;
|
|
16514
|
-
this.isModifierKeyHeld = isModifierPressed;
|
|
16515
|
-
if (this.saveHistoryState) {
|
|
16516
|
-
this.saveHistoryState(isCloneMode ? "polygonClone" : "polygonDrag");
|
|
16517
|
-
}
|
|
16518
|
-
polygon2._polydrawDragData.isDragging = true;
|
|
16519
|
-
polygon2._polydrawDragData.startPosition = e.latlng;
|
|
16520
|
-
polygon2._polydrawDragData.startLatLngs = polygon2.getLatLngs();
|
|
16521
|
-
polygon2.setStyle({ fillOpacity: this.config.interaction.drag.opacity });
|
|
16522
|
-
if (isCloneMode) {
|
|
16523
|
-
this.showCloneGhost(polygon2._polydrawDragData.startLatLngs);
|
|
16524
|
-
} else {
|
|
16525
|
-
this.clearCloneGhost();
|
|
16526
|
-
}
|
|
16527
|
-
if (this.map.dragging) {
|
|
16528
|
-
this.map.dragging.disable();
|
|
16529
|
-
}
|
|
16530
|
-
this.setSubtractVisualMode(polygon2, isModifierPressed);
|
|
16531
|
-
this.setMarkerVisibility(polygon2, false);
|
|
16532
|
-
try {
|
|
16533
|
-
const container = this.map.getContainer();
|
|
16534
|
-
container.style.cursor = this.config.interaction.drag.dragCursor || "move";
|
|
16535
|
-
} catch {
|
|
16536
|
-
}
|
|
16537
|
-
this.attachDragDocumentListeners();
|
|
16538
|
-
this.attachDragCancelHandlers();
|
|
16539
|
-
this.currentDragPolygon = polygon2;
|
|
16588
|
+
this.beginPolygonDrag(polygon2, e.latlng, e.originalEvent);
|
|
16540
16589
|
});
|
|
16541
16590
|
polygon2.on("pointerdown", ((event) => {
|
|
16542
16591
|
const e = event;
|
|
16543
|
-
if (this.transformModeActive) {
|
|
16544
|
-
return;
|
|
16545
|
-
}
|
|
16546
|
-
if (!this.isPolygonInActiveLayer(polygon2)) {
|
|
16547
|
-
return;
|
|
16548
|
-
}
|
|
16549
16592
|
if (!this.isPolygonDragModeActive()) {
|
|
16550
16593
|
const originalEvent = e.originalEvent ?? e;
|
|
16551
16594
|
L.DomEvent.stopPropagation(originalEvent);
|
|
16552
16595
|
this.map.fire("pointerdown", e);
|
|
16553
16596
|
return;
|
|
16554
16597
|
}
|
|
16555
|
-
if (!this.modeManager.canPerformAction("polygonDrag")) {
|
|
16556
|
-
return;
|
|
16557
|
-
}
|
|
16558
16598
|
const orig = e.originalEvent ?? e;
|
|
16559
|
-
|
|
16560
|
-
L.DomEvent.preventDefault(orig);
|
|
16561
|
-
const isCloneMode = this.modeManager.getCurrentMode() === DrawMode.Clone;
|
|
16562
|
-
const isModifierPressed = isCloneMode ? false : this.detectDragSubtractModifierKey(orig);
|
|
16563
|
-
this.currentDragIsClone = isCloneMode;
|
|
16564
|
-
this.currentModifierDragMode = isModifierPressed;
|
|
16565
|
-
this.isModifierKeyHeld = isModifierPressed;
|
|
16566
|
-
if (this.saveHistoryState) {
|
|
16567
|
-
this.saveHistoryState(isCloneMode ? "polygonClone" : "polygonDrag");
|
|
16568
|
-
}
|
|
16569
|
-
polygon2._polydrawDragData.isDragging = true;
|
|
16570
|
-
polygon2._polydrawDragData.startPosition = e.latlng;
|
|
16571
|
-
polygon2._polydrawDragData.startLatLngs = polygon2.getLatLngs();
|
|
16572
|
-
polygon2.setStyle({ fillOpacity: this.config.interaction.drag.opacity });
|
|
16573
|
-
if (isCloneMode) {
|
|
16574
|
-
this.showCloneGhost(polygon2._polydrawDragData.startLatLngs);
|
|
16575
|
-
} else {
|
|
16576
|
-
this.clearCloneGhost();
|
|
16577
|
-
}
|
|
16578
|
-
if (this.map.dragging) {
|
|
16579
|
-
this.map.dragging.disable();
|
|
16580
|
-
}
|
|
16581
|
-
this.setSubtractVisualMode(polygon2, isModifierPressed);
|
|
16582
|
-
this.setMarkerVisibility(polygon2, false);
|
|
16583
|
-
try {
|
|
16584
|
-
const container = this.map.getContainer();
|
|
16585
|
-
container.style.cursor = this.config.interaction.drag.dragCursor || "move";
|
|
16586
|
-
} catch {
|
|
16587
|
-
}
|
|
16588
|
-
this.attachDragDocumentListeners();
|
|
16589
|
-
this.attachDragCancelHandlers();
|
|
16590
|
-
this.currentDragPolygon = polygon2;
|
|
16599
|
+
this.beginPolygonDrag(polygon2, e.latlng, orig);
|
|
16591
16600
|
}));
|
|
16592
16601
|
if (LeafletVersionDetector.isV1()) {
|
|
16593
16602
|
const onTouchStart = (e) => {
|
|
16594
|
-
if (this.transformModeActive) return;
|
|
16595
|
-
if (!this.isPolygonInActiveLayer(polygon2)) return;
|
|
16596
16603
|
if (!this.isPolygonDragModeActive()) {
|
|
16597
16604
|
return;
|
|
16598
16605
|
}
|
|
16599
|
-
if (!this.modeManager.canPerformAction("polygonDrag")) {
|
|
16600
|
-
return;
|
|
16601
|
-
}
|
|
16602
|
-
e.stopPropagation();
|
|
16603
|
-
e.preventDefault();
|
|
16604
16606
|
const latlng = EventAdapter.extractCoordinates(
|
|
16605
16607
|
e,
|
|
16606
16608
|
this.map
|
|
16607
16609
|
);
|
|
16608
|
-
|
|
16609
|
-
const isCloneMode = this.modeManager.getCurrentMode() === DrawMode.Clone;
|
|
16610
|
-
this.currentDragIsClone = isCloneMode;
|
|
16611
|
-
this.currentModifierDragMode = false;
|
|
16612
|
-
this.isModifierKeyHeld = false;
|
|
16613
|
-
if (this.saveHistoryState) {
|
|
16614
|
-
this.saveHistoryState(isCloneMode ? "polygonClone" : "polygonDrag");
|
|
16615
|
-
}
|
|
16616
|
-
polygon2._polydrawDragData.isDragging = true;
|
|
16617
|
-
polygon2._polydrawDragData.startPosition = latlng;
|
|
16618
|
-
polygon2._polydrawDragData.startLatLngs = polygon2.getLatLngs();
|
|
16619
|
-
polygon2.setStyle({ fillOpacity: this.config.interaction.drag.opacity });
|
|
16620
|
-
if (isCloneMode) {
|
|
16621
|
-
this.showCloneGhost(polygon2._polydrawDragData.startLatLngs);
|
|
16622
|
-
} else {
|
|
16623
|
-
this.clearCloneGhost();
|
|
16624
|
-
}
|
|
16625
|
-
if (this.map.dragging) {
|
|
16626
|
-
this.map.dragging.disable();
|
|
16627
|
-
}
|
|
16628
|
-
this.setSubtractVisualMode(polygon2, false);
|
|
16629
|
-
this.setMarkerVisibility(polygon2, false);
|
|
16630
|
-
try {
|
|
16631
|
-
const container = this.map.getContainer();
|
|
16632
|
-
container.style.cursor = this.config.interaction.drag.dragCursor || "move";
|
|
16633
|
-
} catch {
|
|
16634
|
-
}
|
|
16635
|
-
this.attachDragTouchListeners();
|
|
16636
|
-
this.attachDragDocumentListeners();
|
|
16637
|
-
this.attachDragCancelHandlers();
|
|
16638
|
-
this.currentDragPolygon = polygon2;
|
|
16610
|
+
this.beginPolygonDrag(polygon2, latlng, e, { attachTouchListeners: true });
|
|
16639
16611
|
};
|
|
16640
16612
|
this.polygonTouchStartListeners.set(polygon2, onTouchStart);
|
|
16641
16613
|
const attachTouch = () => {
|
|
@@ -16652,6 +16624,7 @@ class PolygonInteractionManager {
|
|
|
16652
16624
|
polygon2.once("add", attachTouch);
|
|
16653
16625
|
}
|
|
16654
16626
|
}
|
|
16627
|
+
this.attachPolygonNativeStartListeners(polygon2);
|
|
16655
16628
|
polygon2.on("mouseover", () => {
|
|
16656
16629
|
if (!this.isPolygonInActiveLayer(polygon2)) return;
|
|
16657
16630
|
if (!polygon2._polydrawDragData || !polygon2._polydrawDragData.isDragging) {
|
|
@@ -16677,6 +16650,7 @@ class PolygonInteractionManager {
|
|
|
16677
16650
|
*/
|
|
16678
16651
|
updateMarkerDraggableState() {
|
|
16679
16652
|
const shouldBeDraggable = this.modeManager.canPerformAction("markerDrag");
|
|
16653
|
+
const markersShouldCapturePointer = this.modeManager.getCurrentMode() !== DrawMode.Clone;
|
|
16680
16654
|
this.getFeatureGroups().forEach((featureGroup) => {
|
|
16681
16655
|
const isActiveLayer = this.isFeatureGroupInActiveLayer(featureGroup);
|
|
16682
16656
|
const effectiveDraggable = shouldBeDraggable && isActiveLayer;
|
|
@@ -16685,6 +16659,10 @@ class PolygonInteractionManager {
|
|
|
16685
16659
|
const marker = layer;
|
|
16686
16660
|
try {
|
|
16687
16661
|
marker.options.draggable = effectiveDraggable;
|
|
16662
|
+
const element = marker.getElement();
|
|
16663
|
+
if (element) {
|
|
16664
|
+
element.style.pointerEvents = markersShouldCapturePointer ? "auto" : "none";
|
|
16665
|
+
}
|
|
16688
16666
|
if (marker.dragging) {
|
|
16689
16667
|
if (effectiveDraggable) {
|
|
16690
16668
|
marker.dragging.enable();
|
|
@@ -16779,6 +16757,7 @@ class PolygonInteractionManager {
|
|
|
16779
16757
|
if (layer instanceof L.Marker) {
|
|
16780
16758
|
this.cleanupMarker(layer);
|
|
16781
16759
|
} else if (layer instanceof L.Polygon) {
|
|
16760
|
+
this.detachPolygonNativeStartListeners(layer);
|
|
16782
16761
|
this.detachPolygonTouchStart(layer);
|
|
16783
16762
|
this.polygonFeatureGroupMap.delete(layer);
|
|
16784
16763
|
}
|
|
@@ -17281,7 +17260,6 @@ class PolygonInteractionManager {
|
|
|
17281
17260
|
if (this.dragUsesPointerEvents) {
|
|
17282
17261
|
document.addEventListener("pointermove", this._boundDragMoveListener);
|
|
17283
17262
|
document.addEventListener("pointerup", this._boundDragEndListener);
|
|
17284
|
-
return;
|
|
17285
17263
|
}
|
|
17286
17264
|
document.addEventListener("mousemove", this._boundDragMoveListener);
|
|
17287
17265
|
document.addEventListener("mouseup", this._boundDragEndListener);
|
|
@@ -17290,17 +17268,15 @@ class PolygonInteractionManager {
|
|
|
17290
17268
|
if (this._boundDragMoveListener) {
|
|
17291
17269
|
if (this.dragUsesPointerEvents) {
|
|
17292
17270
|
document.removeEventListener("pointermove", this._boundDragMoveListener);
|
|
17293
|
-
} else {
|
|
17294
|
-
document.removeEventListener("mousemove", this._boundDragMoveListener);
|
|
17295
17271
|
}
|
|
17272
|
+
document.removeEventListener("mousemove", this._boundDragMoveListener);
|
|
17296
17273
|
this._boundDragMoveListener = null;
|
|
17297
17274
|
}
|
|
17298
17275
|
if (this._boundDragEndListener) {
|
|
17299
17276
|
if (this.dragUsesPointerEvents) {
|
|
17300
17277
|
document.removeEventListener("pointerup", this._boundDragEndListener);
|
|
17301
|
-
} else {
|
|
17302
|
-
document.removeEventListener("mouseup", this._boundDragEndListener);
|
|
17303
17278
|
}
|
|
17279
|
+
document.removeEventListener("mouseup", this._boundDragEndListener);
|
|
17304
17280
|
this._boundDragEndListener = null;
|
|
17305
17281
|
}
|
|
17306
17282
|
this.dragUsesPointerEvents = false;
|
|
@@ -17333,6 +17309,17 @@ class PolygonInteractionManager {
|
|
|
17333
17309
|
}
|
|
17334
17310
|
this.polygonTouchStartListeners.delete(polygon2);
|
|
17335
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
|
+
}
|
|
17336
17323
|
attachDragCancelHandlers() {
|
|
17337
17324
|
if (this.dragCancelHandlersAttached) return;
|
|
17338
17325
|
this.dragCancelHandlersAttached = true;
|