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] layer groups #142528

Merged
merged 41 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4eb259c
[Maps] layer groups
nreese Sep 28, 2022
da6276a
createLayerGroup
nreese Sep 28, 2022
5317c7c
create layer group
nreese Sep 30, 2022
2e3ab89
setChildren
nreese Sep 30, 2022
c139c87
display layer group legend
nreese Sep 30, 2022
4375f06
display nested layers in TOC
nreese Oct 1, 2022
66025fd
setLayerVisibility
nreese Oct 1, 2022
0ade5cf
set parent on layer re-order
nreese Oct 2, 2022
c734dd9
LayerGroup.getBounds
nreese Oct 3, 2022
5997a41
clean-up LayerGroup
nreese Oct 3, 2022
fda76e5
edit layer panel
nreese Oct 3, 2022
fc97ee0
LayerGroup.cloneDescriptor
nreese Oct 3, 2022
6db1186
clean up
nreese Oct 3, 2022
fabf45c
remove layer
nreese Oct 4, 2022
bef3d68
fix reorder bug
nreese Oct 4, 2022
f0d9b0e
move children on layer move
nreese Oct 4, 2022
13927dc
fix re-order bug when dragging layer group with collapsed details
nreese Oct 5, 2022
e184a5b
add check for dragging to same location
nreese Oct 5, 2022
c45bc66
add logic to prevent dragging layer group into its own family tree
nreese Oct 5, 2022
c4ee613
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Oct 5, 2022
90569a3
add layer to layer group combine action with layer group
nreese Oct 5, 2022
afae7c7
clean up
nreese Oct 5, 2022
7e386ad
fix bug where unable to move layer to bottom
nreese Oct 5, 2022
0bb5dd9
mouse cursor styles
nreese Oct 6, 2022
d79fcac
clean up combine styling
nreese Oct 6, 2022
321cfc0
fix jest tests
nreese Oct 6, 2022
8ecd622
Merge branch 'main' into layer_groups
kibanamachine Oct 6, 2022
d5901d9
update toc_entry_actions_popover snapshots
nreese Oct 6, 2022
681e601
click confirm model on removeLayer in functional tests
nreese Oct 10, 2022
7b978b8
Merge branch 'main' into layer_groups
kibanamachine Oct 10, 2022
99c3450
update cloneLayer to move clones beneath parent
nreese Oct 10, 2022
4519cd9
LayerGroup.getErrors
nreese Oct 10, 2022
3acd081
Merge branch 'main' into layer_groups
kibanamachine Oct 11, 2022
c40ad96
Update x-pack/plugins/maps/common/descriptor_types/layer_descriptor_t…
nreese Oct 11, 2022
9959df7
fix show this layer only action when layer is nested
nreese Oct 11, 2022
cd1447c
recursive count children for remove layer warning
nreese Oct 11, 2022
713fade
Update x-pack/plugins/maps/public/components/remove_layer_confirm_mod…
nreese Oct 11, 2022
191ffda
resolve error with show this layer only on layer group
nreese Oct 11, 2022
88600b2
update remove statement to support plural
nreese Oct 11, 2022
1c1cfdb
perserve layer order when cloning layer group
nreese Oct 11, 2022
1d624bd
Merge branch 'main' into layer_groups
kibanamachine Oct 12, 2022
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
1 change: 1 addition & 0 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export enum LAYER_TYPE {
HEATMAP = 'HEATMAP',
BLENDED_VECTOR = 'BLENDED_VECTOR',
MVT_VECTOR = 'MVT_VECTOR',
LAYER_GROUP = 'LAYER_GROUP',
}

