deeptwins-engine-3d 0.1.40 → 0.1.42

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,28 @@
1
+ declare class ViewshedAnalysis {
2
+ private readonly _mapContext;
3
+ options: any;
4
+ isDestroyed: boolean;
5
+ private _viewPositionC3;
6
+ private _viewPositionEndC3;
7
+ private _viewDistance;
8
+ private _viewHeading;
9
+ private _viewPitch;
10
+ private lightCamera;
11
+ private shadowMap;
12
+ private postStage;
13
+ private frustumOutline;
14
+ private sketch;
15
+ constructor(map: any, options: any);
16
+ private _canOperate;
17
+ getMap(): any;
18
+ add(): void;
19
+ update(): void;
20
+ createLightCamera(): void;
21
+ createShadowMap(): void;
22
+ createPostStage(): void;
23
+ drawFrustumOutline(): void;
24
+ drawSketch(): void;
25
+ clear(): void;
26
+ destroy(): void;
27
+ }
28
+ export default ViewshedAnalysis;
@@ -0,0 +1,305 @@
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
+
19
+ // 可视域分析。
20
+ var ViewshedAnalysis = /*#__PURE__*/function () {
21
+ function ViewshedAnalysis(map, options) {
22
+ _classCallCheck(this, ViewshedAnalysis);
23
+ _defineProperty(this, "_mapContext", void 0);
24
+ _defineProperty(this, "options", void 0);
25
+ _defineProperty(this, "isDestroyed", false);
26
+ _defineProperty(this, "_viewPositionC3", void 0);
27
+ _defineProperty(this, "_viewPositionEndC3", void 0);
28
+ _defineProperty(this, "_viewDistance", void 0);
29
+ _defineProperty(this, "_viewHeading", void 0);
30
+ _defineProperty(this, "_viewPitch", void 0);
31
+ _defineProperty(this, "lightCamera", void 0);
32
+ _defineProperty(this, "shadowMap", void 0);
33
+ _defineProperty(this, "postStage", void 0);
34
+ _defineProperty(this, "frustumOutline", void 0);
35
+ _defineProperty(this, "sketch", void 0);
36
+ this._mapContext = map._mapContext;
37
+ this.options = merge(DEFAULT_VIEWSHED_ANALYSIS_OPTIONS(), options);
38
+ if (!this.options.viewPosition) return;
39
+ var _this$options$viewPos = _slicedToArray(this.options.viewPosition, 3),
40
+ lng = _this$options$viewPos[0],
41
+ lat = _this$options$viewPos[1],
42
+ alt = _this$options$viewPos[2];
43
+ this._viewPositionC3 = utils.lngLatAltToCartesian3(lng, lat, alt || 0);
44
+ this._viewDistance = this.options.viewDistance;
45
+ this._viewHeading = this.options.viewHeading;
46
+ this._viewPitch = this.options.viewPitch;
47
+ if (this.options.viewPositionEnd) {
48
+ var _this$options$viewPos2 = _slicedToArray(this.options.viewPositionEnd, 3),
49
+ _lng = _this$options$viewPos2[0],
50
+ _lat = _this$options$viewPos2[1],
51
+ _alt = _this$options$viewPos2[2];
52
+ this._viewPositionEndC3 = utils.lngLatAltToCartesian3(_lng, _lat, _alt || 0);
53
+ this._viewDistance = Cesium.Cartesian3.distance(this._viewPositionC3, this._viewPositionEndC3);
54
+ this._viewHeading = getHeading(this._viewPositionC3, this._viewPositionEndC3);
55
+ this._viewPitch = getPitch(this._viewPositionC3, this._viewPositionEndC3);
56
+ }
57
+ this.add();
58
+ }
59
+
60
+ // 是否能进行操作
61
+ _createClass(ViewshedAnalysis, [{
62
+ key: "_canOperate",
63
+ value: function _canOperate() {
64
+ if (this.isDestroyed) {
65
+ utils.error('SunLightAnalysis实例已销毁');
66
+ return false;
67
+ }
68
+ return true;
69
+ }
70
+ }, {
71
+ key: "getMap",
72
+ value: function getMap() {
73
+ return this._mapContext && this._mapContext.getMap();
74
+ }
75
+ }, {
76
+ key: "add",
77
+ value: function add() {
78
+ this.createLightCamera();
79
+ this.createShadowMap();
80
+ this.createPostStage();
81
+ this.drawFrustumOutline();
82
+ this.drawSketch();
83
+ }
84
+ }, {
85
+ key: "update",
86
+ value: function update() {
87
+ if (!this._canOperate) return;
88
+ this.clear();
89
+ this.add();
90
+ }
91
+
92
+ //创建相机
93
+ }, {
94
+ key: "createLightCamera",
95
+ value: function createLightCamera() {
96
+ if (!this._canOperate) return;
97
+ this.lightCamera = new Cesium.Camera(this.getMap().scene);
98
+ this.lightCamera.position = this._viewPositionC3;
99
+ // if (this.viewPositionEnd) {
100
+ // let direction = Cesium.Cartesian3.normalize(Cesium.Cartesian3.subtract(this.viewPositionEnd, this.viewPosition, new Cesium.Cartesian3()), new Cesium.Cartesian3());
101
+ // this.lightCamera.direction = direction; // direction是相机面向的方向
102
+ // }
103
+ this.lightCamera.frustum.near = this._viewDistance * 0.001;
104
+ this.lightCamera.frustum.far = this._viewDistance;
105
+ var hr = Cesium.Math.toRadians(this.options.horizontalViewAngle);
106
+ var vr = Cesium.Math.toRadians(this.options.verticalViewAngle);
107
+ var aspectRatio = this._viewDistance * Math.tan(hr / 2) * 2 / (this._viewDistance * Math.tan(vr / 2) * 2);
108
+ this.lightCamera.frustum.aspectRatio = aspectRatio;
109
+ if (hr > vr) {
110
+ this.lightCamera.frustum.fov = hr;
111
+ } else {
112
+ this.lightCamera.frustum.fov = vr;
113
+ }
114
+ this.lightCamera.setView({
115
+ destination: this._viewPositionC3,
116
+ orientation: {
117
+ heading: Cesium.Math.toRadians(this._viewHeading || 0),
118
+ pitch: Cesium.Math.toRadians(this._viewPitch || 0),
119
+ roll: 0
120
+ }
121
+ });
122
+ }
123
+
124
+ //创建阴影贴图
125
+ }, {
126
+ key: "createShadowMap",
127
+ value: function createShadowMap() {
128
+ if (!this._canOperate) return;
129
+ // 启用地形阴影
130
+ this.getMap().scene.globe.shadows = Cesium.ShadowMode.ENABLED;
131
+ this.shadowMap = new Cesium.ViewshedShadowMap({
132
+ context: this.getMap().scene.context,
133
+ lightCamera: this.lightCamera,
134
+ enabled: this.options.enabled,
135
+ isPointLight: true,
136
+ pointLightRadius: this._viewDistance,
137
+ cascadesEnabled: false,
138
+ size: this.options.size,
139
+ softShadows: this.options.softShadows,
140
+ normalOffset: false
141
+ });
142
+ this.getMap().scene.shadowMap = this.shadowMap;
143
+ }
144
+
145
+ //创建PostStage
146
+ // --- Replace existing createPostStage() body with this ---
147
+ }, {
148
+ key: "createPostStage",
149
+ value: function createPostStage() {
150
+ var _this = this;
151
+ if (!this._canOperate()) return;
152
+ 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 ";
153
+ var scene = this.getMap().scene;
154
+ var postStage = new Cesium.PostProcessStage({
155
+ fragmentShader: fs,
156
+ uniforms: {
157
+ shadowMap_textureCube: function shadowMap_textureCube() {
158
+ _this.shadowMap.update(Reflect.get(scene, '_frameState'));
159
+ return Reflect.get(_this.shadowMap, '_shadowMapTexture');
160
+ },
161
+ shadowMap_matrix: function shadowMap_matrix() {
162
+ _this.shadowMap.update(Reflect.get(scene, '_frameState'));
163
+ return Reflect.get(_this.shadowMap, '_shadowMapMatrix');
164
+ },
165
+ shadowMap_lightPositionEC: function shadowMap_lightPositionEC() {
166
+ _this.shadowMap.update(Reflect.get(scene, '_frameState'));
167
+ return Reflect.get(_this.shadowMap, '_lightPositionEC');
168
+ },
169
+ shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness: function shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness() {
170
+ _this.shadowMap.update(Reflect.get(scene, '_frameState'));
171
+ var bias = _this.shadowMap._pointBias;
172
+ // Return a Cartesian4 (normalOffsetScale, distance, maximumDistance, darkness)
173
+ return Cesium.Cartesian4.fromElements(bias.normalOffsetScale, _this.shadowMap._distance, _this.shadowMap.maximumDistance, 0.0);
174
+ },
175
+ shadowMap_texelSizeDepthBiasAndNormalShadingSmooth: function shadowMap_texelSizeDepthBiasAndNormalShadingSmooth() {
176
+ _this.shadowMap.update(Reflect.get(scene, '_frameState'));
177
+ var bias = _this.shadowMap._pointBias;
178
+ var texelStepSizeX = 1.0 / _this.shadowMap._textureSize.x;
179
+ var texelStepSizeY = 1.0 / _this.shadowMap._textureSize.y;
180
+ return Cesium.Cartesian4.fromElements(texelStepSizeX, texelStepSizeY, bias.depthBias, bias.normalShadingSmooth);
181
+ },
182
+ camera_projection_matrix: this.lightCamera.frustum.projectionMatrix,
183
+ camera_view_matrix: this.lightCamera.viewMatrix,
184
+ helsing_viewDistance: function helsing_viewDistance() {
185
+ return _this._viewDistance;
186
+ },
187
+ helsing_visibleAreaColor: this.options.visibleAreaColor,
188
+ helsing_invisibleAreaColor: this.options.invisibleAreaColor
189
+ }
190
+ });
191
+ this.postStage = scene.postProcessStages.add(postStage);
192
+ }
193
+
194
+ //创建视锥线
195
+ }, {
196
+ key: "drawFrustumOutline",
197
+ value: function drawFrustumOutline() {
198
+ if (!this._canOperate) return;
199
+ var scratchRight = new Cesium.Cartesian3();
200
+ var scratchRotation = new Cesium.Matrix3();
201
+ var scratchOrientation = new Cesium.Quaternion();
202
+ // const position = this.lightCamera.positionWC;
203
+ var direction = this.lightCamera.directionWC;
204
+ var up = this.lightCamera.upWC;
205
+ var right = this.lightCamera.rightWC;
206
+ right = Cesium.Cartesian3.negate(right, scratchRight);
207
+ var rotation = scratchRotation;
208
+ Cesium.Matrix3.setColumn(rotation, 0, right, rotation);
209
+ Cesium.Matrix3.setColumn(rotation, 1, up, rotation);
210
+ Cesium.Matrix3.setColumn(rotation, 2, direction, rotation);
211
+ var orientation = Cesium.Quaternion.fromRotationMatrix(rotation, scratchOrientation);
212
+ var instance = new Cesium.GeometryInstance({
213
+ geometry: new Cesium.FrustumOutlineGeometry({
214
+ frustum: this.lightCamera.frustum,
215
+ origin: this._viewPositionC3,
216
+ orientation: orientation
217
+ }),
218
+ attributes: {
219
+ color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.YELLOWGREEN //new Cesium.Color(0.0, 1.0, 0.0, 1.0)
220
+ ),
221
+ show: new Cesium.ShowGeometryInstanceAttribute(true)
222
+ }
223
+ });
224
+ this.frustumOutline = this.getMap().scene.primitives.add(new Cesium.Primitive({
225
+ geometryInstances: [instance],
226
+ appearance: new Cesium.PerInstanceColorAppearance({
227
+ flat: true,
228
+ translucent: false
229
+ })
230
+ }));
231
+ }
232
+
233
+ //创建视网
234
+ }, {
235
+ key: "drawSketch",
236
+ value: function drawSketch() {
237
+ if (!this._canOperate) return;
238
+ this.sketch = this.getMap().entities.add({
239
+ name: 'sketch',
240
+ position: this._viewPositionC3,
241
+ orientation: Cesium.Transforms.headingPitchRollQuaternion(this._viewPositionC3, Cesium.HeadingPitchRoll.fromDegrees(this._viewHeading - this.options.horizontalViewAngle, this._viewPitch, 0.0)),
242
+ ellipsoid: {
243
+ radii: new Cesium.Cartesian3(this._viewDistance, this._viewDistance, this._viewDistance),
244
+ // innerRadii: new Cesium.Cartesian3(2.0, 2.0, 2.0),
245
+ minimumClock: Cesium.Math.toRadians(-this.options.horizontalViewAngle / 2),
246
+ maximumClock: Cesium.Math.toRadians(this.options.horizontalViewAngle / 2),
247
+ minimumCone: Cesium.Math.toRadians(this.options.verticalViewAngle + 7.75),
248
+ maximumCone: Cesium.Math.toRadians(180 - this.options.verticalViewAngle - 7.75),
249
+ fill: false,
250
+ outline: true,
251
+ subdivisions: 256,
252
+ stackPartitions: 64,
253
+ slicePartitions: 64,
254
+ outlineColor: Cesium.Color.YELLOWGREEN
255
+ }
256
+ });
257
+ }
258
+ }, {
259
+ key: "clear",
260
+ value: function clear() {
261
+ if (!this._canOperate) return;
262
+ if (this.frustumOutline) {
263
+ this.frustumOutline.destroy();
264
+ this.frustumOutline = null;
265
+ }
266
+ if (this.postStage) {
267
+ this.getMap().scene.postProcessStages.remove(this.postStage);
268
+ this.postStage = null;
269
+ }
270
+ if (this.sketch) {
271
+ this.getMap().entities.remove(this.sketch);
272
+ this.sketch = null;
273
+ }
274
+ }
275
+ }, {
276
+ key: "destroy",
277
+ value: function destroy() {
278
+ if (!this._canOperate) return;
279
+ this.isDestroyed = true;
280
+ this.clear();
281
+ }
282
+ }]);
283
+ return ViewshedAnalysis;
284
+ }();
285
+ export default ViewshedAnalysis;
286
+
287
+ //获取偏航角
288
+ function getHeading(fromPosition, toPosition) {
289
+ var finalPosition = new Cesium.Cartesian3();
290
+ var matrix4 = Cesium.Transforms.eastNorthUpToFixedFrame(fromPosition);
291
+ Cesium.Matrix4.inverse(matrix4, matrix4);
292
+ Cesium.Matrix4.multiplyByPoint(matrix4, toPosition, finalPosition);
293
+ Cesium.Cartesian3.normalize(finalPosition, finalPosition);
294
+ return Cesium.Math.toDegrees(Math.atan2(finalPosition.x, finalPosition.y));
295
+ }
296
+
297
+ //获取俯仰角
298
+ function getPitch(fromPosition, toPosition) {
299
+ var finalPosition = new Cesium.Cartesian3();
300
+ var matrix4 = Cesium.Transforms.eastNorthUpToFixedFrame(fromPosition);
301
+ Cesium.Matrix4.inverse(matrix4, matrix4);
302
+ Cesium.Matrix4.multiplyByPoint(matrix4, toPosition, finalPosition);
303
+ Cesium.Cartesian3.normalize(finalPosition, finalPosition);
304
+ return Cesium.Math.toDegrees(Math.asin(finalPosition.z));
305
+ }
@@ -146,7 +146,20 @@ export declare const DEFAULT_SUN_ANALYSIS_OPTIONS: () => {
146
146
  clockRange: Cesium.ClockRange;
147
147
  clockStep: Cesium.ClockStep;
148
148
  };
