From 6c47ca313d0ae42a1007629e5c7d15954d05da7c Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 27 Jul 2017 17:04:01 -0400 Subject: [PATCH] Region map should respect saved center and zoom (#12883) --- .../public/region_map_controller.js | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core_plugins/region_map/public/region_map_controller.js b/src/core_plugins/region_map/public/region_map_controller.js index b7943c30efb88..afa78b4b3ab71 100644 --- a/src/core_plugins/region_map/public/region_map_controller.js +++ b/src/core_plugins/region_map/public/region_map_controller.js @@ -6,7 +6,6 @@ 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'; @@ -14,10 +13,14 @@ 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(); @@ -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);