I'm using the mapbox-gl-js library trying to implement a function where the user can add polygons to a mapbox map and edit them if desired. I've been able to add the polygon to the map by adding a layer, but I don't know how to allow users to edit them. Is there a simple way to add polygons to mapbox and change whether or not they are editable?
after load map you can add Feature(point,line,polygon)
example:
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9'
});
var draw = new MapboxDraw();
map.addControl(draw);
map.on('load', function () {
var feature = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
49.62524414062499,
31.653381399664
],
[
55.458984375,
31.653381399664
],
[
55.458984375,
35.28150065789119
],
[
49.62524414062499,
35.28150065789119
],
[
49.62524414062499,
31.653381399664
]
]
]
}
}
]
};
var featureIds = draw.add(feature);
});
You're looking for the mapbox-gl-draw
plugin. You can see a demo here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With