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

[Maps] use deep equals for mapbox filter expression equals check #99673

Merged
merged 2 commits into from
May 11, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
}

const filterExpr = getPointFilterExpression(this.hasJoins());
if (filterExpr !== mbMap.getFilter(pointLayerId)) {
if (!_.isEqual(filterExpr, mbMap.getFilter(pointLayerId))) {
mbMap.setFilter(pointLayerId, filterExpr);
mbMap.setFilter(textLayerId, filterExpr);
}
Expand Down Expand Up @@ -817,7 +817,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
}

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

Expand Down Expand Up @@ -899,14 +899,14 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
this.syncVisibilityWithMb(mbMap, fillLayerId);
mbMap.setLayerZoomRange(fillLayerId, this.getMinZoom(), this.getMaxZoom());
const fillFilterExpr = getFillFilterExpression(hasJoins);
if (fillFilterExpr !== mbMap.getFilter(fillLayerId)) {
if (!_.isEqual(fillFilterExpr, mbMap.getFilter(fillLayerId))) {
mbMap.setFilter(fillLayerId, fillFilterExpr);
}

this.syncVisibilityWithMb(mbMap, lineLayerId);
mbMap.setLayerZoomRange(lineLayerId, this.getMinZoom(), this.getMaxZoom());
const lineFilterExpr = getLineFilterExpression(hasJoins);
if (lineFilterExpr !== mbMap.getFilter(lineLayerId)) {
if (!_.isEqual(lineFilterExpr, mbMap.getFilter(lineLayerId))) {
mbMap.setFilter(lineLayerId, lineFilterExpr);
}

Expand All @@ -930,7 +930,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
}

const filterExpr = getCentroidFilterExpression(this.hasJoins());
if (filterExpr !== mbMap.getFilter(centroidLayerId)) {
if (!_.isEqual(filterExpr, mbMap.getFilter(centroidLayerId))) {
mbMap.setFilter(centroidLayerId, filterExpr);
}

Expand Down
82 changes: 38 additions & 44 deletions x-pack/plugins/maps/public/classes/util/mb_filter_expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,55 @@ import {
export const EXCLUDE_TOO_MANY_FEATURES_BOX = ['!=', ['get', KBN_TOO_MANY_FEATURES_PROPERTY], true];
const EXCLUDE_CENTROID_FEATURES = ['!=', ['get', KBN_IS_CENTROID_FEATURE], true];

const VISIBILITY_FILTER_CLAUSE = ['all', ['==', ['get', FEATURE_VISIBLE_PROPERTY_NAME], true]];
// Kibana features are features added by kibana that do not exist in real data
const EXCLUDE_KBN_FEATURES = ['all', EXCLUDE_TOO_MANY_FEATURES_BOX, EXCLUDE_CENTROID_FEATURES];
function getFilterExpression(geometryFilter: unknown[], hasJoins: boolean) {
const filters: unknown[] = [
EXCLUDE_TOO_MANY_FEATURES_BOX,
EXCLUDE_CENTROID_FEATURES,
geometryFilter,
];

const CLOSED_SHAPE_MB_FILTER = [
...EXCLUDE_KBN_FEATURES,
[
'any',
['==', ['geometry-type'], GEO_JSON_TYPE.POLYGON],
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POLYGON],
],
];
if (hasJoins) {
filters.push(['==', ['get', FEATURE_VISIBLE_PROPERTY_NAME], true]);
}

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

const ALL_SHAPE_MB_FILTER = [
...EXCLUDE_KBN_FEATURES,
[
'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 = [
...EXCLUDE_KBN_FEATURES,
[
'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];

const CENTROID_MB_FILTER = ['all', ['==', ['get', KBN_IS_CENTROID_FEATURE], true]];

const VISIBLE_CENTROID_MB_FILTER = [...VISIBILITY_FILTER_CLAUSE, CENTROID_MB_FILTER];
return ['all', ...filters];
}

export function getFillFilterExpression(hasJoins: boolean): unknown[] {
return hasJoins ? VISIBLE_CLOSED_SHAPE_MB_FILTER : CLOSED_SHAPE_MB_FILTER;
return getFilterExpression(
[
'any',
['==', ['geometry-type'], GEO_JSON_TYPE.POLYGON],
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POLYGON],
],
hasJoins
);
}

export function getLineFilterExpression(hasJoins: boolean): unknown[] {
return hasJoins ? VISIBLE_ALL_SHAPE_MB_FILTER : ALL_SHAPE_MB_FILTER;
return getFilterExpression(
[
'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],
],
hasJoins
);
}

export function getPointFilterExpression(hasJoins: boolean): unknown[] {
return hasJoins ? VISIBLE_POINT_MB_FILTER : POINT_MB_FILTER;
return getFilterExpression(
[
'any',
['==', ['geometry-type'], GEO_JSON_TYPE.POINT],
['==', ['geometry-type'], GEO_JSON_TYPE.MULTI_POINT],
],
hasJoins
);
}

export function getCentroidFilterExpression(hasJoins: boolean): unknown[] {
return hasJoins ? VISIBLE_CENTROID_MB_FILTER : CENTROID_MB_FILTER;
return getFilterExpression(['==', ['get', KBN_IS_CENTROID_FEATURE], true], hasJoins);
}
41 changes: 14 additions & 27 deletions x-pack/test/functional/apps/maps/mapbox_styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ export default function ({ getPageObjects, getService }) {
maxzoom: 24,
filter: [
'all',
['!=', ['get', '__kbn_too_many_features__'], true],
['!=', ['get', '__kbn_is_centroid_feature__'], true],
['any', ['==', ['geometry-type'], 'Point'], ['==', ['geometry-type'], 'MultiPoint']],
['==', ['get', '__kbn_isvisibleduetojoin__'], true],
[
'all',
['!=', ['get', '__kbn_too_many_features__'], true],
['!=', ['get', '__kbn_is_centroid_feature__'], true],
['any', ['==', ['geometry-type'], 'Point'], ['==', ['geometry-type'], 'MultiPoint']],
],
],
layout: { visibility: 'visible' },
paint: {
Expand Down Expand Up @@ -124,17 +121,10 @@ export default function ({ getPageObjects, getService }) {
maxzoom: 24,
filter: [
'all',
['!=', ['get', '__kbn_too_many_features__'], true],
['!=', ['get', '__kbn_is_centroid_feature__'], true],
['any', ['==', ['geometry-type'], 'Polygon'], ['==', ['geometry-type'], 'MultiPolygon']],
['==', ['get', '__kbn_isvisibleduetojoin__'], true],
[
'all',
['!=', ['get', '__kbn_too_many_features__'], true],
['!=', ['get', '__kbn_is_centroid_feature__'], true],
[
'any',
['==', ['geometry-type'], 'Polygon'],
['==', ['geometry-type'], 'MultiPolygon'],
],
],
],
layout: { visibility: 'visible' },
paint: {
Expand Down Expand Up @@ -208,19 +198,16 @@ export default function ({ getPageObjects, getService }) {
maxzoom: 24,
filter: [
'all',
['==', ['get', '__kbn_isvisibleduetojoin__'], true],
['!=', ['get', '__kbn_too_many_features__'], true],
['!=', ['get', '__kbn_is_centroid_feature__'], true],
[
'all',
['!=', ['get', '__kbn_too_many_features__'], true],
['!=', ['get', '__kbn_is_centroid_feature__'], true],
[
'any',
['==', ['geometry-type'], 'Polygon'],
['==', ['geometry-type'], 'MultiPolygon'],
['==', ['geometry-type'], 'LineString'],
['==', ['geometry-type'], 'MultiLineString'],
],
'any',
['==', ['geometry-type'], 'Polygon'],
['==', ['geometry-type'], 'MultiPolygon'],
['==', ['geometry-type'], 'LineString'],
['==', ['geometry-type'], 'MultiLineString'],
],
['==', ['get', '__kbn_isvisibleduetojoin__'], true],
],
layout: { visibility: 'visible' },
paint: { 'line-color': '#41937c', 'line-opacity': 0.75, 'line-width': 1 },
Expand Down