-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] Provide ability to create MapEmbeddable directly from a map co…
…nfiguration (#43878) (#44044) * [Maps] Provide ability to create MapEmbeddable directly from a map configuration * call updateInput instead of passing modified input to MapEmbeddable constructor * cleanup i18n translations * update map embeddable documenation to reflect createFromState examples
- Loading branch information
Showing
8 changed files
with
140 additions
and
65 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
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,38 @@ | ||
|
||
### Map specific `input` parameters | ||
- **hideFilterActions:** (Boolean) Set to true to hide all filtering controls. | ||
- **isLayerTOCOpen:** (Boolean) Set to false to render map with legend in collapsed state. | ||
- **openTOCDetails:** (Array of Strings) Array of layer ids. Add layer id to show layer details on initial render. | ||
- **mapCenter:** ({lat, lon, zoom }) Provide mapCenter to customize initial map location. | ||
|
||
### Creating a Map embeddable from saved object | ||
``` | ||
const factory = new MapEmbeddableFactory(); | ||
const input = { | ||
hideFilterActions: true, | ||
isLayerTOCOpen: false, | ||
openTOCDetails: ['tfi3f', 'edh66'], | ||
mapCenter: { lat: 0.0, lon: 0.0, zoom: 7 } | ||
} | ||
const mapEmbeddable = await factory.createFromSavedObject( | ||
'de71f4f0-1902-11e9-919b-ffe5949a18d2', | ||
input, | ||
parent | ||
); | ||
``` | ||
|
||
### Creating a Map embeddable from state | ||
``` | ||
const factory = new MapEmbeddableFactory(); | ||
const state = { | ||
layerList: [], // where layerList is same as saved object layerListJSON property (unstringified) | ||
title: 'my map', | ||
} | ||
const input = { | ||
hideFilterActions: true, | ||
isLayerTOCOpen: false, | ||
openTOCDetails: ['tfi3f', 'edh66'], | ||
mapCenter: { lat: 0.0, lon: 0.0, zoom: 7 } | ||
} | ||
const mapEmbeddable = await factory.createFromState(state, input, parent); | ||
``` |
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
27 changes: 0 additions & 27 deletions
27
x-pack/legacy/plugins/maps/public/embeddable/map_embeddables.md
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.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,42 @@ | ||
/* | ||
* 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 { DEFAULT_IS_LAYER_TOC_OPEN } from '../reducers/ui'; | ||
|
||
const MAP_EMBEDDABLE_INPUT_KEYS = [ | ||
'hideFilterActions', | ||
'isLayerTOCOpen', | ||
'openTOCDetails', | ||
'mapCenter' | ||
]; | ||
|
||
export function mergeInputWithSavedMap(input, savedMap) { | ||
const mergedInput = _.pick(input, MAP_EMBEDDABLE_INPUT_KEYS); | ||
|
||
if (!_.has(input, 'isLayerTOCOpen') && savedMap.uiStateJSON) { | ||
const uiState = JSON.parse(savedMap.uiStateJSON); | ||
mergedInput.isLayerTOCOpen = _.get(uiState, 'isLayerTOCOpen', DEFAULT_IS_LAYER_TOC_OPEN); | ||
} | ||
|
||
if (!_.has(input, 'openTOCDetails') && savedMap.uiStateJSON) { | ||
const uiState = JSON.parse(savedMap.uiStateJSON); | ||
if (_.has(uiState, 'openTOCDetails')) { | ||
mergedInput.openTOCDetails = _.get(uiState, 'openTOCDetails', []); | ||
} | ||
} | ||
|
||
if (!input.mapCenter && savedMap.mapStateJSON) { | ||
const mapState = JSON.parse(savedMap.mapStateJSON); | ||
mergedInput.mapCenter = { | ||
lat: mapState.center.lat, | ||
lon: mapState.center.lon, | ||
zoom: mapState.zoom, | ||
}; | ||
} | ||
|
||
return mergedInput; | ||
} |
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