easy-three-utils 0.0.33 → 0.0.332
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/cameraRecord.ts +187 -0
- package/cesium/glsl/viewable.ts +122 -0
- package/cesium/glsl/weather.ts +78 -0
- package/cesium/index.ts +188 -0
- package/cesium/js/lib/CreatePolygonOnGround.js +191 -0
- package/cesium/js/lib/ReminderTip.js +71 -0
- package/cesium/js/measure.js +753 -0
- package/cesium/js/measure1.ts +194 -0
- package/cesium/js/slope.js +379 -0
- package/cesium/utils/index.ts +20 -0
- package/cesium/utils/useClipping.ts +90 -0
- package/cesium/utils/useCustomCollection.ts +50 -0
- package/cesium/utils/useDrawPolygon.ts +118 -0
- package/cesium/utils/useMeasure.ts +152 -0
- package/cesium/utils/useViewShed.ts +199 -0
- package/cesium/utils/useWeather.ts +127 -0
- package/package.json +1 -1
- package/src/common/useLoader.ts +4 -2
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { v4 as uuid } from 'uuid'
|
|
2
|
+
import * as Cesium from 'cesium'
|
|
3
|
+
|
|
4
|
+
interface ICameraOptions {
|
|
5
|
+
destination: Cesium.Cartesian3,
|
|
6
|
+
orientation: {
|
|
7
|
+
heading: number;
|
|
8
|
+
pitch: number;
|
|
9
|
+
roll: number;
|
|
10
|
+
},
|
|
11
|
+
duration?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface IRecord {
|
|
15
|
+
actionType: EActionTtype;
|
|
16
|
+
data?: ICameraOptions;
|
|
17
|
+
time: number;
|
|
18
|
+
id: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
enum EActionTtype {
|
|
22
|
+
INITVIEW = 'initView',
|
|
23
|
+
MOVE = 'move',
|
|
24
|
+
PAUSE = 'pause'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const useCameraRecord = () => {
|
|
28
|
+
let viewer: Cesium.Viewer | null = null
|
|
29
|
+
let records: IRecord[] = []
|
|
30
|
+
let timer: NodeJS.Timeout | null = null
|
|
31
|
+
let cameraSpeed = 2
|
|
32
|
+
|
|
33
|
+
const setViewer = (cesiumViewer: Cesium.Viewer) => {
|
|
34
|
+
viewer = cesiumViewer
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const recordCameraActions = (time: number) => {
|
|
38
|
+
const camera = viewer!.camera;
|
|
39
|
+
const { positionCartographic: pos, heading, pitch, roll } = camera
|
|
40
|
+
const { x, y, z } = Cesium.Cartesian3.fromRadians(pos.longitude, pos.latitude, pos.height)
|
|
41
|
+
|
|
42
|
+
const data = {
|
|
43
|
+
destination: new Cesium.Cartesian3(x, y, z),
|
|
44
|
+
orientation: {
|
|
45
|
+
heading,
|
|
46
|
+
pitch,
|
|
47
|
+
roll
|
|
48
|
+
},
|
|
49
|
+
duration: time / 1000 * cameraSpeed
|
|
50
|
+
}
|
|
51
|
+
if (time) {
|
|
52
|
+
records.push({
|
|
53
|
+
actionType: EActionTtype.MOVE,
|
|
54
|
+
data,
|
|
55
|
+
time: time,
|
|
56
|
+
id: uuid()
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let idleTime = 0
|
|
62
|
+
let removeMoveStartEvent: Cesium.Event.RemoveCallback, removeMoveEndEvent: Cesium.Event.RemoveCallback;
|
|
63
|
+
let time = 0
|
|
64
|
+
let startTime = 0
|
|
65
|
+
let mouseDownstatus = false
|
|
66
|
+
const recordScript = () => {
|
|
67
|
+
records = []
|
|
68
|
+
viewer!.scene.screenSpaceCameraController.inertiaSpin = 0
|
|
69
|
+
viewer!.scene.screenSpaceCameraController.inertiaTranslate = 0
|
|
70
|
+
viewer!.scene.screenSpaceCameraController.inertiaZoom = 0
|
|
71
|
+
const camera = viewer!.camera;
|
|
72
|
+
const { positionCartographic: pos, heading, pitch, roll } = camera
|
|
73
|
+
const { x, y, z } = Cesium.Cartesian3.fromRadians(pos.longitude, pos.latitude, pos.height)
|
|
74
|
+
|
|
75
|
+
const data = {
|
|
76
|
+
destination: new Cesium.Cartesian3(x, y, z),
|
|
77
|
+
orientation: {
|
|
78
|
+
heading,
|
|
79
|
+
pitch,
|
|
80
|
+
roll
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
records.push({
|
|
84
|
+
actionType: EActionTtype.INITVIEW,
|
|
85
|
+
data,
|
|
86
|
+
time: 0,
|
|
87
|
+
id: uuid()
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
removeMoveStartEvent = viewer!.scene.camera.moveStart.addEventListener(() => {
|
|
91
|
+
startTime = time
|
|
92
|
+
mouseDownstatus = true
|
|
93
|
+
|
|
94
|
+
if (idleTime) {
|
|
95
|
+
records.push({
|
|
96
|
+
actionType: EActionTtype.PAUSE,
|
|
97
|
+
time: idleTime,
|
|
98
|
+
id: uuid()
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
idleTime = 0
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
removeMoveEndEvent = viewer!.scene.camera.moveEnd.addEventListener(() => {
|
|
105
|
+
const timestamp = time - startTime
|
|
106
|
+
recordCameraActions(timestamp)
|
|
107
|
+
mouseDownstatus = false
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
timer = setInterval(() => {
|
|
111
|
+
time += 100;
|
|
112
|
+
if (!mouseDownstatus) {
|
|
113
|
+
idleTime = idleTime + 100;
|
|
114
|
+
}
|
|
115
|
+
}, 100)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const stopRecordScript = () => {
|
|
119
|
+
if (mouseDownstatus) {
|
|
120
|
+
const timestamp = time - startTime
|
|
121
|
+
recordCameraActions(timestamp)
|
|
122
|
+
}
|
|
123
|
+
removeMoveStartEvent()
|
|
124
|
+
removeMoveEndEvent()
|
|
125
|
+
if (idleTime) {
|
|
126
|
+
records.push({
|
|
127
|
+
actionType: EActionTtype.PAUSE,
|
|
128
|
+
time: idleTime,
|
|
129
|
+
id: uuid()
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
idleTime = 0
|
|
133
|
+
clearInterval(timer as NodeJS.Timeout)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let playTime = 0;
|
|
137
|
+
const playScript = () => {
|
|
138
|
+
playTime = 0
|
|
139
|
+
viewer!.camera.setView(records[0].data as any)
|
|
140
|
+
viewer!.scene.screenSpaceCameraController.inertiaSpin = 0.9
|
|
141
|
+
viewer!.scene.screenSpaceCameraController.inertiaTranslate = 0.9
|
|
142
|
+
viewer!.scene.screenSpaceCameraController.inertiaZoom = 0.8
|
|
143
|
+
|
|
144
|
+
records.forEach(async (item) => {
|
|
145
|
+
if (item.actionType === EActionTtype.MOVE) {
|
|
146
|
+
new Promise((resolve) => {
|
|
147
|
+
const func = () => {
|
|
148
|
+
const timer = setTimeout(() => {
|
|
149
|
+
viewer!.camera.flyTo(item.data!)
|
|
150
|
+
clearTimeout(timer)
|
|
151
|
+
}, playTime)
|
|
152
|
+
}
|
|
153
|
+
resolve(func())
|
|
154
|
+
})
|
|
155
|
+
playTime = playTime + item.time * cameraSpeed
|
|
156
|
+
} else {
|
|
157
|
+
playTime = playTime + item.time
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const setScriptRecords = (value: IRecord[]) => {
|
|
163
|
+
records = value
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const getScriptRecords = () => {
|
|
167
|
+
return records
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
setViewer,
|
|
172
|
+
getScriptRecords,
|
|
173
|
+
recordScript,
|
|
174
|
+
stopRecordScript,
|
|
175
|
+
playScript,
|
|
176
|
+
setScriptRecords
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export {
|
|
181
|
+
useCameraRecord,
|
|
182
|
+
EActionTtype
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export type {
|
|
186
|
+
IRecord
|
|
187
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export default `
|
|
2
|
+
#define USE_CUBE_MAP_SHADOW true
|
|
3
|
+
uniform sampler2D colorTexture;
|
|
4
|
+
uniform sampler2D depthTexture;
|
|
5
|
+
varying vec2 v_textureCoordinates;
|
|
6
|
+
uniform mat4 camera_projection_matrix;
|
|
7
|
+
uniform mat4 camera_view_matrix;
|
|
8
|
+
uniform samplerCube shadowMap_textureCube;
|
|
9
|
+
uniform mat4 shadowMap_matrix;
|
|
10
|
+
uniform vec4 shadowMap_lightPositionEC;
|
|
11
|
+
uniform vec4 shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness;
|
|
12
|
+
uniform vec4 shadowMap_texelSizeDepthBiasAndNormalShadingSmooth;
|
|
13
|
+
uniform float helsing_viewDistance;
|
|
14
|
+
uniform vec4 helsing_visibleAreaColor;
|
|
15
|
+
uniform vec4 helsing_invisibleAreaColor;
|
|
16
|
+
|
|
17
|
+
struct zx_shadowParameters
|
|
18
|
+
{
|
|
19
|
+
vec3 texCoords;
|
|
20
|
+
float depthBias;
|
|
21
|
+
float depth;
|
|
22
|
+
float nDotL;
|
|
23
|
+
vec2 texelStepSize;
|
|
24
|
+
float normalShadingSmooth;
|
|
25
|
+
float darkness;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
float czm_shadowVisibility(samplerCube shadowMap, zx_shadowParameters shadowParameters)
|
|
29
|
+
{
|
|
30
|
+
float depthBias = shadowParameters.depthBias;
|
|
31
|
+
float depth = shadowParameters.depth;
|
|
32
|
+
float nDotL = shadowParameters.nDotL;
|
|
33
|
+
float normalShadingSmooth = shadowParameters.normalShadingSmooth;
|
|
34
|
+
float darkness = shadowParameters.darkness;
|
|
35
|
+
vec3 uvw = shadowParameters.texCoords;
|
|
36
|
+
depth -= depthBias;
|
|
37
|
+
float visibility = czm_shadowDepthCompare(shadowMap, uvw, depth);
|
|
38
|
+
return czm_private_shadowVisibility(visibility, nDotL, normalShadingSmooth, darkness);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
vec4 getPositionEC(){
|
|
42
|
+
return czm_windowToEyeCoordinates(gl_FragCoord);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
vec3 getNormalEC(){
|
|
46
|
+
return vec3(1.);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
vec4 toEye(in vec2 uv,in float depth){
|
|
50
|
+
vec2 xy=vec2((uv.x*2.-1.),(uv.y*2.-1.));
|
|
51
|
+
vec4 posInCamera=czm_inverseProjection*vec4(xy,depth,1.);
|
|
52
|
+
posInCamera=posInCamera/posInCamera.w;
|
|
53
|
+
return posInCamera;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
vec3 pointProjectOnPlane(in vec3 planeNormal,in vec3 planeOrigin,in vec3 point){
|
|
57
|
+
vec3 v01=point-planeOrigin;
|
|
58
|
+
float d=dot(planeNormal,v01);
|
|
59
|
+
return(point-planeNormal*d);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
float getDepth(in vec4 depth){
|
|
63
|
+
float z_window=czm_unpackDepth(depth);
|
|
64
|
+
z_window=czm_reverseLogDepth(z_window);
|
|
65
|
+
float n_range=czm_depthRange.near;
|
|
66
|
+
float f_range=czm_depthRange.far;
|
|
67
|
+
return(2.*z_window-n_range-f_range)/(f_range-n_range);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
float shadow(in vec4 positionEC){
|
|
71
|
+
vec3 normalEC=getNormalEC();
|
|
72
|
+
zx_shadowParameters shadowParameters;
|
|
73
|
+
shadowParameters.texelStepSize=shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.xy;
|
|
74
|
+
shadowParameters.depthBias=shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.z;
|
|
75
|
+
shadowParameters.normalShadingSmooth=shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.w;
|
|
76
|
+
shadowParameters.darkness=shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness.w;
|
|
77
|
+
vec3 directionEC=positionEC.xyz-shadowMap_lightPositionEC.xyz;
|
|
78
|
+
float distance=length(directionEC);
|
|
79
|
+
directionEC=normalize(directionEC);
|
|
80
|
+
float radius=shadowMap_lightPositionEC.w;
|
|
81
|
+
if(distance>radius)
|
|
82
|
+
{
|
|
83
|
+
return 2.0;
|
|
84
|
+
}
|
|
85
|
+
vec3 directionWC=czm_inverseViewRotation*directionEC;
|
|
86
|
+
shadowParameters.depth=distance/radius-0.0003;
|
|
87
|
+
shadowParameters.nDotL=clamp(dot(normalEC,-directionEC),0.,1.);
|
|
88
|
+
shadowParameters.texCoords=directionWC;
|
|
89
|
+
float visibility=czm_shadowVisibility(shadowMap_textureCube,shadowParameters);
|
|
90
|
+
return visibility;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
bool visible(in vec4 result)
|
|
94
|
+
{
|
|
95
|
+
result.x/=result.w;
|
|
96
|
+
result.y/=result.w;
|
|
97
|
+
result.z/=result.w;
|
|
98
|
+
return result.x>=-1.&&result.x<=1.
|
|
99
|
+
&&result.y>=-1.&&result.y<=1.
|
|
100
|
+
&&result.z>=-1.&&result.z<=1.;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
void main(){
|
|
104
|
+
gl_FragColor = texture2D(colorTexture, v_textureCoordinates);
|
|
105
|
+
float depth = getDepth(texture2D(depthTexture, v_textureCoordinates));
|
|
106
|
+
vec4 viewPos = toEye(v_textureCoordinates, depth);
|
|
107
|
+
vec4 wordPos = czm_inverseView * viewPos;
|
|
108
|
+
vec4 vcPos = camera_view_matrix * wordPos;
|
|
109
|
+
float near = .001 * helsing_viewDistance;
|
|
110
|
+
float dis = length(vcPos.xyz);
|
|
111
|
+
if(dis > near && dis < helsing_viewDistance){
|
|
112
|
+
vec4 posInEye = camera_projection_matrix * vcPos;
|
|
113
|
+
if(visible(posInEye)){
|
|
114
|
+
float vis = shadow(viewPos);
|
|
115
|
+
if (vis > 0.3) {
|
|
116
|
+
gl_FragColor = mix(gl_FragColor, helsing_visibleAreaColor, .5);
|
|
117
|
+
} else {
|
|
118
|
+
gl_FragColor = mix(gl_FragColor, helsing_invisibleAreaColor, .5);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}`;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const rainShader = "uniform sampler2D colorTexture;\n\
|
|
2
|
+
varying vec2 v_textureCoordinates;\n\
|
|
3
|
+
uniform float tiltAngle;\n\
|
|
4
|
+
uniform float rainSize;\n\
|
|
5
|
+
uniform float rainSpeed;\n\
|
|
6
|
+
float hash(float x) {\n\
|
|
7
|
+
return fract(sin(x * 133.3) * 13.13);\n\
|
|
8
|
+
}\n\
|
|
9
|
+
void main(void) {\n\
|
|
10
|
+
float time = czm_frameNumber / rainSpeed;\n\
|
|
11
|
+
vec2 resolution = czm_viewport.zw;\n\
|
|
12
|
+
vec2 uv = (gl_FragCoord.xy * 2. - resolution.xy) / min(resolution.x, resolution.y);\n\
|
|
13
|
+
vec3 c = vec3(.6, .7, .8);\n\
|
|
14
|
+
float a = tiltAngle;\n\
|
|
15
|
+
float si = sin(a), co = cos(a);\n\
|
|
16
|
+
uv *= mat2(co, -si, si, co);\n\
|
|
17
|
+
uv *= length(uv + vec2(0, 4.9)) * rainSize + 1.;\n\
|
|
18
|
+
float v = 1. - sin(hash(floor(uv.x * 100.)) * 2.);\n\
|
|
19
|
+
float b = clamp(abs(sin(20. * time * v + uv.y * (5. / (2. + v)))) - .95, 0., 1.) * 20.;\n\
|
|
20
|
+
c *= v * b;\n\
|
|
21
|
+
gl_FragColor = mix(texture2D(colorTexture, v_textureCoordinates), vec4(c, 1), .5);\n\
|
|
22
|
+
}\n\
|
|
23
|
+
";
|
|
24
|
+
|
|
25
|
+
const snowShader = "uniform sampler2D colorTexture;\n\
|
|
26
|
+
varying vec2 v_textureCoordinates;\n\
|
|
27
|
+
uniform float snowSpeed;\n\
|
|
28
|
+
uniform float snowSize;\n\
|
|
29
|
+
float snow(vec2 uv,float scale)\n\
|
|
30
|
+
{\n\
|
|
31
|
+
float time=czm_frameNumber/snowSpeed;\n\
|
|
32
|
+
float w=smoothstep(1.,0.,-uv.y*(scale/10.));if(w<.1)return 0.;\n\
|
|
33
|
+
uv+=time/scale;uv.y+=time*2./scale;uv.x+=sin(uv.y+time*.5)/scale;\n\
|
|
34
|
+
uv*=scale;vec2 s=floor(uv),f=fract(uv),p;float k=3.,d;\n\
|
|
35
|
+
p=.5+.35*sin(11.*fract(sin((s+p+scale)*mat2(7,3,6,5))*5.))-f;d=length(p);k=min(d,k);\n\
|
|
36
|
+
k=smoothstep(0.,k,sin(f.x+f.y)*snowSize);\n\
|
|
37
|
+
return k*w;\n\
|
|
38
|
+
}\n\
|
|
39
|
+
void main(void){\n\
|
|
40
|
+
vec2 resolution=czm_viewport.zw;\n\
|
|
41
|
+
vec2 uv=(gl_FragCoord.xy*2.-resolution.xy)/min(resolution.x,resolution.y);\n\
|
|
42
|
+
vec3 finalColor=vec3(0);\n\
|
|
43
|
+
//float c=smoothstep(1.,0.3,clamp(uv.y*.3+.8,0.,.75));\n\
|
|
44
|
+
float c=0.;\n\
|
|
45
|
+
c+=snow(uv,30.)*.0;\n\
|
|
46
|
+
c+=snow(uv,20.)*.0;\n\
|
|
47
|
+
c+=snow(uv,15.)*.0;\n\
|
|
48
|
+
c+=snow(uv,10.);\n\
|
|
49
|
+
c+=snow(uv,8.);\n\
|
|
50
|
+
c+=snow(uv,6.);\n\
|
|
51
|
+
c+=snow(uv,5.);\n\
|
|
52
|
+
finalColor=(vec3(c));\n\
|
|
53
|
+
gl_FragColor=mix(texture2D(colorTexture,v_textureCoordinates),vec4(finalColor,1),.5);\n\
|
|
54
|
+
}\n\
|
|
55
|
+
";
|
|
56
|
+
|
|
57
|
+
const fogShader = "uniform sampler2D colorTexture;\n\
|
|
58
|
+
uniform sampler2D depthTexture;\n\
|
|
59
|
+
uniform float visibility;\n\
|
|
60
|
+
uniform vec4 fogColor;\n\
|
|
61
|
+
varying vec2 v_textureCoordinates; \n\
|
|
62
|
+
void main(void) \n\
|
|
63
|
+
{ \n\
|
|
64
|
+
vec4 origcolor = texture2D(colorTexture, v_textureCoordinates); \n\
|
|
65
|
+
float depth = czm_readDepth(depthTexture, v_textureCoordinates); \n\
|
|
66
|
+
vec4 depthcolor = texture2D(depthTexture, v_textureCoordinates); \n\
|
|
67
|
+
float f = visibility * (depthcolor.r - 0.3) / 0.2; \n\
|
|
68
|
+
if (f < 0.0) f = 0.0; \n\
|
|
69
|
+
else if (f > 1.0) f = 1.0; \n\
|
|
70
|
+
gl_FragColor = mix(origcolor, fogColor, f); \n\
|
|
71
|
+
}\n\
|
|
72
|
+
";
|
|
73
|
+
|
|
74
|
+
export {
|
|
75
|
+
rainShader,
|
|
76
|
+
snowShader,
|
|
77
|
+
fogShader
|
|
78
|
+
}
|
package/cesium/index.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import * as Cesium from 'cesium'
|
|
2
|
+
import { useCameraRecord, EActionTtype } from './cameraRecord'
|
|
3
|
+
import * as hooks from './utils'
|
|
4
|
+
|
|
5
|
+
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkMjBmZGE5MS02ZTE1LTRjNzAtYmJjNS0zNTJhNmI1MDQ4YmQiLCJpZCI6OTQ5NzAsImlhdCI6MTY1MzM3ODM0Mn0.OcAxsSXF6VtqtI83SpUc5oL1fFxSFM60O3gp5YKyDeA'
|
|
6
|
+
|
|
7
|
+
import type { IRecord } from './cameraRecord'
|
|
8
|
+
|
|
9
|
+
type TCesiumUtilsType = {
|
|
10
|
+
dict: typeof hooks.dict;
|
|
11
|
+
|
|
12
|
+
customCollection: ReturnType<typeof hooks.useCustomCollection>;
|
|
13
|
+
drawPolygon: ReturnType<typeof hooks.useDrawPolygon>;
|
|
14
|
+
clipping: ReturnType<typeof hooks.useClipping>;
|
|
15
|
+
weather: ReturnType<typeof hooks.useWeather>;
|
|
16
|
+
measure: ReturnType<typeof hooks.useMeasure>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const useCesium = () => {
|
|
20
|
+
const loadCesium = (containerName: string, callback: (viewer: Cesium.Viewer, utils: TCesiumUtilsType) => void, ev: {
|
|
21
|
+
leftClickEvent: (viewer: Cesium.Viewer, e: Cesium.ScreenSpaceEventHandler.PositionedEvent) => void,
|
|
22
|
+
moveEvent: (viewer: Cesium.Viewer, e: Cesium.ScreenSpaceEventHandler.MotionEvent) => void
|
|
23
|
+
}) => {
|
|
24
|
+
|
|
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);
|
|
72
|
+
|
|
73
|
+
const customCollection = hooks.useCustomCollection(viewer)
|
|
74
|
+
const drawPolygon = hooks.useDrawPolygon(viewer, {
|
|
75
|
+
nodeCollection: customCollection.addCollection(hooks.dict.ECollectionWhiteListNames.POLYGON_NODE),
|
|
76
|
+
polygonCollection: customCollection.addCollection(hooks.dict.ECollectionWhiteListNames.POLYGON),
|
|
77
|
+
})
|
|
78
|
+
const clipping = hooks.useClipping(viewer)
|
|
79
|
+
const weather = hooks.useWeather(viewer)
|
|
80
|
+
const measure = hooks.useMeasure(viewer)
|
|
81
|
+
|
|
82
|
+
callback(viewer, {
|
|
83
|
+
dict: hooks.dict,
|
|
84
|
+
customCollection,
|
|
85
|
+
drawPolygon,
|
|
86
|
+
clipping,
|
|
87
|
+
weather,
|
|
88
|
+
measure
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
|
92
|
+
|
|
93
|
+
handler.setInputAction(((event) => {
|
|
94
|
+
ev.leftClickEvent(viewer, event)
|
|
95
|
+
}) as Cesium.ScreenSpaceEventHandler.PositionedEventCallback, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
96
|
+
|
|
97
|
+
handler.setInputAction(((event) => {
|
|
98
|
+
ev.moveEvent(viewer, event)
|
|
99
|
+
}) as Cesium.ScreenSpaceEventHandler.MotionEventCallback, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const updateCameraEvent = (viewer: Cesium.Viewer) => {
|
|
103
|
+
viewer.scene.screenSpaceCameraController.tiltEventTypes = [
|
|
104
|
+
Cesium.CameraEventType.LEFT_DRAG
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
viewer.scene.screenSpaceCameraController.zoomEventTypes = [
|
|
108
|
+
Cesium.CameraEventType.MIDDLE_DRAG,
|
|
109
|
+
Cesium.CameraEventType.WHEEL,
|
|
110
|
+
Cesium.CameraEventType.PINCH
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
viewer.scene.screenSpaceCameraController.rotateEventTypes = [
|
|
114
|
+
Cesium.CameraEventType.RIGHT_DRAG
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const getCamera = (viewer: Cesium.Viewer) => {
|
|
119
|
+
const camera = viewer.camera;
|
|
120
|
+
const { positionCartographic: pos, heading, pitch, roll } = camera
|
|
121
|
+
const { x, y, z } = Cesium.Cartesian3.fromRadians(pos.longitude, pos.latitude, pos.height)
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
destination: new Cesium.Cartesian3(x, y, z),
|
|
125
|
+
orientation: {
|
|
126
|
+
heading,
|
|
127
|
+
pitch,
|
|
128
|
+
roll
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const setCamera = (viewer: Cesium.Viewer) => {
|
|
134
|
+
viewer.camera.flyTo({
|
|
135
|
+
destination: new Cesium.Cartesian3(-3313326.6764875883, 6046492.400581042, 2681576.8673584852),
|
|
136
|
+
orientation: {
|
|
137
|
+
heading: 0.37123871980838885,
|
|
138
|
+
pitch: -1.245479096883912,
|
|
139
|
+
roll: 6.280549614726131
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const loadTiles = async (viewer: Cesium.Viewer, url: string) => {
|
|
145
|
+
const tileset = await Cesium.Cesium3DTileset.fromUrl(url, {
|
|
146
|
+
skipLevelOfDetail: true,
|
|
147
|
+
preferLeaves: true,
|
|
148
|
+
maximumCacheOverflowBytes: 32,
|
|
149
|
+
baseScreenSpaceError: 256,
|
|
150
|
+
maximumScreenSpaceError: 16,
|
|
151
|
+
skipScreenSpaceErrorFactor: 16,
|
|
152
|
+
skipLevels: 4,
|
|
153
|
+
loadSiblings: true,
|
|
154
|
+
cullWithChildrenBounds: true,
|
|
155
|
+
cullRequestsWhileMoving: true,
|
|
156
|
+
cullRequestsWhileMovingMultiplier: 1,
|
|
157
|
+
progressiveResolutionHeightFraction: 1,
|
|
158
|
+
dynamicScreenSpaceErrorDensity: 128
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
const ts = viewer!.scene.primitives.add(tileset);
|
|
162
|
+
const boundingSphere = ts.boundingSphere;
|
|
163
|
+
viewer!.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.0, -0.5, boundingSphere.radius));
|
|
164
|
+
viewer!.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
|
|
165
|
+
viewer.flyTo(tileset)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
loadCesium,
|
|
170
|
+
updateCameraEvent,
|
|
171
|
+
getCamera,
|
|
172
|
+
setCamera,
|
|
173
|
+
loadTiles
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export {
|
|
178
|
+
EActionTtype,
|
|
179
|
+
|
|
180
|
+
useCesium,
|
|
181
|
+
useCameraRecord
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export type {
|
|
185
|
+
IRecord,
|
|
186
|
+
|
|
187
|
+
TCesiumUtilsType
|
|
188
|
+
}
|