149
- export declare const DEFAULT_VIEWSHED_ANALYSIS_OPTIONS: () => {};
149
+ export declare const DEFAULT_VIEWSHED_ANALYSIS_OPTIONS: () => {
150
+ viewPosition: null;
151
+ viewPositionEnd: null;
152
+ viewDistance: number;
153
+ viewHeading: number;
154
+ viewPitch: number;
155
+ horizontalViewAngle: number;
156
+ verticalViewAngle: number;
157
+ visibleAreaColor: Cesium.Color;
158
+ invisibleAreaColor: Cesium.Color;
159
+ enabled: boolean;
160
+ softShadows: boolean;
161
+ size: number;
162
+ };
150
163
  export declare const DEFAULT_BASE_LAYER_TYPE: any;
151
164
  export declare const DEFAULT_BASE_LAYER: any;
152
165
  export declare const LAYER_TYPE_TO_CLASS: any;
@@ -235,7 +235,31 @@ export var DEFAULT_SUN_ANALYSIS_OPTIONS = function DEFAULT_SUN_ANALYSIS_OPTIONS(
235
235
 
236
236
  // 默认可视域分析
237
237
  export var DEFAULT_VIEWSHED_ANALYSIS_OPTIONS = function DEFAULT_VIEWSHED_ANALYSIS_OPTIONS() {
238
- return {};
238
+ return {
239
+ viewPosition: null,
240
+ // 观测点位置
241
+ viewPositionEnd: null,
242
+ // 最远观测点位置 (如果设置了观测距离,这个属性可以不设置
243
+ viewDistance: 100,
244
+ // 观测距离
245
+ viewHeading: 0.0,
246
+ // 航向角
247
+ viewPitch: 0.0,
248
+ // 俯仰角
249
+ horizontalViewAngle: 90.0,
250
+ // 可视域水平夹角
251
+ verticalViewAngle: 60.0,
252
+ // 可视域垂直夹角
253
+ visibleAreaColor: Cesium.Color.GREEN,
254
+ // 可视区域颜色(默认值`绿色`)。
255
+ invisibleAreaColor: Cesium.Color.RED,
256
+ // 不可视区域颜色(默认值`红色`)。
257
+ enabled: true,
258
+ // 阴影贴图是否可用
259
+ softShadows: true,
260
+ // 是否启用柔和阴影
261
+ size: 2048 // 每个阴影贴图的大小
262
+ };
239
263
  };
240
264
 
241
265
  // 默认的底图类型
@@ -57,7 +57,6 @@ var DeepTwins = /*#__PURE__*/function () {
57
57
  moduleLayer: this._getModuleLayer.bind(this),
58
58
  trafficHistoryLayer: this._YunJing.TrafficHistoryLayer,
59
59
  trafficLayer: this._YunJing.TrafficLayer,
60
- // 优先从 YunjingCesiumPlugins 获取 GridVTLayer(与示例代码一致)
61
60
  gridVTLayer: (_this$_YunjingCesiumP = this._YunjingCesiumPlugins) === null || _this$_YunjingCesiumP === void 0 ? void 0 : _this$_YunjingCesiumP.GridVTLayer
62
61
  });
