shuishen
2022-03-08 3f957f1b2edf8ad7e35f6c3f64b47f7704fa366d
src/components/map/index.vue
@@ -1,26 +1,35 @@
/* 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"
            muted
            autoplay
            loop
            crossorigin
            controls
        >
            <source src="http://dc.dvgis.cn/examples/data/demo.mp4" type="video/mp4" />
        </video>
        <div style="
            position: fixed;
            left: 4px;
            bottom: 4px;
            width: 80px;
            line-height: 24px;
            text-align: center;
            color: #fff;
            font-size: 14px;
            border-radius: 4px;
            background: #2196f3ed;
            z-index: 11;
        ">
            智慧社区
        </div>
        <div
            style="
        position: fixed;
        left: 4px;
        bottom: 4px;
        width: 80px;
        line-height: 24px;
        text-align: center;
        color: #fff;
        font-size: 14px;
        border-radius: 4px;
        background: #2196f3ed;
        z-index: 11;
      "
        >智慧校区</div>
        <dimension :areaLayer='areaLayer' />
        <dimension :areaLayer="areaLayer" />
        <left-nav ref="leftNav"></left-nav>
@@ -28,16 +37,21 @@
        <campusBuildingSearch ref="campusBuildingSearch" />
        <campusNav ref="campusNavRoute"
                   v-show="campusNavFlag" />
        <campusNav ref="campusNavRoute" v-show="campusNavFlag" />
        <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"
            @mouseover="samllMapFlag = true"
            @mouseleave="samllMapFlag = false"
            class="eagle-eye-map"
        ></div>
    </div>
</template>
<script>
import axios from 'axios'
import { mapGetters } from 'vuex'
import mapPopup from './components/mapPopup.vue'
import campusBuildingSearch from './components/campusBuildingSearch.vue'
@@ -53,7 +67,67 @@
    data () {
        return {
            DC: null,
            areaLayer: null
            areaLayer: null,
            samllMapFlag: false
        }
    },
    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('/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)
                    }
                    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)
                    }
                }
            }
        },
        orgNavBarFlag: {
            immediate: true,
            handler (newVal, oldVal) {
                if (newVal == true) {
                    this.$store.commit('SET_SEARCHPOPUPFLAG', false)
                }
            }
        },
        arcNavBarFlag: {
            immediate: true,
            handler (newVal, oldVal) {
                if (newVal == true) {
                    this.$store.commit('SET_SEARCHPOPUPFLAG', false)
                }
            }
        }
    },
    computed: {
@@ -79,16 +153,17 @@
            'detailsPopup',
            // 全景弹框显示关闭
            'panoramaPopup',
            // 社区内导航的显示关闭
            // 校区内导航的显示关闭
            'campusNavFlag',
            'orgNavBarFlag',
            'arcNavBarFlag'
            'arcNavBarFlag',
            'searchPopupFlag'
        ])
    },
    mounted () {
        var that = this
        let viewer
        let viewer, eagleViewer
        that.DC = global.DC
@@ -155,6 +230,167 @@
                    }
                }
            })
            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.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
                })
            )
            var sceneL = viewer.scene
            var sceneR = eagleViewer.scene
            var handlerL = new that.DC.Namespace.Cesium.ScreenSpaceEventHandler(sceneL.canvas)
            var handlerR = new that.DC.Namespace.Cesium.ScreenSpaceEventHandler(sceneR.canvas)
            var isLeftTrigger = false
            var isRightTrigger = false
            handlerL.setInputAction(function (movement) {
                isLeftTrigger = true
                isRightTrigger = false
            }, that.DC.Namespace.Cesium.ScreenSpaceEventType.MOUSE_MOVE)
            handlerR.setInputAction(function (movement) {
                if (that.samllMapFlag) {
                    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 && that.samllMapFlag) {
                    viewer.camera.flyTo({
                        destination: eagleViewer.camera.position,
                        orientation: {
                            heading: eagleViewer.camera.heading,
                            pitch: eagleViewer.camera.pitch,
                            roll: eagleViewer.camera.roll
                        },
                        duration: 0.0
                    })
                }
            }
            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
                }
            })
            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
            //     })
            // })
            that.createdLayers(viewer)
@@ -282,7 +518,7 @@
            //     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)
@@ -291,14 +527,14 @@
            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'
                    }
                )
            )
            // DC的鹰眼地图
            // viewer.hawkeyeMap.enable = true
            // viewer.hawkeyeMap.addBaseLayer(
            //     that.DC.ImageryLayerFactory.createAmapImageryLayer({
            //         crs: 'WGS84'
            //     })
            // )
            // viewer.distanceLegend.enable = true
        }
@@ -321,5 +557,16 @@
}
</script>
<style lang='scss' scope>
<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>