派生自 wuyushui/SewerAndRainNetwork

陈泽平
2021-05-30 e3608132cc667c16ea10f450807e0feddaf55d1f
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
import AjaxUtils from '../../utils/AjaxUtils'
import { WMS_URL } from '../../conf/Constants'
import { highlight, openPropsPopup } from './LocateHelper'
 
class MapManager {
  constructor () {
    this.hightlightLayer = window.L.featureGroup({}).addTo(window.map)
    this.clickDialogSwitch = true // 图层点击弹窗开关
    this.L = window.L
    this.map = window.map
    // wms getfeatureinfo 默认参数
    this.defaultWmsParams = {
      VERSION: '1.1.1',
      SERVICE: 'WMS',
      REQUEST: 'GetFeatureInfo',
      // bbox: bbox,
      FORMAT: 'image/png',
      INFO_FORMAT: 'application/json',
      TRANSPARENT: true,
      FEATURE_COUNT: 50,
      SRS: 'EPSG:4326',
      EXCEPTIONS: 'application/vnd.ogc.se_inimage'
    }
  }
 
  mapClickListener () {
    this.map.on('click', (e) => {
      // console.log(e)
      this.clearHighlight()
      this.loadWfsDatas(e.latlng).then((res) => {
        if (res.features.length > 0) {
          highlight(res.features[0])
          if (this.clickDialogSwitch) {
            openPropsPopup(e.latlng, res.features)
          }
        }
      })
    })
  }
 
  loadWfsDatas (latlng, params) {
    return new Promise((resolve, reject) => {
      const size = this.map.getSize()
      var point = this.map.latLngToContainerPoint(latlng, this.map.getZoom())
      const wmsLayerService = window.layerFactory.wmsLayerService
      const layers = wmsLayerService.wmsLayerList.getLayers()
      const filters = wmsLayerService.wmsLayerList.getFilters()
      const wmsParams = Object.assign({
        LAYERS: layers,
        QUERY_LAYERS: layers,
        WIDTH: size.x,
        HEIGHT: size.y,
        X: Math.round(point.x),
        Y: Math.round(point.y),
        BBOX: this.map.getBounds().toBBoxString()
      }, this.defaultWmsParams, params)
      if (filters) {
        wmsParams.CQL_FILTER = filters
      }
      AjaxUtils.get4JsonDataByUrl(WMS_URL, wmsParams, (res) => {
        resolve(res.data)
      })
    })
  }
 
  clearHighlight () {
    this.hightlightLayer.clearLayers()
  }
}
 
export default MapManager