/**
 * 图层加载工具类
 */
import {setBoat} from '@/utils/map/Boat'
import {addLayer,setOpacity} from "@/utils/map/ArcgisUtil";
import {setCenter,setSxdxCamera} from '@/utils/map/Common'

// let layerList = ['cb','mt','jjq','dtq','md','sszh','hb','hd','sxdx','2023.1','2022.1','2022.2','2021.1','2021.2','2020.1','2020.2']
let layerList = []

export function closeAllLayer() {
    for (let i = layerList.length-1; i >=0;i--) {
        addLayerByName(layerList[i],false)
    }
}

export function addLayerByName(name,isShow){
    // 存储到打开图层列表
    if(isShow){
        let isExist = false
        for(let i = layerList.length-1; i >=0;i--){
            if(layerList[i] == name){
                isExist = true
            }
        }
        if(!isExist){
            layerList.push(name)
        }
    }else{
        for(let i = layerList.length-1; i >=0;i--){
            if(layerList[i] == name){
                layerList.splice(i,1)
            }
        }
    }
    console.log(layerList)

    switch (name) {
        // 船舶
        case 'cb':
            setBoat(isShow)
            break
        // 码头泊位
        case 'mt':
            addLayer({
                id: 'portLayer',
                title: 'portLayer',
                type: 'feature',
                url: 'http://10.83.68.109:6080/arcgis/rest/services/digitalTwain_3857/MapServer/0',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: true
            })
            break
        // 警戒区
        case 'jjq':
            addLayer({
                id: 'jjqLayer',
                title: 'jjqLayer',
                type: 'feature',
                url: 'http://10.83.68.109:6080/arcgis/rest/services/digitalTwain_3857/MapServer/5',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: true
            })
            break
        // 掉头区
        case 'dtq':
            addLayer({
                id: 'dtqLayer',
                title: 'dtqLayer',
                type: 'feature',
                url: 'http://10.83.68.109:6080/arcgis/rest/services/digitalTwain_3857/MapServer/4',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: true
            })
            break
        // 锚地
        case 'md':
            addLayer({
                id: 'mdLayer',
                title: 'mdLayer',
                type: 'feature',
                url: 'http://10.83.68.109:6080/arcgis/rest/services/digitalTwain_3857/MapServer/6',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: true
            })
            break
        // 水上综合绿色服务器
        case 'sszh':
            addLayer({
                id: 'ssfwqLayer',
                title: 'sszhfwqLayer',
                type: 'feature',
                url: 'http://10.83.68.109:6080/arcgis/rest/services/digitalTwain_3857/MapServer/3',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: true
            })
            break
        // 航标
        case 'hb':
            addLayer({
                id: 'hbLayer',
                title: 'hbLayer',
                type: 'feature',
                url: 'http://10.83.68.109:6080/arcgis/rest/services/digitalTwain_3857/MapServer/1',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: true
            })
            break
        // 航道
        case 'hd':
            addLayer({
                id: 'channelLayer',
                title: 'channelLayer',
                type: 'feature',
                url: 'http://10.83.68.109:6080/arcgis/rest/services/digitalTwain_3857/MapServer/2',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: true
            })
            break
        // 水下地形
        case 'sxdx':
            addLayer({
                id: 'dbsLayer',
                title: 'dbsLayer',
                type: 'scene',
                url: 'https://geoscene.geosceneonline.cn/server/rest/services/Hosted/多波束/SceneServer',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: true
            })
            // if(isShow){
            //     setOpacity(0.4)
            //     setSxdxCamera()
            // }else{
            //     setOpacity(1)
            //     setCenter()
            // }
            break
        case '2023.1':
            addLayer({
                id: 'deepthLayer202301',
                title: 'deepthLayer202301',
                type: 'scene',
                url: 'https://geoscene.geosceneonline.cn/server/rest/services/Hosted/多波束/SceneServer',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: true
            })
            break
        case '2022.1':
            addLayer({
                id: 'deepthLayer202201',
                title: 'deepthLayer202201',
                type: 'scene',
                url: 'https://geoscene.geosceneonline.cn/server/rest/services/Hosted/第一期2022/SceneServer',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: false
            })
            break
        case '2022.2':
            addLayer({
                id: 'deepthLayer202202',
                title: 'deepthLayer202202',
                type: 'scene',
                url: 'https://geoscene.geosceneonline.cn/server/rest/services/Hosted/第二期2022/SceneServer',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: false
            })
            break
        case '2021.1':
            addLayer({
                id: 'deepthLayer202101',
                title: 'deepthLayer202101',
                type: 'scene',
                url: 'https://geoscene.geosceneonline.cn/server/rest/services/Hosted/第一期2021/SceneServer',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: false
            })
            break
        case '2021.2':
            addLayer({
                id: 'deepthLayer202102',
                title: 'deepthLayer202102',
                type: 'scene',
                url: 'https://geoscene.geosceneonline.cn/server/rest/services/Hosted/第二期2021/SceneServer',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: false
            })
            break
        case '2020.1':
            addLayer({
                id: 'deepthLayer202001',
                title: 'deepthLayer202001',
                type: 'scene',
                url: 'https://geoscene.geosceneonline.cn/server/rest/services/Hosted/第一期2020/SceneServer',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: false
            })
            break
        case '2020.2':
            addLayer({
                id: 'deepthLayer202002',
                title: 'deepthLayer202002',
                type: 'scene',
                url: 'https://geoscene.geosceneonline.cn/server/rest/services/Hosted/第二期2020/SceneServer',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: false
            })
            break
        // 两岸白膜
        case 'bm':
            addLayer({
                id: 'hpj500mBuildingLayer',
                title: 'hpj500mBuildingLayer',
                type: 'scene',
                url: 'https://geoscene.geosceneonline.cn/server/rest/services/Hosted/黄浦江周边建筑500m/SceneServer',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: false
            })
            addLayer({
                id: 'pxBuildingLayer',
                title: 'pxBuildingLayer',
                type: 'scene',
                url: 'https://geoscene.geosceneonline.cn/server/rest/services/Hosted/浦西核心段白膜/SceneServer',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: false
            })
            break
        // 两岸精膜
        case 'jm':

            break
        // 客运码头
        case 'kymt':
            addLayer({
                id: 'kymtLayer',
                title: 'kymtLayer',
                type: 'scene',
                url: 'https://geoscene.geosceneonline.cn/server/rest/services/Hosted/客运码头/SceneServer',
                visible: isShow,
                opacity: 1,
                token: '',
                is_goto: false
            })
            break
    }
}