From 2bba68f85853abebf93c008e709c40ae24192cd7 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 2 Apr 2019 10:07:19 -0400 Subject: [PATCH] [Maps] Prevent console error by not querying for features in non-existing mapbox layers (#34321) --- .../plugins/maps/public/components/map/mb/view.js | 14 ++++++++++++-- .../maps/public/shared/layers/vector_layer.js | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) 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 775e4bd9c9a0..53d6473cbc69 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 d2736b04f77b..abd9e02e6a36 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) {