Skip to content

Commit

Permalink
prevent thrown error when a geojson tile doesn't have any features in…
Browse files Browse the repository at this point in the history
… it (#4803)

* prevent thrown error when a geojson tile doesn't have any features in it

* test empty geojson tile
  • Loading branch information
mollymerp authored Jun 8, 2017
1 parent e4e84dc commit 369aef9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/source/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ class Tile {
this.vtLayers = new vt.VectorTile(new Protobuf(this.rawTileData)).layers;
}

const layer = this.vtLayers._geojsonTileLayer || this.vtLayers[params.sourceLayer];
const sourceLayer = params ? params.sourceLayer : undefined;
const layer = this.vtLayers._geojsonTileLayer || this.vtLayers[sourceLayer];

if (!layer) return;

Expand Down
17 changes: 17 additions & 0 deletions test/unit/source/tile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ test('querySourceFeatures', (t) => {
t.end();
});

t.test('empty geojson tile', (t) => {
const tile = new Tile(new TileCoord(1, 1, 1));
let result;

result = [];
tile.querySourceFeatures(result, {});
t.equal(result.length, 0);

const geojsonWrapper = new GeoJSONWrapper([]);
geojsonWrapper.name = '_geojsonTileLayer';
tile.rawTileData = vtpbf({ layers: { '_geojsonTileLayer': geojsonWrapper }});
result = [];
t.doesNotThrow(tile.querySourceFeatures(result));
t.equal(result.length, 0);
t.end();
});

t.test('vector tile', (t) => {
const tile = new Tile(new TileCoord(1, 1, 1));
let result;
Expand Down

0 comments on commit 369aef9

Please sign in to comment.