deeptwins-engine-3d 0.1.41 → 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.
- package/dist/esm/analyze/ViewshedAnalysis.d.ts +28 -0
- package/dist/esm/analyze/ViewshedAnalysis.js +305 -442
- package/dist/esm/drawer/index.d.ts +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +4 -3
- package/dist/esm/map/GroundSkyBox.js +2 -2
- package/dist/esm/map/Map.js +7 -7
- package/dist/esm/plot/utils/DomUtil.js +1 -1
- package/dist/esm/tool/Compass.js +20 -4
- package/dist/esm/tool/PrimitiveCluster.js +10 -9
- package/dist/umd/deeptwins-engine-3d.min.js +1 -1
- package/package.json +2 -2
|
@@ -1,442 +1,305 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
//
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
//
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
+
|
|
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
|
+
}
|