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] add migration to switch tile layers with EMS_TMS source to vector tile layer #43777

Merged
merged 4 commits into from
Aug 24, 2019
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
8 changes: 8 additions & 0 deletions x-pack/legacy/plugins/maps/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
};
}
Original file line number Diff line number Diff line change
@@ -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,
});
});
});
9 changes: 9 additions & 0 deletions x-pack/legacy/plugins/maps/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand All @@ -17,5 +18,13 @@ export const migrations = {
references,
};
},
'7.4.0': (doc) => {
const attributes = emsRasterTileToEmsVectorTile(doc);

return {
...doc,
attributes,
};
}
},
};
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/maps/public/layers/heatmap_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/maps/public/layers/tile_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
5 changes: 3 additions & 2 deletions x-pack/legacy/plugins/maps/public/layers/vector_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/maps/public/layers/vector_tile_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/maps/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down