<template>
</template>

<script>
import Config from './config.json'
export default {
    name:"PipeDirectionSwitch",//管道流向
    computed:{
      AppX: function () {
          return this.$store.getters.AppX;
      },
      config:function(){
          return Config
      }
    },
    methods:{
        /**
         * 该方法用于开关管网流向动画
         * @param open 开/关
         */
        psPipeDirectionFlow(open) {
            const layers=window.viewer.scene.layers;
            if (open) {
                //打开流向
                this.config.layer_lx.forEach(item => {
                    if(layers.find(item.layerName)){
                        window.viewer.scene.layers.remove(item.layerName, true);
                        let lxUrl = this.AppX.appConfig.gisResource[item.key].config.lxfxfw.url;
                        //lxUrl场景地址；sceneName场景名称；layerName场景中图层的名称
                        const promise = window.viewer.scene.addLayerService(lxUrl, item.sceneName, item.layerName);
                        promise.then(layer => {
                            this.setStyle3D(layer);
                            layer.textureUVSpeed = new Cesium.Cartesian2(-1.0, 0);
                        })
                    }
                    
                })
            } else {
                //打开管网
                this.config.layer.forEach(item => {
                    if(layers.find(item.layerName)){
                        window.viewer.scene.layers.remove(item.layerName, true);
                        let lxUrl = this.AppX.appConfig.gisResource[item.key].config.yyxj01.url;
                        //lxUrl场景地址；sceneName场景名称；layerName场景中图层的名称
                        const promise = window.viewer.scene.addLayerService(lxUrl, item.sceneName, item.layerName);
                        promise.then(layer => {
                            this.setStyle3D(layer);
                        })
                    }
                })
            }
        },
        /**
         * 该方法用于设置管线抬升高度
         * @param layer 
         */
        setStyle3D(layer) {
            const upDepth = this.AppX.appConfig.upDepth;
            let style3d = new Cesium.Style3D();
            style3d.altitudeMode = 0;
            style3d.bottomAltitude = upDepth;
            layer.style3D = style3d;
            layer.maxVisibleAltitude = this.config.pipeMaxVisibel;
        }
    }
}
</script>

<style>

</style>