@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.
Files changed (86) hide show
  1. package/README.md +3 -0
  2. package/build/index.mjs +113 -0
  3. package/examples/App.vue +18 -0
  4. package/examples/index.js +13 -0
  5. package/examples/router/index.js +35 -0
  6. package/examples/views/amap.vue +29 -0
  7. package/examples/views/amarker.vue +58 -0
  8. package/examples/views/buffer.vue +66 -0
  9. package/examples/views/cluster.vue +74 -0
  10. package/examples/views/cover.vue +85 -0
  11. package/examples/views/draw-line.vue +49 -0
  12. package/examples/views/draw.vue +54 -0
  13. package/examples/views/echarts.vue +142 -0
  14. package/examples/views/emarker.vue +39 -0
  15. package/examples/views/image.vue +182 -0
  16. package/examples/views/index.vue +61 -0
  17. package/examples/views/lrmap.vue +108 -0
  18. package/examples/views/map.vue +82 -0
  19. package/examples/views/measure.vue +86 -0
  20. package/examples/views/parts/popup.vue +39 -0
  21. package/examples/views/parts/tooltip.vue +39 -0
  22. package/examples/views/push-area.vue +52 -0
  23. package/examples/views/push-line.vue +84 -0
  24. package/examples/views/trace.vue +49 -0
  25. package/index.html +13 -0
  26. package/jsconfig.json +17 -0
  27. package/package.json +47 -0
  28. package/public/favicon.ico +0 -0
  29. package/public/images/game.png +0 -0
  30. package/public/images/grid.png +0 -0
  31. package/public/images/marker.png +0 -0
  32. package/public/index.html +30 -0
  33. package/src/components/resize-listener/component.jsx +30 -0
  34. package/src/components/resize-listener/index.js +3 -0
  35. package/src/composables/useAutoMessage.js +41 -0
  36. package/src/composables/useContextMenu.js +99 -0
  37. package/src/composables/useMapMeasure.js +191 -0
  38. package/src/composables/useResizeObserver.js +81 -0
  39. package/src/mixins/message.js +1 -0
  40. package/src/packages/index.js +16 -0
  41. package/src/packages/vae-amap/index.js +8 -0
  42. package/src/packages/vae-amap/style.less +9 -0
  43. package/src/packages/vae-amap/vae-amap.jsx +98 -0
  44. package/src/packages/vae-cloudmap/ctrl-context-menu/index.vue +74 -0
  45. package/src/packages/vae-cloudmap/ctrl-draw/index.vue +499 -0
  46. package/src/packages/vae-cloudmap/ctrl-draw-line/index.vue +161 -0
  47. package/src/packages/vae-cloudmap/index.js +57 -0
  48. package/src/packages/vae-cloudmap/scripts/L.MarkerCluster/index.js +2690 -0
  49. package/src/packages/vae-cloudmap/scripts/L.MarkerCluster/style.css +14 -0
  50. package/src/packages/vae-cloudmap/scripts/L.Vae.CRS/index.js +212 -0
  51. package/src/packages/vae-cloudmap/scripts/L.Vae.Client/index.js +780 -0
  52. package/src/packages/vae-cloudmap/scripts/Mixin.ContextMenu/index.js +101 -0
  53. package/src/packages/vae-cloudmap/style.less +163 -0
  54. package/src/packages/vae-cloudmap/vae-cloudmap.jsx +272 -0
  55. package/src/packages/vae-map/ctrl-context-menu/index.vue +74 -0
  56. package/src/packages/vae-map/ctrl-draw/index.vue +498 -0
  57. package/src/packages/vae-map/ctrl-draw-line/index.vue +128 -0
  58. package/src/packages/vae-map/index.js +59 -0
  59. package/src/packages/vae-map/scripts/L.MarkerCluster/index.js +2690 -0
  60. package/src/packages/vae-map/scripts/L.MarkerCluster/style.css +14 -0
  61. package/src/packages/vae-map/scripts/L.Vae.CRS/index.js +114 -0
  62. package/src/packages/vae-map/scripts/L.Vae.Client/index.js +548 -0
  63. package/src/packages/vae-map/scripts/Mixin.ContextMenu/index.js +1 -0
  64. package/src/packages/vae-map/style.less +161 -0
  65. package/src/packages/vae-map/vae-lrmap.jsx +237 -0
  66. package/src/packages/vae-map/vae-map.jsx +135 -0
  67. package/src/plugins/L.AnimatedMarker/index.js +158 -0
  68. package/src/plugins/L.EchartsLayer/index.js +339 -0
  69. package/src/plugins/L.ElasticMarker/index.js +162 -0
  70. package/src/plugins/L.FootageCalculator.Area/index.js +263 -0
  71. package/src/plugins/L.FootageCalculator.Line/index.js +273 -0
  72. package/src/plugins/L.GeoUtil/buffer.js +67 -0
  73. package/src/plugins/L.GeoUtil/index.js +284 -0
  74. package/src/plugins/L.Glyphicon/index.js +91 -0
  75. package/src/plugins/L.Glyphicon/style.less +37 -0
  76. package/src/plugins/L.MarkerClusterX/index.js +93 -0
  77. package/src/plugins/L.MarkerClusterX/style.less +162 -0
  78. package/src/plugins/L.SafeDivOverlay/index.js +55 -0
  79. package/src/plugins/L.TileLayer.ChinaProvider/index.js +108 -0
  80. package/src/plugins/L.VuePopup/index.js +67 -0
  81. package/src/plugins/L.VueTooltip/index.js +63 -0
  82. package/src/plugins/Mixin.Map.Measure/index.js +248 -0
  83. package/src/plugins/globals/index.js +7 -0
  84. package/src/utils/index.js +36 -0
  85. package/src/utils/resize-event.js +45 -0
  86. package/vite.config.mjs +25 -0
