/* eslint-disable */
|
// 添加文字标注
|
var TextAnnotation = {
|
points: [],
|
color: 'yellow',
|
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
|
},
|
click: function (e) {
|
console.log(TextAnnotation.changeContent)
|
let labIcon = L.divIcon({
|
html: '<div style="color: red;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()
|
}
|
}
|
}
|
|
// 添加 点 的标注
|
var CircleAnnotation = {
|
points: [],
|
color: 'yellow',
|
L: null,
|
map: null,
|
layers: null,
|
polyline: null,
|
marker: null,
|
init: function (map, L) {
|
// console.log(L)
|
CircleAnnotation.L = L
|
CircleAnnotation.map = map
|
CircleAnnotation.points = []
|
CircleAnnotation.polyline = null
|
CircleAnnotation.marker = null
|
CircleAnnotation.layers = L.layerGroup()
|
map.on('click', CircleAnnotation.click).on('dblclick', CircleAnnotation.dblclick)
|
},
|
click: function (e) {
|
// var myIcon = L.divIcon({className: 'my-div-icon'});
|
let marker = L.marker(e.latlng)
|
marker.addTo(CircleAnnotation.map)
|
},
|
dblclick: function (e) {
|
CircleAnnotation.map.off('click', CircleAnnotation.click).off('dblclick', CircleAnnotation.dblclick)
|
},
|
destory: function () {
|
if (CircleAnnotation.polyline) {
|
CircleAnnotation.map.removeLayer(CircleAnnotation.polyline)
|
}
|
if (CircleAnnotation.marker) {
|
CircleAnnotation.marker.remove()
|
}
|
if (CircleAnnotation.layers) {
|
CircleAnnotation.layers.clearLayers()
|
}
|
}
|
}
|
|
const startMakeText = function (map, L) {
|
TextAnnotation.init(map, L)
|
}
|
|
const StartCircleAnnotation = function (map, L) {
|
CircleAnnotation.init(map, L)
|
}
|
|
const setContentText = function (text) {
|
TextAnnotation.setContent(text)
|
}
|
|
const clearText = function () {
|
startMakeText.destory()
|
}
|
export default {
|
startMakeText,
|
clearText,
|
StartCircleAnnotation,
|
setContentText
|
}
|