easy-three-utils 0.0.333 → 0.0.335

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.
@@ -0,0 +1,45 @@
1
+ .slider-box {
2
+ position: absolute;
3
+ z-index: 2;
4
+ bottom: 0;
5
+ width: 360px;
6
+ padding: 10px;
7
+ background: rgba(6, 38, 68, 0.7);
8
+ border: solid 1px #26a1ff;
9
+ display: flex;
10
+ left: calc(50vw - 180px);
11
+
12
+ .left-content {
13
+ color: white;
14
+ font-size: 13px;
15
+ writing-mode: vertical-rl;
16
+ display: flex;
17
+ justify-content: center;
18
+ padding-right: 12px;
19
+ }
20
+
21
+ .right-content {
22
+ flex: 1;
23
+
24
+ .time-text {
25
+ color: white;
26
+ font-size: 12px;
27
+ display: flex;
28
+ justify-content: flex-end;
29
+ width: 98%;
30
+ margin-bottom: 11px;
31
+ }
32
+
33
+ .control-btn {
34
+ display: flex;
35
+ align-items: center;
36
+ justify-content: center;
37
+
38
+ img {
39
+ padding: 0 12px;
40
+ cursor: pointer;
41
+ }
42
+ }
43
+ }
44
+
45
+ }
@@ -0,0 +1,135 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import { Slider, ConfigProvider } from "antd";
3
+ import * as Cesium from "cesium";
4
+ import dayjs from 'dayjs';
5
+ import duration from 'dayjs/plugin/duration';
6
+
7
+ import { viewer } from '@/hooks/cesium'
8
+
9
+ import Styles from './index.module.less'
10
+
11
+ dayjs.extend(duration);
12
+
13
+ const Timeline: React.FC<{
14
+ cesiumStatus: boolean;
15
+ }> = (props) => {
16
+ const [percent, setPercent] = useState(0)
17
+
18
+ const theme = {
19
+ components: {
20
+ Slider: {
21
+ railBg: '#bfbfbf',
22
+ railHoverBg: '#bfbfbf',
23
+ trackBg: '#176fdbff'
24
+ }
25
+ }
26
+ }
27
+
28
+ const setClockEvent = (clock: Cesium.Clock) => {
29
+ const totalSeconds = Cesium.JulianDate.secondsDifference(
30
+ clock.stopTime,
31
+ clock.startTime
32
+ )
33
+ const elapsedSeconds = Cesium.JulianDate.secondsDifference(
34
+ clock.currentTime,
35
+ clock.startTime
36
+ )
37
+
38
+ const timeDuration = dayjs.duration(elapsedSeconds, 'seconds')
39
+ const formattedTime = timeDuration.format('HH:mm:ss')
40
+ setCurrentTime(() => formattedTime)
41
+
42
+ const newPercent = (elapsedSeconds / totalSeconds) * 100
43
+ setPercent(() => newPercent);
44
+ }
45
+
46
+ const addViewerClockEvent = () => {
47
+ viewer.clock.onTick.addEventListener(setClockEvent)
48
+ }
49
+
50
+ const removeViewerClockEvent = () => {
51
+ viewer.clock.onTick.addEventListener(setClockEvent)
52
+ }
53
+
54
+ const onSliderChange = (value: number) => {
55
+ setPercent(() => value);
56
+ const totalSeconds = Cesium.JulianDate.secondsDifference(
57
+ viewer.clock.stopTime,
58
+ viewer.clock.startTime
59
+ );
60
+ const newTime = Cesium.JulianDate.addSeconds(
61
+ viewer.clock.startTime,
62
+ (value / 100) * totalSeconds,
63
+ new Cesium.JulianDate()
64
+ );
65
+ viewer.clock.currentTime = newTime;
66
+ }
67
+
68
+ type TContronType = 'pause' | 'play' | 'stop'
69
+ const control = {
70
+ play: () => {
71
+ viewer.clock.shouldAnimate = true
72
+ },
73
+ pause: () => {
74
+ viewer.clock.shouldAnimate = false
75
+ },
76
+ stop: () => {
77
+ viewer.clock.currentTime = viewer.clock.startTime
78
+ viewer.clock.shouldAnimate = false
79
+ }
80
+ }
81
+
82
+ const [totalTime, setTotalTime] = useState('00:00:00')
83
+ const [currentTime, setCurrentTime] = useState('00:00:00')
84
+ const initTimeDisplay = () => {
85
+ const seconds = viewer.clock.stopTime.secondsOfDay - viewer.clock.startTime.secondsOfDay
86
+ const timeDuration = dayjs.duration(seconds, 'seconds')
87
+ const formattedTime = timeDuration.format('HH:mm:ss')
88
+ setTotalTime(() => formattedTime)
89
+ }
90
+
91
+ useEffect(() => {
92
+
93
+ if (props.cesiumStatus) {
94
+ addViewerClockEvent()
95
+ initTimeDisplay()
96
+ }
97
+
98
+ return () => {
99
+ removeViewerClockEvent()
100
+ }
101
+ }, [props.cesiumStatus])
102
+
103
+ return (
104
+ <ConfigProvider theme={{
105
+ ...theme
106
+ }}>
107
+ <div className={Styles['slider-box']}>
108
+ <div className={Styles['left-content']}>
109
+ 推演控制
110
+ </div>
111
+
112
+ <div className={Styles['right-content']}>
113
+ <Slider
114
+ min={0}
115
+ max={100}
116
+ step={0.1}
117
+ value={percent}
118
+ onChange={(value: number) => onSliderChange(value)}
119
+ />
120
+ <div className={Styles['time-text']}>{currentTime}/{totalTime}</div>
121
+ <div className={Styles['control-btn']}>
122
+ {
123
+ (['pause', 'play', 'stop'] as TContronType[]).map(item =>
124
+ <img key={item} onClick={() => control[item]()} src={require(`/image/${item}.png`)} />
125
+ )
126
+ }
127
+ </div>
128
+ </div>
129
+ </div>
130
+
131
+ </ConfigProvider>
132
+ )
133
+ }
134
+
135
+ export default Timeline
@@ -0,0 +1,55 @@
1
+ //template
2
+ import * as dict from './cesium.dict'
3
+ import * as Cesium from 'cesium'
4
+
5
+ export default {
6
+ //token&container
7
+ containerID: 'cesiumBox',
8
+ defaultAccessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkMjBmZGE5MS02ZTE1LTRjNzAtYmJjNS0zNTJhNmI1MDQ4YmQiLCJpZCI6OTQ5NzAsImlhdCI6MTY1MzM3ODM0Mn0.OcAxsSXF6VtqtI83SpUc5oL1fFxSFM60O3gp5YKyDeA',
9
+
10
+ //地形服务配置
11
+ imagery: {
12
+ status: dict.EImageryStatus.ENABLEDOFFLINE,
13
+ config: {
14
+ url: 'http://127.0.0.1:3001/{TileMatrix}/{TileCol}/{TileRow}.jpg',
15
+ layer: 'acimage',
16
+ format: 'image/jpeg',
17
+ tileMatrixSetID: 'wgs84',
18
+ style: 'default',
19
+ tilingScheme: new Cesium.GeographicTilingScheme(),
20
+ tileMatrixLabels: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"],
21
+ maximumLevel: 20
22
+ }
23
+ },
24
+ terrain: {
25
+ status: dict.ETerrainStatus.ENABLEDOFFLINE,
26
+ config: {
27
+ url: 'http://127.0.0.1:3002'
28
+ }
29
+ },
30
+
31
+ //通用工具配置
32
+ debug: false, //帧数
33
+ shadows: false, //阴影
34
+ lighting: false, //太阳光
35
+ depthTerrain: true, //地形深度检测
36
+ controllerStyle: dict.EControllerStyle.THREE, //操控习惯
37
+
38
+ // cesium基础配置
39
+ cesiumOptions: {
40
+ contextOptions: {
41
+ requestWebgl1: true
42
+ },
43
+ animation: false,
44
+ baseLayerPicker: false,
45
+ fullscreenButton: false,
46
+ geocoder: false,
47
+ homeButton: false,
48
+ infoBox: false,
49
+ sceneModePicker: false,
50
+ selectionIndicator: false,
51
+ timeline: false,
52
+ navigationHelpButton: false,
53
+ navigationInstructionsInitiallyVisible: false
54
+ }
55
+ }
@@ -0,0 +1,21 @@
1
+ enum ETerrainStatus {
2
+ ENABLEDLINE = 'enabledLine',
3
+ ENABLEDOFFLINE = 'enabledOffline',
4
+ DISABLED = 'disabled'
5
+ }
6
+
7
+ enum EImageryStatus {
8
+ ENABLEDLINE = 'enabledLine',
9
+ ENABLEDOFFLINE = 'enabledOffline'
10
+ }
11
+
12
+ enum EControllerStyle {
13
+ CESIUM = 'cesium',
14
+ THREE = 'three'
15
+ }
16
+
17
+ export {
18
+ ETerrainStatus,
19
+ EImageryStatus,
20
+ EControllerStyle
21
+ }
package/cesium/index.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import * as Cesium from 'cesium'
2
- import { useCameraRecord, EActionTtype } from './cameraRecord'
3
- import * as hooks from './utils'
2
+ import * as cesiumConfigDict from './config/cesium.dict'
4
3
 
