GuLiMmo
2023-12-05 c7c9de0214cb1e6ad3d29c8a3a0c7a8ea31fbaaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const layerTreeTypes = ['layer', 'resource'] as const
type LayerTreeType = (typeof layerTreeTypes)[number]
const Spliter = '__'
 
export function getLayerTreeKey (type: LayerTreeType, id: number | string) {
  return `${type}${Spliter}${id}`
}
 
export function isLayerTreeKey (key: string, type?: LayerTreeType) {
  if (type) {
    return key.startsWith(`${type}${Spliter}`)
  } else {
    return layerTreeTypes.some(t => key.startsWith(`${t}${Spliter}`))
  }
}
 
export function getIdFromLayerTreeKey (key: string) {
  return key.split(Spliter)[1]
}