63
62
  }
@@ -18,7 +18,7 @@ export declare const MULTI_POINT_SHAPE_TYPES: {
18
18
  readonly POLYLINE: "polyline";
19
19
  readonly POLYGON: "polygon";
20
20
  };
21
- export declare const MULTI_POINT_SHAPES: ("polygon" | "polyline")[];
21
+ export declare const MULTI_POINT_SHAPES: ("polyline" | "polygon")[];
22
22
  declare class Drawer implements DrawContext {
23
23
  private readonly _mapContext;
24
24
  private readonly _drawContext;
@@ -65,5 +65,6 @@ export declare class DeepTwinsEngine3D {
65
65
  static SunLightAnalysis: any;
66
66
  static KmlDataSource: any;
67
67
  static Compass: any;
68
+ static ViewshedAnalysis: any;
68
69
  }
69
70
  export default DeepTwinsEngine3D;
package/dist/esm/index.js CHANGED
@@ -9,6 +9,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
9
9
  import * as Cesium from 'deeptwins-cesium';
10
10
  import SubmergenceAnalysis from "./analyze/SubmergenceAnalysis";
11
11
  import SunLightAnalysis from "./analyze/SunLightAnalysis";
12
+ import ViewshedAnalysis from "./analyze/ViewshedAnalysis";
12
13
  import ModelRoamHistory from "./cameraControl/ModelRoamHistory";
13
14
  import ModelRoamRealTime from "./cameraControl/ModelRoamRealTime";
14
15
  import Roam from "./cameraControl/Roam";
@@ -53,11 +54,11 @@ DEEP_TWINS_BASE_URL && (window.CESIUM_BASE_URL = DEEP_TWINS_BASE_URL);
53
54
  // 全局加载css
54
55
  loadCss(Cesium.buildModuleUrl('Widgets/widgets.css'));
55
56
  // 打印版本信息
56
- console.log('DeepTwinsEngine3D Version:', "0.1.40");
57
+ console.log('DeepTwinsEngine3D Version:', "0.1.42");
57
58
  export var DeepTwinsEngine3D = /*#__PURE__*/_createClass(function DeepTwinsEngine3D() {
58
59
  _classCallCheck(this, DeepTwinsEngine3D);
59
60
  });
60
- _defineProperty(DeepTwinsEngine3D, "Version", "0.1.40");
61
+ _defineProperty(DeepTwinsEngine3D, "Version", "0.1.42");
61
62
  _defineProperty(DeepTwinsEngine3D, "Map", Map);
62
63
  _defineProperty(DeepTwinsEngine3D, "GroundSkyBox", GroundSkyBox);
63
64
  _defineProperty(DeepTwinsEngine3D, "RasterLayer", RasterLayer);
@@ -122,4 +123,5 @@ _defineProperty(DeepTwinsEngine3D, "SubmergenceAnalysis", SubmergenceAnalysis);
122
123
  _defineProperty(DeepTwinsEngine3D, "SunLightAnalysis", SunLightAnalysis);
123
124
  _defineProperty(DeepTwinsEngine3D, "KmlDataSource", Cesium.KmlDataSource);
124
125
  _defineProperty(DeepTwinsEngine3D, "Compass", Compass);
126
+ _defineProperty(DeepTwinsEngine3D, "ViewshedAnalysis", ViewshedAnalysis);
125
127
  export default DeepTwinsEngine3D;
@@ -9,7 +9,6 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
9
9
  import * as Cesium from 'deeptwins-cesium';
10
10
  var BoxGeometry = Cesium.BoxGeometry;
11
11
  var Cartesian3 = Cesium.Cartesian3;
12
- var defaultValue = Cesium.defaultValue;
13
12
  var defined = Cesium.defined;
14
13
  var destroyObject = Cesium.destroyObject;
15
14
  var DeveloperError = Cesium.DeveloperError;
@@ -39,6 +38,7 @@ var skyboxMatrix3 = new Matrix3();
39
38
  */
40
39
  var GroundSkyBox = /*#__PURE__*/function () {
41
40
  function GroundSkyBox(options) {
41
+ var _options$show;
42
42
  _classCallCheck(this, GroundSkyBox);
43
43
  _defineProperty(this, "sources", void 0);
44
44
  _defineProperty(this, "show", true);
@@ -55,7 +55,7 @@ var GroundSkyBox = /*#__PURE__*/function () {
55
55
  }
56
56
  this.sources = options.sources;
57
57
  this._sources = undefined;
58
- this.show = defaultValue(options.show, true);
58
+ this.show = (_options$show = options.show) !== null && _options$show !== void 0 ? _options$show : true;
59
59
  this._command = new DrawCommand({
60
60
  modelMatrix: Matrix4.clone(Matrix4.IDENTITY),
61
61
  owner: this
@@ -65,11 +65,9 @@ export default class Map extends Cesium.Viewer implements MapContext {
65
65
  addTerrainUrl(url: string): Promise<unknown>;
66
66
  addTerrain(terrain: any): Promise<unknown>;
67
67
  resetTerrain(): void;
68
- showModuleLayer(isShow: boolean): void;
69
68
  addEffect(effect: any): void;
70
69
  removeEffect(effect: any): void;
71
70
  on(type: any, event: any): any;
72
71
  addModuleLayer: (moduleLayer: any) => any;
73
- pickMonomer(data: any): any;
74
72
  destroy(): void;
75
73
  }
@@ -74,7 +74,7 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
74
74
  _defineProperty(_assertThisInitialized(_this), "_defaultSkybox", null);
75
75
  // 近地天空盒监听
76
76
  _defineProperty(_assertThisInitialized(_this), "_handleSkyBox", null);
77
- // 云镜
77
+ // 云镜模型实例
78
78
  _defineProperty(_assertThisInitialized(_this), "_yunjing", void 0);
79
79
  // 事件
80
80
  _defineProperty(_assertThisInitialized(_this), "_event", void 0);
@@ -244,11 +244,11 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
244
244
  !isNil(resolutionScale) && (this.resolutionScale = resolutionScale);
245
245
 
246
246
  // scene
247
- !isNil(showSun) && (this.scene.sun.show = showSun);
248
- !isNil(showMoon) && (this.scene.moon.show = showMoon);
249
- !isNil(showSkyBox) && (this.scene.skyBox.show = showSkyBox);
247
+ !isNil(showSun) && this.scene.sun && (this.scene.sun.show = showSun);
248
+ !isNil(showMoon) && this.scene.moon && (this.scene.moon.show = showMoon);
249
+ !isNil(showSkyBox) && this.scene.skyBox && (this.scene.skyBox.show = showSkyBox);
250
250
  !isNil(fog) && (this.scene.fog.enabled = fog);
251
- !isNil(skyAtmosphere) && (this.scene.skyAtmosphere.show = skyAtmosphere);
251
+ !isNil(skyAtmosphere) && this.scene.skyAtmosphere && (this.scene.skyAtmosphere.show = skyAtmosphere);
252
252
  !isNil(requestRenderMode) && (this.scene.requestRenderMode = requestRenderMode);
253
253
  if (!isNil(postProcessStages)) {
254
254
  for (var key in postProcessStages) {
@@ -307,7 +307,7 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
307
307
  value: function removeGroundSkyBox() {
308
308
  this.showGroundSkyBox = false;
309
309
  this.scene.skyBox = this._defaultSkybox;
310
- this.scene.skyAtmosphere.show = true;
310
+ this.scene.skyAtmosphere && (this.scene.skyAtmosphere.show = true);
311
311
  this.camera.changed.removeEventListener(this._handleSkyBox);
312
312
  this._handleSkyBox = null;
313
313
  }
@@ -320,10 +320,10 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
320
320
  var cameraHeight = Cesium.Cartographic.fromCartesian(position).height;
321
321
  if (cameraHeight < 240000) {
322
322
  this.scene.skyBox = skyBox;
323
- this.scene.skyAtmosphere.show = false;
323
+ this.scene.skyAtmosphere && (this.scene.skyAtmosphere.show = false);
324
324
  } else {
325
325
  this.scene.skyBox = this._defaultSkybox;
326
- this.scene.skyAtmosphere.show = true;
326
+ this.scene.skyAtmosphere && (this.scene.skyAtmosphere.show = true);
327
327
  }
328
328
  }
329
329
 
@@ -658,14 +658,6 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
658
658
  this.scene.terrainProvider = new Cesium.EllipsoidTerrainProvider({});
659
659
  }
660
660
 
661
- // 隐藏模型
662
- }, {
663
- key: "showModuleLayer",
664
- value: function showModuleLayer(isShow) {
665
- if (!this._yunjing) return;
666
- isShow ? this._yunjing.show() : this._yunjing.hide();
667
- }
668
-
669
661
  // 添加特效
670
662
  }, {
671
663
  key: "addEffect",
@@ -695,20 +687,10 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
695
687
  }
696
688
  }
697
689
  }, {
698
- key: "pickMonomer",
690
+ key: "destroy",
699
691
  value:
700
- // 拾取单体
701
- function pickMonomer(data) {
702
- if (!this._yunjing) {
703
- throw new Error('请先加载模型');
704
- }
705
- return this._yunjing.pickMonomer(data);
706
- }
707
-
708
692
  // 销毁
709
- }, {
710
- key: "destroy",
711
- value: function destroy() {
693
+ function destroy() {
712
694
  this._eventTrick.forEach(function (t) {
713
695
  t.off();
714
696
  });
@@ -42,7 +42,7 @@ export var LabelAttributeForm = /*#__PURE__*/function () {
42
42
  }
43
43
  this._customDiv.style.top = this._winPos.y + 'px';
44
44
  this._customDiv.style.left = this._winPos.x + 'px';
45
- this._customDiv.innerHTML = " \n <div>\n <span class=\"title\">\u5BF9\u8C61\u7F16\u53F7\uFF1A</span>\n <span>".concat(this._id, "</span>\n </div>\n <div>\n <span class=\"title\">\u6587\u5B57\u6807\u7B7E\uFF1A</span>\n <input type=\"text\" id=\"text-value\" value=\"").concat(this._text, "\" />\n </div>\n <div>\n <span class=\"title\">\u7ECF\u7EAC\u5750\u6807\uFF1A</span>\n <input type=\"text\" id=\"coor-xy\" value=\"").concat(this._coord.x, ",").concat(this._coord.y, "\" />\n </div>\n <div>\n <span class=\"title\">\u5B57\u4F53\u5927\u5C0F\uFF1A</span>\n <input type=\"number\" id=\"font-size\" value=\"").concat(this._size, "\" />\n </div>\n <div class=\"label-ar-tool-box\">\n <button id=\"label_edit_ok\">\u786E\u8BA4</button>\n <button id=\"label_edit_no\">\u53D6\u6D88</button>\n </div>");
45
+ this._customDiv.innerHTML = "\n <div>\n <span class=\"title\">\u5BF9\u8C61\u7F16\u53F7\uFF1A</span>\n <span>".concat(this._id, "</span>\n </div>\n <div>\n <span class=\"title\">\u6587\u5B57\u6807\u7B7E\uFF1A</span>\n <input type=\"text\" id=\"text-value\" value=\"").concat(this._text, "\" />\n </div>\n <div>\n <span class=\"title\">\u7ECF\u7EAC\u5750\u6807\uFF1A</span>\n <input type=\"text\" id=\"coor-xy\" value=\"").concat(this._coord.x, ",").concat(this._coord.y, "\" />\n </div>\n <div>\n <span class=\"title\">\u5B57\u4F53\u5927\u5C0F\uFF1A</span>\n <input type=\"number\" id=\"font-size\" value=\"").concat(this._size, "\" />\n </div>\n <div class=\"label-ar-tool-box\">\n <button id=\"label_edit_ok\">\u786E\u8BA4</button>\n <button id=\"label_edit_no\">\u53D6\u6D88</button>\n </div>");
46
46
  this.initEvent();
47
47
  }
48
48
  }, {
@@ -13,14 +13,15 @@
13
13
  * ```
14
14
  */
15
15
  export default class BarrierLayer {
16
+ private readonly _mapContext;
17
+ isDestroyed: boolean;
16
18
  private _gridVTLayer;
17
- private _viewer;
18
19
  private _options;
19
20
  private _heightColors;
20
21
  private static readonly DEFAULT_HEIGHT_COLORS;
21
22
  /**
22
23
  * 创建障碍物图层
23
- * @param viewer Cesium Viewer实例
24
+ * @param map Cesium Viewer实例
24
25
  * @param options 配置选项
25
26
  * @param options.gridVTLayer GridVTLayer类(从DeepTwins.onLoad中获取)
26
27
  * @param options.url MVT数据URL模板,默认为障碍物数据地址
@@ -32,7 +33,9 @@ export default class BarrierLayer {
32
33
  * @param options.minHeight 最小高度(米),低于此高度的障碍物不渲染,默认0
33
34
  * @param options.maxHeight 最大高度(米),高于此高度的障碍物不渲染,默认Infinity
34
35
  */
35
- constructor(viewer: any, options?: any);
36
+ constructor(map: any, options?: any);
37
+ private _canOperate;
38
+ getMap(): any;
36
39
  /**
37
40
  * 创建primitives
38
41
  * 按照示例代码的逻辑实现,每个feature创建一个障碍物实例