派生自 wuyushui/SewerAndRainNetwork

XingChuan
2021-05-30 c73a31a4fadbd10651702e8466a46abfcdb1a143
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
/* eslint-disable */
// 添加文字标注
var TextAnnotation = {
  points: [],
  color: '',
  L: null,
  map: null,
  layers: null,
  polyline: null,
  marker: null,
  changeColor: '',
  changeContent: '',
  init: function (map, L) {
    // console.log(L)
    TextAnnotation.L = L
    TextAnnotation.map = map
    TextAnnotation.points = []
    TextAnnotation.polyline = null
    TextAnnotation.marker = null
    TextAnnotation.layers = L.layerGroup()
    map.on('click', TextAnnotation.click).on('dblclick', TextAnnotation.dblclick)
  },
  // 设置改变文字内容
  setContent: function (changeContent) {
    // console.log(changeContent)
    TextAnnotation.changeContent = changeContent
  },
  // 设置改变文字颜色
  setColor: function (changeColor) {
    // console.log(changeColor)
    TextAnnotation.changeColor = changeColor
  },
  click: function (e) {
    // console.log(TextAnnotation.changeContent)
    let labIcon = L.divIcon({
      html: '<div style="color:' + TextAnnotation.changeColor + ';font-size: 18px;">' + TextAnnotation.changeContent + '</div>',
      iconSize: [100, 40],
      iconAnchor: [0, 0],
      className: ''
    })
    let marker = L.marker(e.latlng, { icon: labIcon })
    marker.addTo(TextAnnotation.map)
  },
  dblclick: function (e) {
    TextAnnotation.map.off('click', TextAnnotation.click).off('dblclick', TextAnnotation.dblclick)
  },
  destory: function () {
    if (TextAnnotation.polyline) {
      TextAnnotation.map.removeLayer(TextAnnotation.polyline)
    }
    if (TextAnnotation.marker) {
      TextAnnotation.marker.remove()
    }
    if (TextAnnotation.layers) {
      TextAnnotation.layers.clearLayers()
    }
  }
}
 
// 添加 点 的标注
let pointAnnotation = {
  points: [],
  color: '',
  L: null,
  map: null,
  layers: null,
  polyline: null,
  marker: null,
  init: function (map, L) {
    pointAnnotation.L = L
    pointAnnotation.map = map
    pointAnnotation.points = []
    pointAnnotation.polyline = null
    pointAnnotation.marker = null
    pointAnnotation.layers = L.layerGroup()
    map.on('click', pointAnnotation.click).on('dblclick', pointAnnotation.dblclick)
  },
  click: function (e) {
    let marker = L.marker(e.latlng)
    marker.addTo(pointAnnotation.map)
  },
  dblclick: function (e) {
    pointAnnotation.map.off('click', pointAnnotation.click).off('dblclick', pointAnnotation.dblclick)
  },
  destory: function () {
    if (pointAnnotation.polyline) {
      pointAnnotation.map.removeLayer(pointAnnotation.polyline)
    }
    if (pointAnnotation.marker) {
      pointAnnotation.marker.remove()
    }
    if (pointAnnotation.layers) {
      pointAnnotation.layers.clearLayers()
    }
  }
}
 
// 添加文字标注
const startMakeText = function (map, L) {
  TextAnnotation.init(map, L)
}
// 文字标注的 内容社设置
const setContentText = function (text) {
  TextAnnotation.setContent(text)
}
// 文字标注内容的 颜色 设置
const setContentColor = function (color) {
  TextAnnotation.setColor(color)
}
 
// 点 标注
const StartPointAnnotation = function (map, L) {
  pointAnnotation.init(map, L)
}
 
const clearText = function () {
  startMakeText.destory()
}
export default {
  clearText,
  startMakeText,
  setContentText,
  setContentColor,
  StartPointAnnotation
}