保安服务企业管理项目备份
guoshilong
2023-12-20 7becb16bb38cb3284c7f4e3dc2c486dd55812c8a
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
<!--
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2023-10-11 16:01:58
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2023-11-29 14:17:09
 * @FilePath: \web\business\src\components\OlMapBox\index.vue
 * @Description:
 *
 * Copyright (c) 2023 by shuishen, All Rights Reserved.
-->
<template>
  <div class="w100 h100">
    <div id="OlMapBoxElement" class="w100 h100">
    </div>
  </div>
</template>
 
<script>
// import OLCesium from "ol-cesium"
import "ol/ol.css"
import OlView from "ol/View.js"
import {
  // eslint-disable-next-line no-unused-vars
  defaults as OlControlDefaults,
  defaults,
  // 全屏控件
  FullScreen,
  // 比例尺控件
  ScaleLine,
  // 缩放滚动条控件
  // eslint-disable-next-line no-unused-vars
  ZoomSlider,
  // 鼠标位置控件
  // eslint-disable-next-line no-unused-vars
  MousePosition,
  // -地图属性控件
  Attribution,
  // 鹰眼控件
  // eslint-disable-next-line no-unused-vars
  OverviewMap,
  // 缩放到范围控件
  // eslint-disable-next-line no-unused-vars
  ZoomToExtent,
  Rotate,
} from "ol/control.js"
import OlSourceOSM from "ol/source/OSM.js"
import OlLayerTile from "ol/layer/Tile.js"
 
import { Image as ImageLayer } from 'ol/layer'
import ImageStatic from 'ol/source/ImageStatic.js'
 
import OlLayerVectorTile from "ol/layer/VectorTile.js"
import OlMap from "ol/Map.js"
import OlProjection from "ol/proj/Projection.js"
import OlMVT from "ol/format/MVT.js"
import OlUnits from "ol/proj/Units.js"
import OlFeature from "ol/Feature"
 
import { get as projGet } from "ol/proj.js"
// c
 
import XYZ from "ol/source/XYZ"
 
import Cluster from "ol/source/Cluster"
 
import VectorLayer from "ol/layer/Vector"
import VectorSource from "ol/source/Vector"
 
import TileArcGISRest from "ol/source/TileArcGISRest"
import TilegridTileGrid from "ol/tilegrid/TileGrid"
 
import GeoJSON from "ol/format/GeoJSON"
 
import Feature from 'ol/Feature.js'
import Point from 'ol/geom/Point.js'
import { Icon, Style, Fill, Text, Stroke, Circle } from 'ol/style.js'
 
 
let mapView = null
let layersObjcect = {}
 
let baseMapLayer = {
  yx: [],
  sl: []
}
let options,
  epsgcode,
  isMvt = false
 
let isMapResource = true
export default {
  name: 'OlMapBox',
 
  props: {
    mapType: {
      type: String,
      default: 'sl'
    },
 
    mapContrast: {
      type: String,
      default: 'custom'
    }
  },
 
  data () {
    return {
      publicPath: process.env.BASE_URL,
    }
  },
 
 
  mounted () {
    const that = this
 
    this.$nextTick(() => {
      mapView = new OlMap({
        target: 'OlMapBoxElement',
        layers: [],
        view: new OlView({
          // 初始化中心点坐标,经纬度一会自己换一下
          center: [113, 24],
          zoom: 18,
          projection: "EPSG:4326"
        }),
      })
 
      mapView.on("singleclick", function (event) {
        mapView.forEachFeatureAtPixel(
          event.pixel,
          (feature) => {
            feature.dispatchEvent && feature.dispatchEvent({ type: 'click', event: event })
          }
        )
      })
 
      that.baseInitLayer(that.mapType)
 
 
      this.mapAddClusterLayer(
        'livePersonLocationLayer',
        '/public/img/map/location',
        [{lng: 113, lat: 24}, {lng: 115, lat:24 }],
        (e) => { },
      )
    })
  },
 
  methods: {
    /**
     * @description: 底图加载
     * @param {*} type
     * @return {*}
     */
    baseInitLayer (type) {
      if (baseMapLayer.yx.length) {
        baseMapLayer.yx.forEach(item => {
          mapView.removeLayer(item)
        })
        baseMapLayer.yx = []
      }
 
      if (baseMapLayer.sl.length) {
        baseMapLayer.sl.forEach(item => {
          mapView.removeLayer(item)
        })
        baseMapLayer.sl = []
      }
 
      if (type == 'yx') {
        let yxImgW = new OlLayerTile({
          zIndex: 1,
          title: '影像',
          source: new XYZ({
            url: 'https://t0.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=e45274b0235bb913eceb393aabbf9c9c',
          })
        })
 
        mapView.addLayer(yxImgW)
 
        baseMapLayer.yx.push(yxImgW)
 
        let yxCvaW = new OlLayerTile({
          zIndex: 2,
          title: '影像标注',
          source: new XYZ({
            url: 'https://t0.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=e45274b0235bb913eceb393aabbf9c9c',
          })
        })
 
        mapView.addLayer(yxCvaW)
 
        baseMapLayer.yx.push(yxCvaW)
      } else if (type == 'sl') {
        let slVecW = new OlLayerTile({
          zIndex: 2,
          title: '矢量',
          source: new XYZ({
            url: 'https://t0.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=e45274b0235bb913eceb393aabbf9c9c',
          })
        })
 
        mapView.addLayer(slVecW)
 
        baseMapLayer.sl.push(slVecW)
 
        let slCvaW = new OlLayerTile({
          zIndex: 2,
          title: '矢量标注',
          source: new XYZ({
            url: 'https://t0.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=e45274b0235bb913eceb393aabbf9c9c',
          })
        })
 
        mapView.addLayer(slCvaW)
 
        baseMapLayer.sl.push(slVecW)
      }
    },
 
    // javascript 转换
    lonLat2Mercator (lonlat) {
      var mercator = {
        x: 0,
        y: 0
      }
      var earthRad = 6378137.0
      mercator.x = lonlat.lng * Math.PI / 180 * earthRad
      var a = lonlat.lat * Math.PI / 180
      mercator.y = earthRad / 2 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)))
      return mercator
    },
 
    getCurItemFeature (params) {
      const iconFeature = new Feature({
        geometry: new Point([Number(params.lng), Number(params.lat)]),
        attributes: params.item
      })
 
      let styleOptions = {
        cursor: 'pointer',
      }
 
      if (params.url) {
        styleOptions.image = new Icon({
          scale: params.scale || 1,
          imgSize: params.imgSize || [160, 221],
          src: params.url,
        })
      }
 
      if (params.text) {
        let textElement = document.createElement('span')
        textElement.innerHTML = params.text
 
        let color = '#0000FF'
 
        styleOptions.text = new Text({
          // 对齐方式
          textAlign: 'center',
          // 文本基线
          textBaseline: 'middle',
          text: textElement.innerHTML,
          font: '14px Arial',
          fill: new Fill({
            color: 'white'
          }),
          // 填充背景
          backgroundFill: new Fill({
            color: color
          }),
          padding: [2, 5, 2, 5],
          stroke: new Stroke({ color: '#00000000', width: 1 })
        })
      }
 
      iconFeature.setStyle(new Style(styleOptions))
 
      iconFeature.on('click', (e) => {
        if (params.event) {
          params.event(e.target.values_.attributes.attr)
        }
      })
 
      return iconFeature
    },
 
    /**
     * 删除图层
     * @param {*} layerName 图层名称
     */
    mapRemoveLayer (layerNames) {
      layerNames.forEach(item => {
        if (layersObjcect[item] && layersObjcect[item] != null) {
          mapView.removeLayer(layersObjcect[item])
          delete layersObjcect[item]
        }
 
        if (layersObjcect[item + 'ONE'] && layersObjcect[item + 'ONE'] != null) {
          mapView.removeLayer(layersObjcect[item + 'ONE'])
          delete layersObjcect[item + 'ONE']
        }
 
        if (layersObjcect[item + 'TWO'] && layersObjcect[item + 'TWO'] != null) {
          mapView.removeLayer(layersObjcect[item + 'TWO'])
          delete layersObjcect[item + 'TWO']
        }
      })
    },
 
    // 添加聚合图层的新模式,水库点分布
    mapAddClusterLayer (layerName, imgUrl, positionData, incident = (e) => { }, type = '') {
      const that = this
 
      if (!layersObjcect[layerName]) {
        if (type == 'cluster') {
          let source = new VectorSource()
 
          positionData.forEach(item => {
            source.addFeature(that.getCurItemFeature({
              item,
              lng: item.lng,
              lat: item.lat,
              url: imgUrl,
              event: incident
            }))
          })
 
          let layer = new Cluster({
            source: source,
            distance: 100
          })
 
          layersObjcect[layerName] = new VectorLayer({
            source: layer,
            zIndex: 24,
            style: (feature, resolution) => {
              let size = feature.get('features').length
 
              let radius = 10
 
              if (size > 900) {
                radius = 19
              } else if (size > 600) {
                radius = 16
              } else if (size > 400) {
                radius = 13
              }
 
              let style = new Style({
                image: new Circle({
                  radius: radius,
                  stroke: new Stroke({
                    color: 'blue',
                    width: 1
                  }),
                  fill: new Fill({
                    color: 'blue'
                  })
                }),
                text: new Text({
                  text: size.toString(),
                  fill: new Fill({
                    color: 'white'
                  })
                })
              })
 
              return style
            }
          })
 
          mapView.addLayer(layersObjcect[layerName])
 
          return
        } else {
          layersObjcect[layerName] = new VectorLayer({
            // 图标图层
            zIndex: 24,
            minZoom: 12,
            source: new VectorSource(),
          })
        }
 
        mapView.addLayer(layersObjcect[layerName])
      }
 
      positionData.forEach(item => {
        layersObjcect[layerName].getSource().addFeature(that.getCurItemFeature({
          item,
          lng: item.lng,
          lat: item.lat,
          url: imgUrl,
          event: incident
        }))
      })
    },
  },
}
</script>
 
<style lang='scss' scope>
 
.w100 {
  width: 100%;
}
 
.h100 {
  height: 100%;
}
</style>