@sword916/vae-map-plus 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/build/index.mjs +113 -0
- package/examples/App.vue +18 -0
- package/examples/index.js +13 -0
- package/examples/router/index.js +35 -0
- package/examples/views/amap.vue +29 -0
- package/examples/views/amarker.vue +58 -0
- package/examples/views/buffer.vue +66 -0
- package/examples/views/cluster.vue +74 -0
- package/examples/views/cover.vue +85 -0
- package/examples/views/draw-line.vue +49 -0
- package/examples/views/draw.vue +54 -0
- package/examples/views/echarts.vue +142 -0
- package/examples/views/emarker.vue +39 -0
- package/examples/views/image.vue +182 -0
- package/examples/views/index.vue +61 -0
- package/examples/views/lrmap.vue +108 -0
- package/examples/views/map.vue +82 -0
- package/examples/views/measure.vue +86 -0
- package/examples/views/parts/popup.vue +39 -0
- package/examples/views/parts/tooltip.vue +39 -0
- package/examples/views/push-area.vue +52 -0
- package/examples/views/push-line.vue +84 -0
- package/examples/views/trace.vue +49 -0
- package/index.html +13 -0
- package/jsconfig.json +17 -0
- package/package.json +47 -0
- package/public/favicon.ico +0 -0
- package/public/images/game.png +0 -0
- package/public/images/grid.png +0 -0
- package/public/images/marker.png +0 -0
- package/public/index.html +30 -0
- package/src/components/resize-listener/component.jsx +30 -0
- package/src/components/resize-listener/index.js +3 -0
- package/src/composables/useAutoMessage.js +41 -0
- package/src/composables/useContextMenu.js +99 -0
- package/src/composables/useMapMeasure.js +191 -0
- package/src/composables/useResizeObserver.js +81 -0
- package/src/mixins/message.js +1 -0
- package/src/packages/index.js +16 -0
- package/src/packages/vae-amap/index.js +8 -0
- package/src/packages/vae-amap/style.less +9 -0
- package/src/packages/vae-amap/vae-amap.jsx +98 -0
- package/src/packages/vae-cloudmap/ctrl-context-menu/index.vue +74 -0
- package/src/packages/vae-cloudmap/ctrl-draw/index.vue +499 -0
- package/src/packages/vae-cloudmap/ctrl-draw-line/index.vue +161 -0
- package/src/packages/vae-cloudmap/index.js +57 -0
- package/src/packages/vae-cloudmap/scripts/L.MarkerCluster/index.js +2690 -0
- package/src/packages/vae-cloudmap/scripts/L.MarkerCluster/style.css +14 -0
- package/src/packages/vae-cloudmap/scripts/L.Vae.CRS/index.js +212 -0
- package/src/packages/vae-cloudmap/scripts/L.Vae.Client/index.js +780 -0
- package/src/packages/vae-cloudmap/scripts/Mixin.ContextMenu/index.js +101 -0
- package/src/packages/vae-cloudmap/style.less +163 -0
- package/src/packages/vae-cloudmap/vae-cloudmap.jsx +272 -0
- package/src/packages/vae-map/ctrl-context-menu/index.vue +74 -0
- package/src/packages/vae-map/ctrl-draw/index.vue +498 -0
- package/src/packages/vae-map/ctrl-draw-line/index.vue +128 -0
- package/src/packages/vae-map/index.js +59 -0
- package/src/packages/vae-map/scripts/L.MarkerCluster/index.js +2690 -0
- package/src/packages/vae-map/scripts/L.MarkerCluster/style.css +14 -0
- package/src/packages/vae-map/scripts/L.Vae.CRS/index.js +114 -0
- package/src/packages/vae-map/scripts/L.Vae.Client/index.js +548 -0
- package/src/packages/vae-map/scripts/Mixin.ContextMenu/index.js +1 -0
- package/src/packages/vae-map/style.less +161 -0
- package/src/packages/vae-map/vae-lrmap.jsx +237 -0
- package/src/packages/vae-map/vae-map.jsx +135 -0
- package/src/plugins/L.AnimatedMarker/index.js +158 -0
- package/src/plugins/L.EchartsLayer/index.js +339 -0
- package/src/plugins/L.ElasticMarker/index.js +162 -0
- package/src/plugins/L.FootageCalculator.Area/index.js +263 -0
- package/src/plugins/L.FootageCalculator.Line/index.js +273 -0
- package/src/plugins/L.GeoUtil/buffer.js +67 -0
- package/src/plugins/L.GeoUtil/index.js +284 -0
- package/src/plugins/L.Glyphicon/index.js +91 -0
- package/src/plugins/L.Glyphicon/style.less +37 -0
- package/src/plugins/L.MarkerClusterX/index.js +93 -0
- package/src/plugins/L.MarkerClusterX/style.less +162 -0
- package/src/plugins/L.SafeDivOverlay/index.js +55 -0
- package/src/plugins/L.TileLayer.ChinaProvider/index.js +108 -0
- package/src/plugins/L.VuePopup/index.js +67 -0
- package/src/plugins/L.VueTooltip/index.js +63 -0
- package/src/plugins/Mixin.Map.Measure/index.js +248 -0
- package/src/plugins/globals/index.js +7 -0
- package/src/utils/index.js +36 -0
- package/src/utils/resize-event.js +45 -0
- package/vite.config.mjs +25 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="vae-map-ctrl--draw">
|
|
3
|
+
<div class="item-group">
|
|
4
|
+
<template v-if="showPolyFuncs">
|
|
5
|
+
<div class="item" title="缁樺埗">
|
|
6
|
+
<div class="item-icon fas fa-pen-alt" :class="actionDisabled('draw')" @click="startDrawMode" />
|
|
7
|
+
<div v-if="drawStatus === 'draw'" class="tooltips">
|
|
8
|
+
<span @click="drawStatus = 'none'">鍙栨秷</span>
|
|
9
|
+
<span @click="removeLastVertx">绉婚櫎涓婁釜鑺傜偣</span>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
<div class="item" title="缂栬緫">
|
|
13
|
+
<div class="item-icon fas fa-draw-polygon" :class="actionDisabled('edit')" @click="startEditMode" />
|
|
14
|
+
<div v-if="drawStatus === 'edit'" class="tooltips">
|
|
15
|
+
<span @click="drawStatus = 'none'">瀹屾垚</span>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
<div class="item" title="绉诲姩">
|
|
19
|
+
<div class="item-icon fas fa-expand-arrows-alt" :class="actionDisabled('drag')" @click="startDragMode" />
|
|
20
|
+
<div v-if="drawStatus === 'drag'" class="tooltips">
|
|
21
|
+
<span @click="drawStatus = 'none'">瀹屾垚</span>
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
<div class="item" title="鏈哄ご鏈哄熬">
|
|
26
|
+
<div class="item-icon fas fa-map-pin" :class="actionDisabled('pick')" @click="startPickMode" />
|
|
27
|
+
<div v-if="drawStatus === 'pick'" class="tooltips">
|
|
28
|
+
<span @click="drawStatus = 'none'">鍙栨秷</span>
|
|
29
|
+
<span @click="resetPickMode">閲嶇疆</span>
|
|
30
|
+
<span v-if="htIndex === 5" @click="finishPick">瀹屾垚</span>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
<div v-if="showPolyFuncs" class="item" title="娓呴櫎">
|
|
34
|
+
<div class="item-icon fas fa-trash-alt" @click="clearDrawItems" />
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
<div class="item-group">
|
|
38
|
+
<div class="item" title="淇濆瓨">
|
|
39
|
+
<div class="item-icon fas fa-save" :class="actionDisabled('save')" @click="saveItems" />
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script setup>
|
|
46
|
+
import { computed, ref, watch } from 'vue'
|
|
47
|
+
import { ElMessage } from 'element-plus'
|
|
48
|
+
|
|
49
|
+
defineOptions({
|
|
50
|
+
name: 'VaeMapCtrlDraw'
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
// L.CircleMarker鐨勯厤缃?
|
|
54
|
+
const CMOptions = {
|
|
55
|
+
unpicked: { color: '#ffc107', fillColor: '#fff', fillOpacity: 1, radius: 6 },
|
|
56
|
+
picked: { color: '#28a745', fillColor: '#fff', fillOpacity: 1, radius: 7, weight: 5 },
|
|
57
|
+
hint: { color: 'transparent', radius: 1, weight: 1, interactive: false }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function TTContent({ action, content, style }) {
|
|
61
|
+
const textHtml = `<span class="${style ?? ''}">${content}</span>`
|
|
62
|
+
if (action) {
|
|
63
|
+
return `<span><span class="action">${action}</span>${textHtml}</span>`
|
|
64
|
+
}
|
|
65
|
+
return `<span>${textHtml}</span>`
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function PickedMarker(sign, latLng) {
|
|
69
|
+
let config = { content: '-' }
|
|
70
|
+
switch (sign) {
|
|
71
|
+
case 'hs':
|
|
72
|
+
config = { content: '鏈哄ご璧风偣', style: 'green' }
|
|
73
|
+
break
|
|
74
|
+
case 'ts':
|
|
75
|
+
config = { content: '鏈哄熬璧风偣', style: 'red' }
|
|
76
|
+
break
|
|
77
|
+
case 'he':
|
|
78
|
+
config = { content: '鏈哄ご缁堢偣', style: 'green' }
|
|
79
|
+
break
|
|
80
|
+
case 'te':
|
|
81
|
+
config = { content: '鏈哄熬缁堢偣', style: 'red' }
|
|
82
|
+
break
|
|
83
|
+
}
|
|
84
|
+
return L.circleMarker(latLng, CMOptions.hint).bindTooltip(TTContent(config), {
|
|
85
|
+
direction: 'right',
|
|
86
|
+
permanent: true,
|
|
87
|
+
className: 'ht-tooltip'
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function adjustIndex(index, length) {
|
|
92
|
+
if (index > length - 1) {
|
|
93
|
+
return index - length
|
|
94
|
+
}
|
|
95
|
+
if (index < 0) {
|
|
96
|
+
return index + length
|
|
97
|
+
}
|
|
98
|
+
return index
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const props = defineProps({
|
|
102
|
+
htOnly: {
|
|
103
|
+
type: Boolean,
|
|
104
|
+
default: false
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
const emit = defineEmits(['on-create', 'on-save'])
|
|
109
|
+
|
|
110
|
+
const enabled = ref(false)
|
|
111
|
+
const mapInstance = ref(null)
|
|
112
|
+
const drawItems = L.layerGroup()
|
|
113
|
+
const drawStatus = ref('none')
|
|
114
|
+
const polygon = ref(null)
|
|
115
|
+
const htItems = L.layerGroup()
|
|
116
|
+
const htHelpItems = L.layerGroup()
|
|
117
|
+
const htHelpCacheItems = L.layerGroup()
|
|
118
|
+
const htTooltip = ref(null)
|
|
119
|
+
const htIndex = ref(0)
|
|
120
|
+
const hsIndex = ref(-1)
|
|
121
|
+
const tsIndex = ref(-1)
|
|
122
|
+
const heIndex = ref(-1)
|
|
123
|
+
const teIndex = ref(-1)
|
|
124
|
+
const htHelpMarkers = new Map()
|
|
125
|
+
|
|
126
|
+
const polygonReady = computed(() => polygon.value && polygon.value.getLatLngs()[0].length > 3)
|
|
127
|
+
const drawReady = computed(() => enabled.value && drawStatus.value !== 'finish')
|
|
128
|
+
const editReady = computed(() => enabled.value && polygonReady.value && drawStatus.value !== 'finish')
|
|
129
|
+
const dragReady = computed(() => enabled.value && polygonReady.value && drawStatus.value !== 'finish')
|
|
130
|
+
const pickReady = computed(() => enabled.value && polygonReady.value)
|
|
131
|
+
const saveReady = computed(() => enabled.value && ['finish', 'reset'].includes(drawStatus.value))
|
|
132
|
+
const showPolyFuncs = computed(() => !props.htOnly)
|
|
133
|
+
|
|
134
|
+
watch(drawStatus, (value) => {
|
|
135
|
+
if (value === 'draw') {
|
|
136
|
+
quitEditMode()
|
|
137
|
+
quitDragMode()
|
|
138
|
+
quitPickMode()
|
|
139
|
+
} else if (value === 'edit') {
|
|
140
|
+
quitDrawMode()
|
|
141
|
+
quitDragMode()
|
|
142
|
+
quitPickMode()
|
|
143
|
+
} else if (value === 'drag') {
|
|
144
|
+
quitDrawMode()
|
|
145
|
+
quitEditMode()
|
|
146
|
+
quitPickMode()
|
|
147
|
+
} else if (value === 'pick') {
|
|
148
|
+
quitDrawMode()
|
|
149
|
+
quitEditMode()
|
|
150
|
+
quitDragMode()
|
|
151
|
+
} else if (value === 'none' || value === 'reset') {
|
|
152
|
+
quitDrawMode()
|
|
153
|
+
quitEditMode()
|
|
154
|
+
quitDragMode()
|
|
155
|
+
quitPickMode()
|
|
156
|
+
} else if (value === 'finish') {
|
|
157
|
+
quitDrawMode()
|
|
158
|
+
quitEditMode()
|
|
159
|
+
quitDragMode()
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const enable = (map, data) => {
|
|
164
|
+
if (!map) {
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
enabled.value = true
|
|
169
|
+
mapInstance.value = map
|
|
170
|
+
mapInstance.value.pm.setLang('zh')
|
|
171
|
+
drawItems.addTo(mapInstance.value)
|
|
172
|
+
mapInstance.value.on('pm:create', ({ shape, layer }) => {
|
|
173
|
+
layer.remove()
|
|
174
|
+
layer.addTo(drawItems)
|
|
175
|
+
if (shape === 'Polygon') {
|
|
176
|
+
if (layer.getLatLngs()[0].length === 3) {
|
|
177
|
+
layer.remove()
|
|
178
|
+
drawStatus.value = 'none'
|
|
179
|
+
ElMessage.error('缁樺埗閿欒锛岃鑷冲皯缁樺埗4涓竟')
|
|
180
|
+
} else {
|
|
181
|
+
if (polygon.value) {
|
|
182
|
+
polygon.value.remove()
|
|
183
|
+
}
|
|
184
|
+
polygon.value = layer
|
|
185
|
+
drawStatus.value = 'none'
|
|
186
|
+
ElMessage.success('缁樺埗瀹屾垚')
|
|
187
|
+
emit('on-create', polygon.value)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
const latLngs = data?.latLngs
|
|
193
|
+
const currentHtIndex = data?.htIndex
|
|
194
|
+
if (Array.isArray(latLngs) && latLngs.length > 3) {
|
|
195
|
+
polygon.value = L.polygon(latLngs).addTo(drawItems)
|
|
196
|
+
if (Array.isArray(currentHtIndex) && currentHtIndex.length === 4) {
|
|
197
|
+
if (!drawItems.hasLayer(htItems)) {
|
|
198
|
+
drawItems.addLayer(htItems)
|
|
199
|
+
}
|
|
200
|
+
hsIndex.value = currentHtIndex[0]
|
|
201
|
+
PickedMarker('hs', latLngs[hsIndex.value]).addTo(htItems)
|
|
202
|
+
tsIndex.value = currentHtIndex[1]
|
|
203
|
+
PickedMarker('ts', latLngs[tsIndex.value]).addTo(htItems)
|
|
204
|
+
heIndex.value = currentHtIndex[2]
|
|
205
|
+
PickedMarker('he', latLngs[heIndex.value]).addTo(htItems)
|
|
206
|
+
teIndex.value = currentHtIndex[3]
|
|
207
|
+
PickedMarker('te', latLngs[teIndex.value]).addTo(htItems)
|
|
208
|
+
drawStatus.value = 'finish'
|
|
209
|
+
}
|
|
210
|
+
emit('on-create', polygon.value)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const clearDrawItems = () => {
|
|
215
|
+
drawStatus.value = 'reset'
|
|
216
|
+
drawItems.clearLayers()
|
|
217
|
+
polygon.value = null
|
|
218
|
+
ElMessage.success('宸叉竻鐞?')
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const startDrawMode = () => {
|
|
222
|
+
if (drawReady.value) {
|
|
223
|
+
mapInstance.value.pm.enableDraw('Polygon')
|
|
224
|
+
drawStatus.value = 'draw'
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const removeLastVertx = () => {
|
|
229
|
+
const target = mapInstance.value.pm.Draw.Polygon
|
|
230
|
+
target._removeLastVertex()
|
|
231
|
+
if (!target._enabled) {
|
|
232
|
+
drawStatus.value = 'none'
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const quitDrawMode = () => {
|
|
237
|
+
mapInstance.value?.pm.disableDraw('Polygon')
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const startEditMode = () => {
|
|
241
|
+
if (editReady.value && !polygon.value.pm.enabled()) {
|
|
242
|
+
polygon.value.pm.enable()
|
|
243
|
+
drawStatus.value = 'edit'
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const quitEditMode = () => {
|
|
248
|
+
if (polygon.value?.pm.enabled()) {
|
|
249
|
+
polygon.value.pm.disable()
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const startDragMode = () => {
|
|
254
|
+
if (dragReady.value && !mapInstance.value.pm.globalDragModeEnabled()) {
|
|
255
|
+
mapInstance.value.pm.toggleGlobalDragMode()
|
|
256
|
+
drawStatus.value = 'drag'
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const quitDragMode = () => {
|
|
261
|
+
if (mapInstance.value?.pm.globalDragModeEnabled()) {
|
|
262
|
+
mapInstance.value.pm.toggleGlobalDragMode()
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const handlePickMove = (event) => {
|
|
267
|
+
if (htTooltip.value) {
|
|
268
|
+
htTooltip.value.setLatLng(event.latlng)
|
|
269
|
+
if (!htHelpItems.hasLayer(htTooltip.value)) {
|
|
270
|
+
htTooltip.value.addTo(htHelpItems)
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const resetPickMode = () => {
|
|
276
|
+
htItems.clearLayers()
|
|
277
|
+
htHelpItems.clearLayers()
|
|
278
|
+
htHelpCacheItems.clearLayers()
|
|
279
|
+
htHelpMarkers.clear()
|
|
280
|
+
|
|
281
|
+
const latLngs = polygon.value.getLatLngs()[0]
|
|
282
|
+
latLngs.forEach((latLng, index) => {
|
|
283
|
+
const marker = L.circleMarker(latLng, CMOptions.unpicked).addTo(htHelpItems)
|
|
284
|
+
bindPickEvent(marker, index)
|
|
285
|
+
htHelpMarkers.set(index, marker)
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
hsIndex.value = -1
|
|
289
|
+
tsIndex.value = -1
|
|
290
|
+
heIndex.value = -1
|
|
291
|
+
teIndex.value = -1
|
|
292
|
+
htIndex.value = 1
|
|
293
|
+
|
|
294
|
+
htTooltip.value = L.circleMarker(mapInstance.value.getCenter(), CMOptions.hint).bindTooltip(TTContent({
|
|
295
|
+
action: '璇烽€夋嫨',
|
|
296
|
+
content: '鏈哄ご璧风偣',
|
|
297
|
+
style: 'green'
|
|
298
|
+
}), {
|
|
299
|
+
direction: 'bottom',
|
|
300
|
+
offset: [0, 8],
|
|
301
|
+
permanent: true,
|
|
302
|
+
className: 'ht-tooltip'
|
|
303
|
+
})
|
|
304
|
+
mapInstance.value.off('mousemove', handlePickMove)
|
|
305
|
+
mapInstance.value.on('mousemove', handlePickMove)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const startPickMode = () => {
|
|
309
|
+
if (pickReady.value) {
|
|
310
|
+
drawStatus.value = 'pick'
|
|
311
|
+
htItems.addTo(drawItems)
|
|
312
|
+
htHelpItems.addTo(drawItems)
|
|
313
|
+
resetPickMode()
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const quitPickMode = () => {
|
|
318
|
+
mapInstance.value?.off('mousemove', handlePickMove)
|
|
319
|
+
if (drawStatus.value !== 'finish') {
|
|
320
|
+
htItems.clearLayers()
|
|
321
|
+
hsIndex.value = -1
|
|
322
|
+
tsIndex.value = -1
|
|
323
|
+
heIndex.value = -1
|
|
324
|
+
teIndex.value = -1
|
|
325
|
+
}
|
|
326
|
+
htTooltip.value = null
|
|
327
|
+
htHelpItems.clearLayers()
|
|
328
|
+
htHelpCacheItems.clearLayers()
|
|
329
|
+
htHelpMarkers.clear()
|
|
330
|
+
htIndex.value = 0
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const finishPick = () => {
|
|
334
|
+
if (htIndex.value === 5) {
|
|
335
|
+
drawStatus.value = 'finish'
|
|
336
|
+
quitPickMode()
|
|
337
|
+
ElMessage.success('鏍囨敞瀹屾垚')
|
|
338
|
+
} else {
|
|
339
|
+
drawStatus.value = 'none'
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const doPickMarker = (index) => {
|
|
344
|
+
let sign
|
|
345
|
+
let next
|
|
346
|
+
if (htIndex.value === 1) {
|
|
347
|
+
sign = 'hs'
|
|
348
|
+
next = { action: '璇烽€夋嫨', content: '鏈哄熬璧风偣', style: 'red' }
|
|
349
|
+
} else if (htIndex.value === 2) {
|
|
350
|
+
sign = 'ts'
|
|
351
|
+
next = { action: '璇烽€夋嫨', content: '鏈哄ご缁堢偣', style: 'green' }
|
|
352
|
+
} else if (htIndex.value === 3) {
|
|
353
|
+
sign = 'he'
|
|
354
|
+
next = { action: '璇烽€夋嫨', content: '鏈哄熬缁堢偣', style: 'red' }
|
|
355
|
+
} else {
|
|
356
|
+
sign = 'te'
|
|
357
|
+
next = { content: '-' }
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const target = htHelpMarkers.get(index)
|
|
361
|
+
const indexRefs = { hs: hsIndex, ts: tsIndex, he: heIndex, te: teIndex }
|
|
362
|
+
PickedMarker(sign, target.getLatLng()).addTo(htItems)
|
|
363
|
+
target.off('click')
|
|
364
|
+
target.remove()
|
|
365
|
+
htHelpMarkers.delete(index)
|
|
366
|
+
htIndex.value += 1
|
|
367
|
+
indexRefs[sign].value = index
|
|
368
|
+
htTooltip.value?.setTooltipContent(TTContent(next))
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const bindPickEvent = (target, index) => {
|
|
372
|
+
if (!target) {
|
|
373
|
+
return
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
target.on('click', () => {
|
|
377
|
+
const length = polygon.value.getLatLngs()[0].length
|
|
378
|
+
|
|
379
|
+
if (htIndex.value === 1) {
|
|
380
|
+
doPickMarker(index)
|
|
381
|
+
const leftIndex = index === length - 1 ? 0 : index + 1
|
|
382
|
+
const rightIndex = index === 0 ? length - 1 : index - 1
|
|
383
|
+
for (const [key, marker] of htHelpMarkers) {
|
|
384
|
+
if (key !== leftIndex && key !== rightIndex) {
|
|
385
|
+
htHelpCacheItems.addLayer(marker)
|
|
386
|
+
htHelpItems.removeLayer(marker)
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
} else if (htIndex.value === 2) {
|
|
390
|
+
doPickMarker(index)
|
|
391
|
+
htHelpMarkers.delete(index)
|
|
392
|
+
htHelpCacheItems.eachLayer((layer) => {
|
|
393
|
+
layer.addTo(htHelpItems)
|
|
394
|
+
htHelpCacheItems.removeLayer(layer)
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
let directionPositive = hsIndex.value < tsIndex.value
|
|
398
|
+
if (Math.abs(hsIndex.value - tsIndex.value) === length - 1) {
|
|
399
|
+
directionPositive = tsIndex.value === 0
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (htHelpMarkers.size === 2) {
|
|
403
|
+
const nextHeIndex = adjustIndex(directionPositive ? hsIndex.value - 1 : hsIndex.value + 1, length)
|
|
404
|
+
doPickMarker(nextHeIndex)
|
|
405
|
+
const nextTeIndex = adjustIndex(directionPositive ? tsIndex.value + 1 : tsIndex.value - 1, length)
|
|
406
|
+
doPickMarker(nextTeIndex)
|
|
407
|
+
finishPick()
|
|
408
|
+
} else {
|
|
409
|
+
const banIndex = adjustIndex(directionPositive ? tsIndex.value + 1 : tsIndex.value - 1, length)
|
|
410
|
+
const banMarker = htHelpMarkers.get(banIndex)
|
|
411
|
+
htHelpCacheItems.addLayer(banMarker)
|
|
412
|
+
htHelpItems.removeLayer(banMarker)
|
|
413
|
+
}
|
|
414
|
+
} else if (htIndex.value === 3) {
|
|
415
|
+
doPickMarker(index)
|
|
416
|
+
htHelpMarkers.delete(index)
|
|
417
|
+
htHelpCacheItems.eachLayer((layer) => {
|
|
418
|
+
htHelpCacheItems.removeLayer(layer)
|
|
419
|
+
layer.addTo(htHelpItems)
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
let directionPositive = hsIndex.value < tsIndex.value
|
|
423
|
+
if (Math.abs(hsIndex.value - tsIndex.value) === length - 1) {
|
|
424
|
+
directionPositive = tsIndex.value === 0
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const banIndex = []
|
|
428
|
+
if (directionPositive) {
|
|
429
|
+
const tempEnd = hsIndex.value < index ? hsIndex.value + length : hsIndex.value
|
|
430
|
+
for (let current = index + 1; current < tempEnd; current += 1) {
|
|
431
|
+
banIndex.push(current > length - 1 ? current - length : current)
|
|
432
|
+
}
|
|
433
|
+
} else {
|
|
434
|
+
const tempEnd = hsIndex.value > index ? index + length : index
|
|
435
|
+
for (let current = hsIndex.value + 1; current < tempEnd; current += 1) {
|
|
436
|
+
banIndex.push(current > length - 1 ? current - length : current)
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
banIndex.forEach((value) => {
|
|
441
|
+
const banMarker = htHelpMarkers.get(value)
|
|
442
|
+
htHelpCacheItems.addLayer(banMarker)
|
|
443
|
+
htHelpItems.removeLayer(banMarker)
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
if (length - banIndex.length - 3 === 1) {
|
|
447
|
+
for (const key of htHelpMarkers.keys()) {
|
|
448
|
+
if (_.indexOf(banIndex, key) < 0) {
|
|
449
|
+
doPickMarker(key)
|
|
450
|
+
finishPick()
|
|
451
|
+
break
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
} else if (htIndex.value === 4) {
|
|
456
|
+
doPickMarker(index)
|
|
457
|
+
finishPick()
|
|
458
|
+
}
|
|
459
|
+
})
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const saveItems = () => {
|
|
463
|
+
if (!saveReady.value) {
|
|
464
|
+
return
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (drawStatus.value === 'reset') {
|
|
468
|
+
emit('on-save', { latLngs: null, htIndex: null })
|
|
469
|
+
} else if (drawStatus.value === 'finish') {
|
|
470
|
+
emit('on-save', {
|
|
471
|
+
latLngs: polygon.value.getLatLngs()[0],
|
|
472
|
+
htIndex: [hsIndex.value, tsIndex.value, heIndex.value, teIndex.value]
|
|
473
|
+
})
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const actionDisabled = (action) => {
|
|
478
|
+
if (action === 'draw') {
|
|
479
|
+
return drawReady.value ? null : 'disabled'
|
|
480
|
+
}
|
|
481
|
+
if (action === 'edit') {
|
|
482
|
+
return editReady.value ? null : 'disabled'
|
|
483
|
+
}
|
|
484
|
+
if (action === 'drag') {
|
|
485
|
+
return dragReady.value ? null : 'disabled'
|
|
486
|
+
}
|
|
487
|
+
if (action === 'pick') {
|
|
488
|
+
return pickReady.value ? null : 'disabled'
|
|
489
|
+
}
|
|
490
|
+
if (action === 'save') {
|
|
491
|
+
return saveReady.value ? null : 'disabled'
|
|
492
|
+
}
|
|
493
|
+
return null
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
defineExpose({
|
|
497
|
+
enable
|
|
498
|
+
})
|
|
499
|
+
</script>
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="vae-map-ctrl--draw">
|
|
3
|
+
<div class="item-group">
|
|
4
|
+
<template>
|
|
5
|
+
<div class="item" title="缁樺埗">
|
|
6
|
+
<div class="item-icon fas fa-pen-alt" :class="actionDisabled('draw')" @click="startDrawMode" />
|
|
7
|
+
<div v-if="drawStatus === 'draw'" class="tooltips">
|
|
8
|
+
<span @click="drawStatus = 'none'">鍙栨秷</span>
|
|
9
|
+
<span @click="removeLastVertx">绉婚櫎涓婁釜鑺傜偣</span>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
<div class="item" title="缂栬緫">
|
|
13
|
+
<div class="item-icon fas fa-draw-polygon" :class="actionDisabled('edit')" @click="startEditMode" />
|
|
14
|
+
<div v-if="drawStatus === 'edit'" class="tooltips">
|
|
15
|
+
<span @click="drawStatus = 'none'">瀹屾垚</span>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
<div class="item" title="娓呴櫎">
|
|
19
|
+
<div class="item-icon fas fa-trash-alt" @click="clearDrawItems" />
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
22
|
+
</div>
|
|
23
|
+
<div class="item-group">
|
|
24
|
+
<div class="item" title="淇濆瓨">
|
|
25
|
+
<div class="item-icon fas fa-save" :class="actionDisabled('save')" @click="saveItems" />
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<script setup>
|
|
32
|
+
import { computed, ref, watch } from 'vue'
|
|
33
|
+
import { ElMessage } from 'element-plus'
|
|
34
|
+
|
|
35
|
+
defineOptions({
|
|
36
|
+
name: 'VaeMapCtrlDrawLine'
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const emit = defineEmits(['on-create', 'on-save'])
|
|
40
|
+
|
|
41
|
+
const enabled = ref(false)
|
|
42
|
+
const mapInstance = ref(null)
|
|
43
|
+
const drawItems = L.layerGroup()
|
|
44
|
+
const drawStatus = ref('none')
|
|
45
|
+
const polyline = ref(null)
|
|
46
|
+
|
|
47
|
+
const drawReady = computed(() => enabled.value)
|
|
48
|
+
const saveReady = computed(() => enabled.value)
|
|
49
|
+
|
|
50
|
+
watch(drawStatus, (value) => {
|
|
51
|
+
if (value === 'none') {
|
|
52
|
+
quitDrawMode()
|
|
53
|
+
} else if (value === 'edit') {
|
|
54
|
+
quitDrawMode()
|
|
55
|
+
quitDragMode()
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const enable = (map, data) => {
|
|
60
|
+
if (!map) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
enabled.value = true
|
|
65
|
+
mapInstance.value = map
|
|
66
|
+
mapInstance.value.pm.setLang('zh')
|
|
67
|
+
drawItems.addTo(mapInstance.value)
|
|
68
|
+
mapInstance.value.on('pm:create', ({ shape, layer }) => {
|
|
69
|
+
layer.remove()
|
|
70
|
+
layer.addTo(drawItems)
|
|
71
|
+
if (shape === 'Line') {
|
|
72
|
+
if (polyline.value) {
|
|
73
|
+
polyline.value.remove()
|
|
74
|
+
}
|
|
75
|
+
polyline.value = layer
|
|
76
|
+
drawStatus.value = 'none'
|
|
77
|
+
ElMessage.success('缁樺埗瀹屾垚')
|
|
78
|
+
emit('on-create', polyline.value)
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
const latLngs = data?.latLngs
|
|
83
|
+
if (Array.isArray(latLngs) && latLngs.length > 1) {
|
|
84
|
+
polyline.value = L.polyline(latLngs).addTo(drawItems)
|
|
85
|
+
emit('on-create', polyline.value)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const clearDrawItems = () => {
|
|
90
|
+
drawStatus.value = 'none'
|
|
91
|
+
drawItems.clearLayers()
|
|
92
|
+
polyline.value = null
|
|
93
|
+
ElMessage.success('宸叉竻鐞?')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const startDrawMode = () => {
|
|
97
|
+
if (drawReady.value) {
|
|
98
|
+
mapInstance.value.pm.enableDraw('Line')
|
|
99
|
+
drawStatus.value = 'draw'
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const startEditMode = () => {
|
|
104
|
+
if (drawReady.value && !polyline.value.pm.enabled()) {
|
|
105
|
+
polyline.value.pm.enable()
|
|
106
|
+
drawStatus.value = 'edit'
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const quitEditMode = () => {
|
|
111
|
+
if (polyline.value?.pm.enabled()) {
|
|
112
|
+
polyline.value.pm.disable()
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const removeLastVertx = () => {
|
|
117
|
+
const target = mapInstance.value.pm.Draw.Line
|
|
118
|
+
target._removeLastVertex()
|
|
119
|
+
if (!target._enabled) {
|
|
120
|
+
drawStatus.value = 'none'
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const quitDragMode = () => {
|
|
125
|
+
if (mapInstance.value?.pm.globalDragModeEnabled()) {
|
|
126
|
+
mapInstance.value.pm.toggleGlobalDragMode()
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const quitDrawMode = () => {
|
|
131
|
+
mapInstance.value?.pm.disableDraw('Line')
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const saveItems = () => {
|
|
135
|
+
drawStatus.value = 'finish'
|
|
136
|
+
quitEditMode()
|
|
137
|
+
if (!saveReady.value) {
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (polyline.value) {
|
|
142
|
+
emit('on-save', { latLngs: polyline.value.getLatLngs() })
|
|
143
|
+
} else {
|
|
144
|
+
emit('on-save', { latLngs: null })
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const actionDisabled = (action) => {
|
|
149
|
+
if (action === 'draw') {
|
|
150
|
+
return drawReady.value ? null : 'disabled'
|
|
151
|
+
}
|
|
152
|
+
if (action === 'save') {
|
|
153
|
+
return saveReady.value ? null : 'disabled'
|
|
154
|
+
}
|
|
155
|
+
return null
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
defineExpose({
|
|
159
|
+
enable
|
|
160
|
+
})
|
|
161
|
+
</script>
|