Skip to content

Commit e32fb65

Browse files
authored
[Maps] only provide visiblity check when vector layer has joins (#51388) (#51686)
* [Maps] only provide visiblity check when vector layer has joins * clean up * properly set line filter expression * use ternary statements instead of if * review feedback
1 parent a47a4b3 commit e32fb65

File tree

5 files changed

+102
-49
lines changed

5 files changed

+102
-49
lines changed

x-pack/legacy/plugins/maps/common/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const ZOOM_PRECISION = 2;
6868
export const ES_SIZE_LIMIT = 10000;
6969

7070
export const FEATURE_ID_PROPERTY_NAME = '__kbn__feature_id__';
71-
export const FEATURE_VISIBLE_PROPERTY_NAME = '__kbn__isvisible__';
71+
export const FEATURE_VISIBLE_PROPERTY_NAME = '__kbn_isvisibleduetojoin__';
7272

7373
export const MB_SOURCE_ID_LAYER_ID_PREFIX_DELIMITER = '_';
7474

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { GEO_JSON_TYPE, FEATURE_VISIBLE_PROPERTY_NAME } from '../../../common/constants';
8+
9+
const VISIBILITY_FILTER_CLAUSE = ['all',
10+
[
11+
'==',
12+
['get', FEATURE_VISIBLE_PROPERTY_NAME],
13+
true
14+
]
15+
];
16+
17+
const CLOSED_SHAPE_MB_FILTER = [
18+
'any',
19+
['==', ['geometry-type'], GEO_JSON_TYPE.POLYGON],
20+
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POLYGON]
21+
];
22+
23+
const VISIBLE_CLOSED_SHAPE_MB_FILTER = [
24+
...VISIBILITY_FILTER_CLAUSE,
25+
CLOSED_SHAPE_MB_FILTER,
26+
];
27+
28+
const ALL_SHAPE_MB_FILTER = [
29+
'any',
30+
['==', ['geometry-type'], GEO_JSON_TYPE.POLYGON],
31+
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POLYGON],
32+
['==', ['geometry-type'], GEO_JSON_TYPE.LINE_STRING],
33+
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_LINE_STRING]
34+
];
35+
36+
const VISIBLE_ALL_SHAPE_MB_FILTER = [
37+
...VISIBILITY_FILTER_CLAUSE,
38+
ALL_SHAPE_MB_FILTER,
39+
];
40+
41+
const POINT_MB_FILTER = [
42+
'any',
43+
['==', ['geometry-type'], GEO_JSON_TYPE.POINT],
44+
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POINT]
45+
];
46+
47+
const VISIBLE_POINT_MB_FILTER = [
48+
...VISIBILITY_FILTER_CLAUSE,
49+
POINT_MB_FILTER,
50+
];
51+
52+
export function getFillFilterExpression(hasJoins) {
53+
return hasJoins ? VISIBLE_CLOSED_SHAPE_MB_FILTER : CLOSED_SHAPE_MB_FILTER;
54+
}
55+
56+
export function getLineFilterExpression(hasJoins) {
57+
return hasJoins ? VISIBLE_ALL_SHAPE_MB_FILTER : ALL_SHAPE_MB_FILTER;
58+
}
59+
60+
export function getPointFilterExpression(hasJoins) {
61+
return hasJoins ? VISIBLE_POINT_MB_FILTER : POINT_MB_FILTER;
62+
}

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

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { AbstractLayer } from './layer';
1010
import { VectorStyle } from './styles/vector/vector_style';
1111
import { InnerJoin } from './joins/inner_join';
1212
import {
13-
GEO_JSON_TYPE,
1413
FEATURE_ID_PROPERTY_NAME,
1514
SOURCE_DATA_ID_ORIGIN,
1615
FEATURE_VISIBLE_PROPERTY_NAME,
@@ -24,41 +23,11 @@ import { EuiIcon } from '@elastic/eui';
2423
import { i18n } from '@kbn/i18n';
2524
import { DataRequestAbortError } from './util/data_request';
2625
import { assignFeatureIds } from './util/assign_feature_ids';
27-
28-
const VISIBILITY_FILTER_CLAUSE = ['all',
29-
[
30-
'==',
31-
['get', FEATURE_VISIBLE_PROPERTY_NAME],
32-
true
33-
]
34-
];
35-
36-
const FILL_LAYER_MB_FILTER = [
37-
...VISIBILITY_FILTER_CLAUSE,
38-
[
39-
'any',
40-
['==', ['geometry-type'], GEO_JSON_TYPE.POLYGON],
41-
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POLYGON]
42-
]
43-
];
44-
45-
const LINE_LAYER_MB_FILTER = [...VISIBILITY_FILTER_CLAUSE,
46-
[
47-
'any',
48-
['==', ['geometry-type'], GEO_JSON_TYPE.POLYGON],
49-
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POLYGON],
50-
['==', ['geometry-type'], GEO_JSON_TYPE.LINE_STRING],
51-
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_LINE_STRING]
52-
]
53-
];
54-
55-
const POINT_LAYER_MB_FILTER = [...VISIBILITY_FILTER_CLAUSE,
56-
[
57-
'any',
58-
['==', ['geometry-type'], GEO_JSON_TYPE.POINT],
59-
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POINT]
60-
]
61-
];
26+
import {
27+
getFillFilterExpression,
28+
getLineFilterExpression,
29+
getPointFilterExpression,
30+
} from './util/mb_filter_expressions';
6231

