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] rename layer types provide more distinguishable names that better reflect layer #118617

Merged
merged 16 commits into from
Dec 3, 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 @@ -79,7 +79,7 @@ export const mockLayerList = [
maxZoom: 24,
alpha: 0.75,
visible: true,
type: 'VECTOR',
type: 'GEOJSON_VECTOR',
},
{
joins: [
Expand Down Expand Up @@ -148,6 +148,6 @@ export const mockLayerList = [
maxZoom: 24,
alpha: 0.75,
visible: true,
type: 'VECTOR',
type: 'GEOJSON_VECTOR',
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function useLayerList() {
maxZoom: 24,
alpha: 0.75,
visible: true,
type: LAYER_TYPE.VECTOR,
type: LAYER_TYPE.GEOJSON_VECTOR,
};

ES_TERM_SOURCE_REGION.whereQuery = getWhereQuery(serviceName!);
Expand All @@ -179,7 +179,7 @@ export function useLayerList() {
maxZoom: 24,
alpha: 0.75,
visible: true,
type: LAYER_TYPE.VECTOR,
type: LAYER_TYPE.GEOJSON_VECTOR,
};

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const getChoroplethTopValuesLayer = (
},
isTimeAware: true,
},
type: LAYER_TYPE.VECTOR,
type: LAYER_TYPE.GEOJSON_VECTOR,
};
};

Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ export function getEditPath(id: string | undefined) {
}

export enum LAYER_TYPE {
TILE = 'TILE',
VECTOR = 'VECTOR',
VECTOR_TILE = 'VECTOR_TILE', // for static display of mvt vector tiles with a mapbox stylesheet. Does not support any ad-hoc configurations. Used for consuming EMS vector tiles.
RASTER_TILE = 'RASTER_TILE',
GEOJSON_VECTOR = 'GEOJSON_VECTOR',
EMS_VECTOR_TILE = 'EMS_VECTOR_TILE',
HEATMAP = 'HEATMAP',
BLENDED_VECTOR = 'BLENDED_VECTOR',
TILED_VECTOR = 'TILED_VECTOR', // similar to a regular vector-layer, but it consumes the data as .mvt tilea iso GeoJson. It supports similar ad-hoc configurations like a regular vector layer (E.g. using IVectorStyle), although there is some loss of functionality e.g. does not support term joining
MVT_VECTOR = 'MVT_VECTOR',
}

