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

Guard against non-numeric id in GeoJSON features #4581

Merged
merged 5 commits into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/source/geojson_worker_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
return callback(null, null); // nothing in the given tile
}

// Encode the geojson-vt tile into binary vector tile form form. This
// is a convenience that allows `FeatureIndex` to operate the same way
// across `VectorTileSource` and `GeoJSONSource` data.
const geojsonWrapper = new GeoJSONWrapper(geoJSONTile.features);
geojsonWrapper.name = '_geojsonTileLayer';
let pbf = vtpbf({ layers: { '_geojsonTileLayer': geojsonWrapper }});
Expand Down
4 changes: 2 additions & 2 deletions src/source/geojson_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class FeatureWrapper {
this.rawGeometry = feature.geometry;
}
this.properties = feature.tags;
if ('id' in feature) {
this.id = feature.id;
if ('id' in feature && !isNaN(feature.id)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment here explaining the original issue and the reason for !isNaN/parseInt?

this.id = parseInt(feature.id, 10);
}
this.extent = EXTENT;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-10.01953125,
10.012129557908139
],
[
10.01953125,
10.012129557908139
],
[
10.01953125,
-10.012129557908139
],
[
-10.01953125,
-10.012129557908139
],
[
-10.01953125,
10.012129557908139
]
]
]
},
"type": "Feature",
"properties": {}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"version": 8,
"metadata": {
"test": {
"width": 64,
"height": 64,
"queryGeometry": [
32,
32
],
"debug": true
}
},
"zoom": 0,
"sources": {
"geojson": {
"type": "geojson",
"data": {
"type": "Feature",
"id": "foo",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[ -10, 10 ],
[ 10, 10 ],
[ 10, -10 ],
[ -10, -10 ],
[ -10, 10 ]
]
]
}
}
}
},
"layers": [
{
"id": "fill",
"type": "fill",
"source": "geojson"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
"type": "Feature",
"properties": {},
"id": "a",
"id": 1,
"geometry": {
"type": "Point",
"coordinates": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
"type": "Feature",
"properties": {},
"id": "a",
"id": 1,
"geometry": {
"type": "Point",
"coordinates": [
Expand All @@ -27,7 +27,7 @@
{
"type": "Feature",
"properties": {},
"id": "b",
"id": 2,
"geometry": {
"type": "Point",
"coordinates": [
Expand All @@ -48,7 +48,7 @@
"filter": [
"==",
"$id",
"a"
1
]
}
]
Expand Down