web-component-gallery 2.2.20 → 2.2.21
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/dist/js.umd.js +1 -1
- package/lib/amap-draw/index.jsx +195 -251
- package/package.json +1 -1
package/lib/amap-draw/index.jsx
CHANGED
|
@@ -1,213 +1,203 @@
|
|
|
1
|
+
|
|
1
2
|
import AmapSearch from '../amap-comp/AmapSearch.jsx'
|
|
2
3
|
import PropTypes from 'ant-design-vue/es/_util/vue-types'
|
|
3
4
|
import { getAMapInstance } from '../../extensions/AMap.js'
|
|
4
5
|
|
|
5
6
|
const BASE_IP = process.env.VUE_APP_STATIC_URL || location.origin
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
// 统一配置管理
|
|
9
|
+
const CONFIG = {
|
|
10
|
+
drawTypes: {
|
|
11
|
+
point: 'marker',
|
|
12
|
+
line: 'polyline',
|
|
13
|
+
polygon: 'polygon'
|
|
14
|
+
},
|
|
15
|
+
layers: ['电子', '卫星']
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const AmapDrawProps = {
|
|
19
|
+
// 地图容器实例名称
|
|
9
20
|
drawEl: PropTypes.string.def('AmapDraw'),
|
|
10
|
-
|
|
11
|
-
* 可选值(point点 | line线 | polygon面)
|
|
12
|
-
*/
|
|
21
|
+
// 绘制类型
|
|
13
22
|
drawType: PropTypes.string.def('point'),
|
|
14
|
-
|
|
23
|
+
// 绘制图标
|
|
15
24
|
drawIcon: PropTypes.any.def(`${BASE_IP}/poi/poi-marker-default.png`),
|
|
16
|
-
|
|
25
|
+
// 绘制个数
|
|
17
26
|
drawCount: PropTypes.number.def(1),
|
|
18
|
-
|
|
27
|
+
// 绘制物配置项
|
|
19
28
|
drawOptions: PropTypes.object.def({}),
|
|
20
|
-
|
|
21
|
-
drawInfo: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
22
|
-
|
|
23
|
-
* 格式: { point: ([]||{}), line: ([]||{}) }
|
|
24
|
-
*/
|
|
29
|
+
// 绘制物信息
|
|
30
|
+
drawInfo: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
31
|
+
// 所有不同类型绘制物信息 格式: { point: ([]||{}), line: ([]||{}) }
|
|
25
32
|
drawInfoAll: PropTypes.object,
|
|
26
|
-
|
|
33
|
+
// 限制区域
|
|
27
34
|
drawLimitArea: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
28
|
-
|
|
35
|
+
// 限制区域样式配置
|
|
29
36
|
drawLimitAreaOptions: PropTypes.object.def({}),
|
|
30
|
-
|
|
37
|
+
// 纯地图展示数据
|
|
31
38
|
isExhibition: PropTypes.bool.def(false),
|
|
32
|
-
|
|
33
|
-
drawButtonOperate: PropTypes.
|
|
39
|
+
// 自定义绘制操作
|
|
40
|
+
drawButtonOperate: PropTypes.array
|
|
34
41
|
}
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
export default {
|
|
37
44
|
name: 'AmapDraw',
|
|
38
45
|
props: AmapDrawProps,
|
|
46
|
+
|
|
39
47
|
data() {
|
|
40
48
|
return {
|
|
49
|
+
// 地图实例
|
|
41
50
|
amap: null,
|
|
42
|
-
|
|
51
|
+
// 地图存储商店
|
|
43
52
|
amapStore: null,
|
|
44
53
|
drawArea: null,
|
|
45
54
|
drawLayers: null,
|
|
46
55
|
drawMouseTool: null,
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
drawOperates: [
|
|
57
|
+
{ type: 'primary', text: '绘制', event: { click: this.handleDrawStart } },
|
|
58
|
+
{ text: '清除', event: { click: this.handleDrawClear } },
|
|
59
|
+
{ type: 'primary', text: '保存', event: { click: this.handleDrawSave } },
|
|
60
|
+
{ text: '取消', event: { click: this.handleDrawReset } }
|
|
61
|
+
],
|
|
62
|
+
// 地图类型
|
|
49
63
|
amapType: 1,
|
|
50
|
-
|
|
51
|
-
amapSatellite: null
|
|
64
|
+
// 卫星图
|
|
65
|
+
amapSatellite: null,
|
|
66
|
+
//记录当前活跃操作的下标,-1表示无活跃操作
|
|
67
|
+
activeOperateIndex: -1
|
|
52
68
|
}
|
|
53
69
|
},
|
|
70
|
+
|
|
54
71
|
computed: {
|
|
55
72
|
drawLayersInfo: {
|
|
56
|
-
get() {
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
set(newValue) {
|
|
73
|
+
get() { return this.drawInfo },
|
|
74
|
+
set(newValue) {
|
|
60
75
|
this.$emit('getAMapLayersInfo', this.initDrawInfo(newValue))
|
|
61
76
|
}
|
|
62
|
-
},
|
|
63
|
-
// 优化后的按钮配置
|
|
64
|
-
optimizedButtonProps() {
|
|
65
|
-
return {
|
|
66
|
-
draw: [
|
|
67
|
-
{ type: 'primary', text: '绘制', event: { click: this.handleDrawStart } },
|
|
68
|
-
{ text: '清除', event: { click: this.handleDrawClear } }
|
|
69
|
-
],
|
|
70
|
-
save: [
|
|
71
|
-
{ type: 'primary', text: '保存', event: { click: this.handleDrawSave } },
|
|
72
|
-
{ text: '取消', event: { click: this.handleDrawReset } }
|
|
73
|
-
],
|
|
74
|
-
...(this.drawButtonOperate || {})
|
|
75
|
-
}
|
|
76
77
|
}
|
|
77
78
|
},
|
|
79
|
+
|
|
78
80
|
watch: {
|
|
79
81
|
drawInfo: {
|
|
80
|
-
handler(newVal) {
|
|
81
|
-
newVal && this.echoDrawLayers(this.drawType)
|
|
82
|
-
},
|
|
82
|
+
handler(newVal) { newVal && this.echoDrawLayers(this.drawType) },
|
|
83
83
|
deep: true
|
|
84
84
|
},
|
|
85
|
-
drawInfoAll(newValue) {
|
|
86
|
-
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
/** 检测options覆盖物配置是否更改,更改后要同步到地图上 */
|
|
90
|
-
Object.keys(newValue).length && this.setOverlayOptions(newValue)
|
|
91
|
-
},
|
|
92
|
-
drawLimitArea(newValue) {
|
|
93
|
-
newValue && this.setDrawLimitArea()
|
|
94
|
-
}
|
|
85
|
+
drawInfoAll(newValue) { newValue && this.echoDrawLayers() },
|
|
86
|
+
// 检测options覆盖物配置是否更改,更改后要同步到地图上
|
|
87
|
+
drawOptions(newValue) { Object.keys(newValue).length && this.setOverlayOptions(newValue) },
|
|
88
|
+
drawLimitArea(newValue) { newValue && this.setDrawLimitArea() }
|
|
95
89
|
},
|
|
90
|
+
|
|
96
91
|
async mounted() {
|
|
97
92
|
this.amapStore = await getAMapInstance()
|
|
98
93
|
this.amap = this.amapStore.initMap(this.drawEl)
|
|
99
94
|
this.initMap()
|
|
100
|
-
|
|
95
|
+
|
|
96
|
+
if (this.drawButtonOperate?.length) {
|
|
97
|
+
this.drawOperates = this.drawButtonOperate.concat(this.drawOperates.slice(2))
|
|
98
|
+
}
|
|
99
|
+
|
|
101
100
|
this.echoDrawLayers(this.drawType)
|
|
102
|
-
|
|
101
|
+
// 如有限制区域,则描绘在地图上
|
|
103
102
|
this.drawLimitArea && this.setDrawLimitArea()
|
|
104
103
|
},
|
|
104
|
+
|
|
105
105
|
destroyed() {
|
|
106
|
-
this.
|
|
106
|
+
this.cleanupResources()
|
|
107
107
|
},
|
|
108
|
+
|
|
108
109
|
methods: {
|
|
109
|
-
|
|
110
|
-
* 初始化地图实例
|
|
111
|
-
*/
|
|
110
|
+
// 初始化地图实例
|
|
112
111
|
initMap() {
|
|
113
112
|
this.amap = this.amapStore.initMap(this.drawEl)
|
|
114
113
|
this.amapSatellite = new this.amapStore.AMap.TileLayer.Satellite()
|
|
115
114
|
this.amap.add(this.amapSatellite)
|
|
116
115
|
},
|
|
117
|
-
/**
|
|
118
|
-
* 根据绘制类型初始化绘制属性
|
|
119
|
-
*/
|
|
120
|
-
initDrawInfo(newVal) {
|
|
121
|
-
if (Object.keys(newVal).length) return newVal
|
|
122
|
-
|
|
123
|
-
if (this.drawType === 'point')
|
|
124
|
-
return {
|
|
125
|
-
longitude: null,
|
|
126
|
-
latitude: null,
|
|
127
|
-
address: null
|
|
128
|
-
}
|
|
129
116
|
|
|
130
|
-
|
|
117
|
+
// 根据绘制类型初始化绘制属性
|
|
118
|
+
initDrawInfo(newValue) {
|
|
119
|
+
return Object.keys(newValue).length ? newValue :
|
|
120
|
+
this.drawType === 'point' ?
|
|
121
|
+
{ longitude: null, latitude: null, address: null } :
|
|
122
|
+
{ range: null }
|
|
131
123
|
},
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
124
|
+
|
|
125
|
+
// 开始绘制
|
|
126
|
+
handleDrawStart(i = 0) {
|
|
127
|
+
if (this.activeOperateIndex === i) return this.$message.warning('已处于绘制模式!')
|
|
128
|
+
// 如果存在其他活跃操作项,先关闭并重置状态
|
|
129
|
+
if (this.activeOperateIndex !== -1 && this.activeOperateIndex !== i) {
|
|
130
|
+
this.drawMouseTool.close()
|
|
131
|
+
this.updateDrawOperateState('primary')
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this.activeOperateIndex = i
|
|
135
|
+
this.updateDrawOperateState('danger')
|
|
137
136
|
this.initDrawTool()
|
|
138
|
-
this.prepareDrawEnvironment()
|
|
139
|
-
|
|
140
|
-
this.drawMouseTool.on('draw', ({ obj }) => {
|
|
141
|
-
this.handleDrawComplete(obj)
|
|
142
|
-
})
|
|
143
137
|
},
|
|
144
138
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
this.
|
|
139
|
+
// 处理绘制完成事件
|
|
140
|
+
handleDrawComplete(drawObject) {
|
|
141
|
+
if (this.isOutOfBoundary(drawObject)) return
|
|
142
|
+
|
|
143
|
+
this.updateDrawLayers(drawObject)
|
|
144
|
+
|
|
145
|
+
if (this.isDrawComplete()) this.finishDrawing()
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
isOutOfBoundary(obj) {
|
|
149
|
+
if (!this.drawArea || this.checkInBoundary(obj)) return false
|
|
156
150
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
151
|
+
this.amap.remove(obj)
|
|
152
|
+
this.$message.error('未在范围内描绘!')
|
|
153
|
+
return true
|
|
160
154
|
},
|
|
161
155
|
|
|
162
|
-
|
|
163
|
-
* 检查绘制是否完成
|
|
164
|
-
*/
|
|
156
|
+
// 检查绘制是否完成
|
|
165
157
|
isDrawComplete() {
|
|
166
158
|
return this.drawLayers &&
|
|
167
159
|
(this.drawLayers.length === this.drawCount || this.drawCount === 1)
|
|
168
160
|
},
|
|
169
161
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
this.drawLayers.push(obj)
|
|
177
|
-
} else {
|
|
178
|
-
this.drawLayers = obj
|
|
179
|
-
}
|
|
162
|
+
// 结束绘制
|
|
163
|
+
finishDrawing() {
|
|
164
|
+
this.drawMouseTool.close()
|
|
165
|
+
this.updateDrawOperateState('primary')
|
|
166
|
+
this.activeOperateIndex = -1
|
|
167
|
+
this.$message.success('绘制结束!')
|
|
180
168
|
},
|
|
181
169
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
170
|
+
// 更新绘制物
|
|
171
|
+
updateDrawLayers(drawObject) {
|
|
172
|
+
this.drawLayers = this.drawCount > 1 ?
|
|
173
|
+
(this.drawLayers || []).concat(drawObject) :
|
|
174
|
+
drawObject
|
|
175
|
+
|
|
176
|
+
// 实时保存绘制
|
|
177
|
+
this.assignDrawLayers(this.drawType)
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
// 清除绘制
|
|
185
181
|
handleDrawClear() {
|
|
186
182
|
this.cleanOverlays()
|
|
187
183
|
this.drawLayers = null
|
|
188
184
|
this.drawLayersInfo = {}
|
|
189
185
|
},
|
|
190
186
|
|
|
191
|
-
|
|
192
|
-
* 保存绘制
|
|
193
|
-
*/
|
|
187
|
+
// 保存绘制
|
|
194
188
|
handleDrawSave() {
|
|
195
|
-
if (!this.drawLayers)
|
|
189
|
+
if (!this.drawLayers) {
|
|
190
|
+
return this.$message.error('请先在地图上绘制!')
|
|
191
|
+
}
|
|
196
192
|
this.assignDrawLayers(this.drawType)
|
|
197
|
-
this.buttonProps = [...this.optimizedButtonProps.draw]
|
|
198
193
|
},
|
|
199
194
|
|
|
200
|
-
|
|
201
|
-
* 取消绘制
|
|
202
|
-
*/
|
|
195
|
+
// 取消绘制
|
|
203
196
|
handleDrawReset() {
|
|
204
|
-
this.buttonProps = [...this.optimizedButtonProps.draw]
|
|
205
197
|
this.handleDrawClear()
|
|
206
198
|
},
|
|
207
199
|
|
|
208
|
-
|
|
209
|
-
* 搜索地址选择
|
|
210
|
-
*/
|
|
200
|
+
// 搜索地址选择
|
|
211
201
|
searchChoose(searchMarker, searchInfo) {
|
|
212
202
|
this.handleDrawClear()
|
|
213
203
|
searchMarker.setMap(this.amap)
|
|
@@ -215,22 +205,15 @@ const AmapDraw = {
|
|
|
215
205
|
this.drawType === 'point' && (this.drawLayersInfo = searchInfo)
|
|
216
206
|
},
|
|
217
207
|
|
|
218
|
-
|
|
219
|
-
* 设置覆盖物选项
|
|
220
|
-
*/
|
|
208
|
+
// 设置覆盖物参数
|
|
221
209
|
setOverlayOptions(options) {
|
|
222
210
|
if (!this.drawLayers) return
|
|
223
211
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
} else {
|
|
227
|
-
this.drawLayers.setOptions(options)
|
|
228
|
-
}
|
|
212
|
+
const layers = Array.isArray(this.drawLayers) ? this.drawLayers : [this.drawLayers]
|
|
213
|
+
layers.forEach(item => item.setOptions(options))
|
|
229
214
|
},
|
|
230
215
|
|
|
231
|
-
|
|
232
|
-
* 设置绘制限制区域
|
|
233
|
-
*/
|
|
216
|
+
// 设置绘制限制区域
|
|
234
217
|
setDrawLimitArea() {
|
|
235
218
|
let areaRange = []
|
|
236
219
|
try {
|
|
@@ -244,9 +227,7 @@ const AmapDraw = {
|
|
|
244
227
|
this.validateOverlays()
|
|
245
228
|
},
|
|
246
229
|
|
|
247
|
-
|
|
248
|
-
* 设置地图区域范围
|
|
249
|
-
*/
|
|
230
|
+
// 设置地图区域范围
|
|
250
231
|
setMapArea(jurisdictionRange) {
|
|
251
232
|
this.drawArea = new this.amapStore.AMap.Polygon({
|
|
252
233
|
map: this.amap,
|
|
@@ -260,36 +241,30 @@ const AmapDraw = {
|
|
|
260
241
|
this.amap.setZoomAndCenter(15, [lng, lat])
|
|
261
242
|
},
|
|
262
243
|
|
|
263
|
-
|
|
264
|
-
* 验证覆盖物是否在边界内
|
|
265
|
-
*/
|
|
244
|
+
// 验证覆盖物是否在边界内
|
|
266
245
|
validateOverlays() {
|
|
267
|
-
this.amap.getAllOverlays().forEach(
|
|
268
|
-
if (
|
|
269
|
-
this.removeOverlay(
|
|
246
|
+
this.amap.getAllOverlays().forEach(layer => {
|
|
247
|
+
if (layer.getExtData() !== 'Area' && !this.checkInBoundary(layer)) {
|
|
248
|
+
this.removeOverlay(layer)
|
|
270
249
|
}
|
|
271
250
|
})
|
|
272
251
|
},
|
|
273
252
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
*/
|
|
277
|
-
checkInBoundary(obj) {
|
|
253
|
+
// 检查是否在边界内
|
|
254
|
+
checkInBoundary(object) {
|
|
278
255
|
const type = this.drawType
|
|
279
|
-
return type === 'line' ?
|
|
256
|
+
return type === 'line' ?
|
|
257
|
+
this.isLineInBoundary(object) :
|
|
258
|
+
this.isPointInBoundary(object)
|
|
280
259
|
},
|
|
281
260
|
|
|
282
|
-
|
|
283
|
-
* 检查线段是否在边界内
|
|
284
|
-
*/
|
|
261
|
+
// 检查线段是否在边界内
|
|
285
262
|
isLineInBoundary(polyline) {
|
|
286
263
|
const paths = polyline.getPath()
|
|
287
|
-
return paths.every(
|
|
264
|
+
return paths.every(point => this.isPointInBoundary(point))
|
|
288
265
|
},
|
|
289
266
|
|
|
290
|
-
|
|
291
|
-
* 检查点是否在边界内
|
|
292
|
-
*/
|
|
267
|
+
// 检查点是否在边界内
|
|
293
268
|
isPointInBoundary(point) {
|
|
294
269
|
let position
|
|
295
270
|
try {
|
|
@@ -297,19 +272,22 @@ const AmapDraw = {
|
|
|
297
272
|
} catch {
|
|
298
273
|
position = point
|
|
299
274
|
}
|
|
300
|
-
return this.amapStore.AMap.GeometryUtil.isPointInRing(
|
|
275
|
+
return this.amapStore.AMap.GeometryUtil.isPointInRing(
|
|
276
|
+
position,
|
|
277
|
+
this.drawArea.getPath()
|
|
278
|
+
)
|
|
301
279
|
},
|
|
302
280
|
|
|
303
|
-
|
|
304
|
-
* 移除覆盖物
|
|
305
|
-
*/
|
|
281
|
+
// 移除覆盖物
|
|
306
282
|
removeOverlay(layerItem) {
|
|
307
283
|
this.amap.remove(layerItem)
|
|
308
|
-
this.$message.error('未在区域范围内,请重新描绘!')
|
|
284
|
+
this.$message.error('未在区域范围内,请重新描绘!')
|
|
309
285
|
|
|
310
286
|
try {
|
|
311
287
|
if (Array.isArray(this.drawLayers)) {
|
|
312
|
-
const index = this.drawLayers.findIndex(
|
|
288
|
+
const index = this.drawLayers.findIndex(
|
|
289
|
+
layer => layer.getExtData() === layerItem.getExtData()
|
|
290
|
+
)
|
|
313
291
|
if (index !== -1) {
|
|
314
292
|
this.drawLayers.splice(index, 1)
|
|
315
293
|
}
|
|
@@ -322,61 +300,39 @@ const AmapDraw = {
|
|
|
322
300
|
}
|
|
323
301
|
},
|
|
324
302
|
|
|
325
|
-
|
|
326
|
-
* 初始化绘制工具
|
|
327
|
-
*/
|
|
303
|
+
// 初始化绘制工具
|
|
328
304
|
initDrawTool() {
|
|
329
305
|
this.drawMouseTool = new this.amapStore.AMap.MouseTool(this.amap)
|
|
330
306
|
this.handleDrawClear()
|
|
331
307
|
this.prepareDrawLayers(this.drawType)
|
|
332
|
-
},
|
|
333
308
|
|
|
334
|
-
|
|
335
|
-
* 准备绘制环境
|
|
336
|
-
*/
|
|
337
|
-
prepareDrawEnvironment() {
|
|
309
|
+
// 准备绘制环境
|
|
338
310
|
this.drawMouseTool.on('draw', ({ obj }) => {
|
|
339
311
|
this.handleDrawComplete(obj)
|
|
340
312
|
})
|
|
341
313
|
},
|
|
342
314
|
|
|
343
|
-
|
|
344
|
-
* 准备绘制图层
|
|
345
|
-
*/
|
|
315
|
+
// 准备绘制图层
|
|
346
316
|
async prepareDrawLayers(drawType) {
|
|
347
|
-
const
|
|
348
|
-
point: 'marker',
|
|
349
|
-
line: 'polyline',
|
|
350
|
-
polygon: 'polygon'
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
const baseOptions = drawType === 'point'
|
|
354
|
-
? {
|
|
317
|
+
const baseOptions = drawType === 'point' ? {
|
|
355
318
|
anchor: 'bottom-center',
|
|
356
319
|
icon: await this.amapStore.setIcon(this.drawIcon)
|
|
357
|
-
}
|
|
358
|
-
|
|
320
|
+
} : { strokeWeight: 8 }
|
|
321
|
+
|
|
322
|
+
console.log(drawType, '--drawType绘制类型')
|
|
359
323
|
|
|
360
|
-
this.drawMouseTool[
|
|
324
|
+
this.drawMouseTool[CONFIG.drawTypes[drawType]]({
|
|
361
325
|
...baseOptions,
|
|
362
326
|
...this.drawOptions
|
|
363
327
|
})
|
|
364
328
|
},
|
|
365
329
|
|
|
366
|
-
|
|
367
|
-
* 分配图层数据
|
|
368
|
-
*/
|
|
330
|
+
// 分配图层数据
|
|
369
331
|
assignDrawLayers(drawType) {
|
|
370
|
-
|
|
371
|
-
this.handlePointDraw()
|
|
372
|
-
return
|
|
373
|
-
}
|
|
374
|
-
this.handleShapeDraw()
|
|
332
|
+
drawType === 'point' ? this.handlePointDraw() : this.handleShapeDraw()
|
|
375
333
|
},
|
|
376
334
|
|
|
377
|
-
|
|
378
|
-
* 处理点绘制
|
|
379
|
-
*/
|
|
335
|
+
// 处理点绘制
|
|
380
336
|
handlePointDraw() {
|
|
381
337
|
const { lng, lat } = this.drawLayers.getPosition()
|
|
382
338
|
const position = { longitude: lng, latitude: lat }
|
|
@@ -389,51 +345,40 @@ const AmapDraw = {
|
|
|
389
345
|
})
|
|
390
346
|
},
|
|
391
347
|
|
|
392
|
-
|
|
393
|
-
* 处理形状绘制
|
|
394
|
-
*/
|
|
348
|
+
// 处理形状绘制
|
|
395
349
|
handleShapeDraw() {
|
|
396
350
|
const range = this.drawLayers.getPath().map(({ lng, lat }) => [lng, lat])
|
|
397
351
|
this.drawLayersInfo = { range }
|
|
398
352
|
},
|
|
399
353
|
|
|
400
|
-
|
|
401
|
-
* 回显绘制图层
|
|
402
|
-
*/
|
|
354
|
+
// 回显绘制图层
|
|
403
355
|
echoDrawLayers(drawType) {
|
|
404
356
|
if (!this.amapStore || !this.amap) return
|
|
405
357
|
|
|
406
358
|
this.cleanOverlays()
|
|
407
359
|
|
|
408
|
-
|
|
409
|
-
this.renderAllDrawLayers()
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
this.renderSingleDrawLayer(drawType)
|
|
360
|
+
this.drawInfoAll ?
|
|
361
|
+
this.renderAllDrawLayers() :
|
|
362
|
+
this.renderSingleDrawLayer(drawType)
|
|
414
363
|
},
|
|
415
364
|
|
|
416
|
-
|
|
417
|
-
* 清理覆盖物
|
|
418
|
-
*/
|
|
365
|
+
// 清理覆盖物
|
|
419
366
|
cleanOverlays() {
|
|
420
|
-
this.amap.getAllOverlays().forEach(
|
|
421
|
-
if (
|
|
422
|
-
this.amap.remove(
|
|
367
|
+
this.amap.getAllOverlays().forEach(layer => {
|
|
368
|
+
if (layer.getExtData() !== 'Area') {
|
|
369
|
+
this.amap.remove(layer)
|
|
423
370
|
}
|
|
424
371
|
})
|
|
425
372
|
},
|
|
426
373
|
|
|
427
|
-
|
|
428
|
-
* 渲染所有绘制图层
|
|
429
|
-
*/
|
|
374
|
+
// 渲染所有绘制图层
|
|
430
375
|
renderAllDrawLayers() {
|
|
431
376
|
for (const key in this.drawInfoAll) {
|
|
432
377
|
const isArray = Array.isArray(this.drawInfoAll[key])
|
|
433
378
|
|
|
434
379
|
if (isArray) {
|
|
435
|
-
this.drawInfoAll[key].forEach((
|
|
436
|
-
this.renderDrawLayer(
|
|
380
|
+
this.drawInfoAll[key].forEach((item, index) => {
|
|
381
|
+
this.renderDrawLayer(item, key, index)
|
|
437
382
|
})
|
|
438
383
|
} else {
|
|
439
384
|
this.renderDrawLayer(this.drawInfoAll[key], key)
|
|
@@ -441,16 +386,12 @@ const AmapDraw = {
|
|
|
441
386
|
}
|
|
442
387
|
},
|
|
443
388
|
|
|
444
|
-
|
|
445
|
-
* 渲染单个绘制图层
|
|
446
|
-
*/
|
|
389
|
+
// 渲染单个绘制图层
|
|
447
390
|
renderSingleDrawLayer(drawType) {
|
|
448
391
|
this.renderDrawLayer(this.drawLayersInfo, drawType)
|
|
449
392
|
},
|
|
450
393
|
|
|
451
|
-
|
|
452
|
-
* 渲染绘制图层
|
|
453
|
-
*/
|
|
394
|
+
// 渲染绘制图层
|
|
454
395
|
async renderDrawLayer(drawItem, type, index = 0) {
|
|
455
396
|
if (!drawItem) return
|
|
456
397
|
|
|
@@ -462,10 +403,10 @@ const AmapDraw = {
|
|
|
462
403
|
...this.drawOptions
|
|
463
404
|
}
|
|
464
405
|
|
|
465
|
-
let
|
|
406
|
+
let layerItem = null
|
|
466
407
|
|
|
467
408
|
if (type === 'point') {
|
|
468
|
-
|
|
409
|
+
layerItem = await this.amapStore.setMarker(this.drawIcon, {
|
|
469
410
|
position: [longitude, latitude],
|
|
470
411
|
...setOptions
|
|
471
412
|
})
|
|
@@ -477,34 +418,43 @@ const AmapDraw = {
|
|
|
477
418
|
...baseOptions
|
|
478
419
|
}
|
|
479
420
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
421
|
+
layerItem = type === 'line' ?
|
|
422
|
+
new this.amapStore.AMap.Polyline(options) :
|
|
423
|
+
new this.amapStore.AMap.Polygon(options)
|
|
483
424
|
}
|
|
484
425
|
|
|
485
|
-
|
|
486
|
-
this.amap.setFitView()
|
|
426
|
+
layerItem.setMap(this.amap)
|
|
487
427
|
},
|
|
488
428
|
|
|
489
|
-
|
|
490
|
-
* 切换地图类型
|
|
491
|
-
*/
|
|
429
|
+
// 切换地图类型
|
|
492
430
|
onLayersSwitch(key) {
|
|
493
431
|
this.amapType = key
|
|
494
432
|
this.amapType ? this.amapSatellite.show() : this.amapSatellite.hide()
|
|
495
433
|
},
|
|
496
434
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
435
|
+
// 更改操作状态
|
|
436
|
+
updateDrawOperateState(type) {
|
|
437
|
+
// 创建新的操作数组副本
|
|
438
|
+
const newOperates = [...this.drawOperates]
|
|
439
|
+
|
|
440
|
+
// 更新指定索引的操作项类型
|
|
441
|
+
newOperates[this.activeOperateIndex] = {
|
|
442
|
+
...newOperates[this.activeOperateIndex],
|
|
443
|
+
type
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
this.drawOperates = newOperates
|
|
447
|
+
},
|
|
448
|
+
|
|
449
|
+
// 清理资源
|
|
500
450
|
cleanupResources() {
|
|
501
451
|
this.handleDrawClear()
|
|
502
452
|
this.drawMouseTool && this.drawMouseTool.close()
|
|
503
453
|
}
|
|
504
454
|
},
|
|
455
|
+
|
|
505
456
|
render(h) {
|
|
506
|
-
const
|
|
507
|
-
const { drawEl, drawIcon, amapType, buttonProps, isExhibition } = this
|
|
457
|
+
const { drawEl, drawIcon, amapType, drawOperates: buttonProps, isExhibition } = this
|
|
508
458
|
|
|
509
459
|
return (
|
|
510
460
|
<div class="AmapDraw">
|
|
@@ -521,11 +471,11 @@ const AmapDraw = {
|
|
|
521
471
|
)}
|
|
522
472
|
<div id={drawEl} />
|
|
523
473
|
<div class="AmapDraw__Layers">
|
|
524
|
-
{
|
|
474
|
+
{CONFIG.layers.map((layer, index) => (
|
|
525
475
|
<span
|
|
526
|
-
key={
|
|
527
|
-
class={
|
|
528
|
-
onClick={() => this.onLayersSwitch(
|
|
476
|
+
key={index}
|
|
477
|
+
class={index === amapType && 'LayersActive'}
|
|
478
|
+
onClick={() => this.onLayersSwitch(index)}
|
|
529
479
|
>
|
|
530
480
|
{layer}
|
|
531
481
|
</span>
|
|
@@ -535,9 +485,3 @@ const AmapDraw = {
|
|
|
535
485
|
)
|
|
536
486
|
}
|
|
537
487
|
}
|
|
538
|
-
|
|
539
|
-
AmapDraw.install = function (Vue) {
|
|
540
|
-
Vue.component('AmapDraw', AmapDraw)
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
export default AmapDraw
|