huweili-cesium 1.2.15 → 1.2.17

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,39 @@ 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: new Cesium.CallbackProperty(() => endPosition, false),
257
+ label: {
258
+ text: '删除',
259
+ font: '700 13px Microsoft YaHei',
260
+ style: Cesium.LabelStyle.FILL_AND_OUTLINE,
261
+ fillColor: Cesium.Color.WHITE,
262
+ outlineColor: Cesium.Color.fromCssColorString('#b71c1c'),
263
+ outlineWidth: 4,
264
+ showBackground: true,
265
+ backgroundColor: Cesium.Color.fromCssColorString('rgba(244, 67, 54, 0.96)'),
266
+ backgroundPadding: new Cesium.Cartesian2(12, 7),
267
+ verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
268
+ horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
269
+ pixelOffset: new Cesium.Cartesian2(16, -34),
270
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
271
+ distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, Number.POSITIVE_INFINITY)
272
+ }
273
+ })
274
+ }
275
+
249
276
  const removeTemporaryEntities = () => {
250
- ;[startPointEntity, endPointEntity, lineEntity, distanceLabelEntity, tipEntity].forEach((entity) => {
277
+ ;[startPointEntity, endPointEntity, lineEntity, distanceLabelEntity, deleteButtonEntity, tipEntity].forEach((entity) => {
251
278
  if (entity) map.entities.remove(entity)
252
279
  })
253
280
  startPointEntity = null
254
281
  endPointEntity = null
255
282
  lineEntity = null
256
283
  distanceLabelEntity = null
284
+ deleteButtonEntity = null
257
285
  tipEntity = null
258
286
  }
259
287
 
@@ -262,6 +290,16 @@ export function measureDistance() {
262
290
  handler.destroy()
263
291
  handler = null
264
292
  }
293
+ if (deleteHandler) {
294
+ deleteHandler.destroy()
295
+ deleteHandler = null
296
+ }
297
+ }
298
+
299
+ const destroyGraphic = () => {
300
+ destroyHandler()
301
+ removeTemporaryEntities()
302
+ mapStore.removeGraphicMap(options.id, options.mapId)
265
303
  }
266
304
 
267
305
  const cancel = () => {
@@ -280,6 +318,7 @@ export function measureDistance() {
280
318
  tipEntity = null
281
319
  }
282
320
  createEndPointEntity()
321
+ createDeleteButtonEntity()
283
322
  const result = buildResult()
284
323
  const graphic = {
285
324
  id: options.id,
@@ -287,6 +326,7 @@ export function measureDistance() {
287
326
  endPointEntity,
288
327
  lineEntity,
289
328
  labelEntity: distanceLabelEntity,
329
+ deleteButtonEntity,
290
330
  result,
291
331
  type: 'measureDistance'
292
332
  }
@@ -336,11 +376,21 @@ export function measureDistance() {
336
376
  cancel()
337
377
  }, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
338
378
 
379
+ deleteHandler = new Cesium.ScreenSpaceEventHandler(map.scene.canvas)
380
+ deleteHandler.setInputAction((movement) => {
381
+ const picked = map.scene.pick(movement.position)
382
+ const pickedEntity = picked?.id
383
+ if (!Cesium.defined(pickedEntity) || pickedEntity !== deleteButtonEntity) return
384
+ destroyGraphic()
385
+ if (typeof options.onDelete === 'function') options.onDelete(options.id)
386
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
387
+
339
388
  return {
340
389
  id: options.id,
341
390
  finish: finalize,
342
391
  cancel,
343
392
  destroy: cancel,
393
+ delete: destroyGraphic,
344
394
  getStart: () => (startPosition ? cartesianToLngLatHeight(startPosition) : null),
345
395
  getEnd: () => (endPosition ? cartesianToLngLatHeight(endPosition) : null),
346
396
  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.17",
4
4
  "description": "基于 Cesium 的地图工具库(无人机态势、轨迹、围栏、工具栏等)",
5
5
  "type": "module",
6
6
  "main": "./index.js",