convert geojson-converted layers back to features

This commit is contained in:
Vladimir Agafonkin 2013-04-19 20:16:43 +03:00 committed by John Firebaugh
parent 130d6d0fac
commit 5841fd87a4

View File

@ -158,24 +158,28 @@ L.extend(L.GeoJSON, {
} }
return coords; return coords;
},
getFeature: function (layer, newGeometry) {
return layer.feature ? L.extend(layer.feature, {geometry: newGeometry}) : newGeometry;
} }
}); });
L.Marker.include({ L.Marker.include({
toGeoJSON: function () { toGeoJSON: function () {
return { return L.GeoJSON.getFeature(this, {
type: 'Point', type: 'Point',
coordinates: L.GeoJSON.latLngToCoords(this.getLatLng()) coordinates: L.GeoJSON.latLngToCoords(this.getLatLng())
}; });
} }
}); });
L.Polyline.include({ L.Polyline.include({
toGeoJSON: function () { toGeoJSON: function () {
return { return L.GeoJSON.getFeature(this, {
type: 'LineString', type: 'LineString',
coordinates: L.GeoJSON.latLngsToCoords(this.getLatLngs()) coordinates: L.GeoJSON.latLngsToCoords(this.getLatLngs())
}; });
} }
}); });
@ -194,10 +198,10 @@ L.Polygon.include({
} }
} }
return { return L.GeoJSON.getFeature(this, {
type: 'Polygon', type: 'Polygon',
coordinates: coords coordinates: coords
}; });
} }
}); });
@ -211,10 +215,10 @@ L.Polygon.include({
coords.push(layer.toGeoJSON().coordinates); coords.push(layer.toGeoJSON().coordinates);
}); });
return { return L.GeoJSON.getFeature(this, {
type: type, type: type,
coordinates: coords coordinates: coords
}; });
} }
}); });
} }
@ -233,10 +237,10 @@ L.LayerGroup.include({
} }
}); });
return { return L.GeoJSON.getFeature(this, {
type: 'GeometryCollection', type: 'GeometryCollection',
geometries: geoms geometries: geoms
}; });
} }
}); });