Skip to content

Commit

Permalink
[Maps] Prevent console error by not querying for features in non-exis…
Browse files Browse the repository at this point in the history
…ting mapbox layers (#34321)
  • Loading branch information
thomasneirynck authored Apr 2, 2019
1 parent d3dd95d commit 2bba68f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions x-pack/plugins/maps/public/components/map/mb/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 });
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/shared/layers/vector_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export class VectorLayer extends AbstractLayer {
}

canShowTooltip() {
return this._source.canFormatFeatureProperties();
return this.isVisible() && this._source.canFormatFeatureProperties();
}

getFeatureByFeatureById(id) {
Expand Down

0 comments on commit 2bba68f

Please sign in to comment.