huweili-cesium 1.2.14 → 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.
@@ -77,27 +77,6 @@ export function measureDistance() {
77
77
  }
78
78
  }
79
79
 
80
- const createGroundPolylinePositions = (startPosition, endPosition, segmentCount = 32) => {
81
- if (!startPosition || !endPosition) return []
82
-
83
- const start = Cesium.Cartographic.fromCartesian(startPosition)
84
- const end = Cesium.Cartographic.fromCartesian(endPosition)
85
- const positions = []
86
-
87
- for (let i = 0; i <= segmentCount; i += 1) {
88
- const t = i / segmentCount
89
- positions.push(
90
- Cesium.Cartesian3.fromRadians(
91
- Cesium.Math.lerp(start.longitude, end.longitude, t),
92
- Cesium.Math.lerp(start.latitude, end.latitude, t),
93
- 0
94
- )
95
- )
96
- }
97
-
98
- return positions
99
- }
100
-
101
80
  const getGroundDistance = (startPosition, endPosition) => {
102
81
  if (!startPosition || !endPosition) return 0
103
82
  return Cesium.Cartesian3.distance(startPosition, endPosition)
@@ -135,13 +114,6 @@ export function measureDistance() {
135
114
  const color = Cesium.Color.fromCssColorString(options.color || '#00ffff')
136
115
  const width = options.width ?? 3
137
116
  const clampToGround = options.clampToGround ?? true
138
- const lineMaterial =
139
- options.lineMaterial ||
140
- new Cesium.PolylineGlowMaterialProperty({
141
- color: Cesium.Color.fromAlpha(color, options.opacity ?? 0.95),
142
- glowPower: options.glowPower ?? 0.12,
143
- taperPower: options.taperPower ?? 0
144
- })
145
117
 
146
118
  let startPosition = null
147
119
  let endPosition = null
@@ -151,8 +123,10 @@ export function measureDistance() {
151
123
  let endPointEntity = null
152
124
  let lineEntity = null
153
125
  let distanceLabelEntity = null
126
+ let deleteButtonEntity = null
154
127
  let tipEntity = null
155
128
  let handler = null
129
+ let deleteHandler = null
156
130
  let isFinished = false
157
131
 
158
132
  const tempIds = {
@@ -160,14 +134,15 @@ export function measureDistance() {
160
134
  endPoint: `${options.id}_measure_end_point`,
161
135
  line: `${options.id}_measure_line`,
162
136
  label: `${options.id}_measure_label`,
163
- tip: `${options.id}_measure_tip`
137
+ tip: `${options.id}_measure_tip`,
138
+ deleteButton: `${options.id}_measure_delete_button`
164
139
  }
165
140
 
166
141
  const getLinePositions = () => {
167
142
  if (!startPosition) return []
168
143
  const targetPosition = endPosition || floatingPosition
169
144
  if (!targetPosition) return [startPosition]
170
- return createGroundPolylinePositions(startPosition, targetPosition, options.segmentCount ?? 48)
145
+ return [startPosition, targetPosition]
171
146
  }
172
147
 
173
148
  const getCurrentDistance = () => getGroundDistance(startPosition, endPosition || floatingPosition)
@@ -231,11 +206,8 @@ export function measureDistance() {
231
206
  polyline: {
232
207
  positions: new Cesium.CallbackProperty(() => getLinePositions(), false),
233
208
  width,
234
- material: lineMaterial,
235
- clampToGround,
236
- arcType: Cesium.ArcType.GEODESIC,
237
- granularity: options.granularity ?? Cesium.Math.toRadians(0.2),
238
- depthFailMaterial: options.depthFailMaterial || new Cesium.ColorMaterialProperty(Cesium.Color.fromAlpha(color, 0.7))
209
+ material: color,
210
+ clampToGround
239
211
  }
240
212
  })
241
213
  }
@@ -277,14 +249,36 @@ export function measureDistance() {
277
249
  })
278
250
  }
279
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
+
280
273
  const removeTemporaryEntities = () => {
281
- ;[startPointEntity, endPointEntity, lineEntity, distanceLabelEntity, tipEntity].forEach((entity) => {
274
+ ;[startPointEntity, endPointEntity, lineEntity, distanceLabelEntity, deleteButtonEntity, tipEntity].forEach((entity) => {
282
275
  if (entity) map.entities.remove(entity)
283
276
  })
284
277
  startPointEntity = null
285
278
  endPointEntity = null
286
279
  lineEntity = null
287
280
  distanceLabelEntity = null
281
+ deleteButtonEntity = null
288
282
  tipEntity = null
289
283
  }
290
284
 
@@ -293,6 +287,16 @@ export function measureDistance() {
293
287
  handler.destroy()
294
288
  handler = null
295
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)
296
300
  }
297
301
 
298
302
  const cancel = () => {
@@ -311,6 +315,7 @@ export function measureDistance() {
311
315
  tipEntity = null
312
316
  }
313
317
  createEndPointEntity()
318
+ createDeleteButtonEntity()
314
319
  const result = buildResult()
315
320
  const graphic = {
316
321
  id: options.id,
@@ -318,6 +323,7 @@ export function measureDistance() {
318
323
  endPointEntity,
319
324
  lineEntity,
320
325
  labelEntity: distanceLabelEntity,
326
+ deleteButtonEntity,
321
327
  result,
322
328
  type: 'measureDistance'
323
329
  }
@@ -367,11 +373,20 @@ export function measureDistance() {
367
373
  cancel()
368
374
  }, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
369
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
+
370
384
  return {
371
385
  id: options.id,
372
386
  finish: finalize,
373
387
  cancel,
374
388
  destroy: cancel,
389
+ delete: destroyGraphic,
375
390
  getStart: () => (startPosition ? cartesianToLngLatHeight(startPosition) : null),
376
391
  getEnd: () => (endPosition ? cartesianToLngLatHeight(endPosition) : null),
377
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.14",
3
+ "version": "1.2.16",
4
4
  "description": "基于 Cesium 的地图工具库(无人机态势、轨迹、围栏、工具栏等)",
5
5
  "type": "module",
6
6
  "main": "./index.js",