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

queryRenderedFeatures: Return empty array on errors #4993

Merged
merged 1 commit into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,15 +756,15 @@ class Style extends Evented {
if (params && params.layers) {
if (!Array.isArray(params.layers)) {
this.fire('error', {error: 'parameters.layers must be an Array.'});
return;
return [];
}
for (const layerId of params.layers) {
const layer = this._layers[layerId];
if (!layer) {
// this layer is not in the style.layers array
this.fire('error', {error: `The layer '${layerId}' does not exist ` +
`in the map's style and cannot be queried for features.`});
return;
return [];
}
includedSources[layer.source] = true;
}
Expand Down
3 changes: 2 additions & 1 deletion test/unit/style/style.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1411,8 +1411,9 @@ test('Style#queryRenderedFeatures', (t) => {
t.stub(style, 'fire').callsFake((type, data) => {
if (data.error && data.error.includes('does not exist in the map\'s style and cannot be queried for features.')) errors++;
});
style.queryRenderedFeatures([{column: 1, row: 1, zoom: 1}], {layers:['merp']});
const results = style.queryRenderedFeatures([{column: 1, row: 1, zoom: 1}], {layers:['merp']});
t.equals(errors, 1);
t.equals(results.length, 0);
t.end();
});

Expand Down