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

Add clearer error message for map.queryRenderedFeatures... #3196

Merged
merged 5 commits into from Sep 16, 2016

Conversation

mollymerp
Copy link
Contributor

when called with a layer that does not exist in the map's style.
#3084

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs n/a
  • post benchmark scores n/a
  • manually test the debug page
  • get a PR review

@@ -115,6 +115,7 @@
});

map.on('click', function(e) {
var features = map.queryRenderedFeatures(e.point, {layers:['derp']});
Copy link
Member

Choose a reason for hiding this comment

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

Not necessary for this debug page.

if (!(this._layers[layerId] instanceof StyleLayer)) {
// this layer is not in the style.layers array
return this.fire('error', {error: 'The layer \'' + layerId + '\' does not exist in the map\'s style and cannot be queried for features.'});
}
includedSources[this._layers[layerId].source] = true;
Copy link
Member

Choose a reason for hiding this comment

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

You could remove some repetition here by doing:

var layer = this._layers[params.layers[i]];
...
layer.id

t.test('fires an error if layer included in params does not exist on the style', function(t) {
var errors = 0;
sinon.stub(style, 'fire', function() {
if (arguments[1].error && arguments[1].error.includes('does not exist in the map\'s style and cannot be queried for features.')) errors++;
Copy link
Member

Choose a reason for hiding this comment

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

I think it's cleaner to use usual function parameters rather than arguments.

@mollymerp
Copy link
Contributor Author

fixed @mourner !

Copy link
Member

@mourner mourner left a comment

Choose a reason for hiding this comment

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

Looks good!

var layer = this._layers[params.layers[i]];
if (!(layer instanceof StyleLayer)) {
// this layer is not in the style.layers array
return this.fire('error', {error: 'The layer \'' + params.layers[i] + '\' does not exist in the map\'s style and cannot be queried for features.'});
Copy link
Member

Choose a reason for hiding this comment

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

This line is a bit too long, can we make it two lines?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants