easy-three-utils 0.0.351 → 0.0.353

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.
@@ -1,4 +1,5 @@
1
1
  import Timeline from './react/Timeline/index.tsx'
2
+ import TerrainLine from './react/TerrainLine/index.tsx'
2
3
  import ProFileEcharts from './react/ProFileEcharts/index.tsx'
3
4
 
4
5
  const components = {
@@ -6,6 +7,7 @@ const components = {
6
7
  },
7
8
  react: {
8
9
  Timeline,
10
+ TerrainLine,
9
11
  ProFileEcharts
10
12
  }
11
13
  }
@@ -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,53 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import { Slider, ConfigProvider } from "antd";
3
+ import * as Cesium from "cesium";
4
+
5
+ import Styles from './index.module.less'
6
+
7
+ const Timeline: React.FC<{
8
+ getViewer: () => Cesium.Viewer
9
+ }> = (props) => {
10
+
11
+ const { getViewer } = props
12
+ const [percent, setPercent] = useState(1)
13
+
14
+ const theme = {
15
+ components: {
16
+ Slider: {
17
+ railBg: '#bfbfbf',
18
+ railHoverBg: '#bfbfbf',
19
+ trackBg: '#176fdbff'
20
+ }
21
+ }
22
+ }
23
+
24
+ const onSliderChange = (value: number) => {
25
+ setPercent(() => value);
26
+ getViewer().scene.verticalExaggeration = value
27
+ }
28
+
29
+ useEffect(() => {
30
+ return () => {
31
+ }
32
+ }, [])
33
+
34
+ return (
35
+ <ConfigProvider theme={{
36
+ ...theme
37
+ }}>
38
+ <div className={Styles['slider-box']}>
39
+ <div className={Styles['right-content']}>
40
+ <Slider
41
+ min={0}
42
+ max={10}
43
+ step={1}
44
+ value={percent}
45
+ onChange={(value: number) => onSliderChange(value)}
46
+ />
47
+ </div>
48
+ </div>
49
+ </ConfigProvider>
50
+ )
51
+ }
52
+
53
+ export default Timeline
package/cesium/index.ts CHANGED
@@ -16,6 +16,8 @@ type TCesiumUtilsType = {
16
16
  slope: ReturnType<typeof hooks.useSlope>;
17
17
  profileAnalysis: ReturnType<typeof hooks.useProfileAnalysis>;
18
18
  viewshedAnalysis: ReturnType<typeof hooks.useViewshedAnalysis>;
19
+ cloud: ReturnType<typeof hooks.useCloud>;
20
+ seawater: ReturnType<typeof hooks.useSeawater>;
19
21
  }
20
22
 
21
23
  let config;
@@ -78,7 +80,9 @@ const useCesium = () => {
78
80
  })
79
81
  } else if (config.terrain.status === cesiumConfigDict.ETerrainStatus.ENABLEDOFFLINE) {
80
82
  viewer.imageryLayers.get(0).show = false
81
- const terrainProvider = Cesium.CesiumTerrainProvider.fromUrl(config.terrain.config.url)
83
+ const terrainProvider = Cesium.CesiumTerrainProvider.fromUrl(config.terrain.config.url, {
84
+ requestVertexNormals: true
85
+ })
82
86
  viewer.terrainProvider = await terrainProvider
83
87
  }
84
88
 
