@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,55 @@
|
|
|
1
|
+
import L from 'leaflet'
|
|
2
|
+
|
|
3
|
+
const PATCH_FLAG = '_safeDivOverlayPatched'
|
|
4
|
+
|
|
5
|
+
function canUpdateOverlay(overlay) {
|
|
6
|
+
return !!(
|
|
7
|
+
overlay &&
|
|
8
|
+
overlay._map &&
|
|
9
|
+
overlay._latlng &&
|
|
10
|
+
overlay._container
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function wrapOverlayMethod(target, methodName) {
|
|
15
|
+
if (!target?.prototype?.[methodName]) {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const methodFlag = `${PATCH_FLAG}_${methodName}`
|
|
20
|
+
if (target.prototype[methodFlag]) {
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const originalMethod = target.prototype[methodName]
|
|
25
|
+
|
|
26
|
+
target.include({
|
|
27
|
+
[methodFlag]: true,
|
|
28
|
+
[methodName](...args) {
|
|
29
|
+
if (!canUpdateOverlay(this)) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return originalMethod.apply(this, args)
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function patchLeafletInstance(leaflet) {
|
|
39
|
+
if (!leaflet || leaflet[PATCH_FLAG]) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
wrapOverlayMethod(leaflet.Tooltip, '_animateZoom')
|
|
44
|
+
wrapOverlayMethod(leaflet.Tooltip, '_updatePosition')
|
|
45
|
+
wrapOverlayMethod(leaflet.Popup, '_animateZoom')
|
|
46
|
+
wrapOverlayMethod(leaflet.Popup, '_updatePosition')
|
|
47
|
+
|
|
48
|
+
leaflet[PATCH_FLAG] = true
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
patchLeafletInstance(L)
|
|
52
|
+
|
|
53
|
+
if (typeof window !== 'undefined' && window.L && window.L !== L) {
|
|
54
|
+
patchLeafletInstance(window.L)
|
|
55
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// 国内TMS提供方
|
|
2
|
+
const providers = {
|
|
3
|
+
|
|
4
|
+
TianDiTu: {
|
|
5
|
+
Normal: {
|
|
6
|
+
Map: "https://t{s}.tianditu.gov.cn/DataServer?T=vec_w&X={x}&Y={y}&L={z}&tk={key}",
|
|
7
|
+
Annotion: "https://t{s}.tianditu.gov.cn/DataServer?T=cva_w&X={x}&Y={y}&L={z}&tk={key}",
|
|
8
|
+
},
|
|
9
|
+
Satellite: {
|
|
10
|
+
Map: "https://t{s}.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk={key}",
|
|
11
|
+
Annotion: "https://t{s}.tianditu.gov.cn/DataServer?T=cia_w&X={x}&Y={y}&L={z}&tk={key}",
|
|
12
|
+
},
|
|
13
|
+
Terrain: {
|
|
14
|
+
Map: "https://t{s}.tianditu.gov.cn/DataServer?T=ter_w&X={x}&Y={y}&L={z}&tk={key}",
|
|
15
|
+
Annotion: "https://t{s}.tianditu.gov.cn/DataServer?T=cta_w&X={x}&Y={y}&L={z}&tk={key}"
|
|
16
|
+
},
|
|
17
|
+
Subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
|
|
18
|
+
key: "1a346e3ea95a3227a097cabf11a901b7"
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
GaoDe: {
|
|
22
|
+
Normal: {
|
|
23
|
+
Map: 'https://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',
|
|
24
|
+
},
|
|
25
|
+
Satellite: {
|
|
26
|
+
Map: 'https://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
|
|
27
|
+
Annotion: 'https://webst0{s}.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}'
|
|
28
|
+
},
|
|
29
|
+
Subdomains: ["1", "2", "3", "4"]
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
GaoDe_Mobile: {
|
|
33
|
+
Normal: {
|
|
34
|
+
Map: 'https://wprd0{s}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=7'
|
|
35
|
+
},
|
|
36
|
+
Satellite: {
|
|
37
|
+
Map: 'https://wprd0{s}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=6',
|
|
38
|
+
Annotion: 'https://wprd0{s}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=2&style=8'
|
|
39
|
+
},
|
|
40
|
+
Subdomains: ["1", "2", "3", "4"]
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
Google: {
|
|
44
|
+
Normal: {
|
|
45
|
+
Map: "https://www.google.cn/maps/vt?lyrs=m&gl=cn&x={x}&y={y}&z={z}"
|
|
46
|
+
},
|
|
47
|
+
Satellite: {
|
|
48
|
+
Map: "https://www.google.cn/maps/vt?lyrs=s&gl=cn&x={x}&y={y}&z={z}",
|
|
49
|
+
Annotion: "https://www.google.cn/maps/vt?lyrs=h&gl=cn&x={x}&y={y}&z={z}"
|
|
50
|
+
},
|
|
51
|
+
Subdomains: []
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
Geoq: {
|
|
55
|
+
Normal: {
|
|
56
|
+
Map: "https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer/tile/{z}/{y}/{x}",
|
|
57
|
+
PurplishBlue: "https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}",
|
|
58
|
+
Gray: "https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetGray/MapServer/tile/{z}/{y}/{x}",
|
|
59
|
+
Warm: "https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetWarm/MapServer/tile/{z}/{y}/{x}"
|
|
60
|
+
},
|
|
61
|
+
Theme: {
|
|
62
|
+
Hydro: "https://thematic.geoq.cn/arcgis/rest/services/ThematicMaps/WorldHydroMap/MapServer/tile/{z}/{y}/{x}",
|
|
63
|
+
Division: "https://thematic.geoq.cn/arcgis/rest/services/ThematicMaps/administrative_division_boundaryandlabel/MapServer/tile/{z}/{y}/{x}"
|
|
64
|
+
},
|
|
65
|
+
Subdomains: []
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
L.TileLayer.ChinaProvider = L.TileLayer.extend({
|
|
70
|
+
|
|
71
|
+
initialize(type, options = {}) {
|
|
72
|
+
|
|
73
|
+
const [base, key] = type.split('@')
|
|
74
|
+
const parts = base.split('.')
|
|
75
|
+
if (parts[0] && parts.length == 3) {
|
|
76
|
+
const providerName = parts[0]
|
|
77
|
+
const mapName = parts[1]
|
|
78
|
+
const mapType = parts[2]
|
|
79
|
+
const provider = providers[providerName]
|
|
80
|
+
if (provider) {
|
|
81
|
+
const target = provider?.[mapName]?.[mapType]
|
|
82
|
+
if (target) {
|
|
83
|
+
if (provider.hasOwnProperty('key') && !key) {
|
|
84
|
+
console.error(`provider '${providerName}' need a key`)
|
|
85
|
+
} else {
|
|
86
|
+
const baseOptions = {
|
|
87
|
+
maxZoom: 24,
|
|
88
|
+
subdomains: provider.Subdomains,
|
|
89
|
+
key
|
|
90
|
+
}
|
|
91
|
+
L.TileLayer.prototype.initialize.call(this, target, L.extend(baseOptions, options))
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
console.error(`provider not found '${type}'`)
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
console.error(`provider not found '${type}'`)
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
console.error(`provider not found '${type}'`)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
L.tileLayer.chinaProvider = function (type, options) {
|
|
107
|
+
return new L.TileLayer.ChinaProvider(type, options)
|
|
108
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createApp } from 'vue'
|
|
2
|
+
import { idGen } from '@/utils'
|
|
3
|
+
import { observeElementResize } from '@/composables/useResizeObserver'
|
|
4
|
+
|
|
5
|
+
L.VuePopup = L.Popup.extend({
|
|
6
|
+
app: null,
|
|
7
|
+
stopResize: null,
|
|
8
|
+
|
|
9
|
+
options: {
|
|
10
|
+
vueInstance: null,
|
|
11
|
+
props: null
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
initialize(options) {
|
|
15
|
+
L.setOptions(this, options)
|
|
16
|
+
this._bindEvents()
|
|
17
|
+
L.Popup.prototype.initialize.call(this, _.omit(this.options, ['vueInstance', 'props']))
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
_bindEvents() {
|
|
21
|
+
if (!this.options.vueInstance) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this.on('add', () => {
|
|
26
|
+
const handleResize = () => {
|
|
27
|
+
this._updateVuePopup()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const uuid = `vue-popup-${idGen()}`
|
|
31
|
+
this.setContent(`<div id="${uuid}"></div>`)
|
|
32
|
+
|
|
33
|
+
queueMicrotask(() => {
|
|
34
|
+
const mountEl = document.getElementById(uuid)
|
|
35
|
+
if (!mountEl) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
this.app = createApp(this.options.vueInstance, this.options.props ?? {})
|
|
39
|
+
this.app.mount(mountEl)
|
|
40
|
+
this.stopResize = observeElementResize(mountEl, handleResize)
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
this.on('remove', () => {
|
|
45
|
+
this.stopResize?.()
|
|
46
|
+
this.stopResize = null
|
|
47
|
+
this.app?.unmount()
|
|
48
|
+
this.app = null
|
|
49
|
+
})
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
_updateVuePopup() {
|
|
53
|
+
if (!this._map || !this._latlng || !this._container) {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this._container.style.visibility = 'hidden'
|
|
58
|
+
this._updateLayout()
|
|
59
|
+
this._updatePosition()
|
|
60
|
+
this._container.style.visibility = ''
|
|
61
|
+
this._adjustPan()
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
L.vuePopup = function (options) {
|
|
66
|
+
return new L.VuePopup(options)
|
|
67
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createApp } from 'vue'
|
|
2
|
+
import { idGen } from '@/utils'
|
|
3
|
+
import { observeElementResize } from '@/composables/useResizeObserver'
|
|
4
|
+
|
|
5
|
+
L.VueTooltip = L.Tooltip.extend({
|
|
6
|
+
app: null,
|
|
7
|
+
stopResize: null,
|
|
8
|
+
|
|
9
|
+
options: {
|
|
10
|
+
vueInstance: null,
|
|
11
|
+
props: null
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
initialize(options) {
|
|
15
|
+
L.setOptions(this, options)
|
|
16
|
+
this._bindEvents()
|
|
17
|
+
L.Tooltip.prototype.initialize.call(this, _.omit(this.options, ['vueInstance', 'props']))
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
_bindEvents() {
|
|
21
|
+
if (!this.options.vueInstance) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this.on('add', () => {
|
|
26
|
+
const handleResize = () => {
|
|
27
|
+
this._updateVueTooltip()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const uuid = `vue-tooltip-${idGen()}`
|
|
31
|
+
this.setContent(`<div id="${uuid}"></div>`)
|
|
32
|
+
|
|
33
|
+
queueMicrotask(() => {
|
|
34
|
+
const mountEl = document.getElementById(uuid)
|
|
35
|
+
if (!mountEl) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
this.app = createApp(this.options.vueInstance, this.options.props ?? {})
|
|
39
|
+
this.app.mount(mountEl)
|
|
40
|
+
this.stopResize = observeElementResize(mountEl, handleResize)
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
this.on('remove', () => {
|
|
45
|
+
this.stopResize?.()
|
|
46
|
+
this.stopResize = null
|
|
47
|
+
this.app?.unmount()
|
|
48
|
+
this.app = null
|
|
49
|
+
})
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
_updateVueTooltip() {
|
|
53
|
+
if (!this._map || !this._latlng || !this._container) {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this._updatePosition()
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
L.vueTooltip = function (options) {
|
|
62
|
+
return new L.VueTooltip(options)
|
|
63
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { onBeforeUnmount, ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
// 地图实例
|
|
4
|
+
let map
|
|
5
|
+
|
|
6
|
+
// 绘制层,放置绘制的覆盖物和文字提示
|
|
7
|
+
let drawItems = L.featureGroup()
|
|
8
|
+
|
|
9
|
+
// 绘制辅助层,放置绘制过程中的提示覆盖物和提示信息
|
|
10
|
+
let drawHelpItems = L.featureGroup()
|
|
11
|
+
|
|
12
|
+
// 鼠标当前经纬度
|
|
13
|
+
let currentLatLng
|
|
14
|
+
|
|
15
|
+
// 测距:节点集
|
|
16
|
+
let lineVertexes = []
|
|
17
|
+
|
|
18
|
+
// 测距:当前距离
|
|
19
|
+
let lineCurrentDistance
|
|
20
|
+
|
|
21
|
+
// 测距:当前距离提示标注
|
|
22
|
+
let lineHintMarker
|
|
23
|
+
|
|
24
|
+
// 测面积:节点集
|
|
25
|
+
let polygonVertexes = []
|
|
26
|
+
|
|
27
|
+
// 测面积:当前面积
|
|
28
|
+
let polygonCurrentArea
|
|
29
|
+
|
|
30
|
+
// 测面积:面积提示标注
|
|
31
|
+
let polygonHintMarker
|
|
32
|
+
|
|
33
|
+
// 测面积:提示多边形
|
|
34
|
+
let polygonHintpolygon
|
|
35
|
+
|
|
36
|
+
// 绘制事件集
|
|
37
|
+
const Events = {
|
|
38
|
+
|
|
39
|
+
// 管理绘制的覆盖物
|
|
40
|
+
onLayerCreate(e) {
|
|
41
|
+
e.layer.remove().addTo(drawItems)
|
|
42
|
+
|
|
43
|
+
// 添加测面积标注
|
|
44
|
+
if (e.shape == 'Polygon') {
|
|
45
|
+
const hintMarkerIcon = createTextIcon(L.GeoUtil.readableArea(polygonCurrentArea))
|
|
46
|
+
L.marker(currentLatLng, { interactive: false }).setIcon(hintMarkerIcon).addTo(drawItems)
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
// 绘制开始
|
|
51
|
+
onDrawStart(e) {
|
|
52
|
+
const workingLayer = e.workingLayer
|
|
53
|
+
// 测距
|
|
54
|
+
if (e.shape == 'Line') {
|
|
55
|
+
map.on('mousemove', handleMouseMoveAtLine)
|
|
56
|
+
workingLayer.on('pm:vertexadded', vertex => {
|
|
57
|
+
const hintMarker = L.marker(vertex.latlng, { interactive: false })
|
|
58
|
+
lineVertexes = workingLayer._latlngs
|
|
59
|
+
if (lineVertexes.length == 1) {
|
|
60
|
+
hintMarker.setIcon(createTextIcon('测距起点')).addTo(drawHelpItems)
|
|
61
|
+
} else {
|
|
62
|
+
const distanceText = L.GeometryUtil.readableDistance(lineCurrentDistance)
|
|
63
|
+
hintMarker.setIcon(createTextIcon(distanceText)).addTo(drawHelpItems)
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
// 测面积
|
|
68
|
+
else if (e.shape == 'Polygon') {
|
|
69
|
+
map.on('mousemove', handleMouseMoveAtPolygon)
|
|
70
|
+
workingLayer.on('pm:vertexadded', vertex => {
|
|
71
|
+
polygonVertexes = workingLayer._latlngs
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
// 绘制结束
|
|
77
|
+
onDrawEnd(e) {
|
|
78
|
+
// 重置测距
|
|
79
|
+
if (e.shape == 'Line') {
|
|
80
|
+
map.off('mousemove', handleMouseMoveAtLine)
|
|
81
|
+
if (lineHintMarker) {
|
|
82
|
+
drawHelpItems.removeLayer(lineHintMarker)
|
|
83
|
+
lineHintMarker = null
|
|
84
|
+
}
|
|
85
|
+
lineVertexes = []
|
|
86
|
+
currentLatLng = null
|
|
87
|
+
lineCurrentDistance = null
|
|
88
|
+
}
|
|
89
|
+
// 重置测面积
|
|
90
|
+
else if (e.shape == 'Polygon') {
|
|
91
|
+
map.off('mousemove', handleMouseMoveAtPolygon)
|
|
92
|
+
if (polygonHintMarker) {
|
|
93
|
+
drawHelpItems.removeLayer(polygonHintMarker)
|
|
94
|
+
polygonHintMarker = null
|
|
95
|
+
}
|
|
96
|
+
if (polygonHintpolygon) {
|
|
97
|
+
drawHelpItems.removeLayer(polygonHintpolygon)
|
|
98
|
+
polygonHintpolygon = null
|
|
99
|
+
}
|
|
100
|
+
polygonVertexes = []
|
|
101
|
+
currentLatLng = null
|
|
102
|
+
polygonCurrentArea = null
|
|
103
|
+
}
|
|
104
|
+
// 转移辅助层至绘制层,避免开始新绘制时被清理
|
|
105
|
+
drawHelpItems.eachLayer(layer => {
|
|
106
|
+
drawHelpItems.removeLayer(layer)
|
|
107
|
+
layer.addTo(drawItems)
|
|
108
|
+
})
|
|
109
|
+
drawHelpItems.clearLayers()
|
|
110
|
+
|
|
111
|
+
// 绘制结束,取消事件监听
|
|
112
|
+
unregisterDrawEvents()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 注册绘制事件
|
|
118
|
+
const registerDrawEvents = () => {
|
|
119
|
+
map.on('pm:create', Events.onLayerCreate)
|
|
120
|
+
map.on('pm:drawstart', Events.onDrawStart)
|
|
121
|
+
map.on('pm:drawend', Events.onDrawEnd)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 取消注册绘制事件
|
|
125
|
+
const unregisterDrawEvents = () => {
|
|
126
|
+
map.off('pm:create', Events.onLayerCreate)
|
|
127
|
+
map.off('pm:drawstart', Events.onDrawStart)
|
|
128
|
+
map.off('pm:drawend', Events.onDrawEnd)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 测距:响应鼠标移动(计算距离,更新提示)
|
|
132
|
+
const handleMouseMoveAtLine = _.throttle(e => {
|
|
133
|
+
// 更新位置
|
|
134
|
+
currentLatLng = e.latlng
|
|
135
|
+
// 更新节点集
|
|
136
|
+
const currentLatLngs = _.concat(lineVertexes, currentLatLng)
|
|
137
|
+
// 更新当前距离
|
|
138
|
+
lineCurrentDistance = L.GeoUtil.distanceByLatLngs(currentLatLngs, map)
|
|
139
|
+
// 更新提示
|
|
140
|
+
if (lineVertexes.length > 0) {
|
|
141
|
+
const hintMarkerIcon = createTextIcon(L.GeometryUtil.readableDistance(lineCurrentDistance), 'dark')
|
|
142
|
+
if (lineHintMarker) {
|
|
143
|
+
lineHintMarker.setIcon(hintMarkerIcon).setLatLng(currentLatLng)
|
|
144
|
+
} else {
|
|
145
|
+
lineHintMarker = L.marker(currentLatLng, { interactive: false }).setIcon(hintMarkerIcon).addTo(drawHelpItems)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}, 20)
|
|
149
|
+
|
|
150
|
+
// 测面积:响应鼠标移动(计算面积,更新提示)
|
|
151
|
+
const handleMouseMoveAtPolygon = _.throttle(e => {
|
|
152
|
+
// 更新位置
|
|
153
|
+
currentLatLng = e.latlng
|
|
154
|
+
// 更新节点集
|
|
155
|
+
const currentLatLngs = _.concat(polygonVertexes, currentLatLng)
|
|
156
|
+
// 根据CRS选择算法
|
|
157
|
+
let useLatLng = true
|
|
158
|
+
if (map.vae && !map.vae.crs.code) {
|
|
159
|
+
useLatLng = false
|
|
160
|
+
}
|
|
161
|
+
// 使用simple坐标系时,将LatLng转为Point处理
|
|
162
|
+
polygonCurrentArea = useLatLng ?
|
|
163
|
+
L.GeoUtil.areaByLatLngs(currentLatLngs) :
|
|
164
|
+
L.GeoUtil.areaByPoints(currentLatLngs.map(v => ({ x: v.lat, y: v.lng })))
|
|
165
|
+
// 更新提示
|
|
166
|
+
if (polygonVertexes.length > 1) {
|
|
167
|
+
const hintMarkerIcon = createTextIcon(L.GeoUtil.readableArea(polygonCurrentArea), 'dark')
|
|
168
|
+
if (polygonHintMarker) {
|
|
169
|
+
polygonHintMarker.setIcon(hintMarkerIcon).setLatLng(currentLatLng)
|
|
170
|
+
} else {
|
|
171
|
+
polygonHintMarker = L.marker(currentLatLng, { interactive: false }).setIcon(hintMarkerIcon).addTo(drawHelpItems)
|
|
172
|
+
}
|
|
173
|
+
if (polygonHintpolygon) {
|
|
174
|
+
polygonHintpolygon.setLatLngs(currentLatLngs)
|
|
175
|
+
} else {
|
|
176
|
+
polygonHintpolygon = L.polygon(polygonVertexes, { stroke: false, fillOpacity: 0.1 }).addTo(drawHelpItems)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}, 20)
|
|
180
|
+
|
|
181
|
+
// 创建文字标签
|
|
182
|
+
const createTextIcon = (value, className) => {
|
|
183
|
+
const iconWidth = value.length > 6 ? (value.length - 6) * 5 + 60 : 60
|
|
184
|
+
return L.divIcon({
|
|
185
|
+
html: `<div>${value}</div>`,
|
|
186
|
+
className: `icon--simple-text ${className}`,
|
|
187
|
+
iconSize: [iconWidth, 18]
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 地图测量组合式函数
|
|
192
|
+
export function useMapMeasure() {
|
|
193
|
+
const DrawStatus = ref(false)
|
|
194
|
+
|
|
195
|
+
// 启动插件
|
|
196
|
+
const EnableMeasure = v => {
|
|
197
|
+
map = v
|
|
198
|
+
map.pm.setLang('zh')
|
|
199
|
+
|
|
200
|
+
drawItems.clearLayers().addTo(map)
|
|
201
|
+
drawHelpItems.clearLayers().addTo(map)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 开始绘制
|
|
205
|
+
const StartMeasure = shape => {
|
|
206
|
+
registerDrawEvents()
|
|
207
|
+
map.pm.enableDraw(shape)
|
|
208
|
+
DrawStatus.value = true
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// 取消当前绘制
|
|
212
|
+
const CancelMeasure = () => {
|
|
213
|
+
// 清理辅助层,避免在DrawEnd中被转移
|
|
214
|
+
drawHelpItems.clearLayers()
|
|
215
|
+
map.pm.Draw.getShapes().forEach(v => {
|
|
216
|
+
map.pm.disableDraw(v)
|
|
217
|
+
})
|
|
218
|
+
// 画布空白时,切换绘制状态
|
|
219
|
+
if (drawItems.getLayers().length == 0) {
|
|
220
|
+
DrawStatus.value = false
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// 结束绘制,清理画布
|
|
225
|
+
const ClearMeasure = () => {
|
|
226
|
+
CancelMeasure()
|
|
227
|
+
drawItems.clearLayers()
|
|
228
|
+
DrawStatus.value = false
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
onBeforeUnmount(() => {
|
|
232
|
+
ClearMeasure()
|
|
233
|
+
if (map) {
|
|
234
|
+
map.removeLayer(drawItems)
|
|
235
|
+
map.removeLayer(drawHelpItems)
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
DrawStatus,
|
|
241
|
+
EnableMeasure,
|
|
242
|
+
StartMeasure,
|
|
243
|
+
CancelMeasure,
|
|
244
|
+
ClearMeasure
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export default useMapMeasure
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { v4 as uuid } from 'uuid'
|
|
2
|
+
|
|
3
|
+
// 生成UUID
|
|
4
|
+
export const idGen = () => _.replace(uuid(), /-/g, '')
|
|
5
|
+
|
|
6
|
+
// 获取树结构首个断言为真的节点
|
|
7
|
+
export function getTreeNode(tree, predicate) {
|
|
8
|
+
// 转换断言
|
|
9
|
+
if (predicate && _.isPlainObject(predicate)) {
|
|
10
|
+
let predicateObj = predicate
|
|
11
|
+
predicate = function (e) {
|
|
12
|
+
let result = true
|
|
13
|
+
Object.keys(predicateObj).forEach(v => {
|
|
14
|
+
if (e[v] != predicateObj[v]) {
|
|
15
|
+
result = false
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
return result
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// 递归
|
|
22
|
+
function recurTree(src = [], result) {
|
|
23
|
+
src.forEach(e => {
|
|
24
|
+
if (predicate && _.isObject(predicate) && !result) {
|
|
25
|
+
if (predicate(e)) {
|
|
26
|
+
result = e
|
|
27
|
+
} else if (e.children && Array.isArray(e.children)) {
|
|
28
|
+
result = recurTree(e.children, result) || result
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
return result
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return recurTree(tree)
|
|
36
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { observeElementResize } from '@/composables/useResizeObserver'
|
|
2
|
+
|
|
3
|
+
const legacyRegistry = new WeakMap()
|
|
4
|
+
|
|
5
|
+
export const addResizeListener = function (element, fn) {
|
|
6
|
+
if (!element || typeof fn !== 'function') {
|
|
7
|
+
return
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let listeners = legacyRegistry.get(element)
|
|
11
|
+
if (!listeners) {
|
|
12
|
+
listeners = new Map()
|
|
13
|
+
legacyRegistry.set(element, listeners)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (listeners.has(fn)) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const stop = observeElementResize(element, fn)
|
|
21
|
+
listeners.set(fn, stop)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const removeResizeListener = function (element, fn) {
|
|
25
|
+
if (!element) {
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const listeners = legacyRegistry.get(element)
|
|
30
|
+
if (!listeners) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const stop = listeners.get(fn)
|
|
35
|
+
if (!stop) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
stop()
|
|
40
|
+
listeners.delete(fn)
|
|
41
|
+
|
|
42
|
+
if (listeners.size === 0) {
|
|
43
|
+
legacyRegistry.delete(element)
|
|
44
|
+
}
|
|
45
|
+
}
|
package/vite.config.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import vue from '@vitejs/plugin-vue'
|
|
3
|
+
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import { fileURLToPath } from 'url'
|
|
6
|
+
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
8
|
+
|
|
9
|
+
export default defineConfig(({ command }) => ({
|
|
10
|
+
plugins: [vue(), vueJsx()],
|
|
11
|
+
resolve: {
|
|
12
|
+
alias: {
|
|
13
|
+
'@': path.resolve(__dirname, 'src')
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
server: {
|
|
17
|
+
port: 6602,
|
|
18
|
+
open: false
|
|
19
|
+
},
|
|
20
|
+
build: {
|
|
21
|
+
outDir: 'vae-map',
|
|
22
|
+
sourcemap: false
|
|
23
|
+
},
|
|
24
|
+
base: command === 'serve' ? '/' : '/vae-map/'
|
|
25
|
+
}))
|