Skip to content

Commit 09c950b

Browse files
[Maps] Do not check count for blended layers when layer is not visible (#66460)
* [Maps] Do not check count for blended layers when layer is not visible * move visibility logic to map_actions where syncData is called * clean up * fix syntax error * remove async action * make syncDataForAllLayers a proper redux action * simplify * fix functional test Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 3228f1d commit 09c950b

File tree

6 files changed

+47
-57
lines changed

6 files changed

+47
-57
lines changed

x-pack/plugins/maps/public/actions/map_actions.js

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,36 @@ function getLayerById(layerId, state) {
111111
});
112112
}
113113

114-
async function syncDataForAllLayers(dispatch, getState, dataFilters) {
115-
const state = getState();
116-
const layerList = getLayerList(state);
117-
const syncs = layerList.map(layer => {
118-
const loadingFunctions = getLayerLoadingCallbacks(dispatch, getState, layer.getId());
119-
return layer.syncData({ ...loadingFunctions, dataFilters });
120-
});
121-
await Promise.all(syncs);
114+
function syncDataForAllLayers() {
115+
return async (dispatch, getState) => {
116+
const syncPromises = getLayerList(getState()).map(async layer => {
117+
return dispatch(syncDataForLayer(layer));
118+
});
119+
await Promise.all(syncPromises);
120+
};
121+
}
122+
123+
function syncDataForLayer(layer) {
124+
return async (dispatch, getState) => {
125+
const dataFilters = getDataFilters(getState());
126+
if (!layer.isVisible() || !layer.showAtZoomLevel(dataFilters.zoom)) {
127+
return;
128+
}
129+
130+
await layer.syncData({
131+
...getLayerLoadingCallbacks(dispatch, getState, layer.getId()),
132+
dataFilters,
133+
});
134+
};
135+
}
136+
137+
function syncDataForLayerId(layerId) {
138+
return async (dispatch, getState) => {
139+
const layer = getLayerById(layerId, getState());
140+
if (layer) {
141+
dispatch(syncDataForLayer(layer));
142+
}
143+
};
122144
}
123145

124146
export function cancelAllInFlightRequests() {
@@ -192,7 +214,7 @@ export function rollbackToTrackedLayerStateForSelectedLayer() {
192214
// syncDataForLayer may not trigger endDataLoad if no re-fetch is required
193215
dispatch(updateStyleMeta(layerId));
194216

195-
dispatch(syncDataForLayer(layerId));
217+
dispatch(syncDataForLayerId(layerId));
196218
};
197219
}
198220

@@ -252,7 +274,7 @@ export function addLayer(layerDescriptor) {
252274
type: ADD_LAYER,
253275
layer: layerDescriptor,
254276
});
255-
dispatch(syncDataForLayer(layerDescriptor.id));
277+
dispatch(syncDataForLayerId(layerDescriptor.id));
256278
};
257279
}
258280

@@ -333,7 +355,7 @@ export function setLayerVisibility(layerId, makeVisible) {
333355
visibility: makeVisible,
334356
});
335357
if (makeVisible) {
336-
dispatch(syncDataForLayer(layerId));
358+
dispatch(syncDataForLayer(layer));
337359
}
338360
};
339361
}
@@ -466,8 +488,7 @@ export function mapExtentChanged(newMapConstants) {
466488
...newMapConstants,
467489
},
468490
});
469-
const newDataFilters = { ...dataFilters, ...newMapConstants };
470-
await syncDataForAllLayers(dispatch, getState, newDataFilters);
491+
await dispatch(syncDataForAllLayers());
471492
};
472493
}
473494

@@ -751,7 +772,7 @@ export function updateSourceProp(layerId, propName, value, newLayerType) {
751772
dispatch(updateLayerType(layerId, newLayerType));
752773
}
753774
await dispatch(clearMissingStyleProperties(layerId));
754-
dispatch(syncDataForLayer(layerId));
775+
dispatch(syncDataForLayerId(layerId));
755776
};
756777
}
757778

