I'm unable to convert my Layer properties into the properties of the GEOJson object using Leaflet(0.7.7)/Leaflet.Draw(latest). My workflow is:
1 Create Map: var map = L.map('#map', options);
2 Create a FeatureGroup: features= new L.FeatureGroup();
3 Add to the Leaflet Map: map.addLayer(features);
4 On the draw:created
event, I'm capturing e.layer
and adding a bunch of properties:
var layer = e.layer;
layer.properties = { Title: 'Hello' };
features.addLayer(layer);
geo_features = features.toGeoJSON();
However, my geo_features
always have empty property attributes in each of the features and I can't figure it out!
A (kind of ugly workaround) is using a
L.GeoJSON
layer and add the drawn layer's GeoJSON to it by using it'saddData
method. Afterwards grab the last layer in theL.GeoJSON
layer's_layers
object. At that point the layer has a valid GeoJSONfeature
property you can edit:iH8's initial answer was almost correct.
To specify properties that will appear in a vector layer's GeoJSON export (i.e. through its
.toGeoJSON()
method), you have to fill itsfeature.type
andfeature.properties
members:Now
myVectorLayer.toGeoJSON()
returns a valid GeoJSON feature object represented by: