jxdnsong
2022-10-25 bf5ba56e8a82f0ef699f2eae413d0dc2c4e4f67d
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<template>
    <div id="viewer-container" style="width:100%;height:100%">
        <div class="mapBtnList">
            <div class="btn1 mapBtn" @click.stop="fullImg">全图</div>
            <div class="btn2 mapBtn" @click.stop="ranging">距离</div>
            <div class="btn3 mapBtn" @click.stop="area">面积</div>
            <div class="btn4 mapBtn" @click.stop="ranging">全景</div>
            <div class="btn5 mapBtn" @click.stop="clear">清除</div>
        </div>
    </div>
</template>
 
<script>
import {
    getSceneList
} from '@/api/pc/leftNav/index'
const sceneLayer = null
 
let baseLayer = []
 
let tilesetLayer, tileset
 
import baseLayerImgUrl from '@/assets/baseUrl'
 
export default {
    mounted () {
        const that = this
        function initViewer () {
            global.viewer = new DC.Viewer('viewer-container')
 
            // 去除水印
            const primitiveArr = global.viewer.scene.primitives._primitives
            global.viewer.scene.primitives.remove(primitiveArr[0])
 
 
            global.viewer.setOptions({
                globe:{
                    baseColor:DC.Color.BLACK
                }
            })
            let layer_build = new DC.TilesetLayer('layer_build').addTo(global.viewer)
            let build = new DC.Tileset(
            '//resource.dvgis.cn/data/3dtiles/ljz/tileset.json',
            {skipLevels:true}
            )
            let fs = `
            varying vec3 v_positionEC;
            void main(void){
                vec4 position = czm_inverseModelView * vec4(v_positionEC,1); // 位置
                float glowRange = 100.0; // 光环的移动范围(高度)
                gl_FragColor = vec4(0.2,  0.5, 1.0, 1.0); // 颜色
                gl_FragColor *= vec4(vec3(position.z / 100.0), 1.0); // 渐变
                // 动态光环
                float time = fract(czm_frameNumber / 360.0);
                time = abs(time - 0.5) * 2.0;
                float diff = step(0.005, abs( clamp(position.z / glowRange, 0.0, 1.0) - time));
                gl_FragColor.rgb += gl_FragColor.rgb * (1.0 - diff);
            }
            `
            build.setCustomShader(fs)
            layer_build.addOverlay(build)
            let layer = new DC.PrimitiveLayer('layer').addTo(global.viewer)
            let positions = generatePosition(50,true)
            positions = positions.concat(generatePosition(50,))
            positions.forEach(item=>{
            let position = DC.Position.fromObject(item)
            let end = position.copy()
            end.alt = 5000 * Math.random()
            let line = new DC.FlowLinePrimitive([position,end],0.5)
            line.setStyle({
                speed: 6 * Math.random(),
                color: DC.Color.fromCssColorString("rgb(141,172,172)"),
                percent:0.1,
                gradient:0.01
            })
            layer.addOverlay(line)
            })
            global.viewer.flyToPosition("121.4941629,31.2091462,1859.56,0,-28.71")
 
            // // 天地图 影像
            // global.viewer.imageryLayers.addImageryProvider(
            //     new global.DC.Namespace.Cesium.UrlTemplateImageryProvider({
            //         url: 'https://t{s}.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=789e558be762ff832392a0393fd8a4f1',
            //         subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
            //         format: 'image/jpeg',
            //         show: true,
            //         maximumLevel: 18
            //     })
            // )
            
            // global.viewer.camera.setView({
            //     // Cesium的坐标是以地心为原点,一向指向南美洲,一向指向亚洲,一向指向北极州
            //     // fromDegrees()方法,将经纬度和高程转换为世界坐标
            //     destination: global.DC.Namespace.Cesium.Cartesian3.fromDegrees(
            //         116.027429, 28.681978, 800
            //     ),
            //     orientation: {
            //         // 指向
            //         heading: global.DC.Namespace.Cesium.Math.toRadians(0, 0),
            //         // 视角
            //         pitch: global.DC.Namespace.Cesium.Math.toRadians(-90),
            //         roll: 0.0
            //     }
            // })
            // // that.addBaseLayer()
 
            // global.viewer.use(new global.DC.Measure())
 
            // // that.addMxTileset()//师大需要使用
        }
 
        global.DC.ready(initViewer)
    },
 
    methods: {
 
        addMxTileset () {
            const that = this
            tilesetLayer = new global.DC.TilesetLayer('tilesetLayer')
            global.viewer.addLayer(tilesetLayer)
            tileset = new global.DC.Tileset('/zhjg/qx/tileset.json', {
                luminanceAtZenith: 0.4,
                // cullWithChildrenBounds: false,
                // cullRequestsWhileMoving: false,
                // skipLevelOfDetail: false,
                shadows: global.DC.Namespace.Cesium.ShadowMode.DISABLED
            })
            tileset.setHeight(5)
            tilesetLayer.addOverlay(tileset)
            global.viewer.flyTo(tileset)
            // tileset.on(global.DC.MouseEventType.CLICK, that.tilesetClick)
        },
 
        getViewExtend () {
            const params = {}
            const extend = global.viewer.camera.computeViewRectangle()
            if (typeof extend === 'undefined') {
                // 2D下会可能拾取不到坐标,extend返回undefined,所以做以下转换
                const canvas = global.viewer.scene.canvas
                const upperLeft = new global.DC.Namespace.Cesium.Cartesian2(0, 0)// canvas左上角坐标转2d坐标
                const lowerRight = new global.DC.Namespace.Cesium.Cartesian2(
                    canvas.clientWidth,
                    canvas.clientHeight
                )// canvas右下角坐标转2d坐标
 
                const ellipsoid = global.viewer.scene.globe.ellipsoid
                const upperLeft3 = global.viewer.camera.pickEllipsoid(
                    upperLeft,
                    ellipsoid
                )// 2D转3D世界坐标
 
                const lowerRight3 = global.viewer.camera.pickEllipsoid(
                    lowerRight,
                    ellipsoid
                )// 2D转3D世界坐标
 
                const upperLeftCartographic = global.viewer.scene.globe.ellipsoid.cartesianToCartographic(
                    upperLeft3
                )// 3D世界坐标转弧度
                const lowerRightCartographic = global.viewer.scene.globe.ellipsoid.cartesianToCartographic(
                    lowerRight3
                )// 3D世界坐标转弧度
 
                const minx = global.DC.Namespace.Cesium.Math.toDegrees(upperLeftCartographic.longitude)// 弧度转经纬度
                const maxx = global.DC.Namespace.Cesium.Math.toDegrees(lowerRightCartographic.longitude)// 弧度转经纬度
 
                const miny = global.DC.Namespace.Cesium.Math.toDegrees(lowerRightCartographic.latitude)// 弧度转经纬度
                const maxy = global.DC.Namespace.Cesium.Math.toDegrees(upperLeftCartographic.latitude)// 弧度转经纬度
 
                params.minx = minx
                params.maxx = maxx
                params.miny = miny
                params.maxy = maxy
            } else {
                // 3D获取方式
                params.maxx = global.DC.Namespace.Cesium.Math.toDegrees(extend.east)
                params.maxy = global.DC.Namespace.Cesium.Math.toDegrees(extend.north)
 
                params.minx = global.DC.Namespace.Cesium.Math.toDegrees(extend.west)
                params.miny = global.DC.Namespace.Cesium.Math.toDegrees(extend.south)
            }
            return params // 返回屏幕所在经纬度范围
        },
 
        addBaseLayer () {
            if (baseLayer.length > 0) {
                baseLayer.forEach(item => {
                    global.viewer.imageryLayers.remove(
                        item.layer
                    )
                })
            }
 
            baseLayer = []
 
            this.updateBaseLayer(false)
        },
 
        updateBaseLayer (flag) {
            const extent = this.getViewExtend()
 
            const array = baseLayerImgUrl.filter(item => {
                return item[1000]
            })
 
            array[0][1000].forEach(sm => {
                let startFlag = false
                if (flag == true) {
                    startFlag = baseLayer.some(dt => {
                        return dt.id == sm.id
                    })
                }
 
                if (startFlag == true) return
 
                if (
                    (
                        sm.rectangle[0] > extent.minx &&
                        sm.rectangle[1] > extent.miny &&
                        sm.rectangle[2] < extent.maxx &&
                        sm.rectangle[3] < extent.maxy
                    ) ||
                    (
                        sm.rectangle[0] < extent.minx &&
                        sm.rectangle[1] < extent.maxy &&
                        sm.rectangle[2] > extent.minx &&
                        sm.rectangle[3] > extent.maxy
                    ) ||
                    (
                        sm.rectangle[0] < extent.maxx &&
                        sm.rectangle[1] < extent.maxy &&
                        sm.rectangle[2] > extent.maxx &&
                        sm.rectangle[3] > extent.maxy
                    ) ||
                    (
                        sm.rectangle[0] < extent.maxx &&
                        sm.rectangle[1] < extent.miny &&
                        sm.rectangle[2] > extent.maxx &&
                        sm.rectangle[3] > extent.miny
                    ) ||
                    (
                        sm.rectangle[0] < extent.minx &&
                        sm.rectangle[1] < extent.miny &&
                        sm.rectangle[2] > extent.minx &&
                        sm.rectangle[3] > extent.miny
                    ) ||
                    (
                        sm.rectangle[0] > extent.minx &&
                        sm.rectangle[1] < extent.maxy &&
                        sm.rectangle[2] < extent.maxx &&
                        sm.rectangle[3] > extent.maxy
                    ) ||
                    (
                        sm.rectangle[0] > extent.minx &&
                        sm.rectangle[1] > extent.miny &&
                        sm.rectangle[2] > extent.maxx &&
                        sm.rectangle[3] < extent.maxy
                    ) ||
                    (
                        sm.rectangle[0] > extent.minx &&
                        sm.rectangle[1] < extent.miny &&
                        sm.rectangle[2] < extent.maxx &&
                        sm.rectangle[3] > extent.miny
                    ) ||
                    (
                        sm.rectangle[0] < extent.minx &&
                        sm.rectangle[1] > extent.miny &&
                        sm.rectangle[2] > extent.minx &&
                        sm.rectangle[3] < extent.maxy
                    )
                ) {
                    var layer = global.viewer.imageryLayers.addImageryProvider(new global.DC.Namespace.Cesium.SingleTileImageryProvider({
                        url: sm.url,
                        rectangle: global.DC.Namespace.Cesium.Rectangle.fromDegrees(sm.rectangle[0], sm.rectangle[1], sm.rectangle[2], sm.rectangle[3])
                    }))
 
                    baseLayer.push({ layer, id: sm.id })
                }
            })
        },
        ranging () {
            global.viewer.measure.distanceSurface()
        },
        area () {
            global.viewer.measure.area()
        },
        clear () {
            global.viewer.measure.deactivate()
        },
        fullImg () {
            this.addMxTileset()
        },
    }
}
 
</script>
 
<style lang="scss">
.mapBtnList {
    position: absolute;
    bottom: 10px;
    left: 50%;
    margin-left: -128px;
    display: flex;
    box-sizing: border-box;
    .mapBtn {
        width: 44px;
        height: 44px;
        background-position: -6px -6px;
        z-index: 2;
        margin-left: 5px;
        color: #28f2ff;
        text-align: center;
        line-height: 68px;
        font-size: 14px;
        cursor: default;
        border: 1px solid transparent;
    }
    .btn1 {
        background-image: url(/zhjg/img/home/full-img.png);
    }
    .btn2 {
        background-image: url(/zhjg/img/home/ranging.png);
    }
    .btn3 {
        background-image: url(/zhjg/img/home/area.png);
    }
    .btn4 {
        background-image: url(/zhjg/img/home/panorama.png);
    }
    .btn5 {
        background-image: url(/zhjg/img/home/clear.png);
    }
}
.mapBtnList :hover {
    border: 1px solid white !important;
}
</style>