diff --git a/x-pack/plugins/maps/public/components/map/mb/view.js b/x-pack/plugins/maps/public/components/map/mb/view.js index 775e4bd9c9a08..53d6473cbc69b 100644 --- a/x-pack/plugins/maps/public/components/map/mb/view.js +++ b/x-pack/plugins/maps/public/components/map/mb/view.js @@ -115,9 +115,20 @@ export class MBMapContainer extends React.Component { return popupAnchorLocation; } _getMbLayerIdsForTooltips() { - return this.props.layerList.reduce((mbLayerIds, layer) => { + + const mbLayerIds = this.props.layerList.reduce((mbLayerIds, layer) => { return layer.canShowTooltip() ? mbLayerIds.concat(layer.getMbLayerIds()) : mbLayerIds; }, []); + + + //ensure all layers that are actually on the map + //the raw list may contain layer-ids that have not been added to the map yet. + //For example: + //a vector or heatmap layer will not add a source and layer to the mapbox-map, until that data is available. + //during that data-fetch window, the app should not query for layers that do not exist. + return mbLayerIds.filter((mbLayerId) => { + return !!this._mbMap.getLayer(mbLayerId); + }); } _getMapState() { @@ -156,7 +167,6 @@ export class MBMapContainer extends React.Component { x: mbLngLatPoint.x + PADDING, y: mbLngLatPoint.y + PADDING } - ]; return this._mbMap.queryRenderedFeatures(mbBbox, { layers: mbLayerIds }); } diff --git a/x-pack/plugins/maps/public/shared/layers/vector_layer.js b/x-pack/plugins/maps/public/shared/layers/vector_layer.js index d2736b04f77bd..abd9e02e6a36d 100644 --- a/x-pack/plugins/maps/public/shared/layers/vector_layer.js +++ b/x-pack/plugins/maps/public/shared/layers/vector_layer.js @@ -527,7 +527,7 @@ export class VectorLayer extends AbstractLayer { } canShowTooltip() { - return this._source.canFormatFeatureProperties(); + return this.isVisible() && this._source.canFormatFeatureProperties(); } getFeatureByFeatureById(id) {