校园-江西科技师范大学-前端
shuishen
2023-12-14 e733164e1c779b3aef7245936b9daf7875bf791e
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
<template>
    <div class="mobile-map-container">
        <div id="sceneview"></div>
 
        <mobileCortrolSearch ref="mobileCortrolSearch">
            <template slot="selectCampusBox">
                <div class="select-campus-box" v-if="campusData.length > 1">
                    <el-dropdown trigger="click" @command="handleCommand">
                        <span class="el-dropdown-link icons">
                            {{ campusData.find(item => item.dictKey == campusValue).dictValue }} <i
                                class="el-icon-caret-bottom"></i>
                        </span>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item v-for="(item, index) in campusData" :key="index" :command="item">
                                {{ item.dictValue }}
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </template>
        </mobileCortrolSearch>
 
        <!-- 随地图改变图标弹窗↓ -->
        <div id="mobile-map_popup_content"></div>
        <mobileWindow ref="MobileWindow"></mobileWindow>
        <!-- 地图固定弹窗 -->
        <!-- <mobileWindowFixed></mobileWindowFixed> -->
        <!-- 地图图标弹窗↑ -->
        <!-- 控制↓ -->
        <mobileLeftNav ref="mobileLeftNav"></mobileLeftNav>
        <mobileCortrol ref="mobileCortrol"></mobileCortrol>
        <mobileCortrolButtom ref="mobileCortrolButtom" :mapCenter="mapCenter" :frislayertHeight="frislayertHeight">
        </mobileCortrolButtom>
        <!-- 控制↑ -->
        <!-- 控制大弹窗的弹窗 -->
        <!-- v-if="mBigPopupAfter" -->
        <mobilePopupOurAfter ref="MobilePopupOurAfter"></mobilePopupOurAfter>
        <!-- 大弹窗 -->
        <mobilePopupOur :style="[bigPopup]" v-if="mBigPopup"></mobilePopupOur>
        <!-- 测试-跳转位置 -->
        <!-- <mobileGoTo></mobileGoTo> -->
        <!-- 实景窗口 -->
        <mobilePanorama></mobilePanorama>
        <!-- 退出导航 -->
        <mobileCloseRouter ref="MobileCloseRouter"></mobileCloseRouter>
        <!-- 退出活动 -->
        <mobileCloseRouterMany></mobileCloseRouterMany>
        <!-- 活动窗口 -->
        <mobileActivity></mobileActivity>
        <!-- 指示器 -->
        <!-- <div class="heights">{{ heights }}---{{ heights1 }}</div> -->
    </div>
</template>
<script>
import axios from 'axios'
import { mapGetters } from 'vuex'
import { getBuildClock } from '@/api/mobile/buildsClock/buildsClock' // 楼栋详情
import { getListarc } from '@/api/mobile/public/arc'
 
import OlView from "ol/View.js"
 
import OlLayerTile from "ol/layer/Tile.js"
 
import XYZ from "ol/source/XYZ"
 
import VectorLayer from "ol/layer/Vector"
import VectorSource from "ol/source/Vector"
 
import { OverviewMap, defaults } from "ol/control"
import { Polygon } from 'ol/geom'
 
import Feature from 'ol/Feature.js'
import Point from 'ol/geom/Point.js'
import { Icon, Style, Fill, Text, Stroke, Circle } from 'ol/style.js'
import TilegridTileGrid from "ol/tilegrid/TileGrid"
 
let architecturePolygon = null
let select = null
let sitePositionLayer = null
 
let campusLayers = [
    {
        key: 1,
        tileUrl: "https://fkxt.jxstnu.edu.cn/changjing/arcgis/rest/services/ksdhjzxq/MapServer/tile/{z}/{y}/{x}",
        center: [112.613918275550715, -0.0457081387615907618595],
        resolution: 0.00001903568804664224,
        origin: [-400.0, 399.9999999999998],
        resolutions: [
            0.00015228550437313792, 0.00007614275218656896, 0.00003807137609328448,
            0.00001903568804664224, 0.00000951784402332112, 0.00000475892201166056
        ],
        fullExtent: [
            112.51303616638316, -0.103420786429659, 112.67880038471827,
            0.000004508906477476281
        ],
        polygonUrl: 'https://fkxt.jxstnu.edu.cn/changjing/lkarcgisapp'
    },
 
    {
        key: 2,
        tileUrl: "https://fkxt.jxstnu.edu.cn/changjing/arcgis/rest/services/ksdflxq/MapServer/tile/{z}/{y}/{x}",
        center: [112.6202242373625, -0.0781745423945008147645],
        resolution: 0.00001903568804664224,
        origin: [-400.0, 399.9999999999998],
        resolutions: [
            0.00015228550437313792, 0.00007614275218656896, 0.00003807137609328448,
            0.00001903568804664224, 0.00000951784402332112, 0.00000475892201166056
        ],
        fullExtent: [
            112.51302551881798, -0.16235359398493399, 112.72742295590702, 0.000004509195932360471
        ],
        polygonUrl: 'https://fkxt.jxstnu.edu.cn/changjing/fllkarcgisapp'
    }
]
 
