1.0.1 • Published 5 years ago
mapbox-gl-draw-prevent-drag-feature v1.0.1
mapbox-gl-draw-prevent-drag-feature
Patch for MapboxDraw to prevent dragging features.
A common usecase is a waypoint editing mode, allowing to drag vertices only.
Patched MapboxDraw modes:
- simple_select
- selecting a polygon or line switches to direct_select mode, to save one click when switching from simple_select to direct_select mode
- multi-selection is prevented for consistency with direct_select mode
- direct_select
- dragging a polygon or a line is prevented
Install
npm install mapbox-gl-draw-prevent-drag-feature
or
<script src="https://unpkg.com/mapbox-gl-draw-prevent-drag-feature@1.0.1/dist/mapbox-gl-draw-prevent-drag-feature.min.js"></script>
Usage
This plugin exposes a single function enable
, which should be used to patch the original MapboxDraw.modes
object.
import MapboxDraw from 'mapbox-gl-draw';
import MapboxDrawPreventDragFeature from 'mapbox-gl-draw-prevent-drag-feature';
let modes = MapboxDraw.modes;
modes = MapboxDrawPreventDragFeature.enable(modes);
const draw = new MapboxDraw({ modes });
The second argument to MapboxDrawPreventDragFeature.enable
is a function to control which features can be dragged (defaults to all).
modes = MapboxDrawPreventDragFeature.enable(modes, feature => feature.properties.risk);