派生自 wuyushui/SewerAndRainNetwork

zhangshuaibao
2021-04-01 a25bd679d4a3e69f9ddbe49302b2d24224ab90f5
src/components/plugin/MakeTation.js
@@ -2,12 +2,14 @@
// 添加文字标注
var TextAnnotation = {
  points: [],
  color: 'yellow',
  color: '',
  L: null,
  map: null,
  layers: null,
  polyline: null,
  marker: null,
  changeColor: '',
  changeContent: '',
  init: function (map, L) {
    // console.log(L)
    TextAnnotation.L = L
@@ -18,11 +20,20 @@
    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(e)
    let contents = 'bouncedText'
    // console.log(TextAnnotation.changeContent)
    let labIcon = L.divIcon({
      html: '<div style="color: red;font-size: 18px;">' + contents + '</div>',
      html: '<div style="color:' + TextAnnotation.changeColor + ';font-size: 18px;">' + TextAnnotation.changeContent + '</div>',
      iconSize: [100, 40],
      iconAnchor: [0, 0],
      className: ''
@@ -46,14 +57,69 @@
  }
}
// 添加 点 的标注
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,
  clearText
  setContentText,
  setContentColor,
  StartPointAnnotation
}