Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editable Polygons in Mapbox

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?

like image 566
user1916817 Avatar asked Aug 25 '17 16:08

user1916817


2 Answers

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);

 });
like image 82
esmaeil abootorabi Avatar answered Sep 19 '22 16:09

esmaeil abootorabi


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

like image 34
Steve Bennett Avatar answered Sep 16 '22 16:09

Steve Bennett