@vcmap/viewshed 3.0.5 → 4.0.0
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/CHANGELOG.md +6 -0
- package/dist/index.js +1097 -1119
- package/package.json +25 -24
- package/src/ViewshedConfigEditor.vue +32 -34
- package/src/ViewshedWindow.vue +152 -160
- package/src/{index.js → index.ts} +63 -68
- package/src/util/{toolboxHelper.js → toolboxHelper.ts} +57 -38
- package/src/util/{windowHelper.js → windowHelper.ts} +28 -27
- package/src/{viewshed.js → viewshed.ts} +159 -202
- package/src/{viewshedCategory.js → viewshedCategory.ts} +67 -60
- package/src/{viewshedInteraction.js → viewshedInteraction.ts} +20 -14
- package/src/{viewshedManager.js → viewshedManager.ts} +130 -97
- package/src/{viewshedPrimitive.js → viewshedPrimitive.ts} +34 -19
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import type { CesiumMap, VcsObjectOptions } from '@vcmap/core';
|
|
1
2
|
import { VcsEvent, VcsObject } from '@vcmap/core';
|
|
3
|
+
import type {
|
|
4
|
+
Scene,
|
|
5
|
+
PerspectiveFrustum,
|
|
6
|
+
HeadingPitchRollValues,
|
|
7
|
+
} from '@vcmap-cesium/engine';
|
|
2
8
|
import {
|
|
3
9
|
Camera,
|
|
4
10
|
Cartesian3,
|
|
@@ -8,45 +14,44 @@ import {
|
|
|
8
14
|
} from '@vcmap-cesium/engine';
|
|
9
15
|
import { check } from '@vcsuite/check';
|
|
10
16
|
import { parseEnumValue } from '@vcsuite/parsers';
|
|
17
|
+
import type { Coordinate } from 'ol/coordinate.js';
|
|
11
18
|
import ViewshedCameraPrimitive from './viewshedPrimitive.js';
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
CONE: 'cone',
|
|
20
|
-
THREESIXTY: '360',
|
|
21
|
-
};
|
|
20
|
+
export enum ViewshedTypes {
|
|
21
|
+
/** A cone Viewshed, that can be used for visibility analysis. */
|
|
22
|
+
CONE = 'cone',
|
|
23
|
+
/** A 360 degree Viewshed, that can be used for sensor analysis. */
|
|
24
|
+
THREESIXTY = '360',
|
|
25
|
+
}
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
type ShadowFrustumOptions = {
|
|
28
|
+
/** The angle of the field of view (FOV), in radians. */
|
|
29
|
+
fov: number;
|
|
30
|
+
/** The aspect ratio of the frustum's width to its height. */
|
|
31
|
+
aspectRatio: number;
|
|
32
|
+
/** The distance of the near plane. */
|
|
33
|
+
near: number;
|
|
34
|
+
/** The distance of the far plane. */
|
|
35
|
+
far: number;
|
|
36
|
+
};
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
export type ColorOptions = {
|
|
39
|
+
/** CSS color string of the visible parts of the shadow map */
|
|
40
|
+
visibleColor?: string;
|
|
41
|
+
/** CSS color string of the hidden parts of the shadow map */
|
|
42
|
+
shadowColor?: string;
|
|
43
|
+
};
|
|
36
44
|
|
|
37
45
|
/**
|
|
38
46
|
* Creates camera and sets frustum options and orientation.
|
|
39
|
-
* @param {import("@vcmap-cesium/engine").Scene} scene
|
|
40
|
-
* @param {ShadowFrustumOptions} frustumOptions
|
|
41
|
-
* @returns {import("@vcmap-cesium/engine").Camera}
|
|
42
47
|
*/
|
|
43
|
-
function createShadowCamera(
|
|
48
|
+
function createShadowCamera(
|
|
49
|
+
scene: Scene,
|
|
50
|
+
frustumOptions: ShadowFrustumOptions,
|
|
51
|
+
): Camera {
|
|
44
52
|
const camera = new Camera(scene);
|
|
45
53
|
|
|
46
|
-
const perspectiveFrustum =
|
|
47
|
-
/** @type {import("@vcmap-cesium/engine").PerspectiveFrustum} */ (
|
|
48
|
-
camera.frustum
|
|
49
|
-
);
|
|
54
|
+
const perspectiveFrustum = camera.frustum as PerspectiveFrustum;
|
|
50
55
|
perspectiveFrustum.fov = frustumOptions.fov;
|
|
51
56
|
perspectiveFrustum.near = frustumOptions.near;
|
|
52
57
|
perspectiveFrustum.aspectRatio = frustumOptions.aspectRatio;
|
|
@@ -55,165 +60,139 @@ function createShadowCamera(scene, frustumOptions) {
|
|
|
55
60
|
return camera;
|
|
56
61
|
}
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
type ViewshedSpecificOptions = {
|
|
64
|
+
/** Whether the viewshed has a spot light with limited field of view (cone) or a point light with 360° coverage (360). */
|
|
65
|
+
viewshedType: ViewshedTypes;
|
|
66
|
+
/** The position of the viewshed. Height offset is added to Z value of position to determine actual height of viewshed. */
|
|
67
|
+
position?: Coordinate;
|
|
68
|
+
/** The frustum options with far, near, fov and aspect ratio. */
|
|
69
|
+
frustumOptions?: ShadowFrustumOptions;
|
|
70
|
+
/** The values for heading and pitch. Roll is ignored. */
|
|
71
|
+
orientation?: HeadingPitchRollValues;
|
|
72
|
+
/** The colors of the visible and the hidden areas. */
|
|
73
|
+
colorOptions?: ColorOptions;
|
|
74
|
+
/** Whether the viewsheds primitve should be shown. */
|
|
75
|
+
showPrimitive?: boolean;
|
|
76
|
+
/** Height offset. Is added to Z value of position. */
|
|
77
|
+
heightOffset?: number;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
type ViewshedDefaultOptions = VcsObjectOptions &
|
|
81
|
+
Required<
|
|
82
|
+
Pick<
|
|
83
|
+
ViewshedOptions,
|
|
84
|
+
'colorOptions' | 'frustumOptions' | 'orientation' | 'position'
|
|
85
|
+
>
|
|
86
|
+
> & { colorOptions: Required<ColorOptions> };
|
|
87
|
+
|
|
88
|
+
export type ViewshedOptions = VcsObjectOptions & ViewshedSpecificOptions;
|
|
69
89
|
|
|
70
90
|
/**
|
|
71
91
|
* Viewshed class consists of a Cesium Shadow map and a primitive. Since there can only be one ShadowMap for each Scene, only one viewshed instance at a time is possible.
|
|
72
92
|
*/
|
|
73
93
|
export default class Viewshed extends VcsObject {
|
|
74
|
-
static get className() {
|
|
94
|
+
static get className(): string {
|
|
75
95
|
return 'Viewshed';
|
|
76
96
|
}
|
|
77
97
|
|
|
78
|
-
|
|
79
|
-
* Returns the default viewshed options.
|
|
80
|
-
* @returns {{frustum: ShadowFrustumOptions, shadowColor: string, visibleColor: string, orientation: import("@vcmap-cesium/engine").HeadingPitchRollValues, position: import("ol/coordinate").Coordinate}}
|
|
81
|
-
*/
|
|
82
|
-
static getDefaultOptions() {
|
|
98
|
+
static getDefaultOptions(): ViewshedDefaultOptions {
|
|
83
99
|
return {
|
|
84
|
-
|
|
100
|
+
colorOptions: { shadowColor: '#3333331A', visibleColor: '#FF990080' },
|
|
101
|
+
frustumOptions: {
|
|
85
102
|
fov: CesiumMath.PI / 3,
|
|
86
103
|
near: 1.0,
|
|
87
104
|
aspectRatio: 1.0,
|
|
88
105
|
far: 300,
|
|
89
106
|
},
|
|
90
|
-
|
|
91
|
-
visibleColor: '#FF990080',
|
|
92
|
-
orientation: {
|
|
93
|
-
heading: 0,
|
|
94
|
-
pitch: 0,
|
|
95
|
-
roll: 0,
|
|
96
|
-
},
|
|
107
|
+
orientation: { heading: 0, pitch: 0, roll: 0 },
|
|
97
108
|
position: [0, 0, 0],
|
|
98
109
|
};
|
|
99
110
|
}
|
|
100
111
|
|
|
101
112
|
static MIN_DISTANCE = 10;
|
|
102
113
|
|
|
114
|
+
private _cesiumMap: CesiumMap | null = null;
|
|
115
|
+
|
|
116
|
+
private _shadowCamera: Camera | null = null;
|
|
117
|
+
|
|
118
|
+
private _scene: Scene | null = null;
|
|
119
|
+
|
|
120
|
+
private _frustumOptions: ShadowFrustumOptions;
|
|
121
|
+
|
|
122
|
+
private _headingPitchRollValues: HeadingPitchRollValues;
|
|
123
|
+
|
|
103
124
|
/**
|
|
104
|
-
*
|
|
125
|
+
* The viewsheds position, excluding height offset, in lat/lon degrees.
|
|
105
126
|
*/
|
|
106
|
-
|
|
127
|
+
private _position: Coordinate;
|
|
128
|
+
|
|
129
|
+
private _viewshedType: ViewshedTypes;
|
|
130
|
+
|
|
131
|
+
private _colors: { visibleColor: Color; shadowColor: Color };
|
|
132
|
+
|
|
133
|
+
private _heightOffset: number;
|
|
134
|
+
|
|
135
|
+
private _shadowMap: ShadowMap | null = null;
|
|
136
|
+
|
|
137
|
+
private _primitive: ViewshedCameraPrimitive | null = null;
|
|
138
|
+
|
|
139
|
+
private _showPrimitive: boolean;
|
|
140
|
+
|
|
141
|
+
private _positionChanged = new VcsEvent<number[]>();
|
|
142
|
+
|
|
143
|
+
private _active = false;
|
|
144
|
+
|
|
145
|
+
constructor(options: ViewshedOptions) {
|
|
107
146
|
super(options);
|
|
108
|
-
|
|
109
|
-
* @type {import("@vcmap/core").CesiumMap | null}
|
|
110
|
-
* @private
|
|
111
|
-
*/
|
|
112
|
-
this._cesiumMap = null;
|
|
113
|
-
/**
|
|
114
|
-
* @type {import("@vcmap-cesium/engine").Camera | null}
|
|
115
|
-
* @private
|
|
116
|
-
*/
|
|
117
|
-
this._shadowCamera = null;
|
|
118
|
-
/**
|
|
119
|
-
* @type {import("@vcmap-cesium/engine").Scene | null}
|
|
120
|
-
* @private
|
|
121
|
-
*/
|
|
122
|
-
this._scene = null;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @type {ShadowFrustumOptions}
|
|
126
|
-
* @private
|
|
127
|
-
*/
|
|
147
|
+
|
|
128
148
|
this._frustumOptions = {
|
|
129
149
|
fov:
|
|
130
|
-
options.frustumOptions?.fov ||
|
|
150
|
+
options.frustumOptions?.fov ||
|
|
151
|
+
Viewshed.getDefaultOptions().frustumOptions.fov,
|
|
131
152
|
far:
|
|
132
|
-
options.frustumOptions?.far ||
|
|
153
|
+
options.frustumOptions?.far ||
|
|
154
|
+
Viewshed.getDefaultOptions().frustumOptions.far,
|
|
133
155
|
near:
|
|
134
156
|
options.frustumOptions?.near ||
|
|
135
|
-
Viewshed.getDefaultOptions().
|
|
157
|
+
Viewshed.getDefaultOptions().frustumOptions.near,
|
|
136
158
|
aspectRatio:
|
|
137
159
|
options.frustumOptions?.aspectRatio ||
|
|
138
|
-
Viewshed.getDefaultOptions().
|
|
160
|
+
Viewshed.getDefaultOptions().frustumOptions.aspectRatio,
|
|
139
161
|
};
|
|
140
162
|
|
|
141
|
-
/**
|
|
142
|
-
* @type {import("@vcmap-cesium/engine").HeadingPitchRollValues}
|
|
143
|
-
* @private
|
|
144
|
-
*/
|
|
145
163
|
this._headingPitchRollValues = options.orientation || {
|
|
146
164
|
...Viewshed.getDefaultOptions().orientation,
|
|
147
165
|
};
|
|
148
166
|
|
|
149
|
-
/**
|
|
150
|
-
* The viewsheds position, excluding height offset, in lat/lon degrees.
|
|
151
|
-
* @type {import("ol/coordinate.js").Coordinate}
|
|
152
|
-
* @private
|
|
153
|
-
*/
|
|
154
167
|
this._position = options.position || Viewshed.getDefaultOptions().position;
|
|
155
168
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
* @type {{visibleColor: import("@vcmap-cesium/engine").Color, shadowColor: import("@vcmap-cesium/engine").Color}}
|
|
163
|
-
* @private
|
|
164
|
-
*/
|
|
169
|
+
this._viewshedType = parseEnumValue(
|
|
170
|
+
options.viewshedType,
|
|
171
|
+
ViewshedTypes,
|
|
172
|
+
ViewshedTypes.CONE,
|
|
173
|
+
);
|
|
174
|
+
|
|
165
175
|
this._colors = {
|
|
166
176
|
visibleColor: Color.fromCssColorString(
|
|
167
177
|
options.colorOptions?.visibleColor ||
|
|
168
|
-
Viewshed.getDefaultOptions().visibleColor,
|
|
178
|
+
Viewshed.getDefaultOptions().colorOptions.visibleColor,
|
|
169
179
|
),
|
|
170
180
|
shadowColor: Color.fromCssColorString(
|
|
171
181
|
options.colorOptions?.shadowColor ||
|
|
172
|
-
Viewshed.getDefaultOptions().shadowColor,
|
|
182
|
+
Viewshed.getDefaultOptions().colorOptions.shadowColor,
|
|
173
183
|
),
|
|
174
184
|
};
|
|
175
185
|
|
|
176
|
-
/**
|
|
177
|
-
* @type {number}
|
|
178
|
-
* @private
|
|
179
|
-
*/
|
|
180
186
|
this._heightOffset = options.heightOffset || 0;
|
|
181
187
|
|
|
182
|
-
/**
|
|
183
|
-
* @type {import("@vcmap-cesium/engine").ShadowMap | null}
|
|
184
|
-
* @private
|
|
185
|
-
*/
|
|
186
|
-
this._shadowMap = null;
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @type {ViewshedCameraPrimitive | null}
|
|
190
|
-
* @private
|
|
191
|
-
*/
|
|
192
|
-
this._primitive = null;
|
|
193
|
-
/**
|
|
194
|
-
* @type {boolean}
|
|
195
|
-
* @private
|
|
196
|
-
*/
|
|
197
188
|
this._showPrimitive = !!options.showPrimitive;
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* @type {import("@vcmap/core").VcsEvent<number[]>}
|
|
201
|
-
* @private
|
|
202
|
-
*/
|
|
203
|
-
this._positionChanged = new VcsEvent();
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* @type {boolean}
|
|
207
|
-
* @private
|
|
208
|
-
*/
|
|
209
|
-
this._active = false;
|
|
210
189
|
}
|
|
211
190
|
|
|
212
191
|
/**
|
|
213
192
|
* Sets a new position for the shadow map. If no shadow map was created yet, due to missing position, this method triggers the creation of a shadow map.
|
|
214
|
-
* @param
|
|
193
|
+
* @param coords The new positions coordinates in degrees
|
|
215
194
|
*/
|
|
216
|
-
set position(coords) {
|
|
195
|
+
set position(coords: Coordinate) {
|
|
217
196
|
check(coords, [Number]);
|
|
218
197
|
this._position = coords;
|
|
219
198
|
if (this._shadowCamera) {
|
|
@@ -230,25 +209,25 @@ export default class Viewshed extends VcsObject {
|
|
|
230
209
|
}
|
|
231
210
|
|
|
232
211
|
/**
|
|
233
|
-
* @returns
|
|
212
|
+
* @returns The current position of the viewshed source.
|
|
234
213
|
*/
|
|
235
|
-
get position() {
|
|
214
|
+
get position(): Coordinate {
|
|
236
215
|
return [...this._position];
|
|
237
216
|
}
|
|
238
217
|
|
|
239
218
|
/**
|
|
240
219
|
* Getter for Event that is triggered each time the position is changed.
|
|
241
|
-
* @returns
|
|
220
|
+
* @returns The new position
|
|
242
221
|
*/
|
|
243
|
-
get positionChanged() {
|
|
222
|
+
get positionChanged(): VcsEvent<number[]> {
|
|
244
223
|
return this._positionChanged;
|
|
245
224
|
}
|
|
246
225
|
|
|
247
226
|
/**
|
|
248
227
|
* Sets the height offset of the viewshed.
|
|
249
|
-
* @param
|
|
228
|
+
* @param value the offset that is added to the position height.
|
|
250
229
|
*/
|
|
251
|
-
set heightOffset(value) {
|
|
230
|
+
set heightOffset(value: number) {
|
|
252
231
|
this._heightOffset = value;
|
|
253
232
|
if (this._shadowCamera) {
|
|
254
233
|
this._shadowCamera.position = Cartesian3.fromDegrees(
|
|
@@ -260,19 +239,15 @@ export default class Viewshed extends VcsObject {
|
|
|
260
239
|
}
|
|
261
240
|
}
|
|
262
241
|
|
|
263
|
-
|
|
264
|
-
* Getter for height offset.
|
|
265
|
-
* @returns {number}
|
|
266
|
-
*/
|
|
267
|
-
get heightOffset() {
|
|
242
|
+
get heightOffset(): number {
|
|
268
243
|
return this._heightOffset;
|
|
269
244
|
}
|
|
270
245
|
|
|
271
246
|
/**
|
|
272
247
|
* Sets the reach of the viewshed.
|
|
273
|
-
* @param
|
|
248
|
+
* @param value The distance in meters.
|
|
274
249
|
*/
|
|
275
|
-
set distance(value) {
|
|
250
|
+
set distance(value: number) {
|
|
276
251
|
this._frustumOptions.far =
|
|
277
252
|
value > Viewshed.MIN_DISTANCE ? value : Viewshed.MIN_DISTANCE;
|
|
278
253
|
if (this._shadowCamera) {
|
|
@@ -288,22 +263,21 @@ export default class Viewshed extends VcsObject {
|
|
|
288
263
|
|
|
289
264
|
/**
|
|
290
265
|
* Returns the reach of the viewshed.
|
|
291
|
-
* @returns
|
|
266
|
+
* @returns The distance in meters.
|
|
292
267
|
*/
|
|
293
|
-
get distance() {
|
|
268
|
+
get distance(): number {
|
|
294
269
|
return this._frustumOptions.far;
|
|
295
270
|
}
|
|
296
271
|
|
|
297
272
|
/**
|
|
298
273
|
* Sets the field of view of a cone viewshed. Does not have a impact on 360 viewshed.
|
|
299
|
-
* @param
|
|
274
|
+
* @param value The field of view in degrees.
|
|
300
275
|
*/
|
|
301
|
-
set fov(value) {
|
|
276
|
+
set fov(value: number) {
|
|
302
277
|
this._frustumOptions.fov = value * CesiumMath.RADIANS_PER_DEGREE;
|
|
303
278
|
if (this._shadowCamera) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
).fov = value * CesiumMath.RADIANS_PER_DEGREE;
|
|
279
|
+
(this._shadowCamera.frustum as PerspectiveFrustum).fov =
|
|
280
|
+
value * CesiumMath.RADIANS_PER_DEGREE;
|
|
307
281
|
if (this._viewshedType === ViewshedTypes.CONE) {
|
|
308
282
|
this._updateShadowMap();
|
|
309
283
|
this._updatePrimitive();
|
|
@@ -313,17 +287,17 @@ export default class Viewshed extends VcsObject {
|
|
|
313
287
|
|
|
314
288
|
/**
|
|
315
289
|
* Returns the field of view.
|
|
316
|
-
* @returns
|
|
290
|
+
* @returns The field of view in degrees.
|
|
317
291
|
*/
|
|
318
|
-
get fov() {
|
|
292
|
+
get fov(): number {
|
|
319
293
|
return this._frustumOptions.fov * CesiumMath.DEGREES_PER_RADIAN;
|
|
320
294
|
}
|
|
321
295
|
|
|
322
296
|
/**
|
|
323
297
|
* Sets the heading of a cone viewshed. Does not have impact on 360 viewshed.
|
|
324
|
-
* @param
|
|
298
|
+
* @param value Heading in degrees.
|
|
325
299
|
*/
|
|
326
|
-
set heading(value) {
|
|
300
|
+
set heading(value: number) {
|
|
327
301
|
this._headingPitchRollValues.heading =
|
|
328
302
|
value * CesiumMath.RADIANS_PER_DEGREE;
|
|
329
303
|
if (this._shadowCamera) {
|
|
@@ -340,19 +314,17 @@ export default class Viewshed extends VcsObject {
|
|
|
340
314
|
}
|
|
341
315
|
}
|
|
342
316
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
get heading() {
|
|
348
|
-
return this._headingPitchRollValues.heading * CesiumMath.DEGREES_PER_RADIAN;
|
|
317
|
+
get heading(): number {
|
|
318
|
+
return (
|
|
319
|
+
this._headingPitchRollValues.heading! * CesiumMath.DEGREES_PER_RADIAN
|
|
320
|
+
);
|
|
349
321
|
}
|
|
350
322
|
|
|
351
323
|
/**
|
|
352
324
|
* Sets the pitch of a cone viewshed. 0 is horizontal. Does not have impact on 360 viewshed.
|
|
353
|
-
* @param
|
|
325
|
+
* @param value The pitch in degrees.
|
|
354
326
|
*/
|
|
355
|
-
set pitch(value) {
|
|
327
|
+
set pitch(value: number) {
|
|
356
328
|
this._headingPitchRollValues.pitch = value * CesiumMath.RADIANS_PER_DEGREE;
|
|
357
329
|
if (this._shadowCamera) {
|
|
358
330
|
const amount =
|
|
@@ -364,53 +336,42 @@ export default class Viewshed extends VcsObject {
|
|
|
364
336
|
}
|
|
365
337
|
}
|
|
366
338
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
* @returns {number} The pitch in degrees.
|
|
370
|
-
*/
|
|
371
|
-
get pitch() {
|
|
372
|
-
return this._headingPitchRollValues.pitch * CesiumMath.DEGREES_PER_RADIAN;
|
|
339
|
+
get pitch(): number {
|
|
340
|
+
return this._headingPitchRollValues.pitch! * CesiumMath.DEGREES_PER_RADIAN;
|
|
373
341
|
}
|
|
374
342
|
|
|
375
343
|
/**
|
|
376
344
|
* Sets whether the primitive of the viewshed should be shown or not.
|
|
377
|
-
* @param
|
|
345
|
+
* @param value
|
|
378
346
|
*/
|
|
379
|
-
set showPrimitive(value) {
|
|
347
|
+
set showPrimitive(value: boolean) {
|
|
380
348
|
this._showPrimitive = value;
|
|
381
349
|
this._updatePrimitive();
|
|
382
350
|
}
|
|
383
351
|
|
|
384
352
|
/**
|
|
385
353
|
* Gets if the primitive of the viewshed is shown or not.
|
|
386
|
-
* @returns {boolean}
|
|
387
354
|
*/
|
|
388
|
-
get showPrimitive() {
|
|
355
|
+
get showPrimitive(): boolean {
|
|
389
356
|
return this._showPrimitive;
|
|
390
357
|
}
|
|
391
358
|
|
|
392
|
-
|
|
393
|
-
* Returns the type of the Viewshed.
|
|
394
|
-
* @returns {ViewshedTypes}
|
|
395
|
-
*/
|
|
396
|
-
get type() {
|
|
359
|
+
get type(): ViewshedTypes {
|
|
397
360
|
return this._viewshedType;
|
|
398
361
|
}
|
|
399
362
|
|
|
400
|
-
|
|
401
|
-
* @returns {ShadowMap|null}
|
|
402
|
-
*/
|
|
403
|
-
get shadowMap() {
|
|
363
|
+
get shadowMap(): ShadowMap | null {
|
|
404
364
|
return this._shadowMap;
|
|
405
365
|
}
|
|
406
366
|
|
|
407
367
|
/**
|
|
408
368
|
* Deactivates the viewshed by removing primitive and removing shadowMap.
|
|
409
369
|
*/
|
|
410
|
-
deactivate() {
|
|
370
|
+
deactivate(): void {
|
|
411
371
|
if (this._active) {
|
|
412
372
|
this._removePrimitive();
|
|
413
|
-
this._shadowMap
|
|
373
|
+
this._shadowMap!.enabled = false;
|
|
374
|
+
// @ts-expect-error - ShadowMap destroy method exists but is not in type definitions
|
|
414
375
|
this._shadowMap?.destroy();
|
|
415
376
|
this._shadowCamera = null;
|
|
416
377
|
this._scene = null;
|
|
@@ -422,9 +383,9 @@ export default class Viewshed extends VcsObject {
|
|
|
422
383
|
|
|
423
384
|
/**
|
|
424
385
|
* Activates viewshed.
|
|
425
|
-
* @param
|
|
386
|
+
* @param The cesium map to which the shadow map of the viewshed is applied to.
|
|
426
387
|
*/
|
|
427
|
-
activate(cesiumMap) {
|
|
388
|
+
activate(cesiumMap: CesiumMap): void {
|
|
428
389
|
if (!this._active) {
|
|
429
390
|
this._active = true;
|
|
430
391
|
}
|
|
@@ -452,7 +413,7 @@ export default class Viewshed extends VcsObject {
|
|
|
452
413
|
/**
|
|
453
414
|
* Updates the shadow map by creating a new one and applying all the current parameters.
|
|
454
415
|
*/
|
|
455
|
-
_updateShadowMap() {
|
|
416
|
+
private _updateShadowMap(): void {
|
|
456
417
|
if (
|
|
457
418
|
!this._active ||
|
|
458
419
|
!this._shadowCamera ||
|
|
@@ -462,10 +423,10 @@ export default class Viewshed extends VcsObject {
|
|
|
462
423
|
return;
|
|
463
424
|
}
|
|
464
425
|
|
|
426
|
+
// @ts-expect-error - ShadowMap destroy method exists but is not in type definitions
|
|
465
427
|
this._shadowMap?.destroy();
|
|
466
|
-
// @ts-
|
|
428
|
+
// @ts-expect-error - does not accept parameters
|
|
467
429
|
this._shadowMap = new ShadowMap({
|
|
468
|
-
// @ts-ignore
|
|
469
430
|
context: this._scene.context,
|
|
470
431
|
lightCamera: this._shadowCamera,
|
|
471
432
|
enabled: true,
|
|
@@ -481,7 +442,7 @@ export default class Viewshed extends VcsObject {
|
|
|
481
442
|
this._cesiumMap.setShadowMap(this._shadowMap);
|
|
482
443
|
}
|
|
483
444
|
|
|
484
|
-
_removePrimitive() {
|
|
445
|
+
private _removePrimitive(): void {
|
|
485
446
|
if (this._primitive && !this._primitive.isDestroyed()) {
|
|
486
447
|
this._scene?.primitives.remove(this._primitive);
|
|
487
448
|
this._primitive.destroy();
|
|
@@ -489,11 +450,11 @@ export default class Viewshed extends VcsObject {
|
|
|
489
450
|
}
|
|
490
451
|
}
|
|
491
452
|
|
|
492
|
-
_updatePrimitive() {
|
|
453
|
+
private _updatePrimitive(): void {
|
|
493
454
|
if (this._showPrimitive && this._active && this._scene) {
|
|
494
455
|
this._removePrimitive();
|
|
495
456
|
this._primitive = new ViewshedCameraPrimitive({
|
|
496
|
-
camera: this._shadowCamera
|
|
457
|
+
camera: this._shadowCamera!,
|
|
497
458
|
allowPicking: false,
|
|
498
459
|
spot: this._viewshedType === ViewshedTypes.CONE,
|
|
499
460
|
});
|
|
@@ -505,9 +466,9 @@ export default class Viewshed extends VcsObject {
|
|
|
505
466
|
|
|
506
467
|
/**
|
|
507
468
|
* Sets distance and, in case of cone viewsheds, also heading and pitch. Only works when viewshed is **active**.
|
|
508
|
-
* @param
|
|
469
|
+
* @param target Point to calculate distance, heading and pitch from.
|
|
509
470
|
*/
|
|
510
|
-
lookAt(target) {
|
|
471
|
+
lookAt(target: number[]): void {
|
|
511
472
|
if (!this._shadowCamera) {
|
|
512
473
|
return;
|
|
513
474
|
}
|
|
@@ -542,9 +503,8 @@ export default class Viewshed extends VcsObject {
|
|
|
542
503
|
|
|
543
504
|
/**
|
|
544
505
|
* Returns an object with all the settings of a viewshed instance.
|
|
545
|
-
* @returns {ViewshedOptions}
|
|
546
506
|
*/
|
|
547
|
-
toJSON() {
|
|
507
|
+
toJSON(): ViewshedOptions {
|
|
548
508
|
return {
|
|
549
509
|
...super.toJSON(),
|
|
550
510
|
viewshedType: this.type,
|
|
@@ -560,10 +520,7 @@ export default class Viewshed extends VcsObject {
|
|
|
560
520
|
};
|
|
561
521
|
}
|
|
562
522
|
|
|
563
|
-
|
|
564
|
-
* Destroys the viewshed.
|
|
565
|
-
*/
|
|
566
|
-
destroy() {
|
|
523
|
+
destroy(): void {
|
|
567
524
|
const cesiumMap = this._cesiumMap;
|
|
568
525
|
const shadowMap = this._shadowMap;
|
|
569
526
|
this.deactivate();
|