北京经济技术开发区经开区虚拟城市项目-【前端】-Web
lixuliang
2024-04-12 dbb352c9d988dfac83da979023fe81a0a02f88e9
src/components/map/viewer.vue
@@ -1,31 +1,84 @@
<template>
  <div>
    <div id="sdkContainer"></div>
    <!-- <iframe
      id="digital_page"
      v-if="isShowDigitalPerson"
      src="https://iframetester.com/"
      height="450"
      width="600"
      frameborder="no"
      border="0"
      marginwidth="0"
      marginheight="0"
      scrolling="no"
      allowtransparency="yes"
    ></iframe> -->
    <iframe
      v-if="isShowDigitalPerson"
      id="digital_page"
      allow="microphone;"
      :src="digitalHuman"
      :height="digitalSize.height"
      :width="digitalSize.width"
      frameborder="no"
      border="0"
      marginwidth="0"
      marginheight="0"
      scrolling="no"
      allowtransparency="yes"
    ></iframe>
    <div class="listBox" v-show="viewer1Show && !isLand">
      <ul>
        <li v-for="(item, index) in arr" :key="index" @click="changeLeftMap($event, item, index)">
      <ul id="viewer_lsyx">
        <li
          v-for="(item, index) in arr"
          :key="index"
          @click="changeLeftMap($event, item, index)"
        >
          {{ item }}
        </li>
      </ul>
    </div>
    <layerTreeTwoScreen v-if="layerTreeTwoScreen" />
    <!-- <div id="bottomInfo" v-html="bottomInfo"></div> -->
    <div id="switchImagerLayer" :style="{
      transform: `scale(${scale}) translate(${offset},${offset})`,
      '-webkit-transform': `scale(${scale}) translate(${offset},${offset})`,
      '-moz-transform': `scale(${scale}) translate(${offset},${offset})`,
      '-o-transform': `scale(${scale}) translate(${offset},${offset})`,
      '-ms-transform': `scale(${scale}) translate(${offset},${offset})`,
    }">
      <transition name="animate__animated animate__bounce" @click="switchImagerLayerShowOrHide"
        enter-active-class="animate__backInRight" leave-active-class="animate__backOutRight" appear>
    <div
      id="switchImagerLayer"
      :style="{
        transform: `scale(${scale}) translate(${offset},${offset})`,
        '-webkit-transform': `scale(${scale}) translate(${offset},${offset})`,
        '-moz-transform': `scale(${scale}) translate(${offset},${offset})`,
        '-o-transform': `scale(${scale}) translate(${offset},${offset})`,
        '-ms-transform': `scale(${scale}) translate(${offset},${offset})`,
      }"
    >
      <transition
        name="animate__animated animate__bounce"
        @click="switchImagerLayerShowOrHide"
        enter-active-class="animate__backInRight"
        leave-active-class="animate__backOutRight"
        appear
      >
        <switchImagerLayer ref="switchImagerLayer" v-show="switchImagerLayer" />
      </transition>
      <img class="swichImg" @click="switchImagerLayerShowOrHide" :src="switchImage" />
      <img
        class="swichImg"
        @click="switchImagerLayerShowOrHide"
        :src="switchImage"
      />
      <div class="bgbox">
        <img class="swichImg" @click="switchImagerLayerShowOrHide" src="@/assets/img/new/shiliang.png" />
        <img class="swichImg bgbox" @click="switchImagerLayerShowOrHide" src="@/assets/img/new/shiliang.png" />
        <img
          class="swichImg"
          @click="switchImagerLayerShowOrHide"
          src="@/assets/img/new/shiliang.png"
        />
        <img
          class="swichImg bgbox"
          @click="switchImagerLayerShowOrHide"
          src="@/assets/img/new/shiliang.png"
        />
      </div>
    </div>
  </div>
