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?
Asked
Active
Viewed 3,547 times
2 Answers
4
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);
});

esmaeil abootorabi
- 41
- 2
2
You're looking for the mapbox-gl-draw
plugin. You can see a demo here.

Steve Bennett
- 114,604
- 39
- 168
- 219