Skip to content

Commit

Permalink
treat features with empty coordinates like null geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Jun 17, 2024
1 parent ed8707b commit 2a8b3d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function convertFeature(features, geojson, options, index) {
if (!geojson.geometry) return;

const coords = geojson.geometry.coordinates;
if (coords && coords.length === 0) return;

const type = geojson.geometry.type;
const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
let geometry = [];
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/empty-coords.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type":"Polygon",
"coordinates": []
}
5 changes: 5 additions & 0 deletions test/test-full.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ test('null geometry', () => {
assert.deepEqual({}, genTiles(getJSON('feature-null-geometry.json')));
});

test('empty coordinates', () => {
// should ignore features with empty coordinates
assert.deepEqual({}, genTiles(getJSON('empty-coords.json')));
});

function getJSON(name) {
return JSON.parse(fs.readFileSync(new URL(`fixtures/${name}`, import.meta.url)));
}
Expand Down

0 comments on commit 2a8b3d5

Please sign in to comment.