@@ -771,20 +792,6 @@ function updateLayerType(layerId, newLayerType) {
771792
};
772793
}
773794

774-
export function syncDataForLayer(layerId) {
775-
return async (dispatch, getState) => {
776-
const targetLayer = getLayerById(layerId, getState());
777-
if (targetLayer) {
778-
const dataFilters = getDataFilters(getState());
779-
const loadingFunctions = getLayerLoadingCallbacks(dispatch, getState, layerId);
780-
await targetLayer.syncData({
781-
...loadingFunctions,
782-
dataFilters,
783-
});
784-
}
785-
};
786-
}
787-
788795
export function updateLayerLabel(id, newLabel) {
789796
return {
790797
type: UPDATE_LAYER_PROP,
@@ -830,7 +837,7 @@ export function setLayerQuery(id, query) {
830837
newValue: query,
831838
});
832839

833-
dispatch(syncDataForLayer(id));
840+
dispatch(syncDataForLayerId(id));
834841
};
835842
}
836843

@@ -895,8 +902,7 @@ export function setQuery({ query, timeFilters, filters = [], refresh = false })
895902
filters,
896903
});
897904

898-
const dataFilters = getDataFilters(getState());
899-
await syncDataForAllLayers(dispatch, getState, dataFilters);
905+
await dispatch(syncDataForAllLayers());
900906
};
901907
}
902908

@@ -909,13 +915,12 @@ export function setRefreshConfig({ isPaused, interval }) {
909915
}
910916

911917
export function triggerRefreshTimer() {
912-
return async (dispatch, getState) => {
918+
return async dispatch => {
913919
dispatch({
914920
type: TRIGGER_REFRESH_TIMER,
915921
});
916922

917-
const dataFilters = getDataFilters(getState());
918-
await syncDataForAllLayers(dispatch, getState, dataFilters);
923+
await dispatch(syncDataForAllLayers());
919924
};
920925
}
921926

@@ -956,7 +961,7 @@ export function updateLayerStyle(layerId, styleDescriptor) {
956961
dispatch(updateStyleMeta(layerId));
957962

958963
// Style update may require re-fetch, for example ES search may need to retrieve field used for dynamic styling
959-
dispatch(syncDataForLayer(layerId));
964+
dispatch(syncDataForLayerId(layerId));
960965
};
961966
}
962967

@@ -994,12 +999,12 @@ export function setJoinsForLayer(layer, joins) {
994999
return async dispatch => {
9951000
await dispatch({
9961001
type: SET_JOINS,
997-
layer: layer,
998-
joins: joins,
1002+
layer,
1003+
joins,
9991004
});
10001005

10011006
await dispatch(clearMissingStyleProperties(layer.getId()));
1002-
dispatch(syncDataForLayer(layer.getId()));
1007+
dispatch(syncDataForLayerId(layer.getId()));
10031008
};
10041009
}
10051010

x-pack/plugins/maps/public/classes/layers/tile_layer/tile_layer.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ export class TileLayer extends AbstractLayer {
2525
}
2626