@@ -0,0 +1,191 @@
1
+ import { onBeforeUnmount, ref } from 'vue'
2
+
3
+ let map
4
+ let drawItems = L.featureGroup()
5
+ let drawHelpItems = L.featureGroup()
6
+ let currentLatLng
7
+ let lineVertexes = []
8
+ let lineCurrentDistance
9
+ let lineHintMarker
10
+ let polygonVertexes = []
11
+ let polygonCurrentArea
12
+ let polygonHintMarker
13
+ let polygonHintpolygon
14
+
15
+ const createTextIcon = (value, className) => {
16
+ const iconWidth = value.length > 6 ? (value.length - 6) * 5 + 60 : 60
17
+ return L.divIcon({
18
+ html: `<div>${value}</div>`,
19
+ className: `icon--simple-text ${className ?? ''}`.trim(),
20
+ iconSize: [iconWidth, 18]
21
+ })
22
+ }
23
+
24
+ const unregisterDrawEvents = () => {
25
+ map?.off('pm:create', Events.onLayerCreate)
26
+ map?.off('pm:drawstart', Events.onDrawStart)
27
+ map?.off('pm:drawend', Events.onDrawEnd)
28
+ }
29
+
30
+ const handleMouseMoveAtLine = _.throttle((event) => {
31
+ currentLatLng = event.latlng
32
+ const currentLatLngs = _.concat(lineVertexes, currentLatLng)
33
+ lineCurrentDistance = L.GeoUtil.distanceByLatLngs(currentLatLngs, map)
34
+
35
+ if (lineVertexes.length > 0) {
36
+ const hintMarkerIcon = createTextIcon(L.GeometryUtil.readableDistance(lineCurrentDistance), 'dark')
37
+ if (lineHintMarker) {
38
+ lineHintMarker.setIcon(hintMarkerIcon).setLatLng(currentLatLng)
39
+ } else {
40
+ lineHintMarker = L.marker(currentLatLng, { interactive: false }).setIcon(hintMarkerIcon).addTo(drawHelpItems)
41
+ }
42
+ }
43
+ }, 20)
44
+
45
+ const handleMouseMoveAtPolygon = _.throttle((event) => {
46
+ currentLatLng = event.latlng
47
+ const currentLatLngs = _.concat(polygonVertexes, currentLatLng)
48
+
49
+ let useLatLng = true
50
+ if (map.vae && !map.vae.crs.code) {
51
+ useLatLng = false
52
+ }
53
+
54
+ polygonCurrentArea = useLatLng
55
+ ? L.GeoUtil.areaByLatLngs(currentLatLngs)
56
+ : L.GeoUtil.areaByPoints(currentLatLngs.map((value) => ({ x: value.lat, y: value.lng })))
57
+
58
+ if (polygonVertexes.length > 1) {
59
+ const hintMarkerIcon = createTextIcon(L.GeoUtil.readableArea(polygonCurrentArea), 'dark')
60
+ if (polygonHintMarker) {
61
+ polygonHintMarker.setIcon(hintMarkerIcon).setLatLng(currentLatLng)
62
+ } else {
63
+ polygonHintMarker = L.marker(currentLatLng, { interactive: false }).setIcon(hintMarkerIcon).addTo(drawHelpItems)
64
+ }
65
+
66
+ if (polygonHintpolygon) {
67
+ polygonHintpolygon.setLatLngs(currentLatLngs)
68
+ } else {
69
+ polygonHintpolygon = L.polygon(polygonVertexes, { stroke: false, fillOpacity: 0.1 }).addTo(drawHelpItems)
70
+ }
71
+ }
72
+ }, 20)
73
+
74
+ const Events = {
75
+ onLayerCreate(event) {
76
+ event.layer.remove().addTo(drawItems)
77
+ if (event.shape === 'Polygon') {
78
+ const hintMarkerIcon = createTextIcon(L.GeoUtil.readableArea(polygonCurrentArea))
79
+ L.marker(currentLatLng, { interactive: false }).setIcon(hintMarkerIcon).addTo(drawItems)
80
+ }
81
+ },
82
+ onDrawStart(event) {
83
+ const workingLayer = event.workingLayer
84
+ if (event.shape === 'Line') {
85
+ map.on('mousemove', handleMouseMoveAtLine)
86
+ workingLayer.on('pm:vertexadded', (vertex) => {
87
+ const hintMarker = L.marker(vertex.latlng, { interactive: false })
88
+ lineVertexes = workingLayer._latlngs
89
+ if (lineVertexes.length === 1) {
90
+ hintMarker.setIcon(createTextIcon('测距起点')).addTo(drawHelpItems)
91
+ } else {
92
+ const distanceText = L.GeometryUtil.readableDistance(lineCurrentDistance)
93
+ hintMarker.setIcon(createTextIcon(distanceText)).addTo(drawHelpItems)
94
+ }
95
+ })
96
+ } else if (event.shape === 'Polygon') {
97
+ map.on('mousemove', handleMouseMoveAtPolygon)
98
+ workingLayer.on('pm:vertexadded', () => {
99
+ polygonVertexes = workingLayer._latlngs
100
+ })
101
+ }
102
+ },
103
+ onDrawEnd(event) {
104
+ if (event.shape === 'Line') {
105
+ map.off('mousemove', handleMouseMoveAtLine)
106
+ if (lineHintMarker) {
107
+ drawHelpItems.removeLayer(lineHintMarker)
108
+ lineHintMarker = null
109
+ }
110
+ lineVertexes = []
111
+ currentLatLng = null
112
+ lineCurrentDistance = null
113
+ } else if (event.shape === 'Polygon') {
114
+ map.off('mousemove', handleMouseMoveAtPolygon)
115
+ if (polygonHintMarker) {
116
+ drawHelpItems.removeLayer(polygonHintMarker)
117
+ polygonHintMarker = null
118
+ }
119
+ if (polygonHintpolygon) {
120
+ drawHelpItems.removeLayer(polygonHintpolygon)
121
+ polygonHintpolygon = null
122
+ }
123
+ polygonVertexes = []
124
+ currentLatLng = null
125
+ polygonCurrentArea = null
126
+ }
127
+
128
+ drawHelpItems.eachLayer((layer) => {
129
+ drawHelpItems.removeLayer(layer)
130
+ layer.addTo(drawItems)
131
+ })
132
+ drawHelpItems.clearLayers()
133
+ unregisterDrawEvents()
134
+ }
135
+ }
136
+
137
+ const registerDrawEvents = () => {
138
+ map?.on('pm:create', Events.onLayerCreate)
139
+ map?.on('pm:drawstart', Events.onDrawStart)
140
+ map?.on('pm:drawend', Events.onDrawEnd)
141
+ }
142
+
143
+ export function useMapMeasure() {
144
+ const drawStatus = ref(false)
145
+
146
+ const enableMeasure = (value) => {
147
+ map = value
148
+ map.pm.setLang('zh')
149
+ drawItems.clearLayers().addTo(map)
150
+ drawHelpItems.clearLayers().addTo(map)
151
+ }
152
+
153
+ const startMeasure = (shape) => {
154
+ registerDrawEvents()
155
+ map.pm.enableDraw(shape)
156
+ drawStatus.value = true
157
+ }
158
+
159
+ const cancelMeasure = () => {
160
+ drawHelpItems.clearLayers()
161
+ map.pm.Draw.getShapes().forEach((shape) => {
162
+ map.pm.disableDraw(shape)
163
+ })
164
+
165
+ if (drawItems.getLayers().length === 0) {
166
+ drawStatus.value = false
167
+ }
168
+ }
169
+
170
+ const clearMeasure = () => {
171
+ cancelMeasure()
172
+ drawItems.clearLayers()
173
+ drawStatus.value = false
174
+ }
175
+
176
+ onBeforeUnmount(() => {
177
+ clearMeasure()
178
+ if (map) {
179
+ map.removeLayer(drawItems)
180
+ map.removeLayer(drawHelpItems)
181
+ }
182
+ })
183
+
184
+ return {
185
+ DrawStatus: drawStatus,
186
+ EnableMeasure: enableMeasure,
187
+ StartMeasure: startMeasure,
188
+ CancelMeasure: cancelMeasure,
189
+ ClearMeasure: clearMeasure
190
+ }
191
+ }
@@ -0,0 +1,81 @@
1
+ import { onBeforeUnmount, unref, watch } from 'vue'
2
+
3
+ const observerRegistry = new WeakMap()
4
+
5
+ function normalizeEntry(entry) {
6
+ return {
7
+ width: entry.contentRect.width,
8
+ height: entry.contentRect.height,
9
+ visible: !!(entry.contentRect.height && entry.contentRect.width),
10
+ entry
11
+ }
12
+ }
13
+
14
+ function getOrCreateRecord(element) {
15
+ let record = observerRegistry.get(element)
16
+ if (!record) {
17
+ record = {
18
+ listeners: new Set(),
19
+ observer: new ResizeObserver((entries) => {
20
+ for (const entry of entries) {
21
+ const current = observerRegistry.get(entry.target)
22
+ if (!current) {
23
+ continue
24
+ }
25
+ const payload = normalizeEntry(entry)
26
+ current.listeners.forEach((listener) => listener(payload))
27
+ }
28
+ })
29
+ }
30
+ record.observer.observe(element)
31
+ observerRegistry.set(element, record)
32
+ }
33
+ return record
34
+ }
35
+
36
+ function cleanupRecord(element) {
37
+ const record = observerRegistry.get(element)
38
+ if (!record || record.listeners.size > 0) {
39
+ return
40
+ }
41
+ record.observer.disconnect()
42
+ observerRegistry.delete(element)
43
+ }
44
+
45
+ export function observeElementResize(element, callback) {
46
+ if (!element || typeof callback !== 'function') {
47
+ return () => {}
48
+ }
49
+ const record = getOrCreateRecord(element)
50
+ record.listeners.add(callback)
51
+
52
+ return () => {
53
+ const current = observerRegistry.get(element)
54
+ if (!current) {
55
+ return
56
+ }
57
+ current.listeners.delete(callback)
58
+ cleanupRecord(element)
59
+ }
60
+ }
61
+
62
+ export function useElementResize(target, callback) {
63
+ let stop = null
64
+
65
+ const bind = (element) => {
66
+ stop?.()
67
+ stop = element ? observeElementResize(element, callback) : null
68
+ }
69
+
70
+ watch(
71
+ () => unref(target),
72
+ (element) => {
73
+ bind(element)
74
+ },
75
+ { immediate: true }
76
+ )
77
+
78
+ onBeforeUnmount(() => {
79
+ stop?.()
80
+ })
81
+ }
@@ -0,0 +1 @@
1
+ export { useAutoMessage as default } from '@/composables/useAutoMessage'
@@ -0,0 +1,16 @@
1
+ import '@/plugins/globals'
2
+
3
+ import VaeAmap from './vae-amap/index.js'
4
+ import VaeMap from './vae-map/index.js'
5
+ import VaeCloudmap from './vae-cloudmap'
6
+ const components = [VaeAmap, VaeMap, VaeCloudmap]
7
+
8
+ const install = (app, options = {}) => {
9
+ components.forEach((component) => {
10
+ app.use(component, options)
11
+ })
12
+ }
13
+
14
+ export { VaeAmap, VaeMap, VaeCloudmap }
15
+
16
+ export default { install }
@@ -0,0 +1,8 @@
1
+ import VaeAmap from './vae-amap.jsx'
2
+ import './style.less'
3
+
4
+ VaeAmap.install = (app, options = {}) => {
5
+ app.component(`${options.prefix || 'vae'}-amap`, VaeAmap)
6
+ }
7
+
8
+ export default VaeAmap
@@ -0,0 +1,9 @@
1
+ .vae-amap {
2
+ .amap-logo {
3
+ opacity: 0;
4
+ }
5
+
6
+ .amap-copyright {
7
+ opacity: 0;
8
+ }
9
+ }
@@ -0,0 +1,98 @@
1
+ import { defineComponent, onBeforeUnmount, onMounted, ref, watch } from 'vue'
2
+ import AMapLoader from '@amap/amap-jsapi-loader'
3
+ import { idGen } from '@/utils'
4
+
5
+ export default defineComponent({
6
+ name: 'VaeAmap',
7
+ props: {
8
+ height: {
9
+ type: String,
10
+ default: '100%'
11
+ },
12
+ width: {
13
+ type: String,
14
+ default: '100%'
15
+ },
16
+ apiKey: {
17
+ type: String,
18
+ default: ''
19
+ },
20
+ version: {
21
+ type: String,
22
+ default: '2.0'
23
+ },
24
+ plugins: {
25
+ type: Array,
26
+ default: () => []
27
+ },
28
+ options: {
29
+ type: Object,
30
+ default: () => ({})
31
+ }
32
+ },
33
+ emits: ['amap-ready', 'init-map'],
34
+ setup(props, { emit }) {
35
+ const uuid = ref(`vae_amap_${idGen()}`)
36
+ const amap = ref(null)
37
+
38
+ const redefineAMap = () => {
39
+ const originalConvertFrom = AMap.convertFrom
40
+ AMap.convertFrom = function (lnglat, type = 'gps') {
41
+ return new Promise((resolve) => {
42
+ originalConvertFrom(lnglat, type, (status, result) => {
43
+ resolve(result.locations)
44
+ })
45
+ })
46
+ }
47
+ }
48
+
49
+ const loadResource = async () => {
50
+ if (!window.AMap) {
51
+ await AMapLoader.load({
52
+ key: props.apiKey,
53
+ version: props.version,
54
+ plugins: props.plugins
55
+ })
56
+ redefineAMap()
57
+ }
58
+ emit('amap-ready')
59
+ }
60
+
61
+ const createMap = () => {
62
+ if (!amap.value && !_.isEmpty(props.options)) {
63
+ if (window.AMap) {
64
+ amap.value = new AMap.Map(uuid.value, props.options)
65
+ amap.value.on('complete', () => {
66
+ emit('init-map', amap.value)
67
+ })
68
+ } else {
69
+ console.error("AMap is not ready, set options in 'amap-ready' event")
70
+ }
71
+ }
72
+ }
73
+
74
+ watch(
75
+ () => props.options,
76
+ () => {
77
+ createMap()
78
+ },
79
+ { deep: true }
80
+ )
81
+
82
+ onMounted(() => {
83
+ loadResource()
84
+ })
85
+
86
+ onBeforeUnmount(() => {
87
+ amap.value?.destroy()
88
+ })
89
+
90
+ return () => (
91
+ <div
92
+ id={uuid.value}
93
+ class="vae-amap"
94
+ style={{ height: props.height, width: props.width }}>
95
+ </div>
96
+ )
97
+ }
98
+ })
@@ -0,0 +1,74 @@
1
+ <template>
2
+ <div class="vae-map-ctrl--context-menu" :style="style">
3
+ <template v-for="item in menus" :key="item.text">
4
+ <div class="item" :class="{ 'is-disabled': item.disabled, 'is-divided': item.divided }" @click="handleItemClick(item)">
5
+ {{ item.text }}
6
+ </div>
7
+ </template>
8
+ </div>
9
+ </template>
10
+
11
+ <script setup>
12
+ import { computed } from 'vue'
13
+
14
+ const props = defineProps({
15
+ left: {
16
+ type: Number,
17
+ default: 0
18
+ },
19
+ top: {
20
+ type: Number,
21
+ default: 0
22
+ },
23
+ menus: {
24
+ type: Array,
25
+ default: () => []
26
+ }
27
+ })
28
+
29
+ const emit = defineEmits(['callback'])
30
+
31
+ const handleItemClick = (item) => {
32
+ if (!item.disabled) {
33
+ emit('callback', item.callback)
34
+ }
35
+ }
36
+
37
+ const style = computed(() => ({
38
+ left: `${props.left}px`,
39
+ top: `${props.top}px`
40
+ }))
41
+ </script>
42
+
43
+ <style lang="less" scoped>
44
+ .vae-map-ctrl--context-menu {
45
+ position: absolute;
46
+ width: 200px;
47
+ background-color: white;
48
+ padding: 3px 0px;
49
+ box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2);
50
+ z-index: 2000;
51
+
52
+ .item {
53
+ height: 28px;
54
+ line-height: 28px;
55
+ font-size: 12px;
56
+ padding: 0px 12px;
57
+ letter-spacing: 1px;
58
+ cursor: default;
59
+
60
+ &:not(:first-child).is-divided {
61
+ border-top: 1px solid #dcdfe6;
62
+ }
63
+
64
+ &:hover {
65
+ background-color: #eee;
66
+ }
67
+
68
+ &.is-disabled {
69
+ color: #c0c4cc;
70
+ background-color: white;
71
+ }
72
+ }
73
+ }
74
+ </style>