import { MapSavedObjectAttributes } from '../map_saved_object_type' ; import { LayerDescriptor } from '../descriptor_types' ; export function moveAttribution ( { 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 ( ( layer ) => { const sourceDescriptor = layer . sourceDescriptor as { attributionText ? : string ; attributionUrl ? : string ; } ; if ( sourceDescriptor . attributionText && sourceDescriptor . attributionUrl ) { layer . attribution = { label : sourceDescriptor . attributionText , url : sourceDescriptor . attributionUrl , } ; delete sourceDescriptor . attributionText ; delete sourceDescriptor . attributionUrl ; } } ) ; return { ... attributes , layerListJSON : JSON . stringify ( layerList ) , } ; }