export enum SOURCE_TYPES {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export type LayerDescriptor = {
style?: StyleDescriptor | null;
query?: Query;
includeInFitToBounds?: boolean;
parent?: string;
};

export type VectorLayerDescriptor = LayerDescriptor & {
Expand All @@ -89,3 +90,10 @@ export type EMSVectorTileLayerDescriptor = LayerDescriptor & {
type: LAYER_TYPE.EMS_VECTOR_TILE;
style: EMSVectorTileStyleDescriptor;
};

export type LayerGroupDescriptor = LayerDescriptor & {
type: LAYER_TYPE.LAYER_GROUP;
label: string;
sourceDescriptor: null;
visible: boolean;
};
69 changes: 13 additions & 56 deletions x-pack/plugins/maps/public/actions/data_request_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

import { AnyAction, Dispatch } from 'redux';
import { ThunkDispatch } from 'redux-thunk';
import bbox from '@turf/bbox';
import uuid from 'uuid/v4';
import { multiPoint } from '@turf/helpers';
import { FeatureCollection } from 'geojson';
import { Adapters } from '@kbn/inspector-plugin/common/adapters';
import { MapStoreState } from '../reducers/store';
Expand Down Expand Up @@ -49,7 +47,9 @@ import { ILayer } from '../classes/layers/layer';
import { IVectorLayer } from '../classes/layers/vector_layer';
import { DataRequestMeta, MapExtent, DataFilters } from '../../common/descriptor_types';
import { DataRequestAbortError } from '../classes/util/data_request';
import { scaleBounds, turfBboxToBounds } from '../../common/elasticsearch_util';
import { scaleBounds } from '../../common/elasticsearch_util';
import { getLayersExtent } from './get_layers_extent';
import { isLayerGroup } from '../classes/layers/layer_group';

const FIT_TO_BOUNDS_SCALE_FACTOR = 0.1;

Expand Down Expand Up @@ -101,7 +101,7 @@ export function cancelAllInFlightRequests() {
export function updateStyleMeta(layerId: string | null) {
return async (dispatch: Dispatch, getState: () => MapStoreState) => {
const layer = getLayerById(layerId, getState());
if (!layer) {
if (!layer || isLayerGroup(layer)) {
return;
}

Expand Down Expand Up @@ -378,8 +378,8 @@ export function fitToLayerExtent(layerId: string) {

if (targetLayer) {
try {
const bounds = await targetLayer.getBounds(
getDataRequestContext(dispatch, getState, layerId, false, false)
const bounds = await targetLayer.getBounds((boundsLayerId) =>
getDataRequestContext(dispatch, getState, boundsLayerId, false, false)
);
if (bounds) {
await dispatch(setGotoWithBounds(scaleBounds(bounds, FIT_TO_BOUNDS_SCALE_FACTOR)));
Expand All @@ -401,65 +401,22 @@ export function fitToLayerExtent(layerId: string) {

export function fitToDataBounds(onNoBounds?: () => void) {
return async (dispatch: Dispatch, getState: () => MapStoreState) => {
const layerList = getLayerList(getState());

if (!layerList.length) {
return;
}

const boundsPromises = layerList.map(async (layer: ILayer) => {
if (!(await layer.isFittable())) {
return null;
}
return layer.getBounds(
getDataRequestContext(dispatch, getState, layer.getId(), false, false)
);
const rootLayers = getLayerList(getState()).filter((layer) => {
return layer.getParent() === undefined;
});

let bounds;
try {
bounds = await Promise.all(boundsPromises);
} catch (error) {
if (!(error instanceof DataRequestAbortError)) {
// eslint-disable-next-line no-console
console.warn(
'Unhandled getBounds error for layer. Only DataRequestAbortError should be surfaced',
error
);
}
// new fitToDataBounds request has superseded this thread of execution. Results no longer needed.
return;
}

const corners = [];
for (let i = 0; i < bounds.length; i++) {
const b = bounds[i];

// filter out undefined bounds (uses Infinity due to turf responses)
if (
b === null ||
b.minLon === Infinity ||
b.maxLon === Infinity ||
b.minLat === -Infinity ||
b.maxLat === -Infinity
) {
continue;
}

corners.push([b.minLon, b.minLat]);
corners.push([b.maxLon, b.maxLat]);
}
const extent = await getLayersExtent(rootLayers, (boundsLayerId) =>
getDataRequestContext(dispatch, getState, boundsLayerId, false, false)
);

if (!corners.length) {
if (extent === null) {
if (onNoBounds) {
onNoBounds();
}
return;
}

const dataBounds = turfBboxToBounds(bbox(multiPoint(corners)));

dispatch(setGotoWithBounds(scaleBounds(dataBounds, FIT_TO_BOUNDS_SCALE_FACTOR)));
dispatch(setGotoWithBounds(scaleBounds(extent, FIT_TO_BOUNDS_SCALE_FACTOR)));
};
}

Expand Down
66 changes: 66 additions & 0 deletions x-pack/plugins/maps/public/actions/get_layers_extent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import bbox from '@turf/bbox';
import { multiPoint } from '@turf/helpers';
import { MapExtent } from '../../common/descriptor_types';
import { turfBboxToBounds } from '../../common/elasticsearch_util';
import { ILayer } from '../classes/layers/layer';
import type { DataRequestContext } from './data_request_actions';
import { DataRequestAbortError } from '../classes/util/data_request';

export async function getLayersExtent(
layers: ILayer[],
getDataRequestContext: (layerId: string) => DataRequestContext
): Promise<MapExtent | null> {
if (!layers.length) {
return null;
}

const boundsPromises = layers.map(async (layer: ILayer) => {
if (!(await layer.isFittable())) {
return null;
}
return layer.getBounds(getDataRequestContext);
});

let bounds;
try {
bounds = await Promise.all(boundsPromises);
} catch (error) {
if (!(error instanceof DataRequestAbortError)) {
// eslint-disable-next-line no-console
console.warn(
'Unhandled getBounds error for layer. Only DataRequestAbortError should be surfaced',
error
);
}
// new fitToDataBounds request has superseded this thread of execution. Results no longer needed.
return null;
}

const corners = [];
for (let i = 0; i < bounds.length; i++) {
const b = bounds[i];

// filter out undefined bounds (uses Infinity due to turf responses)
if (
b === null ||
b.minLon === Infinity ||
b.maxLon === Infinity ||
b.minLat === -Infinity ||
b.maxLat === -Infinity
) {
continue;
}

corners.push([b.minLon, b.minLat]);
corners.push([b.maxLon, b.maxLat]);
}

return corners.length ? turfBboxToBounds(bbox(multiPoint(corners))) : null;
}
1 change: 1 addition & 0 deletions x-pack/plugins/maps/public/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ export {
openOnHoverTooltip,
updateOpenTooltips,
} from './tooltip_actions';
export { getLayersExtent } from './get_layers_extent';
Loading