fix: query only the layers that have been loaded (#2128)

This commit is contained in:
Jungzl 2023-04-12 01:43:16 +08:00 committed by GitHub
parent 86efdc0433
commit 1c94856298
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -798,7 +798,7 @@ export default class Mapbox {
if (eventType === 'mousemove') {
try {
features = this._map.queryRenderedFeatures(e.point, {
layers: props.interactiveLayerIds
layers: props.interactiveLayerIds.filter(this._map.getLayer)
});
} catch {
features = [];
@ -832,11 +832,16 @@ export default class Mapbox {
const cb = this.props[pointerEvents[e.type]];
if (cb) {
if (this.props.interactiveLayerIds && e.type !== 'mouseover' && e.type !== 'mouseout') {
const features =
this._hoveredFeatures ||
this._map.queryRenderedFeatures(e.point, {
layers: this.props.interactiveLayerIds
});
let features;
try {
features =
this._hoveredFeatures ||
this._map.queryRenderedFeatures(e.point, {
layers: this.props.interactiveLayerIds.filter(this._map.getLayer)
});
} catch {
features = [];
}
e.features = features;
}
cb(e);