33 * or more contributor license agreements. Licensed under the Elastic License;
44 * you may not use this file except in compliance with the Elastic License.
55 */
6+
67import _ from 'lodash' ;
8+ import rison from 'rison-node' ;
9+ import { i18n } from '@kbn/i18n' ;
710// Import each layer type, even those not used, to init in registry
811import '../../classes/sources/wms_source' ;
912import '../../classes/sources/ems_file_source' ;
@@ -16,7 +19,7 @@ import { KibanaTilemapSource } from '../../classes/sources/kibana_tilemap_source
1619import { TileLayer } from '../../classes/layers/tile_layer/tile_layer' ;
1720import { EMSTMSSource } from '../../classes/sources/ems_tms_source' ;
1821import { VectorTileLayer } from '../../classes/layers/vector_tile_layer/vector_tile_layer' ;
19- import { getIsEmsEnabled } from '../../kibana_services' ;
22+ import { getIsEmsEnabled , getToasts } from '../../kibana_services' ;
2023import { getKibanaTileMap } from '../../meta' ;
2124
2225export function getInitialLayers ( layerListJSON , initialLayers = [ ] ) {
@@ -41,3 +44,33 @@ export function getInitialLayers(layerListJSON, initialLayers = []) {
4144
4245 return initialLayers ;
4346}
47+
48+ export function getInitialLayersFromUrlParam ( ) {
49+ const locationSplit = window . location . href . split ( '?' ) ;
50+ if ( locationSplit . length <= 1 ) {
51+ return [ ] ;
52+ }
53+ const mapAppParams = new URLSearchParams ( locationSplit [ 1 ] ) ;
54+ if ( ! mapAppParams . has ( 'initialLayers' ) ) {
55+ return [ ] ;
56+ }
57+
58+ try {
59+ let mapInitLayers = mapAppParams . get ( 'initialLayers' ) ;
60+ if ( mapInitLayers [ mapInitLayers . length - 1 ] === '#' ) {
61+ mapInitLayers = mapInitLayers . substr ( 0 , mapInitLayers . length - 1 ) ;
62+ }
63+ return rison . decode_array ( mapInitLayers ) ;
64+ } catch ( e ) {
65+ getToasts ( ) . addWarning ( {
66+ title : i18n . translate ( 'xpack.maps.initialLayers.unableToParseTitle' , {
67+ defaultMessage : `Initial layers not added to map` ,
68+ } ) ,
69+ text : i18n . translate ( 'xpack.maps.initialLayers.unableToParseMessage' , {
70+ defaultMessage : `Unable to parse contents of 'initialLayers' parameter. Error: {errorMsg}` ,
71+ values : { errorMsg : e . message } ,
72+ } ) ,
73+ } ) ;
74+ return [ ] ;
75+ }
76+ }
0 commit comments