6332
export class VectorLayer extends AbstractLayer {
6433

@@ -107,6 +76,10 @@ export class VectorLayer extends AbstractLayer {
10776
});
10877
}
10978

79+
_hasJoins() {
80+
return this.getValidJoins().length > 0;
81+
}
82+
11083
isDataLoaded() {
11184
const sourceDataRequest = this.getSourceDataRequest();
11285
if (!sourceDataRequest || !sourceDataRequest.hasData()) {
@@ -495,12 +468,14 @@ export class VectorLayer extends AbstractLayer {
495468
}
496469

497470
const sourceResult = await this._syncSource(syncContext);
498-
if (!sourceResult.featureCollection || !sourceResult.featureCollection.features.length) {
471+
if (
472+
!sourceResult.featureCollection ||
473+
!sourceResult.featureCollection.features.length ||
474+
!this._hasJoins()) {
499475
return;
500476
}
501477

502478
const joinStates = await this._syncJoins(syncContext);
503-
504479
await this._performInnerJoins(sourceResult, joinStates, syncContext.updateSourceData);
505480
}
506481

@@ -571,7 +546,11 @@ export class VectorLayer extends AbstractLayer {
571546
source: sourceId,
572547
paint: {}
573548
});
574-
mbMap.setFilter(pointLayerId, POINT_LAYER_MB_FILTER);
549+
}
550+
551+
const filterExpr = getPointFilterExpression(this._hasJoins());
552+
if (filterExpr !== mbMap.getFilter(pointLayerId)) {
553+
mbMap.setFilter(pointLayerId, filterExpr);
575554
}
576555

577556
this._style.setMBPaintPropertiesForPoints({
@@ -592,7 +571,11 @@ export class VectorLayer extends AbstractLayer {
592571
type: 'symbol',
593572
source: sourceId,
594573
});
595-
mbMap.setFilter(symbolLayerId, POINT_LAYER_MB_FILTER);
574+
}
575+
576+
const filterExpr = getPointFilterExpression(this._hasJoins());
577+
if (filterExpr !== mbMap.getFilter(symbolLayerId)) {
578+
mbMap.setFilter(symbolLayerId, filterExpr);
596579
}
597580

