liuyg
2022-03-05 3d6fe47da90e3335a16b093dccaadcfca9933520
src/components/map/index.vue
@@ -1,10 +1,6 @@
/* eslint-disable camelcase */
<template>
  <div
    id="viewer-container"
    style="height: 100%; width: 100%"
    @click="mapClick($event)"
  >
    <div id="viewer-container" style="height: 100%; width: 100%" @click="mapClick($event)">
    <video
      id="video"
      style="position: fixed; visibility: hidden"
@@ -14,10 +10,7 @@
      crossorigin
      controls
    >
      <source
        src="http://dc.dvgis.cn/examples/data/demo.mp4"
        type="video/mp4"
      />
            <source src="http://dc.dvgis.cn/examples/data/demo.mp4" type="video/mp4" />
    </video>
    <div
@@ -34,9 +27,7 @@
        background: #2196f3ed;
        z-index: 11;
      "
    >
      智慧校区
    </div>
        >智慧校区</div>
    <dimension :areaLayer="areaLayer" />
@@ -51,192 +42,352 @@
    <search-details v-if="searchPopupFlag"></search-details>
    <org-nav-bar v-if="orgNavBarFlag"></org-nav-bar>
    <arc-nav-bar v-if="arcNavBarFlag"></arc-nav-bar>
        <div id="eagleEyeMap" class="eagle-eye-map"></div>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import mapPopup from "./components/mapPopup.vue";
