import { SOURCE_TYPES } from '../constants' ; import { LayerDescriptor , EMSTMSSourceDescriptor } from '../descriptor_types' ; import { MapSavedObjectAttributes } from '../map_saved_object_type' ; export function setEmsTmsDefaultModes ( { attributes , } ) { if ( ! attributes || ! attributes . layerListJSON ) { return attributes ; } let layerList = [ ] ; try { layerList = JSON . parse ( attributes . layerListJSON ) ; } catch ( e ) { throw new Error ( 'Unable to parse attribute layerListJSON' ) ; } layerList . forEach ( ( layerDescriptor ) => { if ( layerDescriptor . sourceDescriptor ?. type === SOURCE_TYPES . EMS_TMS ) { const sourceDescriptor = layerDescriptor . sourceDescriptor as EMSTMSSourceDescriptor ; if ( ! sourceDescriptor . lightModeDefault ) { sourceDescriptor . lightModeDefault = 'road_map' ; } } } ) ; return { ... attributes , layerListJSON : JSON . stringify ( layerList ) , } ; }