1717 * under the License.
1818 */
1919
20- import _ from 'lodash' ;
2120import { i18n } from '@kbn/i18n' ;
2221import * as Rx from 'rxjs' ;
2322import { filter , first } from 'rxjs/operators' ;
2423import { getEmsTileLayerId , getUiSettings , getToasts } from '../kibana_services' ;
24+ import { lazyLoadMapsLegacyModules } from '../lazy_load_bundle' ;
25+ import { getServiceSettings } from '../get_service_settings' ;
2526
2627const WMS_MINZOOM = 0 ;
2728const WMS_MAXZOOM = 22 ; //increase this to 22. Better for WMS
2829
29- export function BaseMapsVisualizationProvider ( getKibanaMap , mapServiceSettings ) {
30+ export function BaseMapsVisualizationProvider ( ) {
3031 /**
3132 * Abstract base class for a visualization consisting of a map with a single baselayer.
3233 * @class BaseMapsVisualization
3334 * @constructor
3435 */
35-
36- const serviceSettings = mapServiceSettings ;
37- const toastService = getToasts ( ) ;
38-
3936 return class BaseMapsVisualization {
4037 constructor ( element , vis ) {
4138 this . vis = vis ;
@@ -95,9 +92,9 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
9592 const centerFromUIState = uiState . get ( 'mapCenter' ) ;
9693 options . zoom = ! isNaN ( zoomFromUiState ) ? zoomFromUiState : this . vis . params . mapZoom ;
9794 options . center = centerFromUIState ? centerFromUIState : this . vis . params . mapCenter ;
98- const services = { toastService } ;
9995
100- this . _kibanaMap = getKibanaMap ( this . _container , options , services ) ;
96+ const modules = await lazyLoadMapsLegacyModules ( ) ;
97+ this . _kibanaMap = new modules . KibanaMap ( this . _container , options ) ;
10198 this . _kibanaMap . setMinZoom ( WMS_MINZOOM ) ; //use a default
10299 this . _kibanaMap . setMaxZoom ( WMS_MAXZOOM ) ; //use a default
103100
@@ -138,6 +135,7 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
138135 const mapParams = this . _getMapsParams ( ) ;
139136 if ( ! this . _tmsConfigured ( ) ) {
140137 try {
138+ const serviceSettings = await getServiceSettings ( ) ;
141139 const tmsServices = await serviceSettings . getTMSServices ( ) ;
142140 const userConfiguredTmsLayer = tmsServices [ 0 ] ;
143141 const initBasemapLayer = userConfiguredTmsLayer
@@ -147,7 +145,7 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
147145 this . _setTmsLayer ( initBasemapLayer ) ;
148146 }
149147 } catch ( e ) {
150- toastService . addWarning ( e . message ) ;
148+ getToasts ( ) . addWarning ( e . message ) ;
151149 return ;
152150 }
153151 return ;
@@ -174,7 +172,7 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
174172 this . _setTmsLayer ( selectedTmsLayer ) ;
175173 }
176174 } catch ( tmsLoadingError ) {
177- toastService . addWarning ( tmsLoadingError . message ) ;
175+ getToasts ( ) . addWarning ( tmsLoadingError . message ) ;
178176 }
179177 }
180178
@@ -189,13 +187,14 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
189187 isDesaturated = true ;
190188 }
191189 const isDarkMode = getUiSettings ( ) . get ( 'theme:darkMode' ) ;
190+ const serviceSettings = await getServiceSettings ( ) ;
192191 const meta = await serviceSettings . getAttributesForTMSLayer (
193192 tmsLayer ,
194193 isDesaturated ,
195194 isDarkMode
196195 ) ;
197196 const showZoomMessage = serviceSettings . shouldShowZoomMessage ( tmsLayer ) ;
198- const options = _ . cloneDeep ( tmsLayer ) ;
197+ const options = { ... tmsLayer } ;
199198 delete options . id ;
200199 delete options . subdomains ;
201200 this . _kibanaMap . setBaseLayer ( {
@@ -228,12 +227,11 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
228227 }
229228
230229 _getMapsParams ( ) {
231- return _ . assign (
232- { } ,
233- this . vis . type . visConfig . defaults ,
234- { type : this . vis . type . name } ,
235- this . _params
236- ) ;
230+ return {
231+ ...this . vis . type . visConfig . defaults ,
232+ type : this . vis . type . name ,
233+ ...this . _params ,
234+ } ;
237235 }
238236
239237 _whenBaseLayerIsLoaded ( ) {
0 commit comments