L.GeoJSON.asFeature should pass through FeatureCollections (#5049)

* L.GeoJSON.asFeature should pass through FeatureCollections

* Add unit test to verify FeatureCollection toGeoJSON
This commit is contained in:
Iván Sánchez Ortega 2016-11-10 13:53:38 +01:00 committed by GitHub
parent d0d699bfa4
commit fd78560036
2 changed files with 25 additions and 1 deletions

View File

@ -68,4 +68,28 @@
}, ctx); }, ctx);
}); });
}); });
describe("#toGeoJSON", function () {
it('should return valid GeoJSON for a layer with a FeatureCollection', function () {
var geoJSON = {
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"properties":{},
"geometry": {
"type":"Point",
"coordinates": [78.3984375, 56.9449741808516]
}
}
]
};
var layerGroup = L.layerGroup();
var layer = L.geoJSON(geoJSON);
layerGroup.addLayer(layer);
L.geoJson(layerGroup.toGeoJSON());
});
});
}); });

View File

@ -264,7 +264,7 @@ L.extend(L.GeoJSON, {
// @function asFeature(geojson: Object): Object // @function asFeature(geojson: Object): Object
// Normalize GeoJSON geometries/features into GeoJSON features. // Normalize GeoJSON geometries/features into GeoJSON features.
asFeature: function (geojson) { asFeature: function (geojson) {
if (geojson.type === 'Feature') { if (geojson.type === 'Feature' || geojson.type === 'FeatureCollection') {
return geojson; return geojson;
} }