diff --git a/x-pack/plugins/maps/public/actions/layer_actions.ts b/x-pack/plugins/maps/public/actions/layer_actions.ts index b7a07e98437a10..57f83b9533bdaf 100644 --- a/x-pack/plugins/maps/public/actions/layer_actions.ts +++ b/x-pack/plugins/maps/public/actions/layer_actions.ts @@ -379,11 +379,13 @@ export function removeSelectedLayer() { ) => { const state = getState(); const layerId = getSelectedLayerId(state); - dispatch(removeLayer(layerId)); + if (layerId) { + dispatch(removeLayer(layerId)); + } }; } -export function removeLayer(layerId: string | null) { +export function removeLayer(layerId: string) { return async ( dispatch: ThunkDispatch, getState: () => MapStoreState @@ -398,7 +400,7 @@ export function removeLayer(layerId: string | null) { }; } -function removeLayerFromLayerList(layerId: string | null) { +function removeLayerFromLayerList(layerId: string) { return ( dispatch: ThunkDispatch, getState: () => MapStoreState @@ -411,7 +413,7 @@ function removeLayerFromLayerList(layerId: string | null) { layerGettingRemoved.getInFlightRequestTokens().forEach((requestToken) => { dispatch(cancelRequest(requestToken)); }); - dispatch(cleanTooltipStateForLayer(layerId!)); + dispatch(cleanTooltipStateForLayer(layerId)); layerGettingRemoved.destroy(); dispatch({ type: REMOVE_LAYER, diff --git a/x-pack/plugins/maps/public/actions/map_actions.test.js b/x-pack/plugins/maps/public/actions/map_actions.test.js index 58621b0a70e04f..cbb6f0a4054cc7 100644 --- a/x-pack/plugins/maps/public/actions/map_actions.test.js +++ b/x-pack/plugins/maps/public/actions/map_actions.test.js @@ -27,6 +27,10 @@ describe('map_actions', () => { require('../selectors/map_selectors').getDataFilters = () => { return {}; }; + + require('../selectors/map_selectors').getLayerList = () => { + return []; + }; }); it('should add newMapConstants to dispatch action mapState', async () => { diff --git a/x-pack/plugins/maps/public/actions/map_actions.ts b/x-pack/plugins/maps/public/actions/map_actions.ts index 4efdd3dda344ec..4e76bb24c9e34a 100644 --- a/x-pack/plugins/maps/public/actions/map_actions.ts +++ b/x-pack/plugins/maps/public/actions/map_actions.ts @@ -18,6 +18,7 @@ import { getWaitingForMapReadyLayerListRaw, getQuery, getTimeFilters, + getLayerList, } from '../selectors/map_selectors'; import { CLEAR_GOTO, @@ -56,6 +57,7 @@ import { } from '../../common/descriptor_types'; import { INITIAL_LOCATION } from '../../common/constants'; import { scaleBounds } from '../../common/elasticsearch_util'; +import { cleanTooltipStateForLayer } from './tooltip_actions'; export function setMapInitError(errorMessage: string) { return { @@ -128,8 +130,7 @@ export function mapExtentChanged(newMapConstants: { zoom: number; extent: MapExt dispatch: ThunkDispatch, getState: () => MapStoreState ) => { - const state = getState(); - const dataFilters = getDataFilters(state); + const dataFilters = getDataFilters(getState()); const { extent, zoom: newZoom } = newMapConstants; const { buffer, zoom: currentZoom } = dataFilters; @@ -164,6 +165,15 @@ export function mapExtentChanged(newMapConstants: { zoom: number; extent: MapExt ...newMapConstants, }, }); + + if (currentZoom !== newZoom) { + getLayerList(getState()).map((layer) => { + if (!layer.showAtZoomLevel(newZoom)) { + dispatch(cleanTooltipStateForLayer(layer.getId())); + } + }); + } + await dispatch(syncDataForAllLayers()); }; } diff --git a/x-pack/plugins/maps/public/actions/tooltip_actions.ts b/x-pack/plugins/maps/public/actions/tooltip_actions.ts index 12451e04efbc3a..98a121e6be7a3b 100644 --- a/x-pack/plugins/maps/public/actions/tooltip_actions.ts +++ b/x-pack/plugins/maps/public/actions/tooltip_actions.ts @@ -72,7 +72,7 @@ export function openOnHoverTooltip(tooltipState: TooltipState) { }; } -export function cleanTooltipStateForLayer(layerId: string | null, layerFeatures: Feature[] = []) { +export function cleanTooltipStateForLayer(layerId: string, layerFeatures: Feature[] = []) { return (dispatch: Dispatch, getState: () => MapStoreState) => { let featuresRemoved = false; const openTooltips = getOpenTooltips(getState())