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
Conversation
@@ -115,6 +115,7 @@ | |||
}); | |||
|
|||
map.on('click', function(e) { | |||
var features = map.queryRenderedFeatures(e.point, {layers:['derp']}); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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++; |
There was a problem hiding this comment.
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
.
8045a5a
to
983feb7
Compare
983feb7
to
20ff98d
Compare
fixed @mourner ! |
There was a problem hiding this 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.'}); |
There was a problem hiding this comment.
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?
when called with a layer that does not exist in the map's style.
#3084
Launch Checklist