@@ -43,7 +96,11 @@
import "animate.css";
import Bus from "@tools/Bus";
let activeLi, nLayer,LWLayer;
import mapData from "../../../static/mapData";
import mapMsg from "../../assets/js/mapMsg";
import vueEvents from "@/utils/vueEvent.js";
let activeLi, nLayer, LWLayer;
export default {
  name: "viewer",
  components: {
@@ -64,6 +121,8 @@
      scale: "1",
      offset: "0%",
      radio: 3,
      digitalHuman: null,
      digitalSize: {},
      arr: [
        2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
        2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021,
@@ -72,29 +131,45 @@
  },
  computed: {
    ...mapState(["viewer1Show", "isLand", "layerTreeTwoScreen", "cesiumInit"]),
    isShowDigitalPerson() {
      return this.$store.state.isShowDigitalPerson;
    },
  },
  watch: {
    viewer1Show(newvalue, oldvalue) {
      if (!newvalue) {
        this.destroyImageLayer();
      } else {
        if (!this.isLand) {
          this.initLSYX();
        }
      }
    },
    isLand(newvalue, oldvalue) {
      if (newvalue) {
        this.destroyImageLayer();
      } else {
        this.initLSYX();
      }
    }
    },
  },
  mounted() {
    this.digitalHuman = window.digitalHumanURL;
    this.digitalSize = window.digitalSize;
    let pathName = window.location.pathname.split("/");
    let StaticFileBaseUrl;
    if (pathName.length != 2) {
      StaticFileBaseUrl = `../../../${pathName[1]}/static/CimSDK/`;
    } else {
      StaticFileBaseUrl = `../../../static/CimSDK/`;
    }
    this.$nextTick(function () {
      let that = this;
      //*********北京sdk************
      window.sgworld = new SmartEarth.EarthCtrl(
        "sdkContainer",
        {
          // StaticFileBaseUrl: "../../../static/CimSDK/",
          StaticFileBaseUrl: "../../../SW/static/CimSDK/",
          StaticFileBaseUrl: StaticFileBaseUrl,
        },
        {},
        {},
@@ -134,12 +209,15 @@
              },
              duration: 5, //飞行时间8s
            });
            // console.log("加载完成");
          }, 14000);
          that.setCesiumInit(true);
        }
      );
      window.Viewer = sgworld._Viewer;
      window.sgwfs = new SmartEarth.WFSTool(sgworld._Viewer);
      window.viewer = sgworld._Viewer;
      sgworld._Viewer.scene.moon.show = false;
      window.sgwfs = new SmartEarth.WFSTool(sgworld._Viewer, Cesium);
      Viewer.shadows = false;
      //深度检测
      sgworld.Analysis.depthTestAgainstTerrain(true);
@@ -147,6 +225,10 @@
      // Viewer.scene.screenSpaceCameraController.enableCollisionDetection = false;
      Viewer.scene.globe.translucency.frontFaceAlpha = 0.5;
      Viewer.scene.globe.undergroundColor = undefined;
      mapMsg.init();
      // rpc.clickToCoordinates();
      // mapMsg.setTime();
      //开启编辑并启用属性弹窗
      sgworld.Creator.SimpleGraphic.setEdit(true, {
        editProp: true,
@@ -209,15 +291,6 @@
        },
      });
      //初始化弹窗事件
      // that.showBottom();
      that.initLayerOpen();
@@ -264,9 +337,14 @@
        this.destroyImageLayer();
      }
    },
    initLSYX() {
      let ul = document.getElementById("viewer_lsyx");
      let lis = ul.getElementsByTagName("li");
      lis[19].click();
    },
    destroyImageLayer() {
      if (activeLi) {
        activeLi.classList.remove('active');
        activeLi.classList.remove("active");
        activeLi = null;
      }
      if (nLayer) {
@@ -281,10 +359,10 @@
    changeLeftMap(event, item, index) {
      let liObj = event.currentTarget;
      if (activeLi) {
        activeLi.classList.remove('active');
        activeLi.classList.remove("active");
        activeLi = null;
      }
      liObj.classList.add('active');
      liObj.classList.add("active");
      activeLi = liObj;
      this.loadImageLayer(item);
    },
@@ -294,8 +372,10 @@
        nLayer = null;
      }
      nLayer = this.loadBJ54ImageLayer(year);
      if(!LWLayer)
      {
      if (!LWLayer || Viewer.imageryLayers.indexOf(LWLayer) < 0) {
        if (LWLayer) {
          LWLayer.destroy();
        }
        LWLayer = this.loadBJ54LWLayer();
      }
    },
@@ -304,15 +384,15 @@
      //let url = option.url;
      //let year = option.year;
      let paramUrl = `${url}?user=jjjskfq&password=Jjjskfq@2022&layer=Shiliang_Lw_2019&style=&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fpng&TileMatrix={z}&TileCol={nx}&TileRow={ny}`;
      let minx = 113.168199 * Math.PI / 180.0;
      let miny = 39.230551 * Math.PI / 180.0;
      let maxx = 118.562362 * Math.PI / 180.0;
      let maxy = 41.294714 * Math.PI / 180.0;
      let minx = (113.168199 * Math.PI) / 180.0;
      let miny = (39.230551 * Math.PI) / 180.0;
      let maxx = (118.562362 * Math.PI) / 180.0;
      let maxy = (41.294714 * Math.PI) / 180.0;
      let rectangle = new Cesium.Rectangle(minx, miny, maxx, maxy);
      let tilingScheme = new Cesium.GeographicTilingScheme({
        rectangle: rectangle,
        numberOfLevelZeroTilesX: 2,
        numberOfLevelZeroTilesY: 1
        numberOfLevelZeroTilesY: 1,
      });
      var dx = {
        url: paramUrl,
@@ -323,11 +403,14 @@
          },
          ny: function (imageryProvider, x, y, level) {
            return (2 << (level - 1)) + y;
          }
        }
          },
        },
      };
      var imageryProvider = new Cesium.UrlTemplateImageryProvider(dx);
      let imageLayer = new Cesium.ImageryLayer(imageryProvider, { alpha: 1, brightness: 1.0 });
      let imageLayer = new Cesium.ImageryLayer(imageryProvider, {
        alpha: 1,
        brightness: 1.0,
      });
      Viewer.imageryLayers.add(imageLayer, 3);
      return imageLayer;
    },
