tengsx
2023-04-07 36c045a4f518f6506eab91e48ee48ce7d1aaa21d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!--
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2023-04-01 21:45:20
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2023-04-04 11:54:53
 * @FilePath: \hbsl\src\components\map\index.vue
 * @Description:
 *
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
-->
<!--
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2022-08-18 17:00:30
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2023-04-02 16:18:38
 * @FilePath: \srs-police-affairs\src\components\map\index.vue
 * @Description: 公用地图组件
 *
 * Copyright (c) 2022 by shuishen 1109946754@qq.com, All Rights Reserved.
-->
<template>
    <div class="viewer-box" id="viewer-container">
        <slot ref="mainContent" name="mainContent"></slot>
    </div>
</template>
 
<script>
 
export default {
    name: 'mapBox',
 
    data () {
        return {
 
        }
    },
 
    computed: {
 
    },
 
    mounted () {
        if (global.viewer != null) {
            global.viewer = null
        }
 
        const that = this
 
        // 初始化地图
        function initViewer () {
            // new Viewer(new 地图)
            global.viewer = new global.DC.Viewer('viewer-container', {
                contextOptions: {
                    webgl: {
                        alpha: true,
                        stencil: true,
                        preserveDrawingBuffer: true
                    }
                }
            })
 
            let primitiveArr = global.viewer.scene.primitives._primitives
            global.viewer.scene.primitives.remove(primitiveArr[0])
 
            // 外网
            let baseLayer = global.viewer.imageryLayers.addImageryProvider(
                new global.DC.Namespace.Cesium.UrlTemplateImageryProvider({
                    url: 'http://t{s}.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=e45274b0235bb913eceb393aabbf9c9c',
                    subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
                    format: 'image/jpeg',
                    show: true,
                    maximumLevel: 18
                })
            )
 
            baseLayer.hue = 3
            baseLayer.contrast = -1.2
 
            // 设置地图初始位置,角度等
            global.viewer.camera.setView({
                // Cesium的坐标是以地心为原点,一向指向南美洲,一向指向亚洲,一向指向北极州
                // fromDegrees()方法,将经纬度和高程转换为世界坐标
                destination: global.DC.Namespace.Cesium.Cartesian3.fromDegrees(
                    117.951478782, 28.447896798, 20000
                ),
                orientation: {
                    // 指向
                    heading: global.DC.Namespace.Cesium.Math.toRadians(0, 0),
                    // 视角
                    pitch: global.DC.Namespace.Cesium.Math.toRadians(-90),
                    roll: 0.0
                }
            })
 
        }
 
        global.DC.ready(initViewer)
 
        function isEleFullScreen () {
            const fullScreenEle =
                document.fullscreenElement ||
                document.msFullscreenElement ||
                document.mozFullScreenElement ||
                document.webkitFullscreenElement
            if (fullScreenEle === null) {
 
                that.isFullscreen = false
                return false
            } else {
                return true
            }
        }
 
        window.onresize = function () {
            console.log(isEleFullScreen())
        }
 
    },
 
    methods: {
 
    },
 
}
</script>
 
<style lang="scss" scope>
.viewer-box {
    position: relative;
    width: 100%;
    height: 100%;
}
</style>