Editing of geojson in mapbox gl

1.8k Views Asked by At

I am working on a map where I need to load->edit->save geojson. For now I am trying to use mapbox-gl-draw.js:

  1. Upload geojson from file.
  2. Add it to draw with draw.add()

    var feature = {
          id: 'unique-id',
          type: 'Feature',
          properties: {},
          geometry: { type: 'Polygon', coordinates: [[[-91.94884436037492,42.807248622513725],[-91.97322027590168,42.7829334446084],[-91.91022055055936,42.7708352918585],[-91.9150270691187,42.79250947320156],[-91.94884436037492,42.807248622513725]]] }
    };
    
    var featureIds = draw.add(feature);
    
  3. Remove the geojson from map

  4. Edit the polygon with draw lib
  5. Transform it back to geojson (put it to the layer) and show it as geojson on the map

Is there an easier way to edit the geojson? Maybe edit it with draw without removing/updating it from the map Thanks.

0

There are 0 best solutions below