@@ -336,15 +419,15 @@
      //let url = option.url;
      //let year = option.year;
      let paramUrl = `${url}?user=jjjskfq&password=Jjjskfq@2022&layer=Sate_${year}&style=&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fpng&TileMatrix={z}&TileCol={nx}&TileRow={ny}`;
      let minx = 113.168199 * Math.PI / 180.0;
      let miny = 39.230551 * Math.PI / 180.0;
      let maxx = 118.562362 * Math.PI / 180.0;
      let maxy = 41.294714 * Math.PI / 180.0;
      let minx = (113.168199 * Math.PI) / 180.0;
      let miny = (39.230551 * Math.PI) / 180.0;
      let maxx = (118.562362 * Math.PI) / 180.0;
      let maxy = (41.294714 * Math.PI) / 180.0;
      let rectangle = new Cesium.Rectangle(minx, miny, maxx, maxy);
      let tilingScheme = new Cesium.GeographicTilingScheme({
        rectangle: rectangle,
        numberOfLevelZeroTilesX: 2,
        numberOfLevelZeroTilesY: 1
        numberOfLevelZeroTilesY: 1,
      });
      var dx = {
        url: paramUrl,
@@ -355,11 +438,14 @@
          },
          ny: function (imageryProvider, x, y, level) {
            return (2 << (level - 1)) + y;
          }
        }
          },
        },
      };
      var imageryProvider = new Cesium.UrlTemplateImageryProvider(dx);
      let imageLayer = new Cesium.ImageryLayer(imageryProvider, { alpha: 1, brightness: 1.0 });
      let imageLayer = new Cesium.ImageryLayer(imageryProvider, {
        alpha: 1,
        brightness: 1.0,
      });
      Viewer.imageryLayers.add(imageLayer, 2);
      return imageLayer;
    },
@@ -383,10 +469,17 @@
      this.switchImagerLayer = !this.switchImagerLayer;
    },
    ArcgisImageryLayer() {
      var layer = sgworld.factory.createImageryLayer({
        sourceType: "arcgis",
        url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
      });
      sgworld.Creator.createArcGisImageryLayer(
        "ARCGIS",
        {
          url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
          enablePickFeatures: false,
        },
        "0",
        1,
        true,
        ""
      );
    },
    //初始化弹窗事件
@@ -432,6 +525,11 @@
          cancel: function () {
            if (cancelFn && typeof cancelFn === "function") {
              cancelFn();
              if (window.pickFeature && window.pickFeature.primitive) {
                window.pickFeature.primitive.image = imgUrl;
                window.pickFeature.primitive.scale = scale;
                window.pickFeature = null;
              }
            }
          },
          end: function () {
@@ -546,7 +644,12 @@
  border-radius: 10px;
  /* box-shadow: 0px 0px 5px 3px #fff; */
}
#digital_page {
  position: absolute;
  left: 0;
  bottom: 120px;
  z-index: 10;
}
/* #switchImagerLayer:before {
  content: "";
  position: absolute;
@@ -588,13 +691,10 @@
  position: absolute;
  left: 20px;
  top: 100px;
}
.listBox .active {
  background: rgba(255, 166, 0, 0.808);
}
.listBox li {