2727
async syncData({ startLoading, stopLoading, onLoadError, dataFilters }) {
28-
if (!this.isVisible() || !this.showAtZoomLevel(dataFilters.zoom)) {
29-
return;
30-
}
3128
const sourceDataRequest = this.getSourceDataRequest();
3229
if (sourceDataRequest) {
3330
//data is immmutable

x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ export class TiledVectorLayer extends VectorLayer {
7878
}
7979

8080
async syncData(syncContext: SyncContext) {
81-
if (!this.isVisible() || !this.showAtZoomLevel(syncContext.dataFilters.zoom)) {
82-
return;
83-
}
84-
8581
await this._syncSourceStyleMeta(syncContext, this._source, this._style);
8682
await this._syncSourceFormatters(syncContext, this._source, this._style);
8783
await this._syncMVTUrlTemplate(syncContext);

x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,6 @@ export class VectorLayer extends AbstractLayer {
571571
// Given 2 above, which source/style to use can not be pulled from data request state.
572572
// Therefore, source and style are provided as arugments and must be used instead of calling getSource or getCurrentStyle.
573573
async _syncData(syncContext, source, style) {
574-
if (!this.isVisible() || !this.showAtZoomLevel(syncContext.dataFilters.zoom)) {
575-
return;
576-
}
577-
578574
await this._syncSourceStyleMeta(syncContext, source, style);
579575
await this._syncSourceFormatters(syncContext, source, style);
580576
const sourceResult = await this._syncSource(syncContext, source, style);

x-pack/plugins/maps/public/classes/layers/vector_tile_layer/vector_tile_layer.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ export class VectorTileLayer extends TileLayer {
4545
}
4646

4747
async syncData({ startLoading, stopLoading, onLoadError, dataFilters }) {
48-
if (!this.isVisible() || !this.showAtZoomLevel(dataFilters.zoom)) {
49-
return;
50-
}
51-
5248
const nextMeta = { tileLayerId: this.getSource().getTileLayerId() };
5349
const canSkipSync = this._canSkipSync({
5450
prevDataRequest: this.getSourceDataRequest(),

x-pack/test/functional/es_archives/maps/kibana/data.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
"title" : "document example top hits",
234234
"description" : "",
235235
"mapStateJSON" : "{\"zoom\":4.1,\"center\":{\"lon\":-100.61091,\"lat\":33.23887},\"timeFilters\":{\"from\":\"2015-09-20T00:00:00.000Z\",\"to\":\"2015-09-24T01:00:00.000Z\"},\"refreshConfig\":{\"isPaused\":true,\"interval\":1000},\"query\":{\"query\":\"\",\"language\":\"kuery\"}}",
236-
"layerListJSON" : "[{\"id\":\"0hmz5\",\"sourceDescriptor\":{\"type\":\"EMS_TMS\",\"id\":\"road_map\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"TILE\",\"properties\":{}},\"type\":\"TILE\",\"minZoom\":0,\"maxZoom\":24},{\"id\":\"z52lq\",\"label\":\"logstash\",\"minZoom\":0,\"maxZoom\":24,\"sourceDescriptor\":{\"id\":\"e1a5e1a6-676c-4a89-8ea9-0d91d64b73c6\",\"type\":\"ES_SEARCH\",\"geoField\":\"geo.coordinates\",\"limit\":2048,\"filterByMapBounds\":true,\"showTooltip\":true,\"tooltipProperties\":[],\"topHitsTimeField\":\"@timestamp\",\"useTopHits\":true,\"topHitsSplitField\":\"machine.os.raw\",\"topHitsSize\":2,\"indexPatternRefName\":\"layer_1_source_index_pattern\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#e6194b\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}}},\"previousStyle\":null},\"type\":\"VECTOR\"}]",
236+
"layerListJSON" : "[{\"id\":\"z52lq\",\"label\":\"logstash\",\"minZoom\":0,\"maxZoom\":24,\"sourceDescriptor\":{\"id\":\"e1a5e1a6-676c-4a89-8ea9-0d91d64b73c6\",\"type\":\"ES_SEARCH\",\"geoField\":\"geo.coordinates\",\"limit\":2048,\"filterByMapBounds\":true,\"showTooltip\":true,\"tooltipProperties\":[],\"topHitsTimeField\":\"@timestamp\",\"useTopHits\":true,\"topHitsSplitField\":\"machine.os.raw\",\"topHitsSize\":2,\"indexPatternRefName\":\"layer_1_source_index_pattern\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#e6194b\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}}},\"previousStyle\":null},\"type\":\"VECTOR\"}]",
237237
"uiStateJSON" : "{\"isLayerTOCOpen\":true,\"openTOCDetails\":[]}",
238238
"bounds" : {
239239
"type" : "polygon",
@@ -467,7 +467,7 @@
467467
"type": "envelope"
468468
},
469469
"description": "",
470-
"layerListJSON" : "[{\"id\":\"0hmz5\",\"label\":\"EMS base layer (road_map)\",\"sourceDescriptor\":{\"type\":\"EMS_TMS\",\"id\":\"road_map\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"TILE\",\"properties\":{}},\"type\":\"VECTOR_TILE\",\"minZoom\":0,\"maxZoom\":24},{\"id\":\"n1t6f\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"sourceDescriptor\":{\"id\":\"62eca1fc-fe42-11e8-8eb2-f2801f1b9fd1\",\"type\":\"ES_SEARCH\",\"geoField\":\"geometry\",\"limit\":2048,\"filterByMapBounds\":false,\"showTooltip\":true,\"tooltipProperties\":[\"name\"],\"applyGlobalQuery\":false,\"indexPatternRefName\":\"layer_1_source_index_pattern\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"DYNAMIC\",\"options\":{\"fieldMetaOptions\":{\"isEnabled\":false,\"sigma\":3},\"field\":{\"label\":\"max(prop1) group by meta_for_geo_shapes*.shape_name\",\"name\":\"__kbnjoin__max_of_prop1_groupby_meta_for_geo_shapes*.shape_name\",\"origin\":\"join\"},\"color\":\"Blues\"}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}}},\"temporary\":true,\"previousStyle\":null},\"type\":\"VECTOR\",\"joins\":[{\"leftField\":\"name\",\"right\":{\"id\":\"855ccb86-fe42-11e8-8eb2-f2801f1b9fd1\",\"indexPatternTitle\":\"meta_for_geo_shapes*\",\"term\":\"shape_name\",\"metrics\":[{\"type\":\"max\",\"field\":\"prop1\"}],\"applyGlobalQuery\":true,\"indexPatternRefName\":\"layer_1_join_0_index_pattern\"}}]}]",
470+
"layerListJSON" : "[{\"id\":\"n1t6f\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"sourceDescriptor\":{\"id\":\"62eca1fc-fe42-11e8-8eb2-f2801f1b9fd1\",\"type\":\"ES_SEARCH\",\"geoField\":\"geometry\",\"limit\":2048,\"filterByMapBounds\":false,\"showTooltip\":true,\"tooltipProperties\":[\"name\"],\"applyGlobalQuery\":false,\"indexPatternRefName\":\"layer_1_source_index_pattern\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"DYNAMIC\",\"options\":{\"fieldMetaOptions\":{\"isEnabled\":false,\"sigma\":3},\"field\":{\"label\":\"max(prop1) group by meta_for_geo_shapes*.shape_name\",\"name\":\"__kbnjoin__max_of_prop1_groupby_meta_for_geo_shapes*.shape_name\",\"origin\":\"join\"},\"color\":\"Blues\"}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}}},\"temporary\":true,\"previousStyle\":null},\"type\":\"VECTOR\",\"joins\":[{\"leftField\":\"name\",\"right\":{\"id\":\"855ccb86-fe42-11e8-8eb2-f2801f1b9fd1\",\"indexPatternTitle\":\"meta_for_geo_shapes*\",\"term\":\"shape_name\",\"metrics\":[{\"type\":\"max\",\"field\":\"prop1\"}],\"applyGlobalQuery\":true,\"indexPatternRefName\":\"layer_1_join_0_index_pattern\"}}]}]",
471471
"mapStateJSON": "{\"zoom\":3.02,\"center\":{\"lon\":77.33426,\"lat\":-0.04647},\"timeFilters\":{\"from\":\"now-17m\",\"to\":\"now\",\"mode\":\"quick\"},\"refreshConfig\":{\"isPaused\":true,\"interval\":1000}}",
472472
"title": "join example",
473473
"uiStateJSON": "{\"isLayerTOCOpen\":true,\"openTOCDetails\":[\"n1t6f\"]}"
@@ -512,7 +512,7 @@
512512
],
513513
"type": "envelope"
514514
},
515-
"layerListJSON": "[{\"id\":\"0hmz5\",\"sourceDescriptor\":{\"type\":\"EMS_TMS\",\"id\":\"road_map\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"TILE\",\"properties\":{}},\"type\":\"TILE\",\"minZoom\":0,\"maxZoom\":24},{\"id\":\"3xlvm\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"sourceDescriptor\":{\"resolution\": \"COARSE\",\"type\":\"ES_GEO_GRID\",\"id\":\"427aa49d-a552-4e7d-a629-67c47db27128\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\",\"geoField\":\"geo.coordinates\",\"requestType\":\"heatmap\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"HEATMAP\",\"refinement\":\"coarse\",\"properties\":{},\"previousStyle\":null},\"type\":\"HEATMAP\"}]",
515+
"layerListJSON": "[{\"id\":\"3xlvm\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"sourceDescriptor\":{\"resolution\": \"COARSE\",\"type\":\"ES_GEO_GRID\",\"id\":\"427aa49d-a552-4e7d-a629-67c47db27128\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\",\"geoField\":\"geo.coordinates\",\"requestType\":\"heatmap\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"HEATMAP\",\"refinement\":\"coarse\",\"properties\":{},\"previousStyle\":null},\"type\":\"HEATMAP\"}]",
516516
"mapStateJSON": "{\"zoom\":3.59,\"center\":{\"lon\":-98.05765,\"lat\":38.32288},\"timeFilters\":{\"from\":\"2015-09-20T00:00:00.000Z\",\"to\":\"2015-09-20T01:00:00.000Z\"},\"refreshConfig\":{\"isPaused\":true,\"interval\":1000}}",
517517
"title": "geo grid heatmap example",
518518
"uiStateJSON": "{\"isDarkMode\":false}"
@@ -543,7 +543,7 @@
543543
"type": "envelope"
544544
},
545545
"description": "",
546-
"layerListJSON": "[{\"id\":\"0hmz5\",\"sourceDescriptor\":{\"type\":\"EMS_TMS\",\"id\":\"road_map\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"TILE\",\"properties\":{}},\"type\":\"TILE\",\"minZoom\":0,\"maxZoom\":24},{\"id\":\"g1xkv\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"sourceDescriptor\":{\"resolution\": \"COARSE\",\"type\":\"ES_GEO_GRID\",\"id\":\"9305f6ea-4518-4c06-95b9-33321aa38d6a\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\",\"geoField\":\"geo.coordinates\",\"requestType\":\"grid\",\"metrics\":[{\"type\":\"count\"},{\"type\":\"max\",\"field\":\"bytes\"}]},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"label\":\"max of bytes\",\"name\":\"max_of_bytes\",\"origin\":\"source\"},\"color\":\"Blues\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#cccccc\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"label\":\"Count\",\"name\":\"doc_count\",\"origin\":\"source\"},\"minSize\":4,\"maxSize\":32}}},\"temporary\":true,\"previousStyle\":null},\"type\":\"VECTOR\"}]",
546+
"layerListJSON": "[{\"id\":\"g1xkv\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"sourceDescriptor\":{\"resolution\": \"COARSE\",\"type\":\"ES_GEO_GRID\",\"id\":\"9305f6ea-4518-4c06-95b9-33321aa38d6a\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\",\"geoField\":\"geo.coordinates\",\"requestType\":\"grid\",\"metrics\":[{\"type\":\"count\"},{\"type\":\"max\",\"field\":\"bytes\"}]},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"label\":\"max of bytes\",\"name\":\"max_of_bytes\",\"origin\":\"source\"},\"color\":\"Blues\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#cccccc\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"label\":\"Count\",\"name\":\"doc_count\",\"origin\":\"source\"},\"minSize\":4,\"maxSize\":32}}},\"temporary\":true,\"previousStyle\":null},\"type\":\"VECTOR\"}]",
547547
"mapStateJSON": "{\"zoom\":3.59,\"center\":{\"lon\":-98.05765,\"lat\":38.32288},\"timeFilters\":{\"from\":\"2015-09-20T00:00:00.000Z\",\"to\":\"2015-09-20T01:00:00.000Z\"},\"refreshConfig\":{\"isPaused\":true,\"interval\":1000}}",
548548
"title": "geo grid vector grid example",
549549
"uiStateJSON": "{\"isDarkMode\":false}"

0 commit comments

Comments
 (0)