Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Maps] only provide visiblity check when vector layer has joins (#51388) #51686

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/maps/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const ZOOM_PRECISION = 2;
export const ES_SIZE_LIMIT = 10000;

export const FEATURE_ID_PROPERTY_NAME = '__kbn__feature_id__';
export const FEATURE_VISIBLE_PROPERTY_NAME = '__kbn__isvisible__';
export const FEATURE_VISIBLE_PROPERTY_NAME = '__kbn_isvisibleduetojoin__';

export const MB_SOURCE_ID_LAYER_ID_PREFIX_DELIMITER = '_';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { GEO_JSON_TYPE, FEATURE_VISIBLE_PROPERTY_NAME } from '../../../common/constants';

const VISIBILITY_FILTER_CLAUSE = ['all',
[
'==',
['get', FEATURE_VISIBLE_PROPERTY_NAME],
true
]
];

const CLOSED_SHAPE_MB_FILTER = [
'any',
['==', ['geometry-type'], GEO_JSON_TYPE.POLYGON],
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POLYGON]
];

const VISIBLE_CLOSED_SHAPE_MB_FILTER = [
...VISIBILITY_FILTER_CLAUSE,
CLOSED_SHAPE_MB_FILTER,
];

const ALL_SHAPE_MB_FILTER = [
'any',
['==', ['geometry-type'], GEO_JSON_TYPE.POLYGON],
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POLYGON],
['==', ['geometry-type'], GEO_JSON_TYPE.LINE_STRING],
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_LINE_STRING]
];

const VISIBLE_ALL_SHAPE_MB_FILTER = [
...VISIBILITY_FILTER_CLAUSE,
ALL_SHAPE_MB_FILTER,
];

const POINT_MB_FILTER = [
'any',
['==', ['geometry-type'], GEO_JSON_TYPE.POINT],
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POINT]
];

const VISIBLE_POINT_MB_FILTER = [
...VISIBILITY_FILTER_CLAUSE,
POINT_MB_FILTER,
];

export function getFillFilterExpression(hasJoins) {
return hasJoins ? VISIBLE_CLOSED_SHAPE_MB_FILTER : CLOSED_SHAPE_MB_FILTER;
}

export function getLineFilterExpression(hasJoins) {
return hasJoins ? VISIBLE_ALL_SHAPE_MB_FILTER : ALL_SHAPE_MB_FILTER;
}

export function getPointFilterExpression(hasJoins) {
return hasJoins ? VISIBLE_POINT_MB_FILTER : POINT_MB_FILTER;
}
77 changes: 34 additions & 43 deletions x-pack/legacy/plugins/maps/public/layers/vector_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { AbstractLayer } from './layer';
import { VectorStyle } from './styles/vector/vector_style';
import { InnerJoin } from './joins/inner_join';
import {
GEO_JSON_TYPE,
FEATURE_ID_PROPERTY_NAME,
SOURCE_DATA_ID_ORIGIN,
FEATURE_VISIBLE_PROPERTY_NAME,
Expand All @@ -24,41 +23,11 @@ import { EuiIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { DataRequestAbortError } from './util/data_request';
import { assignFeatureIds } from './util/assign_feature_ids';

const VISIBILITY_FILTER_CLAUSE = ['all',
[
'==',
['get', FEATURE_VISIBLE_PROPERTY_NAME],
true
]
];

const FILL_LAYER_MB_FILTER = [
...VISIBILITY_FILTER_CLAUSE,
[
'any',
['==', ['geometry-type'], GEO_JSON_TYPE.POLYGON],
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POLYGON]
]
];

const LINE_LAYER_MB_FILTER = [...VISIBILITY_FILTER_CLAUSE,
[
'any',
['==', ['geometry-type'], GEO_JSON_TYPE.POLYGON],
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POLYGON],
['==', ['geometry-type'], GEO_JSON_TYPE.LINE_STRING],
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_LINE_STRING]
]
];

const POINT_LAYER_MB_FILTER = [...VISIBILITY_FILTER_CLAUSE,
[
'any',
['==', ['geometry-type'], GEO_JSON_TYPE.POINT],
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POINT]
]
];
import {
getFillFilterExpression,
getLineFilterExpression,
getPointFilterExpression,
} from './util/mb_filter_expressions';

export class VectorLayer extends AbstractLayer {

Expand Down Expand Up @@ -107,6 +76,10 @@ export class VectorLayer extends AbstractLayer {
});
}

_hasJoins() {
return this.getValidJoins().length > 0;
}

