easy-three-utils 0.0.345 → 0.0.346

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/cesium/index.ts CHANGED
@@ -82,11 +82,13 @@ const useCesium = () => {
82
82
  const customCollection = hooks.useCustomCollection(viewer)
83
83
  const drawPolygon = hooks.useDrawPolygon(viewer, {
84
84
  nodeCollection: customCollection.addCollection(hooks.dict.ECollectionWhiteListNames.POLYGON_NODE),
85
- polygonCollection: customCollection.addCollection(hooks.dict.ECollectionWhiteListNames.POLYGON),
85
+ polygonCollection: customCollection.addCollection(hooks.dict.ECollectionWhiteListNames.POLYGON)
86
86
  })
87
87
  const clipping = hooks.useClipping(viewer)
88
88
  const weather = hooks.useWeather(viewer)
89
- const measure = hooks.useMeasure(viewer)
89
+ const measure = hooks.useMeasure(viewer, {
90
+ distanceCollection: customCollection.addCollection(hooks.dict.ECollectionWhiteListNames.MEASURE_DISTANCE)
91
+ })
90
92
 
91
93
  if (config.controllerStyle === cesiumConfigDict.EControllerStyle.THREE) {
92
94
  updateController(viewer)
@@ -1,8 +1,10 @@
1
1
  import * as Cesium from 'cesium'
2
2
 
3
3
  enum ECollectionWhiteListNames {
4
+ POLYGON_NODE = 'polygon_node',
4
5
  POLYGON = 'polygon',
5
- POLYGON_NODE = 'polygon_node'
6
+
7
+ MEASURE_DISTANCE = 'measure_distance',
6
8
  }
7
9
 
8
10
  const useCustomCollection = (viewer: Cesium.Viewer) => {
@@ -1,6 +1,16 @@
1
1
  import * as Cesium from 'cesium'
2
2
 
3
- const useMeasure = (viewer: Cesium.Viewer) => {
3
+ const useMeasure = (viewer: Cesium.Viewer, options: {
4
+ distanceCollection: Cesium.CustomDataSource
5
+ }) => {
6
+
7
+ const point = {
8
+ color: Cesium.Color.fromCssColorString("rgb(249,157,11)"),
9
+ outlineColor: Cesium.Color.WHITE,
10
+ outlineWidth: 2,
11
+ pixelSize: 10,
12
+ heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
13
+ }
4
14
 
5
15
  const angleMeasurement = () => {
6
16
  let anglePoints = []
@@ -15,14 +25,14 @@ const useMeasure = (viewer: Cesium.Viewer) => {
15
25
  angleMeasurementHandler = null
16
26
  }
17
27
 
18
- angleMeasurementHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
28
+ angleMeasurementHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
19
29
 
20
30
  angleMeasurementHandler.setInputAction((movement) => {
21
- const ray = viewer.camera.getPickRay(movement.position);
22
- const cartesian = viewer.scene.globe.pick(ray, viewer.scene);
31
+ const ray = viewer.camera.getPickRay(movement.position)
32
+ const cartesian = viewer.scene.globe.pick(ray, viewer.scene)
23
33
 
24
34
  if (cartesian) {
25
- anglePoints.push(cartesian);
35
+ anglePoints.push(cartesian)
26
36
 
27
37
  const pointEntity = viewer.entities.add({
28
38
  position: cartesian,
@@ -33,7 +43,7 @@ const useMeasure = (viewer: Cesium.Viewer) => {
33
43
  pixelSize: 10,
34
44
  heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
35
45
  }
36
- });
46
+ })
37
47
  angleEntities.push(pointEntity)
38
48
 
39
49
  if (anglePoints.length >= 2) {
@@ -44,7 +54,7 @@ const useMeasure = (viewer: Cesium.Viewer) => {
44
54
  material: Cesium.Color.fromCssColorString("rgb(249, 157, 11)"),
45
55
  clampToGround: true,
46
56
  }
47
- });
57
+ })
48
58
  angleLines.push(lineEntity)
49
59
  }
50
60
 
@@ -70,7 +80,7 @@ const useMeasure = (viewer: Cesium.Viewer) => {
70
80
  material: Cesium.Color.fromCssColorString("rgb(249, 157, 11)"),
71
81
  clampToGround: true
72
82
  }
73
- });
83
+ })
74
84
  angleLines.push(lineEntity)
75
85
  } else {
76
86
  const line = angleLines[angleLines.length - 1]
@@ -78,7 +88,7 @@ const useMeasure = (viewer: Cesium.Viewer) => {
78
88
  }
79
89
  }
