Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load geoJson in MapBox for editing with Leaflet.Draw

I try to load geoJson data in Mapbox and edit it with the plugin Leaflet.Draw

Here is an example : fiddle

var featureGroup = L.featureGroup().addTo(map);

var geojson = {
  "type": "FeatureCollection",
  "features": [ ...........  ]
}


L.geoJson(geojson).addTo(featureGroup);

When i click to the edit button, i have an error :

Uncaught TypeError: Cannot read property 'enable' of undefined

Object seems to be editable but i can't modify it.

What is the correct way to add geojson object in mapbox draw layer ?

like image 852
manusvs650 Avatar asked May 27 '14 15:05

manusvs650


2 Answers

I have found the solution :

L.geoJson(geojson, {
  onEachFeature: function (feature, layer) {
    featureGroup.addLayer(layer);
  }
});
like image 183
manusvs650 Avatar answered Nov 20 '22 08:11

manusvs650


Here is working example using CoffeeScript:

drawnItems = new L.FeatureGroup()
map.addLayer drawnItems

layers = L.geoJson geojson
layers.eachLayer (layer) => drawnItems.addLayer layer
like image 43
Stepan Kuzmin Avatar answered Nov 20 '22 07:11

Stepan Kuzmin