<template>
    <div id="app">
        <div id="cesiumContainer" class="fullWindow"></div>
        <div id="loadingIndicator" class="loadingIndicator"></div>
        <div id="toolbar" v-if="layers">
            <span>{{selectedText?selectedText:'请选择数据'}}</span>
            <ul>
                <li v-for="(item,key) in layers" :key="key" @click="change(item)">
                    <input type="checkbox" :checked="item.checked" />
                    <span>{{item.text}}</span>
                </li>
            </ul>
        </div>
    </div>
</template>
<script>
import { start } from "./core/viewer";
export default {
    data() {
        return {
            layers: null
        };
    },
    created() {
        this.$bus.$on("config", config => {
            this.layers = config.layers.filter(item=>item.show);
        });
    },
    computed:{
        selectedText(){
            if(this.layers){
                return this.layers.filter(item=>item.checked).map(item=>item.text).join(',')
            }
        }
    },
    mounted() {
        start();
    },
    methods: {
        change(item) {
            item.checked = !item.checked;

            this.$bus.$emit("setLayer",item);
        }
    }
};
</script>
<style lang="less">
html,
body,
#app {
    width: 100%;
    height: 100%;
    overflow: hidden;
}
ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
img {
    border: 0;
    outline: 0;
}
#toolbar {
    cursor: pointer;
    position: absolute;
    left: 5px;
    top: 5px;
    border: solid 1px #b9baba;
    border-radius: 6px;
    width: 200px;
    height: 22px;
    line-height: 22px;
    font-size: 14px;
    color: #fff;
    padding: 3px 10px;
    background: #2c363b;
    &:hover {
        background: #48b;
        border-color: #aef;
        border-bottom-left-radius: 0px;
        border-bottom-right-radius: 0px;
        ul {
            display: block;
        }
    }
    ul {
        display: none;
        padding: 10px;
        box-sizing: border-box;
        position: absolute;
        top: 100%;
        left: -1px;
        right: -1px;
        border: solid 1px #b9baba;
        background: #2c363b;
        user-select: none;
         border-bottom-left-radius: 6px;
        border-bottom-right-radius: 6px;
    }
    li {
        input,
        span {
            vertical-align: middle;
        }
    }
}
</style>
<style lang="less">
#navigationDiv {
    .compass {
        top: 40%;
    }
    .navigation-controls {
        top: calc(40% + 100px);
        border: 1px solid #b9baba;
    }
}
</style>