export enum SOURCE_TYPES {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type LayerDescriptor = {
};

export type VectorLayerDescriptor = LayerDescriptor & {
type: LAYER_TYPE.VECTOR | LAYER_TYPE.TILED_VECTOR | LAYER_TYPE.BLENDED_VECTOR;
type: LAYER_TYPE.GEOJSON_VECTOR | LAYER_TYPE.MVT_VECTOR | LAYER_TYPE.BLENDED_VECTOR;
joins?: JoinDescriptor[];
style: VectorStyleDescriptor;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
*/

import _ from 'lodash';
import { LAYER_TYPE, STYLE_TYPE } from '../constants';
import { STYLE_TYPE } from '../constants';

function isVectorLayer(layerDescriptor) {
const layerType = _.get(layerDescriptor, 'type');
return layerType === LAYER_TYPE.VECTOR;
// can not use LAYER_TYPE because LAYER_TYPE.VECTOR does not exist >8.1
return layerType === 'VECTOR';
}

export function addFieldMetaOptions({ attributes }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('addFieldMetaOptions', () => {
test('Should ignore static style properties', () => {
const layerListJSON = JSON.stringify([
{
type: LAYER_TYPE.VECTOR,
type: 'VECTOR',
style: {
type: 'VECTOR',
properties: {
Expand All @@ -68,7 +68,7 @@ describe('addFieldMetaOptions', () => {
test('Should add field meta options to dynamic style properties', () => {
const layerListJSON = JSON.stringify([
{
type: LAYER_TYPE.VECTOR,
type: 'VECTOR',
style: {
type: 'VECTOR',
properties: {
Expand All @@ -94,7 +94,7 @@ describe('addFieldMetaOptions', () => {
title: 'my map',
layerListJSON: JSON.stringify([
{
type: LAYER_TYPE.VECTOR,
type: 'VECTOR',
style: {
type: 'VECTOR',
properties: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*/

import { addTypeToTermJoin } from './add_type_to_termjoin';
import { LAYER_TYPE, SOURCE_TYPES } from '../constants';
import { SOURCE_TYPES } from '../constants';
import { LayerDescriptor } from '../descriptor_types';

describe('addTypeToTermJoin', () => {
test('Should handle missing type attribute', () => {
const layerListJSON = JSON.stringify([
{
type: LAYER_TYPE.VECTOR,
type: 'VECTOR',
joins: [
{
right: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import _ from 'lodash';
import { SOURCE_TYPES, LAYER_TYPE } from '../constants';
import { SOURCE_TYPES } from '../constants';

function isEmsTileSource(layerDescriptor) {
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
Expand All @@ -15,7 +15,8 @@ function isEmsTileSource(layerDescriptor) {

function isTileLayer(layerDescriptor) {
const layerType = _.get(layerDescriptor, 'type');
return layerType === LAYER_TYPE.TILE;
// can not use LAYER_TYPE because LAYER_TYPE.TILE does not exist >8.1
return layerType === 'TILE';
}

export function emsRasterTileToEmsVectorTile({ attributes }) {
Expand All @@ -33,7 +34,8 @@ export function emsRasterTileToEmsVectorTile({ attributes }) {
layerList.forEach((layer) => {
if (isTileLayer(layer) && isEmsTileSource(layer)) {
// Just need to switch layer type to migrate TILE layer to VECTOR_TILE layer
layer.type = LAYER_TYPE.VECTOR_TILE;
// can not use LAYER_TYPE because LAYER_TYPE.VECTOR_TILE does not exist >8.1
layer.type = 'VECTOR_TILE';
}
});

Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/maps/common/migrations/join_agg_key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { LAYER_TYPE } from '../constants';
import { migrateJoinAggKey } from './join_agg_key';

describe('migrateJoinAggKey', () => {
Expand Down Expand Up @@ -65,7 +64,7 @@ describe('migrateJoinAggKey', () => {
test('Should migrate vector styles from legacy join agg key to new join agg key', () => {
const layerListJSON = JSON.stringify([
{
type: LAYER_TYPE.VECTOR,
type: 'VECTOR',
joins,
style: {
properties: {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/maps/common/migrations/join_agg_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export function migrateJoinAggKey({

layerList.forEach((layerDescriptor: LayerDescriptor) => {
if (
layerDescriptor.type === LAYER_TYPE.VECTOR ||
// can not use LAYER_TYPE because LAYER_TYPE.VECTOR does not exist >8.1
layerDescriptor.type === 'VECTOR' ||
layerDescriptor.type === LAYER_TYPE.BLENDED_VECTOR
) {
const vectorLayerDescriptor = layerDescriptor as VectorLayerDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
*/

import _ from 'lodash';
import { DEFAULT_ICON, LAYER_TYPE, STYLE_TYPE, SYMBOLIZE_AS_TYPES } from '../constants';
import { DEFAULT_ICON, STYLE_TYPE, SYMBOLIZE_AS_TYPES } from '../constants';

function isVectorLayer(layerDescriptor) {
const layerType = _.get(layerDescriptor, 'type');
return layerType === LAYER_TYPE.VECTOR;
// can not use LAYER_TYPE because LAYER_TYPE.VECTOR does not exist >8.1
return layerType === 'VECTOR';
}

export function migrateSymbolStyleDescriptor({ attributes }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('migrateSymbolStyleDescriptor', () => {
test('Should migrate "symbol" style descriptor', () => {
const layerListJSON = JSON.stringify([
{
type: LAYER_TYPE.VECTOR,
type: 'VECTOR',
style: {
properties: {
fillColor: {
Expand All @@ -66,7 +66,7 @@ describe('migrateSymbolStyleDescriptor', () => {
title: 'my map',
layerListJSON: JSON.stringify([
{
type: LAYER_TYPE.VECTOR,
type: 'VECTOR',
style: {
properties: {
fillColor: {
Expand All @@ -90,7 +90,7 @@ describe('migrateSymbolStyleDescriptor', () => {
test('Should migrate style descriptor without "symbol"', () => {
const layerListJSON = JSON.stringify([
{
type: LAYER_TYPE.VECTOR,
type: 'VECTOR',
style: {
properties: {
fillColor: {
Expand All @@ -109,7 +109,7 @@ describe('migrateSymbolStyleDescriptor', () => {
title: 'my map',
layerListJSON: JSON.stringify([
{
type: LAYER_TYPE.VECTOR,
type: 'VECTOR',
style: {
properties: {
fillColor: {
Expand Down
83 changes: 83 additions & 0 deletions x-pack/plugins/maps/common/migrations/rename_layer_types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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 { renameLayerTypes } from './rename_layer_types';

describe('renameLayerTypes', () => {
test('Should handle missing layerListJSON attribute', () => {
const attributes = {
title: 'my map',
};
expect(renameLayerTypes({ attributes })).toEqual({
title: 'my map',
});
});

test('Should rename TILED_VECTOR to MVT_VECTOR', () => {
const layerListJSON = JSON.stringify([
{
type: 'TILED_VECTOR',
},
]);
const attributes = {
title: 'my map',
layerListJSON,
};
expect(renameLayerTypes({ attributes })).toEqual({
title: 'my map',
layerListJSON: '[{"type":"MVT_VECTOR"}]',
});
});

test('Should rename VECTOR_TILE to EMS_VECTOR_TILE', () => {
const layerListJSON = JSON.stringify([
{
type: 'VECTOR_TILE',
},
]);
const attributes = {
title: 'my map',
layerListJSON,
};
expect(renameLayerTypes({ attributes })).toEqual({
title: 'my map',
layerListJSON: '[{"type":"EMS_VECTOR_TILE"}]',
});
});

test('Should rename VECTOR to GEOJSON_VECTOR', () => {
const layerListJSON = JSON.stringify([
{
type: 'VECTOR',
},
]);
const attributes = {
title: 'my map',
layerListJSON,
};
expect(renameLayerTypes({ attributes })).toEqual({
title: 'my map',
layerListJSON: '[{"type":"GEOJSON_VECTOR"}]',
});
});

test('Should rename TILE to RASTER_TILE', () => {
const layerListJSON = JSON.stringify([
{
type: 'TILE',
},
]);
const attributes = {
title: 'my map',
layerListJSON,
};
expect(renameLayerTypes({ attributes })).toEqual({
title: 'my map',
layerListJSON: '[{"type":"RASTER_TILE"}]',
});
});
});
49 changes: 49 additions & 0 deletions x-pack/plugins/maps/common/migrations/rename_layer_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 { LAYER_TYPE } from '../constants';
import { LayerDescriptor } from '../descriptor_types';
import { MapSavedObjectAttributes } from '../map_saved_object_type';

// LAYER_TYPE constants renamed in 8.1 to provide more distinguishable names that better refect layer.
// TILED_VECTOR replaced with MVT_VECTOR
// VECTOR_TILE replaced with EMS_VECTOR_TILE
// VECTOR replaced with GEOJSON_VECTOR
// TILE replaced with RASTER_TILE
export function renameLayerTypes({
attributes,
}: {
attributes: MapSavedObjectAttributes;
}): MapSavedObjectAttributes {
if (!attributes || !attributes.layerListJSON) {
return attributes;
}

let layerList: LayerDescriptor[] = [];
try {
layerList = JSON.parse(attributes.layerListJSON);
} catch (e) {
throw new Error('Unable to parse attribute layerListJSON');
}

layerList.forEach((layerDescriptor: LayerDescriptor) => {
if (layerDescriptor.type === 'TILED_VECTOR') {
layerDescriptor.type = LAYER_TYPE.MVT_VECTOR;
} else if (layerDescriptor.type === 'VECTOR_TILE') {
layerDescriptor.type = LAYER_TYPE.EMS_VECTOR_TILE;
} else if (layerDescriptor.type === 'VECTOR') {
layerDescriptor.type = LAYER_TYPE.GEOJSON_VECTOR;
} else if (layerDescriptor.type === 'TILE') {
layerDescriptor.type = LAYER_TYPE.RASTER_TILE;
}
});

return {
...attributes,
layerListJSON: JSON.stringify(layerList),
};
}
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/actions/data_request_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function endDataLoad(
const eventHandlers = getEventHandlers(getState());
if (eventHandlers && eventHandlers.onDataLoadEnd) {
const resultMeta: ResultMeta = {};
if (layer && layer.getType() === LAYER_TYPE.VECTOR) {
if (layer && layer.getType() === LAYER_TYPE.GEOJSON_VECTOR) {
const featuresWithoutCentroids = features.filter((feature) => {
return feature.properties ? !feature.properties[KBN_IS_CENTROID_FEATURE] : true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('kibana.yml configured with map.tilemap.url', () => {
type: 'KIBANA_TILEMAP',
},
style: { type: 'TILE' },
type: 'TILE',
type: 'RASTER_TILE',
visible: true,
});
});
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('EMS is enabled', () => {
type: 'EMS_TMS',
},
style: { type: 'TILE' },
type: 'VECTOR_TILE',
type: 'EMS_VECTOR_TILE',
visible: true,
});
});
Expand Down
Loading