80
90
  }
81
- }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
91
+ }, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
82
92
  }
83
93
 
84
94
  const calculateAndDisplayAngle = () => {
@@ -110,7 +120,7 @@ const useMeasure = (viewer: Cesium.Viewer) => {
110
120
  heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
111
121
  disableDepthTestDistance: Number.POSITIVE_INFINITY
112
122
  }
113
- });
123
+ })
114
124
  angleLabels.push(angleLabel)
115
125
  }
116
126
 
@@ -141,10 +151,154 @@ const useMeasure = (viewer: Cesium.Viewer) => {
141
151
  }
142
152
  }
143
153
 
154
+ const distanceMeasurement = () => {
155
+ let positions = []
156
+ let tempPositions = []
157
+ let handler = null
158
+
159
+ const draw = () => {
160
+ if (handler) {
161
+ console.log('请先右键结束上次测量!');
162
+ return
163
+ }
164
+ handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
165
+ leftClickEvent()
166
+ rightClickEvent()
167
+ mouseMoveEvent()
168
+ }
169
+
170
+ const stopDraw = () => {
171
+ if (handler) {
172
+ handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
173
+ handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE)
174
+ handler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK)
175
+ handler.destroy()
176
+ handler = null
177
+ }
178
+
179
+ positions = []
180
+ tempPositions = []
181
+ }
182
+
183
+ const removeAll = () => {
184
+ options.distanceCollection.entities.removeAll()
185
+ }
186
+
187
+ const createLine = () => {
188
+ options.distanceCollection.entities.add({
189
+ polyline: {
190
+ positions: new Cesium.CallbackProperty(() => tempPositions, false),
191
+ material: Cesium.Color.fromCssColorString("rgb(249,157,11)"),
192
+ width: 2,
193
+ clampToGround: true
194
+ }
195
+ })
196
+ }
197
+
198
+ const createPoint = () => {
199
+ const pos = positions[positions.length - 1]
200
+ const text = getSpaceDistance(positions) + " 米"
201
+ options.distanceCollection.entities.add({
202
+ position: pos,
203
+ label: {
204
+ text: positions.length === 1 ? '起始点' : text,
205
+ scale: 0.5,
206
+ font: "normal 28px MicroSoft YaHei",
207
+ style: Cesium.LabelStyle.FILL_AND_OUTLINE,
208
+ pixelOffset: new Cesium.Cartesian2(0, -30),
209
+ outlineWidth: 9,
210
+ outlineColor: Cesium.Color.WHITE,
211
+ heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
212
+ disableDepthTestDistance: Number.POSITIVE_INFINITY
213
+ },
214
+ point
215
+ })
216
+ }
217
+
218
+ const getSpaceDistance = (positions) => {
219
+ if (positions.length < 2) return 0
220
+ let distance = 0
221
+
222
+ for (let i = 0; i < positions.length - 1; i++) {
223
+ const c1 = Cesium.Cartographic.fromCartesian(positions[i])
224
+ const c2 = Cesium.Cartographic.fromCartesian(positions[i + 1])
225
+ const geodesic = new Cesium.EllipsoidGeodesic(c1, c2)
226
+ let s = geodesic.surfaceDistance
227
+ s = Math.sqrt(Math.pow(s, 2) + Math.pow(c2.height - c1.height, 2))
228
+ distance += s
229
+ }
230
+
231
+ return distance.toFixed(2)
232
+ }
233
+
234
+ const leftClickEvent = () => {
235
+ handler.setInputAction(event => {
236
+ let position = viewer.scene.pickPosition(event.position)
237
+ if (!position)
238
+ position = viewer.scene.camera.pickEllipsoid(event.position, viewer.scene.globe.ellipsoid)
239
+ if (!position) return
240
+
241
+ positions.push(position)
242
+
243
+ if (positions.length === 1) {
244
+ createPoint()
245
+ createLine()
246
+ } else {
247
+ createPoint()
248
+ }
249
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
250
+ }
251
+
252
+ const mouseMoveEvent = () => {
253
+ handler.setInputAction(event => {
254
+ let position = viewer.scene.pickPosition(event.endPosition)
255
+ if (!position)
256
+ position = viewer.scene.camera.pickEllipsoid(event.endPosition, viewer.scene.globe.ellipsoid)
257
+ if (!position) return
258
+ handleMoveEvent(position)
259
+ }, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
260
+ }
261
+
262
+ const handleMoveEvent = (position) => {
263
+ if (positions.length < 1) return
264
+ tempPositions = positions.concat(position)
265
+ }
266
+
267
+ const rightClickEvent = () => {
268
+ handler.setInputAction(() => {
269
+ if (positions.length < 1) {
270
+ removeAll()
271
+ stopDraw()
272
+ } else {
273
+ options.distanceCollection.entities.add({
274
+ polyline: {
275
+ positions: positions,
276
+ material: Cesium.Color.fromCssColorString("rgb(249,157,11)"),
277
+ width: 2,
278
+ clampToGround: true
279
+ }
280
+ })
281
+ stopDraw()
282
+ }
283
+ }, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
284
+ }
285
+
286
+ return {
287
+ draw,
288
+ removeAll
289
+ }
290
+ }
291
+
292
+ const heightMeasurement = () => {
293
+
294
+ }
295
+
144
296
  const angle = angleMeasurement()
297
+ const distance = distanceMeasurement()
145
298
 
146
299
  return {
147
- angle
300
+ angle,
301
+ distance
148
302
  }
149
303
  }
150
304
 
@@ -1,6 +1,6 @@
1
1
  import * as Cesium from 'cesium'
2
2
 
3
- export enum EPlayStatus {
3
+ export enum EMovementType {
4
4
  SPEED = 'speed',
5
5
  TIME = 'time'
6
6
  }
@@ -14,14 +14,14 @@ export interface IPathType {
14
14
  modelParams: {
15
15
  id: string;
16
16
  name: string;
17
- uri: string;
17
+ url: string;
18
18
  };
19
19
  path: {
20
20
  duration: number;
21
21
  point: Cesium.Cartesian3;
22
22
  speed: number;
23
23
  }[];
24
- playStatus: EPlayStatus;
24
+ movementType: EMovementType;
25
25
  totalDuration: number;
26
26
  }
27
27
 
@@ -40,11 +40,11 @@ const usePath = () => {
40
40
  }
41
41
  if (i > 0) {
42
42
  const distance = Cesium.Cartesian3.distance(item.path[i - 1].point, value.point).toFixed();
43
- if (item.playStatus === EPlayStatus.SPEED) {
43
+ if (item.movementType === EMovementType.SPEED) {
44
44
  const time = Number(distance) / value.speed
45
45
  item.totalDuration = item.totalDuration + time
46
46
  property.addSample(Cesium.JulianDate.addSeconds(startTime, item.totalDuration, new Cesium.JulianDate()), value.point);
47
- } else if (item.playStatus === EPlayStatus.TIME) {
47
+ } else if (item.movementType === EMovementType.TIME) {
48
48
  item.totalDuration = item.totalDuration + Number(value.duration)
49
49
  property.addSample(Cesium.JulianDate.addSeconds(startTime, item.totalDuration, new Cesium.JulianDate()), value.point);
50
50
  }
@@ -62,7 +62,7 @@ const usePath = () => {
62
62
  position: property,
63
63
  orientation: new Cesium.VelocityOrientationProperty(property),
64
64
  model: {
65
- uri: item.modelParams.uri,
65
+ uri: item.modelParams.url,
66
66
  heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
67
67
  }
68
68
  })
@@ -76,22 +76,11 @@ const usePath = () => {
76
76
 
77
77
  viewer.clock.currentTime = startTime.clone();
78
78
  viewer.clock.clockStep = Cesium.ClockStep.SYSTEM_CLOCK;
79
- viewer.clock.shouldAnimate = true;
80
79
  viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
81
80
  }
82
81
 
83
- const controlAction = (viewer: Cesium.Viewer, status: EControlAction) => {
84
- viewer.clock.shouldAnimate = (status === EControlAction.PAUSE ? false : true)
85
- }
86
-
87
- const reset = () => {
88
- //todo
89
- }
90
-
91
82
  return {
92
83
  playAnimation,
93
- controlAction,
94
- reset
95
84
  }
96
85
  }
97
86
 
@@ -104,7 +104,7 @@ const useWeather = (viewer: Cesium.Viewer) => {
104
104
  return color;
105
105
  }
106
106
  }
107
- });
107
+ })
108
108
  viewer.scene.postProcessStages.add(stage);
109
109
  }
110
110
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-three-utils",
3
- "version": "0.0.345",
3
+ "version": "0.0.346",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -8,5 +8,5 @@
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "types": "./index.d.ts",
11
- "description": "延长j标使用时间"
11
+ "description": "更新长度测量"
12
12
  }