diff --git a/x-pack/legacy/plugins/maps/common/constants.js b/x-pack/legacy/plugins/maps/common/constants.js index 9122a3e1df40..65234bcad669 100644 --- a/x-pack/legacy/plugins/maps/common/constants.js +++ b/x-pack/legacy/plugins/maps/common/constants.js @@ -32,6 +32,14 @@ export function createMapPath(id) { return `${MAP_BASE_URL}/${id}`; } +export const LAYER_TYPE = { + TILE: 'TILE', + VECTOR: 'VECTOR', + VECTOR_TILE: 'VECTOR_TILE', + HEATMAP: 'HEATMAP' +}; + +export const EMS_TMS = 'EMS_TMS'; export const EMS_FILE = 'EMS_FILE'; export const ES_GEO_GRID = 'ES_GEO_GRID'; export const ES_SEARCH = 'ES_SEARCH'; diff --git a/x-pack/legacy/plugins/maps/common/migrations/ems_raster_tile_to_ems_vector_tile.js b/x-pack/legacy/plugins/maps/common/migrations/ems_raster_tile_to_ems_vector_tile.js new file mode 100644 index 000000000000..e782f139d629 --- /dev/null +++ b/x-pack/legacy/plugins/maps/common/migrations/ems_raster_tile_to_ems_vector_tile.js @@ -0,0 +1,37 @@ +/* + * 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 _ from 'lodash'; +import { EMS_TMS, LAYER_TYPE } from '../constants'; + +function isEmsTileSource(layerDescriptor) { + const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type'); + return sourceType === EMS_TMS; +} + +function isTileLayer(layerDescriptor) { + const layerType = _.get(layerDescriptor, 'type'); + return layerType === LAYER_TYPE.TILE; +} + +export function emsRasterTileToEmsVectorTile({ attributes }) { + if (!attributes.layerListJSON) { + return attributes; + } + + const layerList = JSON.parse(attributes.layerListJSON); + 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; + } + }); + + return { + ...attributes, + layerListJSON: JSON.stringify(layerList), + }; +} diff --git a/x-pack/legacy/plugins/maps/common/migrations/ems_raster_tile_to_ems_vector_tile.test.js b/x-pack/legacy/plugins/maps/common/migrations/ems_raster_tile_to_ems_vector_tile.test.js new file mode 100644 index 000000000000..8bfe94e7d809 --- /dev/null +++ b/x-pack/legacy/plugins/maps/common/migrations/ems_raster_tile_to_ems_vector_tile.test.js @@ -0,0 +1,59 @@ +/* + * 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. + */ + +/* eslint max-len: 0 */ + +import { emsRasterTileToEmsVectorTile } from './ems_raster_tile_to_ems_vector_tile'; + +describe('emsRasterTileToEmsVectorTile', () => { + + test('Should handle missing layerListJSON attribute', () => { + const attributes = { + title: 'my map', + }; + expect(emsRasterTileToEmsVectorTile({ attributes })).toEqual({ + title: 'my map', + }); + }); + + test('Should update TILE layers with EMS_TMS sources to VECTOR_TILE layers', () => { + const layerListJSON = JSON.stringify([ + { + type: 'TILE', + sourceDescriptor: { + type: 'EMS_TMS' + } + } + ]); + const attributes = { + title: 'my map', + layerListJSON + }; + expect(emsRasterTileToEmsVectorTile({ attributes })).toEqual({ + title: 'my map', + layerListJSON: '[{\"type\":\"VECTOR_TILE\",\"sourceDescriptor\":{\"type\":\"EMS_TMS\"}}]', + }); + }); + + test('Should not update TILE layers that are not EMS_TMS source', () => { + const layerListJSON = JSON.stringify([ + { + type: 'TILE', + sourceDescriptor: { + type: 'KIBANA_TILEMAP' + } + } + ]); + const attributes = { + title: 'my map', + layerListJSON + }; + expect(emsRasterTileToEmsVectorTile({ attributes })).toEqual({ + title: 'my map', + layerListJSON, + }); + }); +}); diff --git a/x-pack/legacy/plugins/maps/migrations.js b/x-pack/legacy/plugins/maps/migrations.js index aaceadaa6549..6a97636e679c 100644 --- a/x-pack/legacy/plugins/maps/migrations.js +++ b/x-pack/legacy/plugins/maps/migrations.js @@ -5,6 +5,7 @@ */ import { extractReferences } from './common/migrations/references'; +import { emsRasterTileToEmsVectorTile } from './common/migrations/ems_raster_tile_to_ems_vector_tile'; export const migrations = { 'map': { @@ -17,5 +18,13 @@ export const migrations = { references, }; }, + '7.4.0': (doc) => { + const attributes = emsRasterTileToEmsVectorTile(doc); + + return { + ...doc, + attributes, + }; + } }, }; diff --git a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js index df20cbff84d3..629fb3284ff1 100644 --- a/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js @@ -8,13 +8,13 @@ import _ from 'lodash'; import { AbstractLayer } from './layer'; import { VectorLayer } from './vector_layer'; import { HeatmapStyle } from './styles/heatmap_style'; -import { EMPTY_FEATURE_COLLECTION } from '../../common/constants'; +import { EMPTY_FEATURE_COLLECTION, LAYER_TYPE } from '../../common/constants'; const SCALED_PROPERTY_NAME = '__kbn_heatmap_weight__';//unique name to store scaled value for weighting export class HeatmapLayer extends VectorLayer { - static type = 'HEATMAP'; + static type = LAYER_TYPE.HEATMAP; static createDescriptor(options) { const heatmapLayerDescriptor = super.createDescriptor(options); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_tms_source/ems_tms_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_tms_source/ems_tms_source.js index 2f817aabeda5..be3c90ffb117 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_tms_source/ems_tms_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_tms_source/ems_tms_source.js @@ -14,10 +14,11 @@ import { getEMSClient } from '../../../meta'; import { EMSTMSCreateSourceEditor } from './create_source_editor'; import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; +import { EMS_TMS } from '../../../../common/constants'; export class EMSTMSSource extends AbstractTMSSource { - static type = 'EMS_TMS'; + static type = EMS_TMS; static title = i18n.translate('xpack.maps.source.emsTileTitle', { defaultMessage: 'Tiles' }); diff --git a/x-pack/legacy/plugins/maps/public/layers/tile_layer.js b/x-pack/legacy/plugins/maps/public/layers/tile_layer.js index b932b5303d40..3dfe83ac83d0 100644 --- a/x-pack/legacy/plugins/maps/public/layers/tile_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/tile_layer.js @@ -6,11 +6,11 @@ import { AbstractLayer } from './layer'; import _ from 'lodash'; -import { SOURCE_DATA_ID_ORIGIN } from '../../common/constants'; +import { SOURCE_DATA_ID_ORIGIN, LAYER_TYPE } from '../../common/constants'; export class TileLayer extends AbstractLayer { - static type = 'TILE'; + static type = LAYER_TYPE.TILE; constructor({ layerDescriptor, source, style }) { super({ layerDescriptor, source, style }); diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index b9f6599da59c..5033979843ab 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -14,7 +14,8 @@ import { FEATURE_ID_PROPERTY_NAME, SOURCE_DATA_ID_ORIGIN, FEATURE_VISIBLE_PROPERTY_NAME, - EMPTY_FEATURE_COLLECTION + EMPTY_FEATURE_COLLECTION, + LAYER_TYPE } from '../../common/constants'; import _ from 'lodash'; import { JoinTooltipProperty } from './tooltips/join_tooltip_property'; @@ -69,7 +70,7 @@ function generateNumericalId() { export class VectorLayer extends AbstractLayer { - static type = 'VECTOR'; + static type = LAYER_TYPE.VECTOR; static createDescriptor(options, mapColors) { const layerDescriptor = super.createDescriptor(options); diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_tile_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_tile_layer.js index f15ffa417d2b..a7f0346b09ef 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_tile_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_tile_layer.js @@ -6,7 +6,7 @@ import { TileLayer } from './tile_layer'; import _ from 'lodash'; -import { SOURCE_DATA_ID_ORIGIN } from '../../common/constants'; +import { SOURCE_DATA_ID_ORIGIN, LAYER_TYPE } from '../../common/constants'; import { isRetina } from '../meta'; import { addSpritesheetToMap } from '../connected_components/map/mb/utils';//todo move this implementation @@ -20,7 +20,7 @@ const MB_STYLE_TYPE_TO_OPACITY = { export class VectorTileLayer extends TileLayer { - static type = 'VECTOR_TILE'; + static type = LAYER_TYPE.VECTOR_TILE; constructor({ layerDescriptor, source, style }) { super({ layerDescriptor, source, style }); diff --git a/x-pack/legacy/plugins/maps/server/sample_data/ecommerce_saved_objects.js b/x-pack/legacy/plugins/maps/server/sample_data/ecommerce_saved_objects.js index 44a6f38177e2..4e8007966e8a 100644 --- a/x-pack/legacy/plugins/maps/server/sample_data/ecommerce_saved_objects.js +++ b/x-pack/legacy/plugins/maps/server/sample_data/ecommerce_saved_objects.js @@ -463,7 +463,7 @@ export const getEcommerceSavedObjects = () => { } ], 'migrationVersion': { - 'map': '7.2.0' + 'map': '7.4.0' }, 'attributes': { 'title': i18n.translate('xpack.maps.sampleData.ecommerceSpec.mapsTitle', { diff --git a/x-pack/legacy/plugins/maps/server/sample_data/flights_saved_objects.js b/x-pack/legacy/plugins/maps/server/sample_data/flights_saved_objects.js index d404946ec3e7..881c2275feed 100644 --- a/x-pack/legacy/plugins/maps/server/sample_data/flights_saved_objects.js +++ b/x-pack/legacy/plugins/maps/server/sample_data/flights_saved_objects.js @@ -253,7 +253,7 @@ export const getFlightsSavedObjects = () => { } ], 'migrationVersion': { - 'map': '7.2.0' + 'map': '7.4.0' }, 'attributes': { 'title': i18n.translate('xpack.maps.sampleData.flightaSpec.mapsTitle', { diff --git a/x-pack/legacy/plugins/maps/server/sample_data/web_logs_saved_objects.js b/x-pack/legacy/plugins/maps/server/sample_data/web_logs_saved_objects.js index f1f10bbbf1c4..2ac1de70b17d 100644 --- a/x-pack/legacy/plugins/maps/server/sample_data/web_logs_saved_objects.js +++ b/x-pack/legacy/plugins/maps/server/sample_data/web_logs_saved_objects.js @@ -245,7 +245,7 @@ export const getWebLogsSavedObjects = () => { } ], 'migrationVersion': { - 'map': '7.2.0' + 'map': '7.4.0' }, 'attributes': { 'title': i18n.translate('xpack.maps.sampleData.flightaSpec.logsTitle', { diff --git a/x-pack/test/api_integration/apis/maps/migrations.js b/x-pack/test/api_integration/apis/maps/migrations.js index 6cab94c99138..d8bdc5e61cb1 100644 --- a/x-pack/test/api_integration/apis/maps/migrations.js +++ b/x-pack/test/api_integration/apis/maps/migrations.js @@ -42,7 +42,7 @@ export default function ({ getService }) { type: 'index-pattern' } ]); - expect(resp.body.migrationVersion).to.eql({ map: '7.2.0' }); + expect(resp.body.migrationVersion).to.eql({ map: '7.4.0' }); expect(resp.body.attributes.layerListJSON.includes('indexPatternRefName')).to.be(true); }); });