598581
this._style.setMBSymbolPropertiesForPoints({
@@ -606,14 +589,14 @@ export class VectorLayer extends AbstractLayer {
606589
const sourceId = this.getId();
607590
const fillLayerId = this._getMbPolygonLayerId();
608591
const lineLayerId = this._getMbLineLayerId();
592+
const hasJoins = this._hasJoins();
609593
if (!mbMap.getLayer(fillLayerId)) {
610594
mbMap.addLayer({
611595
id: fillLayerId,
612596
type: 'fill',
613597
source: sourceId,
614598
paint: {}
615599
});
616-
mbMap.setFilter(fillLayerId, FILL_LAYER_MB_FILTER);
617600
}
618601
if (!mbMap.getLayer(lineLayerId)) {
619602
mbMap.addLayer({
@@ -622,7 +605,6 @@ export class VectorLayer extends AbstractLayer {
622605
source: sourceId,
623606
paint: {}
624607
});
625-
mbMap.setFilter(lineLayerId, LINE_LAYER_MB_FILTER);
626608
}
627609
this._style.setMBPaintProperties({
628610
alpha: this.getAlpha(),
@@ -632,9 +614,18 @@ export class VectorLayer extends AbstractLayer {
632614
});
633615

634616
this.syncVisibilityWithMb(mbMap, fillLayerId);
617+
mbMap.setLayerZoomRange(fillLayerId, this._descriptor.minZoom, this._descriptor.maxZoom);
618+
const fillFilterExpr = getFillFilterExpression(hasJoins);
619+
if (fillFilterExpr !== mbMap.getFilter(fillLayerId)) {
620+
mbMap.setFilter(fillLayerId, fillFilterExpr);
621+
}
622+
635623
this.syncVisibilityWithMb(mbMap, lineLayerId);
636624
mbMap.setLayerZoomRange(lineLayerId, this._descriptor.minZoom, this._descriptor.maxZoom);
637-
mbMap.setLayerZoomRange(fillLayerId, this._descriptor.minZoom, this._descriptor.maxZoom);
625+
const lineFilterExpr = getLineFilterExpression(hasJoins);
626+
if (lineFilterExpr !== mbMap.getFilter(lineLayerId)) {
627+
mbMap.setFilter(lineLayerId, lineFilterExpr);
628+
}
638629
}
639630

640631
_syncStylePropertiesWithMb(mbMap) {

x-pack/test/functional/apps/maps/joins.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export default function ({ getPageObjects, getService }) {
102102
const vectorSource = mapboxStyle.sources[VECTOR_SOURCE_ID];
103103

104104
const visibilitiesOfFeatures = vectorSource.data.features.map(feature => {
105-
return feature.properties.__kbn__isvisible__;
105+
return feature.properties.__kbn_isvisibleduetojoin__;
106106
});
107107

108108
expect(visibilitiesOfFeatures).to.eql([false, true, true, true]);
@@ -166,7 +166,7 @@ export default function ({ getPageObjects, getService }) {
166166
const vectorSource = mapboxStyle.sources[VECTOR_SOURCE_ID];
167167

168168
const visibilitiesOfFeatures = vectorSource.data.features.map(feature => {
169-
return feature.properties.__kbn__isvisible__;
169+
return feature.properties.__kbn_isvisibleduetojoin__;
170170
});
171171

172172
expect(visibilitiesOfFeatures).to.eql([false, true, false, false]);

x-pack/test/functional/apps/maps/mapbox_styles.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const MAPBOX_STYLES = {
1515
'all',
1616
[
1717
'==',
18-
['get', '__kbn__isvisible__'],
18+
['get', '__kbn_isvisibleduetojoin__'],
1919
true
2020
],
2121
[
@@ -89,7 +89,7 @@ export const MAPBOX_STYLES = {
8989
'all',
9090
[
9191
'==',
92-
['get', '__kbn__isvisible__'],
92+
['get', '__kbn_isvisibleduetojoin__'],
9393
true
9494
],
9595
[
@@ -160,7 +160,7 @@ export const MAPBOX_STYLES = {
160160
'all',
161161
[
162162
'==',
163-
['get', '__kbn__isvisible__'],
163+
['get', '__kbn_isvisibleduetojoin__'],
164164
true
165165
],
166166
[

0 commit comments

Comments
 (0)