From 1c9485629838bd8879573633b31eabcf5ca8c5f8 Mon Sep 17 00:00:00 2001 From: Jungzl <13jungzl@gmail.com> Date: Wed, 12 Apr 2023 01:43:16 +0800 Subject: [PATCH] fix: query only the layers that have been loaded (#2128) --- src/mapbox/mapbox.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/mapbox/mapbox.ts b/src/mapbox/mapbox.ts index 4ed449c4..8387f2ce 100644 --- a/src/mapbox/mapbox.ts +++ b/src/mapbox/mapbox.ts @@ -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);