Skip to content

Commit

Permalink
Region map should respect saved center and zoom (elastic#12883)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Jul 27, 2017
1 parent 4ded8a6 commit 6c47ca3
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/core_plugins/region_map/public/region_map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import { KibanaMap } from '../../tile_map/public/kibana_map';
import ChoroplethLayer from './choropleth_layer';
import { truncatedColorMaps } from 'ui/vislib/components/color/truncated_colormaps';
import AggResponsePointSeriesTooltipFormatterProvider from './tooltip_formatter';
// import '../../tile_map/public/lib/service_settings';
import 'ui/vis/map/service_settings';


const module = uiModules.get('kibana/region_map', ['kibana']);
module.controller('KbnRegionMapController', function ($scope, $element, Private, Notifier, getAppState,
serviceSettings, config) {

const DEFAULT_ZOOM_SETTINGS = {
zoom: 2,
mapCenter: [0, 0]
};

const tooltipFormatter = Private(AggResponsePointSeriesTooltipFormatterProvider);
const notify = new Notifier({ location: 'Region map' });


let kibanaMap = null;
let choroplethLayer = null;
const kibanaMapReady = makeKibanaMap();
Expand Down Expand Up @@ -90,10 +93,19 @@ module.controller('KbnRegionMapController', function ($scope, $element, Private,
async function makeKibanaMap() {
const tmsSettings = await serviceSettings.getTMSService();
const minMaxZoom = tmsSettings.getMinMaxZoom(false);
kibanaMap = new KibanaMap($element[0], minMaxZoom);
const url = tmsSettings.getUrl();
const options = tmsSettings.getTMSOptions();
kibanaMap.setBaseLayer({ baseLayerType: 'tms', options: { url, ...options } });

const options = { ...minMaxZoom };
const uiState = $scope.vis.getUiState();
const zoomFromUiState = parseInt(uiState.get('mapZoom'));
const centerFromUIState = uiState.get('mapCenter');
options.zoom = !isNaN(zoomFromUiState) ? zoomFromUiState : DEFAULT_ZOOM_SETTINGS.zoom;
options.center = centerFromUIState ? centerFromUIState : DEFAULT_ZOOM_SETTINGS.mapCenter;
kibanaMap = new KibanaMap($element[0], options);


const tmsUrl = tmsSettings.getUrl();
const tmsOptions = tmsSettings.getTMSOptions();
kibanaMap.setBaseLayer({ baseLayerType: 'tms', options: { tmsUrl, ...tmsOptions } });
kibanaMap.addLegendControl();
kibanaMap.addFitControl();
kibanaMap.persistUiStateForVisualization($scope.vis);
Expand Down

0 comments on commit 6c47ca3

Please sign in to comment.