Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix invalid GeoJSON produced by nested LayerGroups #5359

Merged

Conversation

Resonance1584
Copy link
Contributor

When a LayerGroup contains another LayerGroup .toGeoJSON returns an invalid GeoJSON object as it will return nested FeatureCollection objects.

This fix squashes nested FeatureCollections by concatenating their features array with the parent FeatureCollection's features array.

The GeoJSON spec states that a FeatureCollection's features property contains an array of Feature objects.

http://geojson.org/geojson-spec.html#feature-collection-objects

The value corresponding to "features" is an array. Each element in the array is a feature object as defined above.

Currently LayerGroup.toGeoJSON will return a FeatureCollection where the features array may contain one or more FeatureCollection objects.

Example:
https://playground-leaflet.rhcloud.com/pin/2/edit?html,console

Copy link
Member

@IvanSanchez IvanSanchez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading https://gis.stackexchange.com/questions/176801/how-to-include-a-geojson-featurecollection-inside-another-featurecollection , I'm inclined to accept this. I wonder if any other core devs @perliedman @mourner have any opinions on this.

@@ -356,4 +356,17 @@ describe("L.LayerGroup#toGeoJSON", function () {
features: []
});
});

it('should return only one FeatureCollection for nested LayerGroups', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay tests!! 👍 😄

@perliedman perliedman merged commit 0ed260c into Leaflet:master Mar 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants