Skip to content

Commit

Permalink
load map settings in embeddable
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Apr 21, 2020
1 parent f8549bf commit 5ee2da9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions x-pack/plugins/maps/public/embeddable/map_embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from '../../../../../src/plugins/data/public';
import { GisMap } from '../connected_components/gis_map';
import { createMapStore, MapStore } from '../reducers/store';
import { MapSettings } from '../reducers/map';
import {
setGotoWithCenter,
replaceLayerList,
Expand All @@ -40,6 +41,7 @@ import {
hideLayerControl,
hideViewControl,
setHiddenLayers,
setMapSettings,
} from '../actions/map_actions';
import { MapCenterAndZoom } from '../../common/descriptor_types';
import { setReadOnly, setIsLayerTOCOpen, setOpenTOCDetails } from '../actions/ui_actions';
Expand All @@ -60,6 +62,7 @@ interface MapEmbeddableConfig {
editable: boolean;
title?: string;
layerList: unknown[];
settings?: MapSettings;
}

export interface MapEmbeddableInput extends EmbeddableInput {
Expand Down Expand Up @@ -97,6 +100,7 @@ export class MapEmbeddable extends Embeddable<MapEmbeddableInput, MapEmbeddableO
private _prevFilters?: Filter[];
private _domNode?: HTMLElement;
private _unsubscribeFromStore?: Unsubscribe;
private _settings?: MapSettings;

constructor(
config: MapEmbeddableConfig,
Expand All @@ -119,6 +123,7 @@ export class MapEmbeddable extends Embeddable<MapEmbeddableInput, MapEmbeddableO
this._renderTooltipContent = renderTooltipContent;
this._eventHandlers = eventHandlers;
this._layerList = config.layerList;
this._settings = config.settings;
this._store = createMapStore();

this._subscription = this.getInput$().subscribe(input => this.onContainerStateChanged(input));
Expand Down Expand Up @@ -194,6 +199,10 @@ export class MapEmbeddable extends Embeddable<MapEmbeddableInput, MapEmbeddableO
this._store.dispatch(setReadOnly(true));
this._store.dispatch(disableScrollZoom());

if (this._settings) {
this._store.dispatch(setMapSettings(this._settings));
}

if (_.has(this.input, 'isLayerTOCOpen')) {
this._store.dispatch(setIsLayerTOCOpen(this.input.isLayerTOCOpen));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,22 @@ export class MapEmbeddableFactory implements EmbeddableFactoryDefinition {
const layerList = getInitialLayers(savedMap.layerListJSON);
const indexPatterns = await this._getIndexPatterns(layerList);

let settings;
if (savedMap.mapStateJSON) {
const mapState = JSON.parse(savedMap.mapStateJSON);
if (mapState.settings) {
settings = mapState.settings;
}
}

const embeddable = new MapEmbeddable(
{
layerList,
title: savedMap.title,
editUrl: getHttp().basePath.prepend(createMapPath(savedObjectId)),
indexPatterns,
editable: await this.isEditable(),
settings,
},
input,
parent
Expand Down

0 comments on commit 5ee2da9

Please sign in to comment.