5
- Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkMjBmZGE5MS02ZTE1LTRjNzAtYmJjNS0zNTJhNmI1MDQ4YmQiLCJpZCI6OTQ5NzAsImlhdCI6MTY1MzM3ODM0Mn0.OcAxsSXF6VtqtI83SpUc5oL1fFxSFM60O3gp5YKyDeA'
4
+ import * as hooks from './utils'
6
5
 
7
- import type { IRecord } from './cameraRecord'
6
+ import type { IRecord } from './testFunc/cameraRecord'
8
7
 
9
8
  type TCesiumUtilsType = {
10
9
  dict: typeof hooks.dict;
@@ -16,59 +15,70 @@ type TCesiumUtilsType = {
16
15
  measure: ReturnType<typeof hooks.useMeasure>;
17
16
  }
18
17
 
18
+ let viewer: Cesium.Viewer;
19
+ let config;
20
+
21
+ const defineCesiumConfig = (cesiumConfig) => {
22
+ config = cesiumConfig
23
+ }
24
+
19
25
  const useCesium = () => {
20
- const loadCesium = (containerName: string, callback: (viewer: Cesium.Viewer, utils: TCesiumUtilsType) => void, ev: {
26
+
27
+ let handler: Cesium.ScreenSpaceEventHandler;
28
+
29
+ const updateController = (viewer: Cesium.Viewer) => {
30
+ viewer.scene.screenSpaceCameraController.tiltEventTypes = [
31
+ Cesium.CameraEventType.LEFT_DRAG
32
+ ]
33
+
34
+ viewer.scene.screenSpaceCameraController.zoomEventTypes = [
35
+ Cesium.CameraEventType.MIDDLE_DRAG,
36
+ Cesium.CameraEventType.WHEEL,
37
+ Cesium.CameraEventType.PINCH
38
+ ]
39
+
40
+ viewer.scene.screenSpaceCameraController.rotateEventTypes = [
41
+ Cesium.CameraEventType.RIGHT_DRAG
42
+ ]
43
+ }
44
+
45
+ const load = async (callback: (viewer: Cesium.Viewer, utils: TCesiumUtilsType) => void, ev: {
21
46
  leftClickEvent: (viewer: Cesium.Viewer, e: Cesium.ScreenSpaceEventHandler.PositionedEvent) => void,
47
+ rightClickEvent: (viewer: Cesium.Viewer, e: Cesium.ScreenSpaceEventHandler.PositionedEvent) => void,
22
48
  moveEvent: (viewer: Cesium.Viewer, e: Cesium.ScreenSpaceEventHandler.MotionEvent) => void
23
49
  }) => {
24
50
 
25
- const viewer = new Cesium.Viewer(containerName, {
26
- contextOptions: {
27
- requestWebgl1: true
28
- },
29
- animation: false,
30
- baseLayerPicker: false,
31
- fullscreenButton: false,
32
- geocoder: false,
33
- homeButton: false,
34
- infoBox: false,
35
- sceneModePicker: false,
36
- selectionIndicator: false,
37
- timeline: false,
38
- navigationHelpButton: false,
39
- navigationInstructionsInitiallyVisible: false
40
- });
41
-
42
- viewer.scene.moon.show = false;
43
- viewer.scene.fog.enabled = false;
44
- viewer.scene.sun.show = true;
45
- viewer.scene.skyBox.show = false;
46
- // viewer.scene.debugShowFramesPerSecond = true;
47
- (viewer.cesiumWidget.creditContainer as HTMLElement).style.display = "none";
48
- viewer.scene.globe.depthTestAgainstTerrain = true;
49
-
50
- // const appConfig = {
51
- // WMTSMap: {
52
- // url: "http://10.10.0.99:9101/WeServer/wmts",
53
- // layer: 'East_image',
54
- // format: 'image/jpeg',
55
- // tileMatrixSetID: 'wgs84',
56
- // style: 'default'
57
- // }
58
- // }
59
-
60
- // const wmtsimage = new Cesium.WebMapTileServiceImageryProvider({
61
- // url: appConfig.WMTSMap.url,
62
- // layer: appConfig.WMTSMap.layer,
63
- // format: appConfig.WMTSMap.format,
64
- // tileMatrixSetID: appConfig.WMTSMap.tileMatrixSetID,
65
- // style: appConfig.WMTSMap.style,
66
- // tilingScheme: new Cesium.GeographicTilingScheme(),
67
- // maximumLevel: 19,
68
- // tileMatrixLabels: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"],
69
- // });
70
- // viewer.imageryLayers.removeAll();
71
- // viewer.imageryLayers.addImageryProvider(wmtsimage);
51
+ Cesium.Ion.defaultAccessToken = config.defaultAccessToken
52
+
53
+ viewer = new Cesium.Viewer(config.containerID, config.cesiumOptions);
54
+ (viewer.cesiumWidget.creditContainer as HTMLElement).style.display = "none"
55
+ viewer.scene.skyAtmosphere.show = true
56
+
57
+ viewer.scene.debugShowFramesPerSecond = config.debug
58
+ viewer.scene.globe.depthTestAgainstTerrain = config.depthTerrain
59
+ viewer.scene.globe.enableLighting = config.lighting
60
+
61
+ if (config.shadows) {
62
+ viewer.shadows = true
63
+ viewer.scene.globe.shadows = Cesium.ShadowMode.ENABLED
64
+ }
65
+
66
+ if (config.imagery.status === cesiumConfigDict.EImageryStatus.ENABLEDOFFLINE) {
67
+ viewer.imageryLayers.get(0).show = false
68
+ const imageryProvider = new Cesium.WebMapTileServiceImageryProvider(config.imagery.config)
69
+ viewer.imageryLayers.addImageryProvider(imageryProvider)
70
+ }
71
+
72
+ if (config.terrain.status === cesiumConfigDict.ETerrainStatus.ENABLEDLINE) {
73
+ viewer.terrainProvider = await Cesium.createWorldTerrainAsync({
74
+ requestVertexNormals: true,
75
+ requestWaterMask: true
76
+ })
77
+ } else if (config.terrain.status === cesiumConfigDict.ETerrainStatus.ENABLEDOFFLINE) {
78
+ viewer.imageryLayers.get(0).show = false
79
+ const terrainProvider = Cesium.CesiumTerrainProvider.fromUrl(config.terrain.config.url)
80
+ viewer.terrainProvider = await terrainProvider
81
+ }
72
82
 
73
83
  const customCollection = hooks.useCustomCollection(viewer)
74
84
  const drawPolygon = hooks.useDrawPolygon(viewer, {
@@ -79,6 +89,10 @@ const useCesium = () => {
79
89
  const weather = hooks.useWeather(viewer)
80
90
  const measure = hooks.useMeasure(viewer)
81
91
 
92
+ if (config.controllerStyle === cesiumConfigDict.EControllerStyle.THREE) {
93
+ updateController(viewer)
94
+ }
95
+
82
96
  callback(viewer, {
83
97
  dict: hooks.dict,
84
98
  customCollection,
@@ -88,31 +102,48 @@ const useCesium = () => {
88
102
  measure
89
103
  })
90
104
 
91
- const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
105
+ handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
92
106
 
93
107
  handler.setInputAction(((event) => {
94
108
  ev.leftClickEvent(viewer, event)
95
109
  }) as Cesium.ScreenSpaceEventHandler.PositionedEventCallback, Cesium.ScreenSpaceEventType.LEFT_CLICK);
96
110
 
111
+ handler.setInputAction(((event) => {
112
+ ev.rightClickEvent(viewer, event)
113
+ }) as Cesium.ScreenSpaceEventHandler.PositionedEventCallback, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
114
+
97
115
  handler.setInputAction(((event) => {
98
116
  ev.moveEvent(viewer, event)
99
117
  }) as Cesium.ScreenSpaceEventHandler.MotionEventCallback, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
100
118
  }
101
119
 
102
- const updateCameraEvent = (viewer: Cesium.Viewer) => {
103
- viewer.scene.screenSpaceCameraController.tiltEventTypes = [
104
- Cesium.CameraEventType.LEFT_DRAG
105
- ]
120
+ const dispose = (viewer: Cesium.Viewer) => {
121
+ handler && handler.destroy()
106
122
 
107
- viewer.scene.screenSpaceCameraController.zoomEventTypes = [
108
- Cesium.CameraEventType.MIDDLE_DRAG,
109
- Cesium.CameraEventType.WHEEL,
110
- Cesium.CameraEventType.PINCH
111
- ]
123
+ if (viewer && !viewer.isDestroyed()) {
124
+ viewer.entities.removeAll();
125
+ viewer.dataSources.removeAll();
126
+ viewer.imageryLayers.removeAll();
127
+ viewer.terrainProvider = new Cesium.EllipsoidTerrainProvider();
128
+ viewer.screenSpaceEventHandler?.destroy();
129
+ viewer.destroy();
130
+ }
131
+ }
112
132
 
113
- viewer.scene.screenSpaceCameraController.rotateEventTypes = [
114
- Cesium.CameraEventType.RIGHT_DRAG
115
- ]
133
+ const getPosition = (viewer: Cesium.Viewer, e: Cesium.ScreenSpaceEventHandler.PositionedEvent) => {
134
+ const ray = viewer.camera.getPickRay(e.position);
135
+ const cartesian = viewer.scene.globe.pick(ray, viewer.scene);
136
+ const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
137
+ const lng = Cesium.Math.toDegrees(cartographic.longitude);
138
+ const lat = Cesium.Math.toDegrees(cartographic.latitude);
139
+ const height = cartographic.height
140
+
141
+ return {
142
+ cartesian,
143
+ lng,
144
+ lat,
145
+ height
146
+ }
116
147
  }
117
148
 
118
149
  const getCamera = (viewer: Cesium.Viewer) => {
@@ -132,11 +163,11 @@ const useCesium = () => {
132
163
 
133
164
  const setCamera = (viewer: Cesium.Viewer) => {
134
165
  viewer.camera.flyTo({
135
- destination: new Cesium.Cartesian3(-3313326.6764875883, 6046492.400581042, 2681576.8673584852),
166
+ destination: new Cesium.Cartesian3(-2861904.995492709, 7226032.775714475, 1792790.547405678),
136
167
  orientation: {
137
- heading: 0.37123871980838885,
138
- pitch: -1.245479096883912,
139
- roll: 6.280549614726131
168
+ heading: 0.3720644640946844,
169
+ pitch: -1.2461928516756395,
170
+ roll: 6.279678267113614
140
171
  }
141
172
  })
142
173
  }
@@ -165,20 +196,89 @@ const useCesium = () => {
165
196
  viewer.flyTo(tileset)
166
197
  }
167
198
 
199
+ const getViewRectangle = (viewer: Cesium.Viewer) => {
200
+ const rectangle = viewer.camera.computeViewRectangle()
201
+
202
+ const northwest = Cesium.Rectangle.northwest(rectangle)
203
+ const northwestLon = Cesium.Math.toDegrees(northwest.longitude)
204
+ const northwestLat = Cesium.Math.toDegrees(northwest.latitude)
205
+
206
+ const southeast = Cesium.Rectangle.southeast(rectangle)
207
+ const southeastLon = Cesium.Math.toDegrees(southeast.longitude)
208
+ const southeastLat = Cesium.Math.toDegrees(southeast.latitude)
209
+
210
+ return {
211
+ northwest: {
212
+ lon: northwestLon,
213
+ lat: northwestLat
214
+ },
215
+ southeast: {
216
+ lon: southeastLon,
217
+ lat: southeastLat
218
+ }
219
+ }
220
+ }
221
+
222
+ const getRoom = (viewer: Cesium.Viewer) => {
223
+ const h = viewer.camera.positionCartographic.height
224
+ if (h <= 100) {
225
+ return 19
226
+ } else if (h < 300) {
227
+ return 18
228
+ } else if (h < 660) {
229
+ return 17
230
+ } else if (h < 1300) {
231
+ return 16
232
+ } else if (h < 2600) {
233
+ return 15
234
+ } else if (h < 6400) {
235
+ return 14
236
+ } else if (h < 13200) {
237
+ return 13
238
+ } else if (h < 26000) {
239
+ return 12
240
+ } else if (h < 67985) {
241
+ return 11
242
+ } else if (h < 139780) {
243
+ return 10
244
+ } else if (h < 250600) {
245
+ return 9
246
+ } else if (h < 380000) {
247
+ return 8
248
+ } else if (h < 640000) {
249
+ return 7
250
+ } else if (h < 1280000) {
251
+ return 6
252
+ } else if (h < 2600000) {
253
+ return 5
254
+ } else if (h < 610000) {
255
+ return 4
256
+ } else if (h < 11900000) {
257
+ return 3
258
+ } else {
259
+ return 2
260
+ }
261
+ }
262
+
168
263
  return {
169
- loadCesium,
170
- updateCameraEvent,
264
+ load,
265
+ dispose,
171
266
  getCamera,
172
267
  setCamera,
173
- loadTiles
268
+ loadTiles,
269
+ getPosition,
270
+ getViewRectangle,
271
+ getRoom
174
272
  }
175
273
  }
176
274
 
177
275
  export {
178
- EActionTtype,
179
-
180
276
  useCesium,
181
- useCameraRecord
277
+
278
+ viewer,
279
+
280
+ defineCesiumConfig,
281
+ cesiumConfigDict
182
282
  }
183
283
 
184
284
  export type {
@@ -68,14 +68,13 @@ class MeasureDistance {
68
68
  label: {
69
69
  text: spaceDistance(this.positions) + "米",
70
70
  scale: 0.5,
71
- font: 'normal 24px MicroSoft YaHei',
72
- distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000),
73
- scaleByDistance: new Cesium.NearFarScalar(1000, 1, 3000, 0.4),
74
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
71
+ font: 'normal 28px MicroSoft YaHei',
75
72
  style: Cesium.LabelStyle.FILL_AND_OUTLINE,
76
73
  pixelOffset: new Cesium.Cartesian2(0, -30),
77
74
  outlineWidth: 9,
78
- outlineColor: Cesium.Color.WHITE
75
+ outlineColor: Cesium.Color.WHITE,
76
+ heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
77
+ disableDepthTestDistance: Number.POSITIVE_INFINITY
79
78
  },
80
79
  point: {
81
80
  color: Cesium.Color.FUCHSIA,
@@ -93,7 +92,9 @@ class MeasureDistance {
93
92
  billboard: {
94
93
  scaleByDistance: new Cesium.NearFarScalar(300, 1, 1200, 0.4),
95
94
  distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 10000),
96
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM
95
+ verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
96
+ heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
97
+ disableDepthTestDistance: Number.POSITIVE_INFINITY
97
98
  },
98
99
  point: {
99
100
  color: Cesium.Color.FUCHSIA,
@@ -128,7 +129,9 @@ class MeasureDistance {
128
129
  image: "../../static/images/end.png",
129
130
  scaleByDistance: new Cesium.NearFarScalar(300, 1, 1200, 0.4),
130
131
  distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 10000),
131
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM
132
+ verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
133
+ heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
134
+ disableDepthTestDistance: Number.POSITIVE_INFINITY
132
135
  },
133
136
  point: {
134
137
  color: Cesium.Color.FUCHSIA,
@@ -299,14 +302,13 @@ class MeasureHeight {
299
302
  label: {
300
303
  text: "",
301
304
  scale: 0.5,
302
- font: 'normal 40px MicroSoft YaHei',
303
- distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000),
304
- scaleByDistance: new Cesium.NearFarScalar(500, 1, 1500, 0.4),
305
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
305
+ font: 'normal 28px MicroSoft YaHei',
306
306
  style: Cesium.LabelStyle.FILL_AND_OUTLINE,
307
307
  pixelOffset: new Cesium.Cartesian2(0, -30),
308
308
  outlineWidth: 9,
309
- outlineColor: Cesium.Color.WHITE
309
+ outlineColor: Cesium.Color.WHITE,
310
+ heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
311
+ disableDepthTestDistance: Number.POSITIVE_INFINITY
310
312
  }
311
313
  })
312
314
  }
@@ -544,13 +546,12 @@ class MeasureArea {
544
546
  }, false),
545
547
  scale: 0.5,
546
548
  font: 'normal 28px MicroSoft YaHei',
547
- distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000),
548
- scaleByDistance: new Cesium.NearFarScalar(1000, 1, 3000, 0.4),
549
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
550
549
  style: Cesium.LabelStyle.FILL_AND_OUTLINE,
551
550
  pixelOffset: new Cesium.Cartesian2(0, -30),
552
551
  outlineWidth: 9,
553
- outlineColor: Cesium.Color.WHITE
552
+ outlineColor: Cesium.Color.WHITE,
553
+ // heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
554
+ disableDepthTestDistance: Number.POSITIVE_INFINITY
554
555
  }
555
556
  });
556
557
  }
@@ -611,9 +612,10 @@ class MeasureArea {
611
612
 
612
613
  handleMoveEvent(position) {
613
614
  if (this.positions.length < 1) return;
614
-
615
615
  this.height = this.unifiedHeight(this.positions, this.height);
616
616
  this.tempPositions = this.positions.concat(position);
617
+ console.log(this.tempPositions.length,!this.mesureResultEntity);
618
+
617
619
  if (this.tempPositions.length >= 3 && !this.mesureResultEntity) {
618
620
  this.createResultLabel();
619
621
  }
@@ -1,17 +1,31 @@
1
1
  import * as Cesium from 'cesium'
2
2
 
3
3
  const useMeasureTools = (viewer: Cesium.Viewer) => {
4
- let handler = new Cesium.ScreenSpaceEventHandler((viewer.scene as any)._imageryLayerCollection);
5
- const positions = []
4
+ let handler = new Cesium.ScreenSpaceEventHandler((viewer.scene as any)._imageryLayerCollection)
5
+ let positions = []
6
6
  let positionsCartographic = []
7
7
  let positions_Inter = []
8
8
  let poly = null
9
9
  let distance = null
10
10
  let cartesian = null
11
- const DistanceArray = []
11
+ let DistanceArray = []
12
12
  let profileItem = []
13
13
 
14
+ const reset = () => {
15
+ handler = new Cesium.ScreenSpaceEventHandler((viewer.scene as any)._imageryLayerCollection)
16
+ positions = []
17
+ positionsCartographic = []
18
+ positions_Inter = []
19
+ poly = null
20
+ distance = null
21
+ cartesian = null
22
+ DistanceArray = []
23
+ profileItem = []
24
+ }
25
+
14
26
  const measureDistance = () => {
27
+ reset()
28
+
15
29
  handler.setInputAction(((movement) => {
16
30
  cartesian = viewer.scene.pickPosition(movement.endPosition);
17
31
  if (positions.length >= 2) {
@@ -2,7 +2,7 @@ import { v4 as uuid } from 'uuid'
2
2
  import * as Cesium from 'cesium'
3
3
 
4
4
  interface ICameraOptions {
5
- destination: Cesium.Cartesian3,
5
+ destination: Cesium.Cartesian3;
6
6
  orientation: {
7
7
  heading: number;
8
8
  pitch: number;
@@ -27,7 +27,7 @@ enum EActionTtype {
27
27
  const useCameraRecord = () => {
28
28
  let viewer: Cesium.Viewer | null = null
29
29
  let records: IRecord[] = []
30
- let timer: NodeJS.Timeout | null = null
30
+ let timer: number | null = null
31
31
  let cameraSpeed = 2
32
32
 
33
33
  const setViewer = (cesiumViewer: Cesium.Viewer) => {
@@ -130,7 +130,7 @@ const useCameraRecord = () => {
130
130
  })
131
131
  }
132
132
  idleTime = 0
133
- clearInterval(timer as NodeJS.Timeout)
133
+ clearInterval(timer as number)
134
134
  }
135
135
 
136
136
  let playTime = 0;
@@ -10,7 +10,7 @@ const useDrawPolygon = (viewer: Cesium.Viewer, options: {
10
10
  const moveHandler: Cesium.ScreenSpaceEventHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
11
11
  let pointPosData: Cesium.Cartesian3[][] = []
12
12
 
13
- const start = () => {
13
+ const start = (cb: (geoJSONData: string) => void) => {
14
14
 
15
15
  const points: Cesium.Cartesian3[] = []
16
16
 
@@ -57,10 +57,24 @@ const useDrawPolygon = (viewer: Cesium.Viewer, options: {
57
57
  points.pop()
58
58
 
59
59
  stop()
60
- start()
60
+ // start()
61
61
 
62
62
  pointPosData.push(points)
63
63
 
64
+ const coordinates = points.map(item => {
65
+ const cart = Cesium.Cartographic.fromCartesian(item)
66
+ const lon = Cesium.Math.toDegrees(cart.longitude);
67
+ const lat = Cesium.Math.toDegrees(cart.latitude);
68
+
69
+ return [lon, lat]
70
+ })
71
+
72
+ cb(JSON.stringify({
73
+ "type": "Polygon",
74
+ "coordinates": [
75
+ [...coordinates, coordinates[0]]
76
+ ]
77
+ }))
64
78
  }, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
65
79
  }
66
80
 
@@ -42,7 +42,7 @@ const useMeasure = (viewer: Cesium.Viewer) => {
42
42
  positions: [anglePoints[anglePoints.length - 2], anglePoints[anglePoints.length - 1]],
43
43
  width: 2,
44
44
  material: Cesium.Color.fromCssColorString("rgb(249, 157, 11)"),
45
- clampToGround: true
45
+ clampToGround: true,
46
46
  }
47
47
  });
48
48
  angleLines.push(lineEntity)
@@ -107,7 +107,8 @@ const useMeasure = (viewer: Cesium.Viewer) => {
107
107
  fillColor: Cesium.Color.WHITE,
108
108
  verticalOrigin: Cesium.VerticalOrigin.CENTER,
109
109
  pixelOffset: new Cesium.Cartesian2(20, 0),
110
- heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
110
+ heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
111
+ disableDepthTestDistance: Number.POSITIVE_INFINITY
111
112
  }
112
113
  });
113
114
  angleLabels.push(angleLabel)
@@ -0,0 +1,100 @@
1
+ import * as Cesium from 'cesium'
2
+
3
+ export enum EPlayStatus {
4
+ SPEED = 'speed',
5
+ TIME = 'time'
6
+ }
7
+
8
+ export enum EControlAction {
9
+ PLAY = 'play',
10
+ PAUSE = 'pause'
11
+ }
12
+
13
+ export interface IPathType {
14
+ modelParams: {
15
+ id: string;
16
+ name: string;
17
+ uri: string;
18
+ };
19
+ path: {
20
+ duration: number;
21
+ point: Cesium.Cartesian3;
22
+ speed: number;
23
+ }[];
24
+ playStatus: EPlayStatus;
25
+ totalDuration: number;
26
+ }
27
+
28
+ const usePath = () => {
29
+
30
+ const playAnimation = (viewer: Cesium.Viewer, path: IPathType[]) => {
31
+ const startTime = Cesium.JulianDate.fromDate(new Date())
32
+
33
+ path.forEach(item => {
34
+ const property = new Cesium.SampledPositionProperty();
35
+ item.totalDuration = 0
36
+
37
+ item.path.forEach((value, i) => {
38
+ if (i === 0) {
39
+ property.addSample(Cesium.JulianDate.addSeconds(startTime, 0, new Cesium.JulianDate()), value.point);
40
+ }
41
+ if (i > 0) {
42
+ const distance = Cesium.Cartesian3.distance(item.path[i - 1].point, value.point).toFixed();
43
+ if (item.playStatus === EPlayStatus.SPEED) {
44
+ const time = Number(distance) / value.speed
45
+ item.totalDuration = item.totalDuration + time
46
+ property.addSample(Cesium.JulianDate.addSeconds(startTime, item.totalDuration, new Cesium.JulianDate()), value.point);
47
+ } else if (item.playStatus === EPlayStatus.TIME) {
48
+ item.totalDuration = item.totalDuration + Number(value.duration)
49
+ property.addSample(Cesium.JulianDate.addSeconds(startTime, item.totalDuration, new Cesium.JulianDate()), value.point);
50
+ }
51
+ }
52
+ if (i === item.path.length - 1) {
53
+ property.addSample(Cesium.JulianDate.fromDate(new Date(2099, 12, 31)), value.point);
54
+ }
55
+ })
56
+
57
+ if (item.path.length) {
58
+ viewer.entities.removeById(item.modelParams.id)
59
+ viewer.entities.add({
60
+ id: item.modelParams.id,
61
+ name: item.modelParams.name,
62
+ position: property,
63
+ orientation: new Cesium.VelocityOrientationProperty(property),
64
+ model: {
65
+ uri: item.modelParams.uri,
66
+ heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
67
+ }
68
+ })
69
+ }
70
+ })
71
+
72
+ path.sort((pre, cur) => cur.totalDuration - pre.totalDuration)
73
+
74
+ viewer.clock.startTime = startTime.clone();
75
+ viewer.clock.stopTime = Cesium.JulianDate.addSeconds(startTime, path[0].totalDuration, new Cesium.JulianDate())
76
+
77
+ viewer.clock.currentTime = startTime.clone();
78
+ viewer.clock.clockStep = Cesium.ClockStep.SYSTEM_CLOCK;
79
+ viewer.clock.shouldAnimate = true;
80
+ viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
81
+ }
82
+
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
+ return {
92
+ playAnimation,
93
+ controlAction,
94
+ reset
95
+ }
96
+ }
97
+
98
+ export {
99
+ usePath
100
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-three-utils",
3
- "version": "0.0.333",
3
+ "version": "0.0.335",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"