-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Allow null GeoJSON geometries. #1240
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
Conversation
This change checks if a geometry/ies in GeoJSON are set as null, in which case it will skip it.
|
Here's some sample JSON in case it's needed for testing or demonstration. The first feature has a single point, second is a collection of geometries and the third is null. {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
126.982812881,
37.5944097607
]
},
"properties": {
"popupContent": "I'm a single point."
}
},
{
"type": "GeometryCollection",
"geometries": [
{
"type": "Polygon",
"coordinates": [
[
[
-33.3984375,
49.8379824531
],
[
-33.837890625,
43.0046471278
],
[
-23.466796875,
42.6177914328
],
[
-33.3984375,
49.8379824531
]
]
]
},
{
"type": "Polygon",
"coordinates": [
[
[
-27.158203125,
49.8946343957
],
[
-19.423828125,
44.9647979303
],
[
-11.6015625,
41.3768085657
],
[
-4.04296875,
44.715513732
],
[
-7.3828125,
50.2331518325
],
[
-17.05078125,
51.6725551484
],
[
-27.158203125,
49.8946343957
]
]
]
},
{
"type": "LineString",
"coordinates": [
[
0,
50.5134265263
],
[
4.04296875,
42.4883019796
],
[
0,
50.5134265263
]
]
},
{
"type": "Point",
"coordinates": [
5.361328125,
50.5134265263
]
},
{
"type": "LineString",
"coordinates": [
[
-33.310546875,
51.1793429793
],
[
-13.359375,
38.8225909762
],
[
-33.310546875,
51.1793429793
]
]
}
],
"properties": {
"popupContent": "I should have multiple geometries showing."
}
},
{
"type": "Feature",
"geometry": null,
"properties": {
"popupContent": "This is some content in a null geometry which shouldn't show up."
}
}
]
} |
| this.addData(features[i]); | ||
| // Only add this if geometry or geometries are set and not null | ||
| if ((typeof features[i].geometries !== undefined && features[i].geometries !== null) && | ||
| (typeof features[i].geometry !== undefined && features[i].geometry !== null)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just if (features[i].geometries || features[i].geometry) will be enough. It will coerce to false if not present or null and to true otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that's much more elegant. Let me make the changes.
|
Just ran into this bug today as well. Can't wait to see a solution merged. |
Used feedback from @mourner to make the change from the pull request Leaflet#1240
|
I made the changes and it seems to check out fine on my end. Everything looks good? |
|
Yep! |
Allow null GeoJSON geometries.
Used feedback from @mourner to make the change from the pull request Leaflet#1240
Used feedback from @mourner to make the change from the pull request Leaflet#1240
This change checks if a geometry/ies in GeoJSON are set as null, in which case it will skip it.
I tried to follow the coding style for conditionals but I couldn't find any long if statements like the one I'm contributing. Should there be a better way to format this?
Related to issue #1235