forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] add migration to switch tile layers with EMS_TMS source to ve…
…ctor tile layer (elastic#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
- Loading branch information
Showing
13 changed files
with
128 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
x-pack/legacy/plugins/maps/common/migrations/ems_raster_tile_to_ems_vector_tile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; | ||
} |
59 changes: 59 additions & 0 deletions
59
x-pack/legacy/plugins/maps/common/migrations/ems_raster_tile_to_ems_vector_tile.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters