deeptwins-engine-3d 0.1.41 → 0.1.43

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.
Files changed (33) hide show
  1. package/dist/esm/analyze/ViewshedAnalysis.d.ts +28 -0
  2. package/dist/esm/analyze/ViewshedAnalysis.js +291 -442
  3. package/dist/esm/constant.d.ts +44 -6
  4. package/dist/esm/constant.js +86 -7
  5. package/dist/esm/deepTwins/index.js +2 -1
  6. package/dist/esm/graphicLayer/BaseSource.d.ts +1 -1
  7. package/dist/esm/index.d.ts +5 -1
  8. package/dist/esm/index.js +13 -6
  9. package/dist/esm/lowAltitude/BarrierLayer.d.ts +29 -0
  10. package/dist/esm/{tileLayer → lowAltitude}/BarrierLayer.js +39 -165
  11. package/dist/esm/lowAltitude/BaseGridMvtLayer.d.ts +34 -0
  12. package/dist/esm/lowAltitude/BaseGridMvtLayer.js +122 -0
  13. package/dist/esm/lowAltitude/FlightPlanning.d.ts +27 -0
  14. package/dist/esm/lowAltitude/FlightPlanning.js +426 -0
  15. package/dist/esm/{visualization/Airspace.d.ts → lowAltitude/GridDraw.d.ts} +2 -1
  16. package/dist/esm/{visualization/Airspace.js → lowAltitude/GridDraw.js} +9 -9
  17. package/dist/esm/lowAltitude/PoiLayer.d.ts +13 -0
  18. package/dist/esm/lowAltitude/PoiLayer.js +74 -0
  19. package/dist/esm/lowAltitude/RiskEvaluation.d.ts +0 -0
  20. package/dist/esm/lowAltitude/RiskEvaluation.js +0 -0
  21. package/dist/esm/lowAltitude/VisitLayer.d.ts +26 -0
  22. package/dist/esm/lowAltitude/VisitLayer.js +180 -0
  23. package/dist/esm/map/GroundSkyBox.js +2 -2
  24. package/dist/esm/map/Map.js +10 -10
  25. package/dist/esm/plot/utils/DomUtil.js +1 -1
  26. package/dist/esm/tool/Compass.js +20 -4
  27. package/dist/esm/tool/PrimitiveCluster.js +10 -9
  28. package/dist/esm/tool/common.d.ts +1 -1
  29. package/dist/esm/tool/common.js +1 -1
  30. package/dist/esm/visualization/FrustumWithCamera.js +10 -8
  31. package/dist/umd/deeptwins-engine-3d.min.js +1 -1
  32. package/package.json +2 -2
  33. package/dist/esm/tileLayer/BarrierLayer.d.ts +0 -76
@@ -1,442 +1,291 @@
1
- // import * as Cesium from 'deeptwins-cesium';
2
- // import { merge } from 'lodash';
3
- // import { DEFAULT_VIEWSHED_ANALYSIS_OPTIONS } from '../constant';
4
- // import { MapContext } from '../map/Map';
5
- // import * as utils from '../tool/utils';
6
- //
7
- // // 可视域分析。
8
- // class ViewshedAnalysis {
9
- // private readonly _mapContext: MapContext;
10
- // public options: any;
11
- // public isDestroyed: boolean = false;
12
- // private _viewPositionC3: any;
13
- // private _viewPositionEndC3: any;
14
- // private _viewDistance: any;
15
- // private _viewHeading: any;
16
- // private _viewPitch: any;
17
- // private lightCamera: any;
18
- // private shadowMap: any;
19
- // private postStage: any;
20
- // private frustumOutline: any;
21
- // private sketch: any;
22
- //
23
- // constructor(map: any, options: any) {
24
- // this._mapContext = map._mapContext;
25
- // this.options = merge(DEFAULT_VIEWSHED_ANALYSIS_OPTIONS(), options);
26
- // if (!this.options.viewPosition) return;
27
- // const [lng, lat, alt] = this.options.viewPosition;
28
- // this._viewPositionC3 = utils.lngLatAltToCartesian3(lng, lat, alt || 0);
29
- // this._viewDistance = this.options.viewDistance;
30
- // this._viewHeading = this.options.viewHeading;
31
- // this._viewPitch = this.options.viewPitch;
32
- // if (this.options.viewPositionEnd) {
33
- // const [lng, lat, alt] = this.options.viewPositionEnd;
34
- // this._viewPositionEndC3 = utils.lngLatAltToCartesian3(lng, lat, alt || 0);
35
- // this._viewDistance = Cesium.Cartesian3.distance(
36
- // this._viewPositionC3,
37
- // this._viewPositionEndC3,
38
- // );
39
- // this._viewHeading = getHeading(
40
- // this._viewPositionC3,
41
- // this._viewPositionEndC3,
42
- // );
43
- // this._viewPitch = getPitch(this._viewPositionC3, this._viewPositionEndC3);
44
- // }
45
- // this.add();
46
- // }
47
- //
48
- // // 是否能进行操作
49
- // private _canOperate() {
50
- // if (this.isDestroyed) {
51
- // utils.error('SunLightAnalysis实例已销毁');
52
- // return false;
53
- // }
54
- // return true;
55
- // }
56
- //
57
- // public getMap() {
58
- // return this._mapContext && this._mapContext.getMap();
59
- // }
60
- //
61
- // public add() {
62
- // this.createLightCamera();
63
- // this.createShadowMap();
64
- // this.createPostStage();
65
- // this.drawFrustumOutline();
66
- // this.drawSketch();
67
- // }
68
- //
69
- // public update() {
70
- // if (!this._canOperate) return;
71
- // this.clear();
72
- // this.add();
73
- // }
74
- //
75
- // //创建相机
76
- // public createLightCamera() {
77
- // if (!this._canOperate) return;
78
- // this.lightCamera = new Cesium.Camera(this.getMap().scene);
79
- // this.lightCamera.position = this._viewPositionC3;
80
- // // if (this.viewPositionEnd) {
81
- // // let direction = Cesium.Cartesian3.normalize(Cesium.Cartesian3.subtract(this.viewPositionEnd, this.viewPosition, new Cesium.Cartesian3()), new Cesium.Cartesian3());
82
- // // this.lightCamera.direction = direction; // direction是相机面向的方向
83
- // // }
84
- // this.lightCamera.frustum.near = this._viewDistance * 0.001;
85
- // this.lightCamera.frustum.far = this._viewDistance;
86
- // const hr = Cesium.Math.toRadians(this.options.horizontalViewAngle);
87
- // const vr = Cesium.Math.toRadians(this.options.verticalViewAngle);
88
- // const aspectRatio =
89
- // (this._viewDistance * Math.tan(hr / 2) * 2) /
90
- // (this._viewDistance * Math.tan(vr / 2) * 2);
91
- // this.lightCamera.frustum.aspectRatio = aspectRatio;
92
- // if (hr > vr) {
93
- // this.lightCamera.frustum.fov = hr;
94
- // } else {
95
- // this.lightCamera.frustum.fov = vr;
96
- // }
97
- // this.lightCamera.setView({
98
- // destination: this._viewPositionC3,
99
- // orientation: {
100
- // heading: Cesium.Math.toRadians(this._viewHeading || 0),
101
- // pitch: Cesium.Math.toRadians(this._viewPitch || 0),
102
- // roll: 0,
103
- // },
104
- // });
105
- // }
106
- //
107
- // //创建阴影贴图
108
- // public createShadowMap() {
109
- // if (!this._canOperate) return;
110
- // // 启用地形阴影
111
- // this.getMap().scene.globe.shadows = Cesium.ShadowMode.ENABLED;
112
- // // this.shadowMap = new Cesium.ShadowMap();
113
- // // this.shadowMap.enabled = this.options.enabled;
114
- // // this.shadowMap.size = this.options.size;
115
- // // this.shadowMap.softShadows = this.options.softShadows;
116
- // // this.shadowMap.normalOffset = false;
117
- // this.shadowMap = new Cesium.ShadowMap({
118
- // context: this.getMap().scene.context,
119
- // lightCamera: this.lightCamera,
120
- // enabled: this.options.enabled,
121
- // isPointLight: true,
122
- // pointLightRadius: this._viewDistance,
123
- // cascadesEnabled: false,
124
- // size: this.options.size,
125
- // softShadows: this.options.softShadows,
126
- // normalOffset: false,
127
- // fromLightSource: false,
128
- // });
129
- // this.getMap().scene.shadowMap = this.shadowMap;
130
- // }
131
- //
132
- // //创建PostStage
133
- // public createPostStage() {
134
- // if (!this._canOperate) return;
135
- // const fs = `
136
- // #define USE_CUBE_MAP_SHADOW true
137
- // uniform sampler2D colorTexture;
138
- // uniform sampler2D depthTexture;
139
- // varying vec2 v_textureCoordinates;
140
- // uniform mat4 camera_projection_matrix;
141
- // uniform mat4 camera_view_matrix;
142
- // uniform samplerCube shadowMap_textureCube;
143
- // uniform mat4 shadowMap_matrix;
144
- // uniform vec4 shadowMap_lightPositionEC;
145
- // uniform vec4 shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness;
146
- // uniform vec4 shadowMap_texelSizeDepthBiasAndNormalShadingSmooth;
147
- // uniform float helsing_viewDistance;
148
- // uniform vec4 helsing_visibleAreaColor;
149
- // uniform vec4 helsing_invisibleAreaColor;
150
- // struct zx_shadowParameters
151
- // {
152
- // vec3 texCoords;
153
- // float depthBias;
154
- // float depth;
155
- // float nDotL;
156
- // vec2 texelStepSize;
157
- // float normalShadingSmooth;
158
- // float darkness;
159
- // };
160
- // float czm_shadowVisibility(samplerCube shadowMap, zx_shadowParameters shadowParameters)
161
- // {
162
- // float depthBias = shadowParameters.depthBias;
163
- // float depth = shadowParameters.depth;
164
- // float nDotL = shadowParameters.nDotL;
165
- // float normalShadingSmooth = shadowParameters.normalShadingSmooth;
166
- // float darkness = shadowParameters.darkness;
167
- // vec3 uvw = shadowParameters.texCoords;
168
- // depth -= depthBias;
169
- // float visibility = czm_shadowDepthCompare(shadowMap, uvw, depth);
170
- // return czm_private_shadowVisibility(visibility, nDotL, normalShadingSmooth, darkness);
171
- // }
172
- // vec4 getPositionEC(){
173
- // return czm_windowToEyeCoordinates(gl_FragCoord);
174
- // }
175
- // vec3 getNormalEC(){
176
- // return vec3(1.);
177
- // }
178
- // vec4 toEye( vec2 uv, float depth){
179
- // vec2 xy=vec2((uv.x*2.-1.),(uv.y*2.-1.));
180
- // vec4 posInCamera=czm_inverseProjection*vec4(xy,depth,1.);
181
- // posInCamera=posInCamera/posInCamera.w;
182
- // return posInCamera;
183
- // }
184
- // vec3 pointProjectOnPlane( vec3 planeNormal, vec3 planeOrigin, vec3 point){
185
- // vec3 v01=point-planeOrigin;
186
- // float d=dot(planeNormal,v01);
187
- // return(point-planeNormal*d);
188
- // }
189
- // float getDepth( vec4 depth){
190
- // float z_window=czm_unpackDepth(depth);
191
- // z_window=czm_reverseLogDepth(z_window);
192
- // float n_range=czm_depthRange.near;
193
- // float f_range=czm_depthRange.far;
194
- // return(2.*z_window-n_range-f_range)/(f_range-n_range);
195
- // }
196
- // float shadow( vec4 positionEC){
197
- // vec3 normalEC=getNormalEC();
198
- // zx_shadowParameters shadowParameters;
199
- // shadowParameters.texelStepSize=shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.xy;
200
- // shadowParameters.depthBias=shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.z;
201
- // shadowParameters.normalShadingSmooth=shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.w;
202
- // shadowParameters.darkness=shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness.w;
203
- // vec3 directionEC=positionEC.xyz-shadowMap_lightPositionEC.xyz;
204
- // float distance=length(directionEC);
205
- // directionEC=normalize(directionEC);
206
- // float radius=shadowMap_lightPositionEC.w;
207
- // if(distance>radius)
208
- // {
209
- // return 2.0;
210
- // }
211
- // vec3 directionWC=czm_inverseViewRotation*directionEC;
212
- // shadowParameters.depth=distance/radius-0.0003;
213
- // shadowParameters.nDotL=clamp(dot(normalEC,-directionEC),0.,1.);
214
- // shadowParameters.texCoords=directionWC;
215
- // float visibility=czm_shadowVisibility(shadowMap_textureCube,shadowParameters);
216
- // return visibility;
217
- // }
218
- // bool visible( vec4 result)
219
- // {
220
- // result.x/=result.w;
221
- // result.y/=result.w;
222
- // result.z/=result.w;
223
- // return result.x>=-1.&&result.x<=1.
224
- // &&result.y>=-1.&&result.y<=1.
225
- // &&result.z>=-1.&&result.z<=1.;
226
- // }
227
- // void main(){
228
- // // 釉色 = 结构二维(颜色纹理, 纹理坐标)
229
- // gl_FragColor = texture2D(colorTexture, v_textureCoordinates);
230
- // // 深度 = 获取深度(结构二维(深度纹理, 纹理坐标))
231
- // float depth = getDepth(texture2D(depthTexture, v_textureCoordinates));
232
- // // 视角 = (纹理坐标, 深度)
233
- // vec4 viewPos = toEye(v_textureCoordinates, depth);
234
- // // 世界坐标
235
- // vec4 wordPos = czm_inverseView * viewPos;
236
- // // 虚拟相机中坐标
237
- // vec4 vcPos = camera_view_matrix * wordPos;
238
- // float near = .001 * helsing_viewDistance;
239
- // float dis = length(vcPos.xyz);
240
- // if(dis > near && dis < helsing_viewDistance){
241
- // // 透视投影
242
- // vec4 posInEye = camera_projection_matrix * vcPos;
243
- // // 可视区颜色
244
- // // vec4 helsing_visibleAreaColor=vec4(0.,1.,0.,.5);
245
- // // vec4 helsing_invisibleAreaColor=vec4(1.,0.,0.,.5);
246
- // if(visible(posInEye)){
247
- // float vis = shadow(viewPos);
248
- // if(vis > 0.3){
249
- // gl_FragColor = mix(gl_FragColor,helsing_visibleAreaColor,.5);
250
- // } else{
251
- // gl_FragColor = mix(gl_FragColor,helsing_invisibleAreaColor,.5);
252
- // }
253
- // }
254
- // }
255
- // }`;
256
- // const scene = this.getMap().scene;
257
- // const postStage = new Cesium.PostProcessStage({
258
- // fragmentShader: fs,
259
- // uniforms: {
260
- // shadowMap_textureCube: () => {
261
- // this.shadowMap.update(Reflect.get(scene, '_frameState'));
262
- // return Reflect.get(this.shadowMap, '_shadowMapTexture');
263
- // },
264
- // shadowMap_matrix: () => {
265
- // this.shadowMap.update(Reflect.get(scene, '_frameState'));
266
- // return Reflect.get(this.shadowMap, '_shadowMapMatrix');
267
- // },
268
- // shadowMap_lightPositionEC: () => {
269
- // this.shadowMap.update(Reflect.get(scene, '_frameState'));
270
- // return Reflect.get(this.shadowMap, '_lightPositionEC');
271
- // },
272
- // shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness: () => {
273
- // this.shadowMap.update(Reflect.get(scene, '_frameState'));
274
- // const bias = this.shadowMap._pointBias;
275
- // return Cesium.Cartesian4.fromElements(
276
- // bias.normalOffsetScale,
277
- // this.shadowMap._distance,
278
- // this.shadowMap.maximumDistance,
279
- // 0.0,
280
- // new Cesium.Cartesian4(),
281
- // );
282
- // },
283
- // shadowMap_texelSizeDepthBiasAndNormalShadingSmooth: () => {
284
- // this.shadowMap.update(Reflect.get(scene, '_frameState'));
285
- // const bias = this.shadowMap._pointBias;
286
- // const scratchTexelStepSize = new Cesium.Cartesian2();
287
- // const texelStepSize = scratchTexelStepSize;
288
- // texelStepSize.x = 1.0 / this.shadowMap._textureSize.x;
289
- // texelStepSize.y = 1.0 / this.shadowMap._textureSize.y;
290
- //
291
- // return Cesium.Cartesian4.fromElements(
292
- // texelStepSize.x,
293
- // texelStepSize.y,
294
- // bias.depthBias,
295
- // bias.normalShadingSmooth,
296
- // new Cesium.Cartesian4(),
297
- // );
298
- // },
299
- // camera_projection_matrix: this.lightCamera.frustum.projectionMatrix,
300
- // camera_view_matrix: this.lightCamera.viewMatrix,
301
- // helsing_viewDistance: () => {
302
- // return this._viewDistance;
303
- // },
304
- // helsing_visibleAreaColor: this.options.visibleAreaColor,
305
- // helsing_invisibleAreaColor: this.options.invisibleAreaColor,
306
- // },
307
- // });
308
- // this.postStage = scene.postProcessStages.add(postStage);
309
- // }
310
- //
311
- // //创建视锥线
312
- // public drawFrustumOutline() {
313
- // if (!this._canOperate) return;
314
- // const scratchRight = new Cesium.Cartesian3();
315
- // const scratchRotation = new Cesium.Matrix3();
316
- // const scratchOrientation = new Cesium.Quaternion();
317
- // // const position = this.lightCamera.positionWC;
318
- // const direction = this.lightCamera.directionWC;
319
- // const up = this.lightCamera.upWC;
320
- // let right = this.lightCamera.rightWC;
321
- // right = Cesium.Cartesian3.negate(right, scratchRight);
322
- // const rotation = scratchRotation;
323
- // Cesium.Matrix3.setColumn(rotation, 0, right, rotation);
324
- // Cesium.Matrix3.setColumn(rotation, 1, up, rotation);
325
- // Cesium.Matrix3.setColumn(rotation, 2, direction, rotation);
326
- // const orientation = Cesium.Quaternion.fromRotationMatrix(
327
- // rotation,
328
- // scratchOrientation,
329
- // );
330
- //
331
- // const instance = new Cesium.GeometryInstance({
332
- // geometry: new Cesium.FrustumOutlineGeometry({
333
- // frustum: this.lightCamera.frustum,
334
- // origin: this._viewPositionC3,
335
- // orientation: orientation,
336
- // }),
337
- // attributes: {
338
- // color: Cesium.ColorGeometryInstanceAttribute.fromColor(
339
- // Cesium.Color.YELLOWGREEN, //new Cesium.Color(0.0, 1.0, 0.0, 1.0)
340
- // ),
341
- // show: new Cesium.ShowGeometryInstanceAttribute(true),
342
- // },
343
- // });
344
- //
345
- // this.frustumOutline = this.getMap().scene.primitives.add(
346
- // new Cesium.Primitive({
347
- // geometryInstances: [instance],
348
- // appearance: new Cesium.PerInstanceColorAppearance({
349
- // flat: true,
350
- // translucent: false,
351
- // }),
352
- // }),
353
- // );
354
- // }
355
- //
356
- // //创建视网
357
- // public drawSketch() {
358
- // if (!this._canOperate) return;
359
- // this.sketch = this.getMap().entities.add({
360
- // name: 'sketch',
361
- // position: this._viewPositionC3,
362
- // orientation: Cesium.Transforms.headingPitchRollQuaternion(
363
- // this._viewPositionC3,
364
- // Cesium.HeadingPitchRoll.fromDegrees(
365
- // this._viewHeading - this.options.horizontalViewAngle,
366
- // this._viewPitch,
367
- // 0.0,
368
- // ),
369
- // ),
370
- // ellipsoid: {
371
- // radii: new Cesium.Cartesian3(
372
- // this._viewDistance,
373
- // this._viewDistance,
374
- // this._viewDistance,
375
- // ),
376
- // // innerRadii: new Cesium.Cartesian3(2.0, 2.0, 2.0),
377
- // minimumClock: Cesium.Math.toRadians(
378
- // -this.options.horizontalViewAngle / 2,
379
- // ),
380
- // maximumClock: Cesium.Math.toRadians(
381
- // this.options.horizontalViewAngle / 2,
382
- // ),
383
- // minimumCone: Cesium.Math.toRadians(
384
- // this.options.verticalViewAngle + 7.75,
385
- // ),
386
- // maximumCone: Cesium.Math.toRadians(
387
- // 180 - this.options.verticalViewAngle - 7.75,
388
- // ),
389
- // fill: false,
390
- // outline: true,
391
- // subdivisions: 256,
392
- // stackPartitions: 64,
393
- // slicePartitions: 64,
394
- // outlineColor: Cesium.Color.YELLOWGREEN,
395
- // },
396
- // });
397
- // }
398
- //
399
- // public clear() {
400
- // if (!this._canOperate) return;
401
- // if (this.frustumOutline) {
402
- // this.frustumOutline.destroy();
403
- // this.frustumOutline = null;
404
- // }
405
- // if (this.postStage) {
406
- // this.getMap().scene.postProcessStages.remove(this.postStage);
407
- // this.postStage = null;
408
- // }
409
- // if (this.sketch) {
410
- // this.getMap().entities.remove(this.sketch);
411
- // this.sketch = null;
412
- // }
413
- // }
414
- //
415
- // public destroy() {
416
- // if (!this._canOperate) return;
417
- // this.isDestroyed = true;
418
- // this.clear();
419
- // }
420
- // }
421
- //
422
- // export default ViewshedAnalysis;
423
- //
424
- // //获取偏航角
425
- // function getHeading(fromPosition: any, toPosition: any) {
426
- // const finalPosition = new Cesium.Cartesian3();
427
- // const matrix4 = Cesium.Transforms.eastNorthUpToFixedFrame(fromPosition);
428
- // Cesium.Matrix4.inverse(matrix4, matrix4);
429
- // Cesium.Matrix4.multiplyByPoint(matrix4, toPosition, finalPosition);
430
- // Cesium.Cartesian3.normalize(finalPosition, finalPosition);
431
- // return Cesium.Math.toDegrees(Math.atan2(finalPosition.x, finalPosition.y));
432
- // }
433
- //
434
- // //获取俯仰角
435
- // function getPitch(fromPosition: any, toPosition: any) {
436
- // const finalPosition = new Cesium.Cartesian3();
437
- // const matrix4 = Cesium.Transforms.eastNorthUpToFixedFrame(fromPosition);
438
- // Cesium.Matrix4.inverse(matrix4, matrix4);
439
- // Cesium.Matrix4.multiplyByPoint(matrix4, toPosition, finalPosition);
440
- // Cesium.Cartesian3.normalize(finalPosition, finalPosition);
441
- // return Cesium.Math.toDegrees(Math.asin(finalPosition.z));
442
- // }
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
10
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
+ import * as Cesium from 'deeptwins-cesium';
15
+ import { merge } from 'lodash';
16
+ import { DEFAULT_VIEWSHED_ANALYSIS_OPTIONS } from "../constant";
17
+ import * as utils from "../tool/utils";
18
+ import FrustumWithCamera from "../visualization/FrustumWithCamera";
19
+
20
+ // 可视域分析。
21
+ var ViewshedAnalysis = /*#__PURE__*/function () {
22
+ function ViewshedAnalysis(map, options) {
23
+ _classCallCheck(this, ViewshedAnalysis);
24
+ _defineProperty(this, "_mapContext", void 0);
25
+ _defineProperty(this, "options", void 0);
26
+ _defineProperty(this, "isDestroyed", false);
27
+ _defineProperty(this, "_viewPositionC3", void 0);
28
+ _defineProperty(this, "_viewPositionEndC3", void 0);
29
+ _defineProperty(this, "_viewDistance", void 0);
30
+ _defineProperty(this, "_viewHeading", void 0);
31
+ _defineProperty(this, "_viewPitch", void 0);
32
+ _defineProperty(this, "lightCamera", void 0);
33
+ _defineProperty(this, "shadowMap", void 0);
34
+ _defineProperty(this, "postStage", void 0);
35
+ _defineProperty(this, "frustumCamera", void 0);
36
+ _defineProperty(this, "sketchLayer", void 0);
37
+ this._mapContext = map._mapContext;
38
+ this.options = merge(DEFAULT_VIEWSHED_ANALYSIS_OPTIONS(), options);
39
+ if (!this.options.position) return;
40
+ var _this$options$positio = _slicedToArray(this.options.position, 3),
41
+ lng = _this$options$positio[0],
42
+ lat = _this$options$positio[1],
43
+ alt = _this$options$positio[2];
44
+ this._viewPositionC3 = utils.lngLatAltToCartesian3(lng, lat, alt || 0);
45
+ this._viewDistance = this.options.distance;
46
+ this._viewHeading = this.options.heading;
47
+ this._viewPitch = this.options.pitch;
48
+ if (this.options.positionEnd) {
49
+ var _this$options$positio2 = _slicedToArray(this.options.positionEnd, 3),
50
+ _lng = _this$options$positio2[0],
51
+ _lat = _this$options$positio2[1],
52
+ _alt = _this$options$positio2[2];
53
+ this._viewPositionEndC3 = utils.lngLatAltToCartesian3(_lng, _lat, _alt || 0);
54
+ this._viewDistance = Cesium.Cartesian3.distance(this._viewPositionC3, this._viewPositionEndC3);
55
+ this._viewHeading = getHeading(this._viewPositionC3, this._viewPositionEndC3);
56
+ this._viewPitch = getPitch(this._viewPositionC3, this._viewPositionEndC3);
57
+ }
58
+ this.create();
59
+ }
60
+
61
+ // 是否能进行操作
62
+ _createClass(ViewshedAnalysis, [{
63
+ key: "_canOperate",
64
+ value: function _canOperate() {
65
+ if (this.isDestroyed) {
66
+ utils.error('SunLightAnalysis实例已销毁');
67
+ return false;
68
+ }
69
+ return true;
70
+ }
71
+ }, {
72
+ key: "getMap",
73
+ value: function getMap() {
74
+ return this._mapContext && this._mapContext.getMap();
75
+ }
76
+ }, {
77
+ key: "create",
78
+ value: function create() {
79
+ this._createLightCamera();
80
+ this._createShadowMap();
81
+ this._createPostStage();
82
+ this._drawFrustumOutline();
83
+ this._drawSketch();
84
+ }
85
+ }, {
86
+ key: "update",
87
+ value: function update() {
88
+ if (!this._canOperate) return;
89
+ this.clear();
90
+ this.create();
91
+ }
92
+
93
+ //创建相机
94
+ }, {
95
+ key: "_createLightCamera",
96
+ value: function _createLightCamera() {
97
+ if (!this._canOperate) return;
98
+ this.lightCamera = new Cesium.Camera(this.getMap().scene);
99
+ this.lightCamera.position = this._viewPositionC3;
100
+ // if (this._viewPositionEndC3) {
101
+ // this.lightCamera.direction = Cesium.Cartesian3.normalize(
102
+ // Cesium.Cartesian3.subtract(
103
+ // this._viewPositionEndC3,
104
+ // this._viewPositionC3,
105
+ // new Cesium.Cartesian3(),
106
+ // ),
107
+ // new Cesium.Cartesian3(),
108
+ // ); // direction是相机面向的方向
109
+ // }
110
+ this.lightCamera.frustum.near = this._viewDistance * 0.001;
111
+ this.lightCamera.frustum.far = this._viewDistance;
112
+ var hr = Cesium.Math.toRadians(this.options.horizontalViewAngle);
113
+ var vr = Cesium.Math.toRadians(this.options.verticalViewAngle);
114
+ this.lightCamera.frustum.aspectRatio = this._viewDistance * Math.tan(hr / 2) * 2 / (this._viewDistance * Math.tan(vr / 2) * 2);
115
+ if (hr > vr) {
116
+ this.lightCamera.frustum.fov = hr;
117
+ } else {
118
+ this.lightCamera.frustum.fov = vr;
119
+ }
120
+ this.lightCamera.setView({
121
+ destination: this._viewPositionC3,
122
+ orientation: {
123
+ heading: Cesium.Math.toRadians(this._viewHeading || 0),
124
+ pitch: Cesium.Math.toRadians(this._viewPitch || 0),
125
+ roll: 0
126
+ }
127
+ });
128
+ }
129
+
130
+ //创建阴影贴图
131
+ }, {
132
+ key: "_createShadowMap",
133
+ value: function _createShadowMap() {
134
+ if (!this._canOperate) return;
135
+ // 启用地形阴影
136
+ this.getMap().scene.globe.shadows = Cesium.ShadowMode.ENABLED;
137
+ this.shadowMap = new Cesium.ViewshedShadowMap({
138
+ context: this.getMap().scene.context,
139
+ lightCamera: this.lightCamera,
140
+ enabled: this.options.enabled,
141
+ isPointLight: true,
142
+ pointLightRadius: this._viewDistance,
143
+ cascadesEnabled: false,
144
+ size: this.options.size,
145
+ softShadows: this.options.softShadows,
146
+ normalOffset: false,
147
+ // @ts-ignore
148
+ fromLightSource: false,
149
+ fadingEnabled: false
150
+ });
151
+ this.getMap().scene.shadowMap = this.shadowMap;
152
+ }
153
+
154
+ //创建PostStage
155
+ }, {
156
+ key: "_createPostStage",
157
+ value: function _createPostStage() {
158
+ var _this = this;
159
+ if (!this._canOperate()) return;
160
+ var fs = "\n #ifdef GL_ES\n precision highp float;\n #endif\n\n #define USE_CUBE_MAP_SHADOW true\n\n uniform sampler2D colorTexture;\n uniform sampler2D depthTexture;\n in vec2 v_textureCoordinates;\n\n uniform mat4 camera_projection_matrix;\n uniform mat4 camera_view_matrix;\n uniform samplerCube shadowMap_textureCube;\n uniform mat4 shadowMap_matrix;\n uniform vec4 shadowMap_lightPositionEC;\n uniform vec4 shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness;\n uniform vec4 shadowMap_texelSizeDepthBiasAndNormalShadingSmooth;\n uniform float helsing_viewDistance;\n uniform vec4 helsing_visibleAreaColor;\n uniform vec4 helsing_invisibleAreaColor;\n\n out vec4 fragColor;\n\n struct zx_shadowParameters {\n vec3 texCoords;\n float depthBias;\n float depth;\n float nDotL;\n vec2 texelStepSize;\n float normalShadingSmooth;\n float darkness;\n };\n\n float czm_shadowVisibility(samplerCube shadowMap, zx_shadowParameters shadowParameters) {\n float depthBias = shadowParameters.depthBias;\n float depth = shadowParameters.depth;\n float nDotL = shadowParameters.nDotL;\n float normalShadingSmooth = shadowParameters.normalShadingSmooth;\n float darkness = shadowParameters.darkness;\n vec3 uvw = shadowParameters.texCoords;\n depth -= depthBias;\n float visibility = czm_shadowDepthCompare(shadowMap, uvw, depth);\n return czm_private_shadowVisibility(visibility, nDotL, normalShadingSmooth, darkness);\n }\n\n vec4 getPositionEC(){\n return czm_windowToEyeCoordinates(gl_FragCoord);\n }\n\n vec3 getNormalEC(){\n return vec3(1.0);\n }\n\n vec4 toEye( vec2 uv, float depth){\n vec2 xy = vec2((uv.x * 2.0 - 1.0), (uv.y * 2.0 - 1.0));\n vec4 posInCamera = czm_inverseProjection * vec4(xy, depth, 1.0);\n posInCamera = posInCamera / posInCamera.w;\n return posInCamera;\n }\n\n vec3 pointProjectOnPlane( vec3 planeNormal, vec3 planeOrigin, vec3 point ){\n vec3 v01 = point - planeOrigin;\n float d = dot(planeNormal, v01);\n return (point - planeNormal * d);\n }\n\n float getDepth( vec4 depth){\n float z_window = czm_unpackDepth(depth);\n z_window = czm_reverseLogDepth(z_window);\n float n_range = czm_depthRange.near;\n float f_range = czm_depthRange.far;\n return (2.0 * z_window - n_range - f_range) / (f_range - n_range);\n }\n\n float shadow( vec4 positionEC ){\n vec3 normalEC = getNormalEC();\n zx_shadowParameters shadowParameters;\n shadowParameters.texelStepSize = shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.xy;\n shadowParameters.depthBias = shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.z;\n shadowParameters.normalShadingSmooth = shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.w;\n shadowParameters.darkness = shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness.w;\n vec3 directionEC = positionEC.xyz - shadowMap_lightPositionEC.xyz;\n float distance = length(directionEC);\n directionEC = normalize(directionEC);\n float radius = shadowMap_lightPositionEC.w;\n if (distance > radius) {\n return 2.0;\n }\n vec3 directionWC = czm_inverseViewRotation * directionEC;\n shadowParameters.depth = distance / radius - 0.0003;\n shadowParameters.nDotL = clamp(dot(normalEC, -directionEC), 0.0, 1.0);\n shadowParameters.texCoords = directionWC;\n float visibility = czm_shadowVisibility(shadowMap_textureCube, shadowParameters);\n return visibility;\n }\n\n bool visible( vec4 result ) {\n vec4 r = result / result.w;\n return r.x >= -1.0 && r.x <= 1.0 &&\n r.y >= -1.0 && r.y <= 1.0 &&\n r.z >= -1.0 && r.z <= 1.0;\n }\n\n void main() {\n // base color from the color texture\n vec4 baseColor = texture(colorTexture, v_textureCoordinates);\n\n // fetch depth and convert\n float depth = getDepth(texture(depthTexture, v_textureCoordinates));\n vec4 viewPos = toEye(v_textureCoordinates, depth);\n vec4 worldPos = czm_inverseView * viewPos;\n vec4 vcPos = camera_view_matrix * worldPos;\n\n float near = 0.001 * helsing_viewDistance;\n float dis = length(vcPos.xyz);\n\n fragColor = baseColor;\n\n if (dis > near && dis < helsing_viewDistance) {\n vec4 posInEye = camera_projection_matrix * vcPos;\n if (visible(posInEye)) {\n float vis = shadow(viewPos);\n if (vis > 0.3) {\n fragColor = mix(fragColor, helsing_visibleAreaColor, 0.5);\n } else {\n fragColor = mix(fragColor, helsing_invisibleAreaColor, 0.5);\n }\n }\n }\n }\n ";
161
+ var scene = this.getMap().scene;
162
+ var postStage = new Cesium.PostProcessStage({
163
+ fragmentShader: fs,
164
+ uniforms: {
165
+ shadowMap_textureCube: function shadowMap_textureCube() {
166
+ _this.shadowMap.update(Reflect.get(scene, '_frameState'));
167
+ return Reflect.get(_this.shadowMap, '_shadowMapTexture');
168
+ },
169
+ shadowMap_matrix: function shadowMap_matrix() {
170
+ _this.shadowMap.update(Reflect.get(scene, '_frameState'));
171
+ return Reflect.get(_this.shadowMap, '_shadowMapMatrix');
172
+ },
173
+ shadowMap_lightPositionEC: function shadowMap_lightPositionEC() {
174
+ _this.shadowMap.update(Reflect.get(scene, '_frameState'));
175
+ return Reflect.get(_this.shadowMap, '_lightPositionEC');
176
+ },
177
+ shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness: function shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness() {
178
+ _this.shadowMap.update(Reflect.get(scene, '_frameState'));
179
+ var bias = _this.shadowMap._pointBias;
180
+ // Return a Cartesian4 (normalOffsetScale, distance, maximumDistance, darkness)
181
+ return Cesium.Cartesian4.fromElements(bias.normalOffsetScale, _this.shadowMap._distance, _this.shadowMap.maximumDistance, 0.0);
182
+ },
183
+ shadowMap_texelSizeDepthBiasAndNormalShadingSmooth: function shadowMap_texelSizeDepthBiasAndNormalShadingSmooth() {
184
+ _this.shadowMap.update(Reflect.get(scene, '_frameState'));
185
+ var bias = _this.shadowMap._pointBias;
186
+ var texelStepSizeX = 1.0 / _this.shadowMap._textureSize.x;
187
+ var texelStepSizeY = 1.0 / _this.shadowMap._textureSize.y;
188
+ return Cesium.Cartesian4.fromElements(texelStepSizeX, texelStepSizeY, bias.depthBias, bias.normalShadingSmooth);
189
+ },
190
+ camera_projection_matrix: this.lightCamera.frustum.projectionMatrix,
191
+ camera_view_matrix: this.lightCamera.viewMatrix,
192
+ helsing_viewDistance: function helsing_viewDistance() {
193
+ return _this._viewDistance;
194
+ },
195
+ helsing_visibleAreaColor: this.options.visibleAreaColor,
196
+ helsing_invisibleAreaColor: this.options.invisibleAreaColor
197
+ }
198
+ });
199
+ this.postStage = scene.postProcessStages.add(postStage);
200
+ }
201
+
202
+ //创建视锥线
203
+ }, {
204
+ key: "_drawFrustumOutline",
205
+ value: function _drawFrustumOutline() {
206
+ if (!this._canOperate) return;
207
+ this.frustumCamera = new FrustumWithCamera(this.getMap(), {
208
+ position: this.options.position,
209
+ fill: false,
210
+ outlineColor: this.options.outlineColor,
211
+ camera: this.lightCamera
212
+ });
213
+ }
214
+
215
+ //创建视网
216
+ }, {
217
+ key: "_drawSketch",
218
+ value: function _drawSketch() {
219
+ if (!this._canOperate) return;
220
+ this.sketchLayer = this.getMap().addGraphicLayer({
221
+ type: 'Feature',
222
+ geometry: {
223
+ type: 'Point',
224
+ coordinates: this.options.position
225
+ }
226
+ }, {
227
+ type: 'ellipsoid',
228
+ style: {
229
+ radii: [this._viewDistance, this._viewDistance, this._viewDistance],
230
+ minimumClock: -this.options.horizontalViewAngle / 2,
231
+ maximumClock: this.options.horizontalViewAngle / 2,
232
+ minimumCone: this.options.verticalViewAngle + 7.75,
233
+ maximumCone: 180 - this.options.verticalViewAngle - 7.75,
234
+ fill: false,
235
+ outline: true,
236
+ subdivisions: 256,
237
+ stackPartitions: 64,
238
+ slicePartitions: 64,
239
+ outlineColor: this.options.outlineColor
240
+ }
241
+ });
242
+ this.sketchLayer.layers[0].entity.orientation = Cesium.Transforms.headingPitchRollQuaternion(this._viewPositionC3, Cesium.HeadingPitchRoll.fromDegrees(this._viewHeading - this.options.horizontalViewAngle, this._viewPitch, 0.0));
243
+ }
244
+ }, {
245
+ key: "clear",
246
+ value: function clear() {
247
+ if (!this._canOperate) return;
248
+ if (this.frustumCamera) {
249
+ this.frustumCamera.destroy();
250
+ this.frustumCamera = null;
251
+ }
252
+ if (this.postStage) {
253
+ this.getMap().scene.postProcessStages.remove(this.postStage);
254
+ this.postStage = null;
255
+ }
256
+ if (this.sketchLayer) {
257
+ this.sketchLayer.remove();
258
+ this.sketchLayer = null;
259
+ }
260
+ }
261
+ }, {
262
+ key: "destroy",
263
+ value: function destroy() {
264
+ if (!this._canOperate) return;
265
+ this.isDestroyed = true;
266
+ this.clear();
267
+ }
268
+ }]);
269
+ return ViewshedAnalysis;
270
+ }();
271
+ export default ViewshedAnalysis;
272
+
273
+ //获取偏航角
274
+ function getHeading(fromPosition, toPosition) {
275
+ var finalPosition = new Cesium.Cartesian3();
276
+ var matrix4 = Cesium.Transforms.eastNorthUpToFixedFrame(fromPosition);
277
+ Cesium.Matrix4.inverse(matrix4, matrix4);
278
+ Cesium.Matrix4.multiplyByPoint(matrix4, toPosition, finalPosition);
279
+ Cesium.Cartesian3.normalize(finalPosition, finalPosition);
280
+ return Cesium.Math.toDegrees(Math.atan2(finalPosition.x, finalPosition.y));
281
+ }
282
+
283
+ //获取俯仰角
284
+ function getPitch(fromPosition, toPosition) {
285
+ var finalPosition = new Cesium.Cartesian3();
286
+ var matrix4 = Cesium.Transforms.eastNorthUpToFixedFrame(fromPosition);
287
+ Cesium.Matrix4.inverse(matrix4, matrix4);
288
+ Cesium.Matrix4.multiplyByPoint(matrix4, toPosition, finalPosition);
289
+ Cesium.Cartesian3.normalize(finalPosition, finalPosition);
290
+ return Cesium.Math.toDegrees(Math.asin(finalPosition.z));
291
+ }