Drag Mode
Drag Mode
You can enable Drag Mode for all layers on a map like this:
// enable Drag Mode like this:
map.pm.enableGlobalDragMode();
Or you enable dragging for a specific layer:
layer.pm.enableLayerDrag();
The following methods are available on layer.pm:
| Method | Returns | Description |
|---|---|---|
| enableLayerDrag() | - | Enables dragging for the layer. |
| disableLayerDrag() | - | Disables dragging for the layer. |
| layerDragEnabled() | Boolean | Returns if Drag Mode is enabled for the layer. |
| dragging() | Boolean | Returns if the layer is currently dragging. |
| cancel() | - | Reverts the layer to the state before changing. ⭐ |
The following methods are available on map.pm:
| Method | Returns | Description |
|---|---|---|
| enableGlobalDragMode() | - | Enables global Drag Mode. |
| disableGlobalDragMode() | - | Disables global Drag Mode. |
| toggleGlobalDragMode() | - | Toggles global Drag Mode. |
| globalDragModeEnabled() | Boolean | Returns true if global Drag Mode is enabled. false when disabled. |
| cancelGlobalDragMode() | - | Reverts the layers to the state before changing. ⭐ |
The following events are available on a layer instance:
| Event | Params | Description | Output |
|---|---|---|---|
| pm:dragstart | e | Fired when a layer starts being dragged. | layer, shape |
| pm:drag | e | Fired when a layer is dragged. | layer, containerPoint,latlng, layerPoint,originalEvent, shape |
| pm:dragend | e | Fired when a layer stops being dragged. | layer, shape |
| pm:dragenable | e | Fired when Drag Mode on a layer is enabled. | layer, shape |
| pm:dragdisable | e | Fired when Drag Mode on a layer is disabled. | layer, shape |
| pm:change | e | Fired coordinates of the layer changed. | layer, latlngs, shape |
| pm:cancel | e | Fired when the layer changes are canceled. ⭐ | layer |
The following events are available on a map instance:
| Event | Params | Description | Output |
|---|---|---|---|
| pm:globaldragmodetoggled | e | Fired when Drag Mode is toggled. | enabled, map |
| pm:globalcancel | e | Fired when cancel of a Mode is called. ⭐ | map |
You can also listen to specific Drag Mode events on the map instance like this:
map.on("pm:globaldragmodetoggled", (e) => {
console.log(e);
});
Example
Loading...