<template>
  <el-container class="main-container">
    <div class="header-container">
      <menu-panel></menu-panel>
    </div>
    <el-container class="content-container">
      <el-main>
        <div class="home-view">
          <MainMap :mapKey="mapName" :url="configUrl" :options="mapOptions" @onload="onMapload" />
          <LayerListPanel></LayerListPanel>
          <SandMonitorLeft v-if="this.mainMenu === 'sandMonitor'"></SandMonitorLeft>
          <SandMonitorRight v-if="this.mainMenu === 'sandMonitor'"></SandMonitorRight>
          <SafetyInspectionLeft v-if="this.mainMenu === 'safetyInspection'"></SafetyInspectionLeft>
          <SafetyInspectionRight v-if="this.mainMenu === 'safetyInspection'"></SafetyInspectionRight>
          <AddInspectionTask />
          <ComprehensiveOverview v-if="this.mainMenu === 'comprehensiveOverview'"></ComprehensiveOverview>
          <HydrologicInfo v-if="this.mainMenu === 'hydrologicInfo'"></HydrologicInfo>
          <SmartEarlyWarning v-if="this.mainMenu === 'smartEarlyWarning'" />
          <WaterStationPopup />
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import menuPanel from '@/views/components/menu'
import MainMap from '@/views/components/map'
import LayerListPanel from '@/views/components/layerList'
import SandMonitorLeft from './sand-monitor/left.vue'
import SandMonitorRight from './sand-monitor/right.vue'
import SafetyInspectionLeft from './safety-inspection/left.vue'
import SafetyInspectionRight from './safety-inspection/right.vue'
import ComprehensiveOverview from '@/views/comprehensive-overview/index'
import HydrologicInfo from '@/views/hydrologic-info/index'
import WaterStationPopup from '@/views/water-station-popup'
import AddInspectionTask from './safety-inspection/addInspectionTask.vue'
import SmartEarlyWarning from '@/views/smart-early-warning/index'
const basePathUrl = window.basePathUrl || ''
export default {
  name: 'MainView',
  components: {
    MainMap,
    LayerListPanel,
    menuPanel,
    SandMonitorLeft,
    SandMonitorRight,
    SafetyInspectionLeft,
    ComprehensiveOverview,
    SafetyInspectionRight,
    HydrologicInfo,
    WaterStationPopup,
    AddInspectionTask,
    SmartEarlyWarning
  },
  data() {
    return {
      mapName: 'cMap',
      configUrl: basePathUrl + 'config/config.json',
      mapOptions: {
        scene: { center: { lat: 34.203789, lng: 108.30656, alt: 36020, heading: 0.8, pitch: -85.9 } },
        basemaps: [
          //   {
          //     name: "天地图电子",
          //     type: "group",
          //     layers: [
          //       { name: "底图", type: "tdt", layer: "vec_d", key: ["d7077257b0ca8c279c3e1bf92fb437dc"] },
          //       { name: "注记", type: "tdt", layer: "vec_z", key: ["d7077257b0ca8c279c3e1bf92fb437dc"] },
          //     ],
          //   },
          {
            name: '天地图影像',
            type: 'group',
            layers: [{ name: '底图', type: 'tdt', layer: 'img_d', key: ['d7077257b0ca8c279c3e1bf92fb437dc'] }],
            show: true
          },
          {
            type: 'tdt',
            name: '天地图注记',
            layer: 'img_z',
            key: ['d7077257b0ca8c279c3e1bf92fb437dc'],
            show: true
          }
        ]
      },
      mainMenu:'comprehensiveOverview',
    }
  },
  created(){
    this.mainMenu = this.$route.params.menu
  },
  methods: {
    // 地图加载回调优化
    async onMapload(map) {
      window.map = map
      map.hasTerrain = true
      this.addWaterSurface(map)
    },
    // 添加水面
    addWaterSurface(map) {
      const geoJsonLayer = new this.mars3d.layer.GeoJsonLayer({
        name: '渭河',
        url: '/geojson/weihe.geojson',
        crs: 'EPSG:4326',
        symbol: {
          type: 'water',
          styleOptions: {
            normalMap: '/img/waterNormals.jpg',
            addHeight: 120,
            frequency: 8000.0, // 控制波数的数字。
            animationSpeed: 0.04, // 控制水的动画速度的数字。
            amplitude: 5.0, // 控制水波振幅的数字。
            specularIntensity: 0.8, // 控制镜面反射强度的数字。
            baseWaterColor: '#006ab4', // rgba颜色对象基础颜色的水。#00ffff,#00baff,#006ab4
            blendColor: '#006ab4', // 从水中混合到非水域时使用的rgba颜色对象。
            opacity: 0.7, // 透明度
            clampToGround: true // 是否贴地
          }
        }
      })
      map.addLayer(geoJsonLayer)
    }
  }
}
</script>

<style lang="scss">
.main-container {
  width: 100%;
  flex-direction: column;
  .el-main {
    padding: 0px;
  }
}
.header-container {
  z-index: 100;
  position: absolute;
  width: 100%;
}
.content-container {
  height: 100vh;
}
.home-view {
  position: relative;
  overflow: hidden;
  height: 100%;
  box-sizing: border-box;
}
</style>