@@ -104,7 +108,8 @@ const useCesium = () => {
104
108
  const viewshedAnalysis = hooks.useViewshedAnalysis(viewer, {
105
109
  collection: customCollection.addCollection(hooks.dict.ECollectionWhiteListNames.VIEWSHEDANALYSIS)
106
110
  })
107
-
111
+ const cloud = hooks.useCloud(viewer)
112
+ const seawater = hooks.useSeawater(viewer)
108
113
 
109
114
  if (config.controllerStyle === cesiumConfigDict.EControllerStyle.THREE) {
110
115
  updateController(viewer)
@@ -119,7 +124,9 @@ const useCesium = () => {
119
124
  measure,
120
125
  slope,
121
126
  profileAnalysis,
122
- viewshedAnalysis
127
+ viewshedAnalysis,
128
+ cloud,
129
+ seawater
123
130
  })
124
131
 
125
132
  handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
@@ -6,6 +6,8 @@ import { useMeasure } from './useMeasure'
6
6
  import { useSlope } from './useSlope'
7
7
  import { useProfileAnalysis } from './useProfileAnalysis'
8
8
  import { useViewshedAnalysis } from './useViewshedAnalysis'
9
+ import { useCloud } from './useCloud'
10
+ import { useSeawater } from './useSeawater'
9
11
 
10
12
  const dict = {
11
13
  ECollectionWhiteListNames,
@@ -21,6 +23,8 @@ export {
21
23
  useSlope,
22
24
  useProfileAnalysis,
23
25
  useViewshedAnalysis,
26
+ useCloud,
27
+ useSeawater,
24
28
 
25
29
  dict
26
30
  }
@@ -1,4 +1,5 @@
1
1
  import * as Cesium from 'cesium'
2
+ import { v7 as uuidv7 } from 'uuid'
2
3
 
3
4
  const useCloud = (viewer: Cesium.Viewer) => {
4
5
 
@@ -11,7 +12,7 @@ const useCloud = (viewer: Cesium.Viewer) => {
11
12
  return {
12
13
  lon: Cesium.Math.toDegrees(cartographic.longitude),
13
14
  lat: Cesium.Math.toDegrees(cartographic.latitude),
14
- height: cartographic.height + h,
15
+ height: cartographic.height + h
15
16
  }
16
17
  })
17
18
 
@@ -45,7 +46,7 @@ const useCloud = (viewer: Cesium.Viewer) => {
45
46
  return inside;
46
47
  }
47
48
 
48
- const points = [];
49
+ const points = []
49
50
  while (points.length < numPoints) {
50
51
  const lon = Math.random() * (maxLon - minLon) + minLon
51
52
  const lat = Math.random() * (maxLat - minLat) + minLat
@@ -57,20 +58,39 @@ const useCloud = (viewer: Cesium.Viewer) => {
57
58
  return points;
58
59
  }
59
60
 
60
- const activateDrawCloud = (cloudWidth: number, cloudLength: number, density: number, points: Cesium.Cartesian3[]) => {
61
+ const draw = (points: Cesium.Cartesian3[], params: {
62
+ cloudWidth?: number,
63
+ cloudLength?: number,
64
+ density?: number,
65
+ color?: string
66
+ } = {
67
+ cloudWidth: 100000,
68
+ cloudLength: 100000,
69
+ density: 0.8,
70
+ color: 'rgba(255, 255, 255, 0.8)'
71
+ }) => {
72
+
73
+ const options = Object.assign({}, {
74
+ cloudWidth: 100000,
75
+ cloudLength: 100000,
76
+ density: 0.8,
77
+ color: 'rgba(255, 255, 255, 0.8)'
78
+ }, params)
79
+
61
80
  const clouds = viewer.scene.primitives.add(new Cesium.CloudCollection())
62
81
 
63
- // cloudsCollection.push({
64
- // id:
65
- // })
82
+ cloudsCollection.push({
83
+ id: uuidv7(),
84
+ clouds
85
+ })
66
86
 
67
87
  const width = Math.max(...points.map(p => p.x)) - Math.min(...points.map(p => p.x))
68
88
  const length = Math.max(...points.map(p => p.y)) - Math.min(...points.map(p => p.y))
69
- const num = Math.floor(width * length / (cloudLength * cloudWidth)) * density
70
- const _points = getRandomPoints(points, num, 5000 + (cloudLength + cloudWidth) / 2)
89
+ const num = Math.floor(width * length / (options.cloudLength * options.cloudWidth)) * options.density
90
+ const _points = getRandomPoints(points, num, 5000 + (options.cloudLength + options.cloudWidth) / 2)
71
91
 
72
92
  _points.forEach(point => {
73
- const r = Math.random();
93
+ const r = Math.random()
74
94
  clouds.add({
75
95
  show: true,
76
96
  position: point,
@@ -80,17 +100,12 @@ const useCloud = (viewer: Cesium.Viewer) => {
80
100
  3 + r * 5
81
101
  ),
82
102
  scale: new Cesium.Cartesian2(
83
- cloudWidth * (0.8 + Math.random() * 0.4),
84
- cloudLength * (0.8 + Math.random() * 0.4)
103
+ options.cloudWidth * (0.8 + Math.random() * 0.4),
104
+ options.cloudLength * (0.8 + Math.random() * 0.4)
85
105
  ),
86
106
  slice: 0.2 + Math.random() * 0.3,
87
107
  brightness: 0.8 + Math.random() * 0.4,
88
- color: new Cesium.Color(
89
- 0.9 + Math.random() * 0.1,
90
- 0.7 + Math.random() * 0.2,
91
- 0.6 + Math.random() * 0.2,
92
- 0.8
93
- ),
108
+ color: Cesium.Color.fromCssColorString(options.color),
94
109
  noiseDetail: 3.0 + Math.random(),
95
110
  noiseOffset: new Cesium.Cartesian3(
96
111
  Math.random() * 100,
@@ -103,11 +118,20 @@ const useCloud = (viewer: Cesium.Viewer) => {
103
118
  )
104
119
  })
105
120
  })
106
-
107
121
  }
108
122
 
109
- const clearAll = () => {
123
+ const removeAll = () => {
124
+ cloudsCollection.forEach(item => item.clouds.removeAll())
125
+ viewer.scene.primitives.removeAll()
126
+ cloudsCollection = []
127
+ }
110
128
 
129
+ return {
130
+ draw,
131
+ removeAll
111
132
  }
133
+ }
112
134
 
135
+ export {
136
+ useCloud
113
137
  }
@@ -10,7 +10,10 @@ 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 = (cb: (geoJSONData: string) => void) => {
13
+ const start = (cb: (data: {
14
+ geoJSON: string;
15
+ points: Cesium.Cartesian3[];
16
+ }) => void) => {
14
17
 
15
18
  const points: Cesium.Cartesian3[] = []
16
19
 
@@ -69,12 +72,15 @@ const useDrawPolygon = (viewer: Cesium.Viewer, options: {
69
72
  return [lon, lat]
70
73
  })
71
74
 
72
- cb(JSON.stringify({
73
- "type": "Polygon",
74
- "coordinates": [
75
- [...coordinates, coordinates[0]]
76
- ]
77
- }))
75
+ cb({
76
+ geoJSON: JSON.stringify({
77
+ "type": "Polygon",
78
+ "coordinates": [
79
+ [...coordinates, coordinates[0]]
80
+ ]
81
+ }),
82
+ points: [...points, points[0]]
83
+ })
78
84
  }, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
79
85
  }
80
86
 
@@ -0,0 +1,50 @@
1
+ import * as Cesium from 'cesium'
2
+
3
+ const useSeawater = (viewer: Cesium.Viewer) => {
4
+ let water;
5
+
6
+ const enabled = () => {
7
+ if (water) return
8
+ water = viewer.scene.primitives.add(
9
+ new Cesium.Primitive({
10
+ geometryInstances: new Cesium.GeometryInstance({
11
+ geometry: new Cesium.RectangleGeometry({
12
+ rectangle: Cesium.Rectangle.fromDegrees(-180.0, -90.0, 180.0, 90.0),
13
+ vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
14
+ height: 450
15
+ })
16
+ }),
17
+ appearance: new Cesium.EllipsoidSurfaceAppearance({
18
+ aboveGround: false,
19
+ material: new Cesium.Material({
20
+ fabric: {
21
+ type: 'Water',
22
+ uniforms: {
23
+ specularMap: __POLT__URL__ + '/assets/image/earthspec.jpg',
24
+ normalMap: Cesium.buildModuleUrl('Assets/Textures/waterNormals.jpg'),
25
+ frequency: 10000.0,
26
+ animationSpeed: 0.01,
27
+ amplitude: 1.0,
28
+ },
29
+ },
30
+ }),
31
+ }),
32
+ show: true
33
+ })
34
+ )
35
+ }
36
+
37
+ const disabled = () => {
38
+ viewer.scene.primitives.remove(water)
39
+ water = null
40
+ }
41
+
42
+ return {
43
+ enabled,
44
+ disabled
45
+ }
46
+ }
47
+
48
+ export {
49
+ useSeawater
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-three-utils",
3
- "version": "0.0.351",
3
+ "version": "0.0.353",
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": "新增可视域分析"
11
+ "description": "新增海水"
12
12
  }