派生自 wuyushui/SewerAndRainNetwork

chenzeping
2021-03-10 b85b0e9ea957fac745b9e7350cb0315578abef85
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
/* eslint-disable */
// 添加文字标注
var TextAnnotation = {
  points: [],
  color: 'yellow',
  L: null,
  map: null,
  layers: null,
  polyline: null,
  marker: null,
  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)
  },
  click: function (e) {
    // console.log(e)
    let contents = 'bouncedText'
    let labIcon = L.divIcon({
      html: '<div style="color: red;font-size: 18px;">' + contents + '</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()
    }
  }
}
 
const startMakeText = function (map, L) {
  TextAnnotation.init(map, L)
}
 
const clearText = function () {
  startMakeText.destory()
}
export default {
  startMakeText,
  clearText
}