web-component-gallery 2.3.3 → 2.3.5

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.
@@ -8,36 +8,38 @@ const BASE_IP = process.env.VUE_APP_STATIC_URL || location.origin
8
8
 
9
9
  // 统一配置管理
10
10
  const CONFIG = {
11
+ // 定义绘制类型与高德地图对应对象类型的映射关系
11
12
  drawTypes: {
12
- point: 'marker',
13
- line: 'polyline',
14
- polygon: 'polygon'
13
+ point: 'marker', // 点标记
14
+ line: 'polyline', // 折线
15
+ polygon: 'polygon' // 多边形
15
16
  },
17
+ // 地图图层类型:电子地图和卫星图
16
18
  layers: ['电子', '卫星']
17
19
  }
18
20
 
19
21
  export const AmapDrawProps = {
20
- // 地图容器实例名称
22
+ // 地图容器DOM元素ID
21
23
  drawEl: PropTypes.string.def('AmapDraw'),
22
- // 绘制类型
24
+ // 当前绘制类型:point(点)/line(线)/polygon(面)
23
25
  drawType: PropTypes.string.def('point'),
24
- // 绘制图标
26
+ // 点标记的图标路径
25
27
  drawIcon: PropTypes.any.def(`${BASE_IP}/poi/poi-marker-default.png`),
26
- // 绘制个数
28
+ // 允许绘制的最大数量
27
29
  drawCount: PropTypes.number.def(1),
28
- // 绘制物配置项
30
+ // 绘制物的自定义配置项(如颜色、大小等)
29
31
  drawOptions: PropTypes.object.def({}),
30
- // 绘制物信息
31
- drawInfo: PropTypes.object,
32
- // 所有不同类型绘制物信息 格式: { point: ([] || {}), line: ([] || {}) }
32
+ // 当前绘制物的信息(坐标、地址等)
33
+ drawInfo: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
34
+ // 包含所有类型绘制物信息的对象,格式: { point: [], line: [] }
33
35
  drawInfoAll: PropTypes.object,
34
- // 限制区域
35
- drawLimitArea: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
36
- // 限制区域样式配置
36
+ // 限制绘制区域的边界坐标数组
37
+ drawLimitArea: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
38
+ // 限制区域的样式配置
37
39
  drawLimitAreaOptions: PropTypes.object.def({}),
38
- // 纯地图展示数据
40
+ // 是否为纯展示模式(不显示控制按钮)
39
41
  isExhibition: PropTypes.bool.def(false),
40
- // 自定义绘制操作
42
+ // 自定义绘制操作按钮
41
43
  drawButtonOperate: PropTypes.array
42
44
  }
43
45
 
@@ -47,221 +49,286 @@ export default {
47
49
 
48
50
  data() {
49
51
  return {
50
- // 地图实例
52
+ // 高德地图实例引用
51
53
  amap: null,
52
- // 地图存储商店
54
+ // 地图服务存储实例
53
55
  amapStore: null,
56
+ // 限制绘制区域的多边形对象
54
57
  drawArea: null,
58
+ // 当前绘制的图层对象
55
59
  drawLayers: null,
60
+ // 鼠标绘制工具实例
56
61
  drawMouseTool: null,
62
+ // 绘制操作按钮配置
57
63
  drawOperates: [
58
64
  { type: 'primary', text: '绘制', event: { click: () => this.handleDrawStart() } },
59
65
  { text: '清除', event: { click: this.handleDrawClear } },
60
66
  { type: 'primary', text: '保存', event: { click: this.handleDrawSave } },
61
67
  { text: '取消', event: { click: this.handleDrawReset } }
62
68
  ],
63
- // 地图类型
69
+ // 地图显示类型:0-电子地图,1-卫星图
64
70
  amapType: 1,
65
- // 卫星图
71
+ // 卫星图层对象
66
72
  amapSatellite: null,
67
- //记录当前活跃操作的下标,-1表示无活跃操作
73
+ // 记录当前活跃操作的下标,-1表示无活跃操作
68
74
  activeOperateIndex: -1
69
75
  }
70
76
  },
71
77
 
72
78
  computed: {
79
+ // 绘制图层信息的计算属性,用于获取和设置绘制结果
73
80
  drawLayersInfo: {
74
- get() { return this.drawInfo },
81
+ get() { return transferData(this.drawInfo, 'Object') },
75
82
  set(newValue) {
83
+ // 触发外部事件,传递绘制的图层信息
76
84
  this.$emit('getAMapLayersInfo', this.initDrawInfo(newValue))
77
85
  }
78
86
  }
79
87
  },
80
88
 
81
89
  watch: {
90
+ // 监听绘制信息变化,当变化时重新渲染对应类型的绘制图层
82
91
  drawInfo: {
83
92
  handler(newVal) { newVal && this.echoDrawLayers(this.drawType) },
84
93
  deep: true
85
94
  },
95
+ // 监听所有绘制信息变化,重新渲染全部绘制图层
86
96
  drawInfoAll(newValue) { newValue && this.echoDrawLayers() },
87
- // 检测options覆盖物配置是否更改,更改后要同步到地图上
97
+ // 监听绘制选项变化,更新已存在的覆盖物样式
88
98
  drawOptions(newValue) { Object.keys(newValue).length && this.setOverlayOptions(newValue) },
99
+ // 监听限制区域变化,重新设置限制区域
89
100
  drawLimitArea(newValue) { newValue && this.setDrawLimitArea() }
90
101
  },
91
102
 
92
103
  async mounted() {
104
+ // 获取高德地图实例
93
105
  this.amapStore = await getAMapInstance()
106
+ // 初始化地图容器
94
107
  this.amap = this.amapStore.initMap(this.drawEl)
108
+ // 初始化地图相关组件
95
109
  this.initMap()
96
110
 
111
+ // 如果提供了自定义操作按钮,则合并到默认按钮中
97
112
  if (this.drawButtonOperate?.length) {
98
113
  this.drawOperates = this.drawButtonOperate.concat(this.drawOperates.slice(2))
99
114
  }
100
115
 
116
+ // 渲染已有的绘制图层
101
117
  this.echoDrawLayers(this.drawType)
102
- // 如有限制区域,则描绘在地图上
118
+ // 如果设置了限制区域,则在地图上绘制限制区域
103
119
  this.drawLimitArea && this.setDrawLimitArea()
104
120
  },
105
121
 
106
122
  beforeDestroy() {
123
+ // 组件销毁前清理资源
107
124
  this.cleanupResources()
108
125
  },
109
126
 
110
127
  methods: {
111
- // 初始化地图实例
128
+ // 初始化地图实例及相关组件
112
129
  initMap() {
113
130
  this.amap = this.amapStore.initMap(this.drawEl)
131
+ // 创建卫星图层
114
132
  this.amapSatellite = new this.amapStore.AMap.TileLayer.Satellite()
133
+ // 将卫星图层添加到地图
115
134
  this.amap.add(this.amapSatellite)
116
135
  },
117
136
 
118
137
  // 根据绘制类型初始化绘制属性
119
138
  initDrawInfo(newValue) {
139
+ // 如果传入了新值则直接返回,否则根据绘制类型返回默认结构
120
140
  return Object.keys(newValue).length ? newValue :
121
141
  this.drawType === 'point' ?
122
142
  { longitude: null, latitude: null, address: null } :
123
143
  { range: null }
124
144
  },
125
145
 
126
- // 开始绘制
146
+ // 开始绘制操作
127
147
  handleDrawStart(i = 0) {
148
+ // 检查是否已在绘制模式
128
149
  if (this.activeOperateIndex === i) return this.$message.warning('已处于绘制模式!')
150
+
129
151
  // 如果存在其他活跃操作项,先关闭并重置状态
130
152
  if (this.activeOperateIndex !== -1 && this.activeOperateIndex !== i) {
131
153
  this.drawMouseTool.close()
132
154
  this.updateDrawOperateState('primary')
133
155
  }
134
156
 
157
+ // 设置当前活跃操作索引
135
158
  this.activeOperateIndex = i
159
+ // 更新操作按钮状态为危险(红色)
136
160
  this.updateDrawOperateState('danger')
161
+ // 初始化绘制工具
137
162
  this.initDrawTool()
138
163
  },
139
164
 
140
165
  // 处理绘制完成事件
141
166
  handleDrawComplete(drawObject) {
167
+ // 检查绘制对象是否超出限制区域
142
168
  if (this.isOutOfBoundary(drawObject)) return
143
-
169
+
170
+ // 更新绘制图层
144
171
  this.updateDrawLayers(drawObject)
145
-
172
+
173
+ // 检查是否已完成所有绘制
146
174
  if (this.isDrawComplete()) this.finishDrawing()
147
175
  },
148
-
176
+
177
+ // 检查绘制对象是否超出边界限制
149
178
  isOutOfBoundary(obj) {
179
+ // 如果没有设置限制区域或者对象在边界内,则返回false
150
180
  if (!this.drawArea || this.checkInBoundary(obj)) return false
151
-
181
+
182
+ // 移除超出边界的对象
152
183
  this.amap.remove(obj)
153
184
  this.$message.error('未在范围内描绘!')
154
185
  return true
155
186
  },
156
-
157
- // 检查绘制是否完成
187
+
188
+ // 检查绘制是否完成(达到最大绘制数量)
158
189
  isDrawComplete() {
159
190
  return this.drawLayers &&
160
191
  (this.drawLayers.length === this.drawCount || this.drawCount === 1)
161
192
  },
162
-
163
- // 结束绘制
193
+
194
+ // 结束绘制流程
164
195
  finishDrawing() {
196
+ // 关闭鼠标绘制工具
165
197
  this.drawMouseTool.close()
198
+ // 恢复操作按钮状态
166
199
  this.updateDrawOperateState('primary')
200
+ // 重置活跃操作索引
167
201
  this.activeOperateIndex = -1
168
202
  this.$message.success('绘制结束!')
169
203
  },
170
204
 
171
- // 更新绘制物
205
+ // 更新绘制图层(支持单个或多个绘制对象)
172
206
  updateDrawLayers(drawObject) {
207
+ // 如果允许绘制多个对象,则将新对象追加到现有对象数组中,否则直接替换
173
208
  this.drawLayers = this.drawCount > 1 ?
174
209
  (this.drawLayers || []).concat(drawObject) :
175
210
  drawObject
176
211
 
177
- // 实时保存绘制
212
+ // 实时保存绘制结果
178
213
  this.assignDrawLayers(this.drawType)
179
214
  },
180
215
 
181
- // 清除绘制
216
+ // 清除当前绘制的所有图层
182
217
  handleDrawClear() {
218
+ // 清理地图上的所有覆盖物
183
219
  this.cleanOverlays()
220
+ // 重置绘制图层数组
184
221
  this.drawLayers = null
222
+ // 重置绘制图层信息
185
223
  this.drawLayersInfo = {}
186
224
  },
187
225
 
188
- // 保存绘制
226
+ // 保存当前绘制结果
189
227
  handleDrawSave() {
228
+ // 如果没有绘制任何内容,则重置绘制状态
190
229
  if (!this.drawLayers) {
191
230
  return this.handleDrawReset()
192
231
  }
232
+ // 分配绘制图层信息
193
233
  this.assignDrawLayers(this.drawType)
194
234
  },
195
235
 
196
- // 取消绘制
236
+ // 取消绘制操作
197
237
  handleDrawReset() {
238
+ // 直接调用清除方法
198
239
  this.handleDrawClear()
199
240
  },
200
241
 
201
- // 搜索地址选择
242
+ // 处理搜索结果选择
202
243
  searchChoose(searchMarker, searchInfo) {
244
+ // 清除当前绘制内容
203
245
  this.handleDrawClear()
246
+ // 将选中的标记添加到地图
204
247
  searchMarker.setMap(this.amap)
248
+ // 设置地图缩放级别和中心点
205
249
  this.amap.setZoomAndCenter(15, searchMarker.getPosition())
250
+ // 如果是点类型绘制,则更新绘制信息
206
251
  this.drawType === 'point' && (this.drawLayersInfo = searchInfo)
207
252
  },
208
253
 
209
- // 设置覆盖物参数
254
+ // 设置覆盖物的参数选项
210
255
  setOverlayOptions(options) {
256
+ // 如果没有绘制图层则直接返回
211
257
  if (!this.drawLayers) return
212
258
 
259
+ // 将绘制图层转换为数组以便统一处理
213
260
  const layers = Array.isArray(this.drawLayers) ? this.drawLayers : [this.drawLayers]
261
+ // 为每个图层设置新的选项
214
262
  layers.forEach(item => item.setOptions(options))
215
263
  },
216
264
 
217
- // 设置绘制限制区域
265
+ /**
266
+ * 设置绘制限制区域(在指定区域内才能进行绘制)
267
+ */
218
268
  setDrawLimitArea() {
219
- let areaRange = []
220
269
  try {
221
- areaRange = JSON.parse(this.drawLimitArea)
222
- } catch {
223
- areaRange = this.drawLimitArea
270
+ // 验证限制区域数据是否存在
271
+ if (!this.drawLimitArea) return
272
+
273
+ // 转换区域范围数据为数组格式
274
+ const areaRange = transferData(this.drawLimitArea, 'Array')
275
+
276
+ // 移除现有的限制区域
277
+ if (this.drawArea) {
278
+ this.amap.remove(this.drawArea)
279
+ this.drawArea = null
280
+ }
281
+
282
+ // 设置新的地图区域
283
+ this.setMapArea(areaRange)
284
+
285
+ // 验证现有覆盖物是否在区域内
286
+ this.validateOverlays()
287
+ } catch (error) {
288
+ console.error('设置绘制限制区域失败:', error)
224
289
  }
225
-
226
- this.drawArea && this.amap.remove(this.drawArea)
227
- this.setMapArea(areaRange)
228
- this.validateOverlays()
229
290
  },
230
291
 
231
- // 设置地图区域范围
292
+ // 设置地图限制区域范围
232
293
  setMapArea(jurisdictionRange) {
294
+ // 创建限制区域多边形
233
295
  this.drawArea = new this.amapStore.AMap.Polygon({
234
296
  map: this.amap,
235
297
  path: jurisdictionRange,
236
- extData: 'Area',
237
- strokeWeight: 6,
238
- ...this.drawLimitAreaOptions
298
+ extData: 'Area', // 标记为区域类型,避免被误删
299
+ strokeWeight: 6, // 边框粗细
300
+ ...this.drawLimitAreaOptions // 应用用户自定义样式
239
301
  })
240
302
 
303
+ // 获取限制区域中心点并设置地图视图
241
304
  const { lng, lat } = this.drawArea.getBounds().getCenter()
242
305
  this.amap.setZoomAndCenter(15, [lng, lat])
243
306
  },
244
307
 
245
- // 验证覆盖物是否在边界内
308
+ // 验证覆盖物是否在边界内,不在边界内的覆盖物会被移除
246
309
  validateOverlays() {
310
+ // 获取地图上所有覆盖物
247
311
  this.amap?.getAllOverlays().forEach(layer => {
312
+ // 排除限制区域本身,并检查是否在边界内
248
313
  if (layer.getExtData() !== 'Area' && !this.checkInBoundary(layer)) {
249
314
  this.removeOverlay(layer)
250
315
  }
251
316
  })
252
317
  },
253
318
 
254
- // 检查是否在边界内
319
+ // 检查对象是否在边界内
255
320
  checkInBoundary(object) {
256
321
  const type = this.drawType
322
+ // 根据绘制类型选择相应的边界检查方法
257
323
  return type === 'line' ?
258
324
  this.isLineInBoundary(object) :
259
325
  this.isPointInBoundary(object)
260
326
  },
261
327
 
262
- // 检查线段是否在边界内
328
+ // 检查线段是否完全在边界内
263
329
  isLineInBoundary(polyline) {
264
330
  const paths = polyline.getPath()
331
+ // 检查线段的所有点是否都在边界内
265
332
  return paths.every(point => this.isPointInBoundary(point))
266
333
  },
267
334
 
@@ -269,22 +336,27 @@ export default {
269
336
  isPointInBoundary(point) {
270
337
  let position
271
338
  try {
339
+ // 尝试获取点的位置信息
272
340
  position = point.getPosition()
273
341
  } catch {
342
+ // 如果获取失败,则直接使用传入的点作为位置
274
343
  position = point
275
344
  }
345
+ // 使用高德地图的几何工具判断点是否在多边形内
276
346
  return this.amapStore.AMap.GeometryUtil.isPointInRing(
277
347
  position,
278
348
  this.drawArea.getPath()
279
349
  )
280
350
  },
281
351
 
282
- // 移除覆盖物
352
+ // 移除超出边界的覆盖物
283
353
  removeOverlay(layerItem) {
354
+ // 从地图上移除覆盖物
284
355
  this.amap.remove(layerItem)
285
356
  this.$message.error('未在区域范围内,请重新描绘!')
286
357
 
287
358
  try {
359
+ // 如果绘制图层是数组,则从中移除对应的元素
288
360
  if (Array.isArray(this.drawLayers)) {
289
361
  const index = this.drawLayers.findIndex(
290
362
  layer => layer.getExtData() === layerItem.getExtData()
@@ -294,6 +366,7 @@ export default {
294
366
  }
295
367
  return
296
368
  }
369
+ // 如果不是数组,直接重置绘制图层
297
370
  this.drawLayers = null
298
371
  this.drawLayersInfo = {}
299
372
  } catch (error) {
@@ -303,40 +376,49 @@ export default {
303
376
 
304
377
  // 初始化绘制工具
305
378
  initDrawTool() {
379
+ // 创建鼠标绘制工具实例
306
380
  this.drawMouseTool = new this.amapStore.AMap.MouseTool(this.amap)
381
+ // 清除之前的绘制内容
307
382
  this.handleDrawClear()
383
+ // 准备绘制图层
308
384
  this.prepareDrawLayers(this.drawType)
309
385
 
310
- // 准备绘制环境
386
+ // 监听绘制完成事件
311
387
  this.drawMouseTool.on('draw', ({ obj }) => {
312
388
  this.handleDrawComplete(obj)
313
389
  })
314
390
  },
315
391
 
316
- // 准备绘制图层
392
+ // 准备绘制图层(根据绘制类型设置默认选项)
317
393
  async prepareDrawLayers(drawType) {
394
+ // 根据绘制类型设置默认选项
318
395
  const defaultOptions = drawType === 'point' ? {
319
- anchor: 'bottom-center',
320
- icon: await this.amapStore.setIcon(this.drawIcon)
321
- } : { strokeWeight: 8 }
396
+ anchor: 'bottom-center', // 点标记锚点位置
397
+ icon: await this.amapStore.setIcon(this.drawIcon) // 设置图标
398
+ } : { strokeWeight: 8 } // 线条宽度
322
399
 
400
+ // 根据绘制类型启动相应的绘制工具
323
401
  this.drawMouseTool[CONFIG.drawTypes[drawType]]({
324
402
  ...defaultOptions,
325
- ...this.drawOptions
403
+ ...this.drawOptions // 合并用户自定义选项
326
404
  })
327
405
  },
328
406
 
329
- // 分配图层数据
407
+ // 根据绘制类型分配图层数据
330
408
  assignDrawLayers(drawType) {
409
+ // 根据绘制类型调用相应的处理方法
331
410
  drawType === 'point' ? this.handlePointDraw() : this.handleShapeDraw()
332
411
  },
333
412
 
334
- // 处理点绘制
413
+ // 处理点类型绘制,获取点的详细地址信息
335
414
  handlePointDraw() {
415
+ // 获取点的经纬度坐标
336
416
  const { lng, lat } = this.drawLayers.getPosition()
337
417
  const position = { longitude: lng, latitude: lat }
338
418
 
419
+ // 通过坐标获取详细地址信息
339
420
  this.amapStore.getMapAddress(position, address => {
421
+ // 合并坐标和地址信息
340
422
  this.drawLayersInfo = {
341
423
  ...position,
342
424
  ...address
@@ -344,27 +426,34 @@ export default {
344
426
  })
345
427
  },
346
428
 
347
- // 处理形状绘制
429
+ // 处理形状类型绘制(线或多边形),提取路径坐标
348
430
  handleShapeDraw() {
431
+ // 将路径转换为经纬度坐标数组
349
432
  const range = this.drawLayers.getPath().map(({ lng, lat }) => [lng, lat])
433
+ // 更新绘制图层信息
350
434
  this.drawLayersInfo = { range }
351
435
  },
352
436
 
353
- // 回显绘制图层
437
+ // 回显绘制图层(根据已有数据重新渲染地图上的绘制内容)
354
438
  echoDrawLayers(drawType) {
439
+ // 检查地图实例是否存在
355
440
  if (!this.amapStore || !this.amap) return
356
441
 
442
+ // 清理现有覆盖物
357
443
  this.cleanOverlays()
358
444
 
445
+ // 根据是否有全部绘制信息决定渲染方式
359
446
  this.drawInfoAll ?
360
447
  this.renderAllDrawLayers() :
361
448
  this.renderSingleDrawLayer(drawType)
362
449
 
450
+ // 如果没有活跃操作,则自动调整地图视野以适应所有图层
363
451
  if (this.activeOperateIndex === -1) setTimeout(this.amap.setFitView(), 0)
364
452
  },
365
453
 
366
- // 清理覆盖物
454
+ // 清理地图上除限制区域外的所有覆盖物
367
455
  cleanOverlays() {
456
+ // 获取地图上所有覆盖物并移除非区域类的覆盖物
368
457
  this.amap?.getAllOverlays().forEach(layer => {
369
458
  if (layer.getExtData() !== 'Area') {
370
459
  this.amap.remove(layer)
@@ -372,91 +461,101 @@ export default {
372
461
  })
373
462
  },
374
463
 
375
- // 渲染所有绘制图层
464
+ // 渲染所有绘制图层(遍历所有类型的绘制信息并渲染)
376
465
  renderAllDrawLayers() {
377
466
  for (const key in this.drawInfoAll) {
378
467
  const isArray = Array.isArray(this.drawInfoAll[key])
379
468
 
380
469
  if (isArray) {
470
+ // 如果是数组类型,则遍历数组中的每一项进行渲染
381
471
  this.drawInfoAll[key].forEach((item, index) => {
382
472
  this.renderDrawLayer(item, key, index)
383
473
  })
384
474
  return
385
475
  }
386
476
 
477
+ // 如果不是数组,则直接渲染单个项目
387
478
  this.renderDrawLayer(this.drawInfoAll[key], key)
388
479
  }
389
480
  },
390
481
 
391
482
  // 渲染单个绘制图层
392
483
  renderSingleDrawLayer(drawType) {
484
+ // 使用当前绘制图层信息进行渲染
393
485
  this.renderDrawLayer(this.drawLayersInfo, drawType)
394
486
  },
395
487
 
396
- // 渲染绘制图层
488
+ // 渲染单个绘制图层(根据类型创建相应的地图对象)
397
489
  async renderDrawLayer(drawItem, type, index = 0) {
398
490
  if (!drawItem) return
399
491
 
400
492
  const { longitude, latitude, range, options: innerOptions } = drawItem
401
493
 
402
- // 验证必要参数
494
+ // 验证必要参数是否存在
403
495
  if (!((longitude && latitude) || range)) return
404
496
 
405
- // 创建图层选项
497
+ // 合并图层选项(基础选项、用户选项和内部选项)
406
498
  const layerOptions = {
407
- extData: `draw${type}${index}`,
408
- ...this.drawOptions,
409
- ...innerOptions
499
+ extData: `draw${type}${index}`, // 设置扩展数据标识
500
+ ...this.drawOptions, // 用户自定义选项
501
+ ...innerOptions // 内部选项
410
502
  }
411
503
 
412
504
  let layerItem = null
413
505
 
414
- // 根据类型创建不同的图层
506
+ // 根据绘制类型创建不同的地图对象
415
507
  if (type === 'point') {
508
+ // 创建点标记
416
509
  layerItem = await this.amapStore.setMarker(this.drawIcon, {
417
- position: [longitude, latitude],
418
- ...layerOptions
510
+ position: [longitude, latitude], // 设置点位置
511
+ ...layerOptions // 应用图层选项
419
512
  })
420
513
  } else {
514
+ // 创建线或面对象
421
515
  const options = {
422
- path: transferData(range, 'Array'),
423
- strokeWeight: 8,
424
- ...layerOptions
516
+ path: transferData(range, 'Array'), // 路径坐标
517
+ strokeWeight: 8, // 线宽
518
+ ...layerOptions // 应用图层选项
425
519
  }
426
520
 
427
- // 根据类型创建线或面
521
+ // 根据类型创建线或多边形
428
522
  layerItem = type === 'line'
429
- ? new this.amapStore.AMap.Polyline(options)
430
- : new this.amapStore.AMap.Polygon(options)
523
+ ? new this.amapStore.AMap.Polyline(options) // 折线
524
+ : new this.amapStore.AMap.Polygon(options) // 多边形
431
525
  }
432
526
 
433
- // 将图层添加到地图
527
+ // 将创建的地图对象添加到地图上
434
528
  layerItem?.setMap(this.amap)
435
529
  },
436
530
 
437
- // 切换地图类型
531
+ // 切换地图显示类型(电子地图/卫星图)
438
532
  onLayersSwitch(key) {
533
+ // 更新地图类型状态(0为电子地图,1为卫星图)
439
534
  this.amapType = key
535
+ // 根据选择的类型显示或隐藏卫星图层
440
536
  this.amapType ? this.amapSatellite.show() : this.amapSatellite.hide()
441
537
  },
442
538
 
443
- // 更改操作状态
539
+ // 更新绘制操作按钮的状态(如颜色变化)
444
540
  updateDrawOperateState(type) {
445
- // 创建新的操作数组副本
541
+ // 创建新的操作数组副本以避免直接修改原数组
446
542
  const newOperates = [...this.drawOperates]
447
543
 
448
- // 更新指定索引的操作项类型
544
+ // 更新指定索引的操作项类型(例如:primary/danger)
449
545
  newOperates[this.activeOperateIndex] = {
450
546
  ...newOperates[this.activeOperateIndex],
451
547
  type
452
548
  }
453
549
 
550
+ // 更新操作按钮数组
454
551
  this.drawOperates = newOperates
455
552
  },
456
553
 
457
- // 清理资源
554
+ // 清理组件使用的资源,防止内存泄漏
458
555
  cleanupResources() {
556
+ // 清除地图上的所有绘制内容
459
557
  this.handleDrawClear()
558
+ // 关闭并清理鼠标绘制工具
460
559
  this.drawMouseTool && this.drawMouseTool.close()
461
560
  }
462
561
  },
@@ -492,4 +591,4 @@ export default {
492
591
  </div>
493
592
  )
494
593
  }
495
- }
594
+ }