[Maps] add migration to switch tile layers with EMS_TMS source to vector tile layer (#43777)
* [Maps] add migration to switch tile layers with EMS_TMS source to vector tile layers * update migration on sample data saved objects since they have already been migrated * update jest test expect
This commit is contained in:
parent
ab7874efb2
commit
14a8192f0a
13 changed files with 128 additions and 13 deletions
|
@ -32,6 +32,14 @@ export function createMapPath(id) {
|
||||||
return `${MAP_BASE_URL}/${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 EMS_FILE = 'EMS_FILE';
|
||||||
export const ES_GEO_GRID = 'ES_GEO_GRID';
|
export const ES_GEO_GRID = 'ES_GEO_GRID';
|
||||||
export const ES_SEARCH = 'ES_SEARCH';
|
export const ES_SEARCH = 'ES_SEARCH';
|
||||||
|
|
|
@ -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),
|
||||||
|
};
|
||||||
|
}
|
|
@ -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,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { extractReferences } from './common/migrations/references';
|
import { extractReferences } from './common/migrations/references';
|
||||||
|
import { emsRasterTileToEmsVectorTile } from './common/migrations/ems_raster_tile_to_ems_vector_tile';
|
||||||
|
|
||||||
export const migrations = {
|
export const migrations = {
|
||||||
'map': {
|
'map': {
|
||||||
|
@ -17,5 +18,13 @@ export const migrations = {
|
||||||
references,
|
references,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
'7.4.0': (doc) => {
|
||||||
|
const attributes = emsRasterTileToEmsVectorTile(doc);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...doc,
|
||||||
|
attributes,
|
||||||
|
};
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,13 +8,13 @@ import _ from 'lodash';
|
||||||
import { AbstractLayer } from './layer';
|
import { AbstractLayer } from './layer';
|
||||||
import { VectorLayer } from './vector_layer';
|
import { VectorLayer } from './vector_layer';
|
||||||
import { HeatmapStyle } from './styles/heatmap_style';
|
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
|
const SCALED_PROPERTY_NAME = '__kbn_heatmap_weight__';//unique name to store scaled value for weighting
|
||||||
|
|
||||||
export class HeatmapLayer extends VectorLayer {
|
export class HeatmapLayer extends VectorLayer {
|
||||||
|
|
||||||
static type = 'HEATMAP';
|
static type = LAYER_TYPE.HEATMAP;
|
||||||
|
|
||||||
static createDescriptor(options) {
|
static createDescriptor(options) {
|
||||||
const heatmapLayerDescriptor = super.createDescriptor(options);
|
const heatmapLayerDescriptor = super.createDescriptor(options);
|
||||||
|
|
|
@ -14,10 +14,11 @@ import { getEMSClient } from '../../../meta';
|
||||||
import { EMSTMSCreateSourceEditor } from './create_source_editor';
|
import { EMSTMSCreateSourceEditor } from './create_source_editor';
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
import { getDataSourceLabel } from '../../../../common/i18n_getters';
|
import { getDataSourceLabel } from '../../../../common/i18n_getters';
|
||||||
|
import { EMS_TMS } from '../../../../common/constants';
|
||||||
|
|
||||||
export class EMSTMSSource extends AbstractTMSSource {
|
export class EMSTMSSource extends AbstractTMSSource {
|
||||||
|
|
||||||
static type = 'EMS_TMS';
|
static type = EMS_TMS;
|
||||||
static title = i18n.translate('xpack.maps.source.emsTileTitle', {
|
static title = i18n.translate('xpack.maps.source.emsTileTitle', {
|
||||||
defaultMessage: 'Tiles'
|
defaultMessage: 'Tiles'
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
|
|
||||||
import { AbstractLayer } from './layer';
|
import { AbstractLayer } from './layer';
|
||||||
import _ from 'lodash';
|
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 {
|
export class TileLayer extends AbstractLayer {
|
||||||
|
|
||||||
static type = 'TILE';
|
static type = LAYER_TYPE.TILE;
|
||||||
|
|
||||||
constructor({ layerDescriptor, source, style }) {
|
constructor({ layerDescriptor, source, style }) {
|
||||||
super({ layerDescriptor, source, style });
|
super({ layerDescriptor, source, style });
|
||||||
|
|
|
@ -14,7 +14,8 @@ import {
|
||||||
FEATURE_ID_PROPERTY_NAME,
|
FEATURE_ID_PROPERTY_NAME,
|
||||||
SOURCE_DATA_ID_ORIGIN,
|
SOURCE_DATA_ID_ORIGIN,
|
||||||
FEATURE_VISIBLE_PROPERTY_NAME,
|
FEATURE_VISIBLE_PROPERTY_NAME,
|
||||||
EMPTY_FEATURE_COLLECTION
|
EMPTY_FEATURE_COLLECTION,
|
||||||
|
LAYER_TYPE
|
||||||
} from '../../common/constants';
|
} from '../../common/constants';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { JoinTooltipProperty } from './tooltips/join_tooltip_property';
|
import { JoinTooltipProperty } from './tooltips/join_tooltip_property';
|
||||||
|
@ -69,7 +70,7 @@ function generateNumericalId() {
|
||||||
|
|
||||||
export class VectorLayer extends AbstractLayer {
|
export class VectorLayer extends AbstractLayer {
|
||||||
|
|
||||||
static type = 'VECTOR';
|
static type = LAYER_TYPE.VECTOR;
|
||||||
|
|
||||||
static createDescriptor(options, mapColors) {
|
static createDescriptor(options, mapColors) {
|
||||||
const layerDescriptor = super.createDescriptor(options);
|
const layerDescriptor = super.createDescriptor(options);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
import { TileLayer } from './tile_layer';
|
import { TileLayer } from './tile_layer';
|
||||||
import _ from 'lodash';
|
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 { isRetina } from '../meta';
|
||||||
import { addSpritesheetToMap } from '../connected_components/map/mb/utils';//todo move this implementation
|
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 {
|
export class VectorTileLayer extends TileLayer {
|
||||||
|
|
||||||
static type = 'VECTOR_TILE';
|
static type = LAYER_TYPE.VECTOR_TILE;
|
||||||
|
|
||||||
constructor({ layerDescriptor, source, style }) {
|
constructor({ layerDescriptor, source, style }) {
|
||||||
super({ layerDescriptor, source, style });
|
super({ layerDescriptor, source, style });
|
||||||
|
|
|
@ -463,7 +463,7 @@ export const getEcommerceSavedObjects = () => {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'migrationVersion': {
|
'migrationVersion': {
|
||||||
'map': '7.2.0'
|
'map': '7.4.0'
|
||||||
},
|
},
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'title': i18n.translate('xpack.maps.sampleData.ecommerceSpec.mapsTitle', {
|
'title': i18n.translate('xpack.maps.sampleData.ecommerceSpec.mapsTitle', {
|
||||||
|
|
|
@ -253,7 +253,7 @@ export const getFlightsSavedObjects = () => {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'migrationVersion': {
|
'migrationVersion': {
|
||||||
'map': '7.2.0'
|
'map': '7.4.0'
|
||||||
},
|
},
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'title': i18n.translate('xpack.maps.sampleData.flightaSpec.mapsTitle', {
|
'title': i18n.translate('xpack.maps.sampleData.flightaSpec.mapsTitle', {
|
||||||
|
|
|
@ -245,7 +245,7 @@ export const getWebLogsSavedObjects = () => {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'migrationVersion': {
|
'migrationVersion': {
|
||||||
'map': '7.2.0'
|
'map': '7.4.0'
|
||||||
},
|
},
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'title': i18n.translate('xpack.maps.sampleData.flightaSpec.logsTitle', {
|
'title': i18n.translate('xpack.maps.sampleData.flightaSpec.logsTitle', {
|
||||||
|
|
|
@ -42,7 +42,7 @@ export default function ({ getService }) {
|
||||||
type: 'index-pattern'
|
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);
|
expect(resp.body.attributes.layerListJSON.includes('indexPatternRefName')).to.be(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue