huweili-cesium 1.2.15 → 1.2.16

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.
@@ -123,8 +123,10 @@ export function measureDistance() {
123
123
  let endPointEntity = null
124
124
  let lineEntity = null
125
125
  let distanceLabelEntity = null
126
+ let deleteButtonEntity = null
126
127
  let tipEntity = null
127
128
  let handler = null
129
+ let deleteHandler = null
128
130
  let isFinished = false
129
131
 
130
132
  const tempIds = {
@@ -132,7 +134,8 @@ export function measureDistance() {
132
134
  endPoint: `${options.id}_measure_end_point`,
133
135
  line: `${options.id}_measure_line`,
134
136
  label: `${options.id}_measure_label`,
135
- tip: `${options.id}_measure_tip`
137
+ tip: `${options.id}_measure_tip`,
138
+ deleteButton: `${options.id}_measure_delete_button`
136
139
  }
137
140
 
138
141
  const getLinePositions = () => {
@@ -246,14 +249,36 @@ export function measureDistance() {
246
249
  })
247
250
  }
248
251
 
252
+ const createDeleteButtonEntity = () => {
253
+ if (deleteButtonEntity || !endPosition) return
254
+ deleteButtonEntity = map.entities.add({
255
+ id: tempIds.deleteButton,
256
+ position: endPosition,
257
+ label: {
258
+ text: '删除',
259
+ font: '12px Microsoft YaHei',
260
+ fillColor: Cesium.Color.WHITE,
261
+ showBackground: true,
262
+ backgroundColor: Cesium.Color.fromCssColorString('rgba(220, 53, 69, 0.95)'),
263
+ backgroundPadding: new Cesium.Cartesian2(10, 6),
264
+ verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
265
+ horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
266
+ pixelOffset: new Cesium.Cartesian2(14, -28),
267
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
268
+ distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, Number.POSITIVE_INFINITY)
269
+ }
270
+ })
271
+ }
272
+
249
273
  const removeTemporaryEntities = () => {
250
- ;[startPointEntity, endPointEntity, lineEntity, distanceLabelEntity, tipEntity].forEach((entity) => {
274
+ ;[startPointEntity, endPointEntity, lineEntity, distanceLabelEntity, deleteButtonEntity, tipEntity].forEach((entity) => {
251
275
  if (entity) map.entities.remove(entity)
252
276
  })
253
277
  startPointEntity = null
254
278
  endPointEntity = null
255
279
  lineEntity = null
256
280
  distanceLabelEntity = null
281
+ deleteButtonEntity = null
257
282
  tipEntity = null
258
283
  }
259
284
 
@@ -262,6 +287,16 @@ export function measureDistance() {
262
287
  handler.destroy()
263
288
  handler = null
264
289
  }
290
+ if (deleteHandler) {
291
+ deleteHandler.destroy()
292
+ deleteHandler = null
293
+ }
294
+ }
295
+
296
+ const destroyGraphic = () => {
297
+ destroyHandler()
298
+ removeTemporaryEntities()
299
+ mapStore.removeGraphicMap(options.id, options.mapId)
265
300
  }
266
301
 
267
302
  const cancel = () => {
@@ -280,6 +315,7 @@ export function measureDistance() {
280
315
  tipEntity = null
281
316
  }
282
317
  createEndPointEntity()
318
+ createDeleteButtonEntity()
283
319
  const result = buildResult()
284
320
  const graphic = {
285
321
  id: options.id,
@@ -287,6 +323,7 @@ export function measureDistance() {
287
323
  endPointEntity,
288
324
  lineEntity,
289
325
  labelEntity: distanceLabelEntity,
326
+ deleteButtonEntity,
290
327
  result,
291
328
  type: 'measureDistance'
292
329
  }
@@ -336,11 +373,20 @@ export function measureDistance() {
336
373
  cancel()
337
374
  }, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
338
375
 
376
+ deleteHandler = new Cesium.ScreenSpaceEventHandler(map.scene.canvas)
377
+ deleteHandler.setInputAction((movement) => {
378
+ const picked = map.scene.pick(movement.position)
379
+ if (!Cesium.defined(picked) || picked.id !== deleteButtonEntity) return
380
+ destroyGraphic()
381
+ if (typeof options.onDelete === 'function') options.onDelete(options.id)
382
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
383
+
339
384
  return {
340
385
  id: options.id,
341
386
  finish: finalize,
342
387
  cancel,
343
388
  destroy: cancel,
389
+ delete: destroyGraphic,
344
390
  getStart: () => (startPosition ? cartesianToLngLatHeight(startPosition) : null),
345
391
  getEnd: () => (endPosition ? cartesianToLngLatHeight(endPosition) : null),
346
392
  getDistance: () => getGroundDistance(startPosition, endPosition || floatingPosition),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huweili-cesium",
3
- "version": "1.2.15",
3
+ "version": "1.2.16",
4
4
  "description": "基于 Cesium 的地图工具库(无人机态势、轨迹、围栏、工具栏等)",
5
5
  "type": "module",
6
6
  "main": "./index.js",