isDataLoaded() {
const sourceDataRequest = this.getSourceDataRequest();
if (!sourceDataRequest || !sourceDataRequest.hasData()) {
Expand Down Expand Up @@ -495,12 +468,14 @@ export class VectorLayer extends AbstractLayer {
}

const sourceResult = await this._syncSource(syncContext);
if (!sourceResult.featureCollection || !sourceResult.featureCollection.features.length) {
if (
!sourceResult.featureCollection ||
!sourceResult.featureCollection.features.length ||
!this._hasJoins()) {
return;
}

const joinStates = await this._syncJoins(syncContext);

await this._performInnerJoins(sourceResult, joinStates, syncContext.updateSourceData);
}

Expand Down Expand Up @@ -571,7 +546,11 @@ export class VectorLayer extends AbstractLayer {
source: sourceId,
paint: {}
});
mbMap.setFilter(pointLayerId, POINT_LAYER_MB_FILTER);
}

const filterExpr = getPointFilterExpression(this._hasJoins());
if (filterExpr !== mbMap.getFilter(pointLayerId)) {
mbMap.setFilter(pointLayerId, filterExpr);
}

this._style.setMBPaintPropertiesForPoints({
Expand All @@ -592,7 +571,11 @@ export class VectorLayer extends AbstractLayer {
type: 'symbol',
source: sourceId,
});
mbMap.setFilter(symbolLayerId, POINT_LAYER_MB_FILTER);
}

const filterExpr = getPointFilterExpression(this._hasJoins());
if (filterExpr !== mbMap.getFilter(symbolLayerId)) {
mbMap.setFilter(symbolLayerId, filterExpr);
}

this._style.setMBSymbolPropertiesForPoints({
Expand All @@ -606,14 +589,14 @@ export class VectorLayer extends AbstractLayer {
const sourceId = this.getId();
const fillLayerId = this._getMbPolygonLayerId();
const lineLayerId = this._getMbLineLayerId();
const hasJoins = this._hasJoins();
if (!mbMap.getLayer(fillLayerId)) {
mbMap.addLayer({
id: fillLayerId,
type: 'fill',
source: sourceId,
paint: {}
});
mbMap.setFilter(fillLayerId, FILL_LAYER_MB_FILTER);
}
if (!mbMap.getLayer(lineLayerId)) {
mbMap.addLayer({
Expand All @@ -622,7 +605,6 @@ export class VectorLayer extends AbstractLayer {
source: sourceId,
paint: {}
});
mbMap.setFilter(lineLayerId, LINE_LAYER_MB_FILTER);
}
this._style.setMBPaintProperties({
alpha: this.getAlpha(),
Expand All @@ -632,9 +614,18 @@ export class VectorLayer extends AbstractLayer {
});

this.syncVisibilityWithMb(mbMap, fillLayerId);
mbMap.setLayerZoomRange(fillLayerId, this._descriptor.minZoom, this._descriptor.maxZoom);
const fillFilterExpr = getFillFilterExpression(hasJoins);
if (fillFilterExpr !== mbMap.getFilter(fillLayerId)) {
mbMap.setFilter(fillLayerId, fillFilterExpr);
}

this.syncVisibilityWithMb(mbMap, lineLayerId);
mbMap.setLayerZoomRange(lineLayerId, this._descriptor.minZoom, this._descriptor.maxZoom);
mbMap.setLayerZoomRange(fillLayerId, this._descriptor.minZoom, this._descriptor.maxZoom);
const lineFilterExpr = getLineFilterExpression(hasJoins);
if (lineFilterExpr !== mbMap.getFilter(lineLayerId)) {
mbMap.setFilter(lineLayerId, lineFilterExpr);
}
}

_syncStylePropertiesWithMb(mbMap) {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/functional/apps/maps/joins.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default function ({ getPageObjects, getService }) {
const vectorSource = mapboxStyle.sources[VECTOR_SOURCE_ID];

const visibilitiesOfFeatures = vectorSource.data.features.map(feature => {
return feature.properties.__kbn__isvisible__;
return feature.properties.__kbn_isvisibleduetojoin__;
});

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

const visibilitiesOfFeatures = vectorSource.data.features.map(feature => {
return feature.properties.__kbn__isvisible__;
return feature.properties.__kbn_isvisibleduetojoin__;
});

expect(visibilitiesOfFeatures).to.eql([false, true, false, false]);
Expand Down
6 changes: 3 additions & 3 deletions x-pack/test/functional/apps/maps/mapbox_styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const MAPBOX_STYLES = {
'all',
[
'==',
['get', '__kbn__isvisible__'],
['get', '__kbn_isvisibleduetojoin__'],
true
],
[
Expand Down Expand Up @@ -89,7 +89,7 @@ export const MAPBOX_STYLES = {
'all',
[
'==',
['get', '__kbn__isvisible__'],
['get', '__kbn_isvisibleduetojoin__'],
true
],
[
Expand Down Expand Up @@ -160,7 +160,7 @@ export const MAPBOX_STYLES = {
'all',
[
'==',
['get', '__kbn__isvisible__'],
['get', '__kbn_isvisibleduetojoin__'],
true
],
[
Expand Down