import campusBuildingSearch from "./components/campusBuildingSearch.vue";
import dimension from "./components/dimension.vue";
import { mapGetters } from 'vuex'
import mapPopup from './components/mapPopup.vue'
import campusBuildingSearch from './components/campusBuildingSearch.vue'
import dimension from './components/dimension.vue'
export default {
  name: "mapBox",
    name: 'mapBox',
  components: {
    mapPopup,
    campusBuildingSearch,
    dimension,
        dimension
  },
  data() {
    return {
      DC: null,
      areaLayer: null,
    };
            areaLayer: null
        }
  },
  watch: {
    searchPopupFlag: {
      immediate: true,
      handler(newVal, oldVal) {
        if (newVal == true) {
          if (this.$route.path.indexOf("/pcLayout/default/service") != -1) {
            this.$store.dispatch("delVisitedViews", this.$route);
            this.$router.push("/pcLayout/default");
                    if (this.$route.path.indexOf('/pcLayout/default/service') != -1) {
                        this.$store.dispatch('delVisitedViews', this.$route)
                        this.$router.push('/pcLayout/default')
          }
          if (this.$route.path.indexOf("/orgnav") != -1) {
            this.$store.dispatch("delVisitedViews", this.$route);
            this.$router.push("/pcLayout/default");
            this.$store.commit("SET_ORGNAVBARTITLE", "");
            this.$store.commit("SET_ORGNAVBARLIST", []);
            this.$store.commit("SET_ORGNAVBARFLAG", false);
                    if (this.$route.path.indexOf('/orgnav') != -1) {
                        this.$store.dispatch('delVisitedViews', this.$route)
                        this.$router.push('/pcLayout/default')
                        this.$store.commit('SET_ORGNAVBARTITLE', '')
                        this.$store.commit('SET_ORGNAVBARLIST', [])
                        this.$store.commit('SET_ORGNAVBARFLAG', false)
          }
          if (this.orgNavBarFlag == true) {
            this.$store.commit("SET_ORGNAVBARTITLE", "");
            this.$store.commit("SET_ORGNAVBARLIST", []);
            this.$store.commit("SET_ORGNAVBARFLAG", false);
                        this.$store.commit('SET_ORGNAVBARTITLE', '')
                        this.$store.commit('SET_ORGNAVBARLIST', [])
                        this.$store.commit('SET_ORGNAVBARFLAG', false)
          }
          if (this.$route.path.indexOf("/arc") != -1) {
            this.$store.dispatch("delVisitedViews", this.$route);
            this.$router.push("/pcLayout/default");
            this.$store.commit("SET_ARCNAVBARTITLE", "");
            this.$store.commit("SET_ARCNAVBARCODE", "");
            this.$store.commit("SET_ARCNAVBARFLAG", false);
                    if (this.$route.path.indexOf('/arc') != -1) {
                        this.$store.dispatch('delVisitedViews', this.$route)
                        this.$router.push('/pcLayout/default')
                        this.$store.commit('SET_ARCNAVBARTITLE', '')
                        this.$store.commit('SET_ARCNAVBARCODE', '')
                        this.$store.commit('SET_ARCNAVBARFLAG', false)
          }
          if (this.arcNavBarFlag == true) {
            this.$store.commit("SET_ARCNAVBARTITLE", "");
            this.$store.commit("SET_ARCNAVBARCODE", "");
            this.$store.commit("SET_ARCNAVBARFLAG", false);
                        this.$store.commit('SET_ARCNAVBARTITLE', '')
                        this.$store.commit('SET_ARCNAVBARCODE', '')
                        this.$store.commit('SET_ARCNAVBARFLAG', false)
          }
        }
      },
            }
    },
    orgNavBarFlag: {
      immediate: true,
      handler(newVal, oldVal) {
        if (newVal == true) {
          this.$store.commit("SET_SEARCHPOPUPFLAG", false);
                    this.$store.commit('SET_SEARCHPOPUPFLAG', false)
        }
      },
            }
    },
    arcNavBarFlag: {
      immediate: true,
      handler(newVal, oldVal) {
        if (newVal == true) {
          this.$store.commit("SET_SEARCHPOPUPFLAG", false);
                    this.$store.commit('SET_SEARCHPOPUPFLAG', false)
        }
      },
    },
            }
        }
  },
  computed: {
    ...mapGetters([
      "viewer",
      "popupBgUrl",
      "pupupQRUrl",
            'viewer',
            'popupBgUrl',
            'pupupQRUrl',
      // 终点
      "terminus",
            'terminus',
      // 起点
      "startingPoint",
            'startingPoint',
      // 点信息
      "pointPosition",
            'pointPosition',
      // 点名称
      "stateName",
            'stateName',
      // 地址
      "siteName",
            'siteName',
      // 介绍
      "introduceText",
            'introduceText',
      // 全景地址
      "panoramaUrl",
            'panoramaUrl',
      // 详情弹框显示关闭
      "detailsPopup",
            'detailsPopup',
      // 全景弹框显示关闭
      "panoramaPopup",
            'panoramaPopup',
      // 校区内导航的显示关闭
      "campusNavFlag",
      "orgNavBarFlag",
      "arcNavBarFlag",
      "searchPopupFlag",
    ]),
            'campusNavFlag',
            'orgNavBarFlag',
            'arcNavBarFlag',
            'searchPopupFlag'
        ])
  },
  mounted() {
    var that = this;
        var that = this
    let viewer;
        let viewer, eagleViewer
    that.DC = global.DC;
        that.DC = global.DC
    function distanceSurface() {
      viewer.measure.distanceSurface();
            viewer.measure.distanceSurface()
    }
    function calcArea() {
      viewer.measure.area();
            viewer.measure.area()
    }
    function areaSurface() {
      viewer.measure.areaSurface();
            viewer.measure.areaSurface()
    }
    function calcAngle() {
      viewer.measure.angle();
            viewer.measure.angle()
    }
    function calcModelAngle() {
      viewer.measure.angle({
        clampToModel: true,
      });
                clampToModel: true
            })
    }
    function calcHeight() {
      viewer.measure.height();
            viewer.measure.height()
    }
    function calcModelHeight() {
      viewer.measure.height({
        clampToModel: true,
      });
                clampToModel: true
            })
    }
    function calcHeading() {
      viewer.measure.heading();
            viewer.measure.heading()
    }
    function areaHeight() {
      viewer.measure.areaHeight();
            viewer.measure.areaHeight()
    }
    function calcTriangleHeight() {
      viewer.measure.triangleHeight();
            viewer.measure.triangleHeight()
    }
    function calcModelTriangleHeight() {
      viewer.measure.triangleHeight({
        clampToModel: true,
      });
                clampToModel: true
            })
    }
    function deactivate() {
      viewer.measure.deactivate();
            viewer.measure.deactivate()
    }
    function initViewer() {
      viewer = new that.DC.Viewer("viewer-container", {
            viewer = new that.DC.Viewer('viewer-container', {
        contextOptions: {
          webgl: {
            stencil: true,
            preserveDrawingBuffer: true,
                        preserveDrawingBuffer: true
                    }
                }
            })
            eagleViewer = new that.DC.Viewer('eagleEyeMap', {
                animation: false,
                baseLayerPicker: false,
                imageryProvider: false,
                fullscreenButton: false,
                geocoder: false,
                homeButton: false,
                infoBox: false,
                sceneModePicker: false,
                selectionIndicator: false,
                timeline: false,
                navigationHelpButton: false,
                navigationInstructionsInitiallyVisible: false,
                creditContainer: undefined
                // sceneMode: that.DC.Namespace.Cesium.SceneMode.SCENE2D
            })
            eagleViewer.camera.setView({
                // Cesium的坐标是以地心为原点,一向指向南美洲,一向指向亚洲,一向指向北极州
                // fromDegrees()方法,将经纬度和高程转换为世界坐标
                destination: that.DC.Namespace.Cesium.Cartesian3.fromDegrees(
                    115.871863, 28.743861, 1400.0
                ),
                orientation: {
                    // 指向
                    heading: that.DC.Namespace.Cesium.Math.toRadians(0, 0),
                    // 视角
                    pitch: that.DC.Namespace.Cesium.Math.toRadians(-90),
                    roll: 0.0
                }
            })
            var sceneR = eagleViewer.scene
            var handlerR = new that.DC.Namespace.Cesium.ScreenSpaceEventHandler(sceneR.canvas)
            var isLeftTrigger = false
            var isRightTrigger = false
            viewer.on(that.DC.MouseEventType.MOUSE_MOVE, () => {
                isLeftTrigger = true
                isRightTrigger = false
            })
            handlerR.setInputAction(function (movement) {
                isLeftTrigger = false
                isRightTrigger = true
            }, that.DC.Namespace.Cesium.ScreenSpaceEventType.MOUSE_MOVE)
            var syncviewer = function () {
                if (isLeftTrigger) {
                    const position = that.DC.Transform.transformCartesianToWGS84(viewer.camera.position)
                    eagleViewer.camera.flyTo({
                        destination: that.DC.Transform.transformWGS84ToCartesian(new that.DC.Position(position.lng, position.lat, position.alt + 1000)),
                        orientation: {
                            heading: viewer.camera.heading,
                            pitch: viewer.camera.pitch,
                            roll: viewer.camera.roll
          },
                        duration: 0.0
                    })
                }
            }
            viewer.camera.changed.addEventListener(syncviewer)
            viewer.scene.preRender.addEventListener(syncviewer)
            var synceagleViewer = function () {
                if (isRightTrigger) {
                    console.log(eagleViewer.camera.heading)
                    viewer.camera.flyTo({
                        destination: eagleViewer.camera.position,
                        orientation: {
                            heading: eagleViewer.camera.heading,
                            pitch: eagleViewer.camera.pitch,
                            roll: eagleViewer.camera.roll
        },
      });
      that.createdLayers(viewer);
                        duration: 0.0
      that.$store.commit("SET_VIEWER", viewer);
                    })
                }
            }
      that.$refs.leftNav.initialize(viewer);
            eagleViewer.camera.changed.addEventListener(synceagleViewer)
            eagleViewer.scene.preRender.addEventListener(synceagleViewer)
            // viewer.camera.percentageChanged = 0.01
            // eagleViewer.camera.percentageChanged = 0.01
            // viewer.camera.changed.addEventListener((e) => {
            //     eagleViewer.camera.flyTo({
            //         destination: viewer.camera.position,
            //         orientation: {
            //             heading: viewer.camera.heading + 5000,
            //             pitch: viewer.camera.pitch,
            //             roll: viewer.camera.roll
            //         },
            //         duration: 0.0
            //     })
            // })
            // eagleViewer.camera.changed.addEventListener((e) => {
            //     viewer.camera.flyTo({
            //         destination: eagleViewer.camera.position,
            //         orientation: {
            //             heading: eagleViewer.camera.heading - 5000,
            //             pitch: eagleViewer.camera.pitch,
            //             roll: eagleViewer.camera.roll
            //         },
            //         duration: 0.0
            //     })
            // })
            eagleViewer.imageryLayers.addImageryProvider(
                new that.DC.Namespace.Cesium.WebMapTileServiceImageryProvider({
                    url: ' http://t1.tianditu.gov.cn/vec_w/wmts?tk=9ae78c51a0a28f06444d541148496e36',
                    type: 'wmts',
                    layer: 'vec',
                    style: 'default',
                    format: 'tiles',
                    tileMatrixSetID: 'w',
                    show: true,
                    maximumLevel: 18
                })
            )
            eagleViewer.imageryLayers.addImageryProvider(
                new that.DC.Namespace.Cesium.WebMapTileServiceImageryProvider({
                    url: ' http://t1.tianditu.gov.cn/cva_w/wmts?tk=9ae78c51a0a28f06444d541148496e36',
                    type: 'wmts',
                    layer: 'cva',
                    style: 'default',
                    format: 'tiles',
                    tileMatrixSetID: 'w',
                    show: true,
                    maximumLevel: 18
                })
            )
            that.createdLayers(viewer)
            that.$store.commit('SET_VIEWER', viewer)
            that.$refs.leftNav.initialize(viewer)
      // const key = '0f7c1d161d7352116a21aacf0e9f44c1'
      // const vec = that.DC.ImageryLayerFactory.createTdtImageryLayer({
@@ -358,41 +509,55 @@
      //     name: '地形'
      // })
      viewer.use(new that.DC.Measure());
            viewer.use(new that.DC.Measure())
      // viewer.flyToPosition(
      //     new that.DC.Position(117.08489820, 31.65413916, 1500, 0, -90, 45)
      // )
      viewer.compass.enable = true;
      viewer.zoomController.enable = true;
      viewer.locationBar.enable = true;
      viewer.hawkeyeMap.enable = true;
      viewer.hawkeyeMap.addBaseLayer(
        that.DC.ImageryLayerFactory.createAmapImageryLayer({
          crs: "WGS84",
        })
      );
            viewer.compass.enable = true
            viewer.zoomController.enable = true
            viewer.locationBar.enable = true
            // DC的鹰眼地图
            // viewer.hawkeyeMap.enable = true
            // viewer.hawkeyeMap.addBaseLayer(
            //     that.DC.ImageryLayerFactory.createAmapImageryLayer({
            //         crs: 'WGS84'
            //     })
            // )
      // viewer.distanceLegend.enable = true
    }
    that.DC.ready(initViewer);
        that.DC.ready(initViewer)
  },
  methods: {
    mapClick(e) {
      this.$refs.campusNavRoute.shortcutShow(e);
      this.$refs.campusBuildingSearch.shortcutShow(e);
            this.$refs.campusNavRoute.shortcutShow(e)
            this.$refs.campusBuildingSearch.shortcutShow(e)
    },
    createdLayers(viewer) {
      const layerGroup = new this.DC.LayerGroup("modelBox");
      viewer.addLayerGroup(layerGroup);
            const layerGroup = new this.DC.LayerGroup('modelBox')
            viewer.addLayerGroup(layerGroup)
      this.areaLayer = new this.DC.VectorLayer("areaLayer");
      layerGroup.addLayer(this.areaLayer);
    },
  },
};
            this.areaLayer = new this.DC.VectorLayer('areaLayer')
            layerGroup.addLayer(this.areaLayer)
        }
    }
}
</script>
<style lang="scss" scope></style>
<style lang="scss" scope>
.eagle-eye-map {
    position: fixed;
    right: 10px;
    bottom: 10px;
    border: 5px solid orange;
    border-radius: 50%;
    width: 200px;
    height: 200px;
    z-index: 99;
    overflow: hidden;
}
</style>