import { LAYER_TYPE } from '../constants' ; import { LayerDescriptor } from '../descriptor_types' ; import { MapSavedObjectAttributes } from '../map_saved_object_type' ; export function renameLayerTypes ( { 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 . type === 'TILED_VECTOR' ) { layerDescriptor . type = LAYER_TYPE . MVT_VECTOR ; } else if ( layerDescriptor . type === 'VECTOR_TILE' ) { layerDescriptor . type = LAYER_TYPE . EMS_VECTOR_TILE ; } else if ( layerDescriptor . type === 'VECTOR' ) { layerDescriptor . type = LAYER_TYPE . GEOJSON_VECTOR ; } else if ( layerDescriptor . type === 'TILE' ) { layerDescriptor . type = LAYER_TYPE . RASTER_TILE ; } } ) ; return { ... attributes , layerListJSON : JSON . stringify ( layerList ) , } ; }