<template>
  <div id="map">
    <iframe id="i_map" name="i_map">

    </iframe>
  </div>
</template>

<script>
import CityGis from '../../unit/map/CityGis.Bridge.js';
import {myBridge} from "@/unit/map/map.js";
import {watch ,onMounted} from "vue";
import {serviceGHLayer,serviceCXLayer,serviceGLLayer} from "@/data/all-layers.js";
import {AddSingleLayer, invokeParams, MapClickByType, SetBackground} from "@/unit/map/addLayer.js";
let bridge;
export default {
  name: "Map",
  props: {
    type: {
      default: () => ''  // 默认值为空数组
    },
    serviceNos: {
      type: Array,
      default: () => []  // 默认值为空数组
    }
  },
  setup(props){
    onMounted(()=>{
      myBridge.bridgeContent =  bridge = new CityGis.Bridge({
        id: "i_map",
        url: 'https://cimweb.zjw.sh.cegn.cn:2007/VUE-Map-Tool-Widget/#/jk_map?theme=dark&type=3D', //建科发布
        // url: 'http://localhost:8081/#/jk_map?theme=dark&type=3D',
        onReady: function () {

        }
      })


      console.log("地图创建完成");
      if(props.type == 'plan'){
        debugger
        serviceGHLayer.forEach(data => {
          AddSingleLayer({
            id: data.labelId,
            title: data.label,
            visible: true,
            wkid: 1,
            url: data.ADDRESS,
            type: "切片地图"
          });
        });
      }else if(props.type =='project'){
        serviceGLLayer.forEach(data => {
          AddSingleLayer({
            id: data.labelId,
            title: data.label,
            visible: true,
            wkid: 1,
            url: data.ADDRESS,
            type: "切片地图"
          });
        });
      }else if(props.type =='effect'){
        serviceCXLayer.forEach(data => {
          AddSingleLayer({
            id: data.labelId,
            title: data.label,
            visible: true,
            wkid: 1,
            url: data.ADDRESS,
            type: "切片地图"
          });
        });
      }
      MapClickByType(true);
      // watch(() => props.serviceNos, (newServiceNos) => {
      //   loadServices(newServiceNos);
      // }, { immediate: true });
      // function loadServices(serviceNos) {
      //   debugger
      //   serviceNos.forEach(serviceNo => {
      //     AddSingleLayer({
      //       id:"serviceNo",
      //       title: "默认服务",
      //       visible: true,
      //       wkid: 1,
      //       url: `https://cimweb.zjw.sh.cegn.cn:2008/MapProxyApi/getSceneServer/gxjh_fwjk/${serviceNo}`,
      //       type: "切片地图"
      //     });
      //   });
      //   MapClickByType(true);
      // }
    });
  }
}
</script>

<style scoped lang="scss">
#map{
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}
#i_map {
  position: fixed;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  border: none;
}
</style>