let campusLoadLayer
 
export default {
    name: 'mobilemapBox',
    components: {
    },
 
    // 将当前实例注入到子组件
    provide () {
        return {
            mobileMapElement: this
        }
    },
 
    computed: {
        ...mapGetters([
            // "mviewer",
            // "MobileWindowsHide",
            'zoomRange',
            'mBigPopup',
            // "mBigPopupAfter",
            'iconHide',
            // "popupsDom",
            'dimension',
            'dimensionData',
            // "areaLayer", // 绿布
            // "areaLayerSelect", // 绿布颜色控制
            'urlParameterData', // url 参数
            'pinchFlag'
        ])
    },
 
    data () {
        return {
            bigPopup: {
                width: 0,
                height: 0
            },
            map2D: this.$store.state.openlayerData.openlayers.map2D,
            campusData: [],
            campusValue: 1
        }
    },
 
    watch: {
        mBigPopup () {
            if (this.mBigPopup) {
                this.bigPopup.width = '100%'
                this.bigPopup.height = '100%'
                this.bigPopup.display = 'inline-block'
            } else {
                this.bigPopup.width = '0'
                this.bigPopup.height = '0'
                this.bigPopup.display = 'none'
            }
        },
 
        campusValue: {
            handler (newData) {
                this.$nextTick(() => {
                    this.$refs.MobileCloseRouter.mobileRouterClose()
 
                    this.campusCut(newData)
 
                    this.$refs.mobileLeftNav.initialize(newData)
 
                    this.createdLayers(newData)
                })
            }
        }
    },
 
    created () {
        this.getStreet()
    },
 
    mounted () {
        const that = this
        this.map2D.setTarget('sceneview')
 
        this.$nextTick(() => {
            sitePositionLayer = new VectorLayer({
                // 图标图层
                zIndex: 99,
                source: new VectorSource(),
            })
 
            this.map2D.addLayer(sitePositionLayer)
 
 
            this.map2D.on("singleclick", function (event) {
                let flag = true
                that.map2D.forEachFeatureAtPixel(
                    event.pixel,
                    (feature) => {
                        if (select != null && select.values_.type == 'polygon') {
                            select.setStyle(new Style({
 
                                fill: new Fill({
                                    color: 'rgba(255, 255, 255, 0)'
                                })
 
                            }))
                        }
                        select = null
 
                        if (flag == false) {
                            return
                        }
                        if (feature.values_.type == 'point') {
                            flag = false
 
                            const graphicAttributes = feature.values_.attributes
 
                            const d = {
                                name: graphicAttributes.data.mechanismname ||
                                    graphicAttributes.data.roadname ||
                                    graphicAttributes.data.vrname ||
                                    (graphicAttributes.ourD.label == '监控' ? '监控' : '无显示名字'),
                                bgImg: graphicAttributes.data.tpurl,
                                video: graphicAttributes.ourD.label == '监控' ? graphicAttributes.data.vrurl : '',
                                from: 'labels',
                                introduce: graphicAttributes.data.introduce,
                                panoramaurl: graphicAttributes.ourD.label == '实景' ? graphicAttributes.data.vrurl : '',
                                lntLat: graphicAttributes.lntLat
                            }
 
                            that.$refs.MobileWindow.showPopupOrData(d)
 
                            return
                        }
                        feature.dispatchEvent && feature.dispatchEvent({ type: 'click', event: event })
                    }
                )
            })
        })
 
        that.$EventBus.$on('addSitePositionLayer', (params) => {
            const iconFeature = new Feature({
                geometry: new Point([Number(params.lntLat[0]), Number(params.lntLat[1])]),
                type: 'point'
            })
 
            iconFeature.setStyle(new Style({
                image: new Icon({
                    imgSize: [48, 48],
                    src: '/changjing/img/icon/site-position.png'
                })
            }))
 
            sitePositionLayer.getSource().addFeature(iconFeature)
        })
 
        that.$EventBus.$on('removeSitePositionLayer', () => {
            sitePositionLayer.getSource().clear()
        })
    },
 
    methods: {
        resetPolygonStyle () {
            if (select != null && select.values_.type == 'polygon') {
                select.setStyle(new Style({
 
                    fill: new Fill({
                        color: 'rgba(255, 255, 255, 0)'
                    })
 
                }))
            }
            select = null
        },
 
        createdLayers (campusKey) {
            const that = this
            let curCampus = campusLayers.find(item => item.key == campusKey)
 
            if (architecturePolygon) {
                this.map2D.removeLayer(architecturePolygon)
            }
            architecturePolygon = new VectorLayer({
                // 图标图层
                source: new VectorSource(),
            })
 
            this.map2D.addLayer(architecturePolygon)
 
            axios
                .get(
                    curCampus.polygonUrl + '?where=1%3D1&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&returnTrueCurves=false&resultOffset=&resultRecordCount=&f=pjson'
                )
                .then((resultData) => {
                    resultData.data.features.forEach((item) => {
                        var polygonFeature = new Feature({
                            id: 'DefaultAreaLayer',
                            type: 'polygon',
                            geometry: new Polygon(item.geometry.rings),
                            attributes: item.attributes
                        })
 
                        polygonFeature.setStyle(new Style({
 
                            fill: new Fill({
                                color: 'rgba(255, 255, 255, 0)'
                            })
 
                        }))
 
                        polygonFeature.on('click', that.polygonFeatureEvent)
 
                        architecturePolygon.getSource().addFeature(polygonFeature)
                    })
                })
        },
 
        polygonFeatureEvent (event) {
            const that = this
 
            getBuildClock({
                mechanismname: event.target.values_.attributes['楼栋号'],
                campus: this.campusValue
            }).then((res) => {
                if (JSON.stringify(res.data.data) == '{}') return
                const item = res.data.data
 
                const useData = {
                    name: item.mechanismname,
                    bgImg: item.tpurl,
                    video: item.videourl,
                    panoramaurl: item.panoramaurl,
                    introduce: item.introduce,
                    lntLat: [event.event.coordinate[0], event.event.coordinate[1]],
                }
 
                that.$refs.MobileWindow.showPopupOrData(useData)
            })
 
            if (select != null) {
                if (event.target != select) {
                    select.setStyle(new Style({
 
                        fill: new Fill({
                            color: 'rgba(255, 255, 255, 0)'
                        })
 
                    }))
 
                    select = null
                }
            }
 
            if (select == null) {
                select = event.target
 
                select.setStyle(
                    new Style({
 
                        fill: new Fill({
                            color: 'rgba(108, 245, 113, 0.6)'
                        }),
 
                        stroke: new Stroke({
                            color: 'rgba(3, 255, 13, 1)',
                            width: 1,
                        }),
 
                    })
                )
            }
        },
 
        campusCut (campusKey) {
            if (campusLoadLayer) this.map2D.removeLayer(campusLoadLayer)
            let curCampus = campusLayers.find(item => item.key == campusKey)
 
            const tileGrid = new TilegridTileGrid({
                tileSize: 256,
                origin: curCampus.origin,
                extent: curCampus.fullExtent,
                resolutions: curCampus.resolutions,
            })
            // 瓦片数据源
            const tileArcGISXYZ = new XYZ({
                projection: "EPSG:4326",
                tileGrid: tileGrid,
                url: curCampus.tileUrl,
            })
 
            campusLoadLayer = new OlLayerTile({
                source: tileArcGISXYZ,
            })
 
            this.map2D.addLayer(campusLoadLayer)
 
 
            this.map2D.controls = defaults().extend([
                // 添加一个鹰眼控件
                new OverviewMap({
                    // 实例化一个OverviewMap类的对象,并加入到地图中
                    collapsed: false,
                    view: new OlView({
                        // 初始化中心点坐标
                        center: curCampus.center,
                    }),
                    layers: [
                        campusLoadLayer
                    ]
                })
            ])
 
            this.map2D.setView(new OlView({
                // 初始化中心点坐标
                projection: "EPSG:4326",
                center: curCampus.center,
                resolution: curCampus.resolution,
                extent: curCampus.fullExtent,
            }))
        },
 
        setCampusValue (val) {
            this.campusValue = val
 
            this.$store.commit('SET_CURRENTCAMPUS', val)
        },
 
        handleCommand (command) {
            this.$refs.MobilePopupOurAfter.closeBigPopupAfter()
            this.setCampusValue(command.dictKey)
        },
 
        getStreet () {
            getListarc().then((res) => {
                this.setCampusValue(res.data.data[0].dictKey)
                this.campusData = res.data.data
            })
        }
    }
}
</script>
<style>
.mobile-map-container {
    position: relative;
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}
 
#sceneview {
    position: absolute;
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* overflow: hidden; */
}
 
.select-campus-box {
    width: 28%;
    height: 32px;
    line-height: 32px;
    text-align: center;
    background: #f1f1f1;
    border-right: 1px solid #C0C4CC;
    box-sizing: border-box;
    z-index: 299;
}
 
.esri-view-surface--inset-outline:focus::after {
    outline: none !important;
}
 
.heights {
    background-color: #fff;
    font-size: 24px;
    position: fixed;
    top: 0;
    right: 0;
    z-index: 9999999;
}
</style>