[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:
Nathan Reese 2019-08-24 07:15:54 -06:00 committed by GitHub
parent ab7874efb2
commit 14a8192f0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 128 additions and 13 deletions

View file

@ -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';

View file

@ -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),
};
}

View file

@ -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,
});
});
});

View file

@ -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,
};
}
},
};

View file

@ -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);

View file

@ -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'
});

View file

@ -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 });

View file

@ -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);

View file

@ -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 });

View file

@ -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', {

View file

@ -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', {

View file

@ -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', {

View file

@ -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);
});
});