Skip to content

Commit

Permalink
pull map state from visualizations created in 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Apr 19, 2017
1 parent 9b8c68b commit d018cea
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions public/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,28 @@ define(function (require) {
};
},
getMapStateFromVis: function(vis) {
const mapState = {
center: [15, 5],
zoom: 2
}
const mapState = {};
//Visualizations created in 5.x will have map state in uiState
if (vis.hasUiState()) {
const uiStateCenter = vis.uiStateVal('mapCenter');
if(uiStateCenter) mapState.center = uiStateCenter;
const uiStateZoom = vis.uiStateVal('mapZoom');
if(uiStateZoom) mapState.zoom = uiStateZoom;
if(uiStateCenter && uiStateZoom) {
mapState.center = uiStateCenter;
mapState.zoom = uiStateZoom;
}
}
//Visualizations created in 4.x will have map state in segment aggregation
if (!_.has(mapState, 'center') && !_.has(mapState, 'zoom')) {
const agg = this.getAggConfig(vis.aggs, 'segment');
if (agg) {
mapState.center = _.get(agg, 'params.mapCenter');
mapState.zoom = _.get(agg, 'params.mapZoom');
}
}
//Provide defaults if no state found
if (!_.has(mapState, 'center') && !_.has(mapState, 'zoom')) {
mapState.center = [15, 5];
mapState.zoom = 2;
}
return mapState;
},
Expand Down

0 comments on commit d018cea

Please sign in to comment.