A mode collection for MapboxGL Draw
View the Project on GitHub nifty10m/mapbox-gl-draw-mode-collection
This mode collection implements some useful modes for splitting and transforming polygons.
npm install @nifty10m/mapbox-gl-draw-mode-collection
import { StampMode, TransformMode } from '@nifty10m/mapbox-gl-draw-mode-collection';
Get the js file from the dist/
folder and include in your project.
<script type="text/javascript" src="mode-collection.min.js"></script>
Ensure you are loading draw onto your map as a control before triggering changeMode
.
var draw = new MapboxDraw(
modes: Object.assign(
'stamp': ModeCollection.StampMode,
'transform': ModeCollection.TransformMode,
}, MapboxDraw.modes)
});
map.addControl(draw);
/*
Activate the stamp mode with a base feature collection that should be stamped/split with a hand drawn polygon
*/
draw.changeMode('stamp', {
baseFeatureCollection: someFeatureCollection
});
/*
Activate the transform mode with an array of feature IDs that are added to draw
*/
var featureIds = draw.set(someFeatureCollection);
draw.changeMode('transform', {
featureIds: featureIds,
boundary: someBoundary // optional,
});