-
Notifications
You must be signed in to change notification settings - Fork 1
/
terrainLayer.ts
112 lines (97 loc) · 3.01 KB
/
terrainLayer.ts
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
import { parseBoolean } from '@vcsuite/parsers';
import type { Coordinate } from 'ol/coordinate.js';
import Layer, { LayerImplementationOptions, LayerOptions } from './layer.js';
import {
getHeightFromTerrainProvider,
getTerrainProviderForUrl,
} from './terrainHelpers.js';
import CesiumMap from '../map/cesiumMap.js';
import TerrainCesiumImpl from './cesium/terrainCesiumImpl.js';
import { layerClassRegistry } from '../classRegistry.js';
import VcsMap from '../map/vcsMap.js';
export type TerrainOptions = LayerOptions & {
requestVertexNormals?: boolean;
requestWaterMask?: boolean;
};
export type TerrainImplementationOptions = LayerImplementationOptions & {
requestVertexNormals: boolean;
requestWaterMask: boolean;
};
/**
* @group Layer
*/
class TerrainLayer extends Layer<TerrainCesiumImpl> {
static get className(): string {
return 'TerrainLayer';
}
static getDefaultOptions(): TerrainOptions {
return {
...Layer.getDefaultOptions(),
requestVertexNormals: true,
requestWaterMask: false,
};
}
protected _supportedMaps = [CesiumMap.className];
requestVertexNormals: boolean;
requestWaterMask: boolean;
constructor(options: TerrainOptions) {
super(options);
const defaultOptions = TerrainLayer.getDefaultOptions();
this.requestVertexNormals = parseBoolean(
options.requestVertexNormals,
defaultOptions.requestVertexNormals,
);
this.requestWaterMask = parseBoolean(
options.requestWaterMask,
defaultOptions.requestWaterMask,
);
}
getImplementationOptions(): TerrainImplementationOptions {
return {
...super.getImplementationOptions(),
requestVertexNormals: this.requestVertexNormals,
requestWaterMask: this.requestWaterMask,
};
}
createImplementationsForMap(map: VcsMap): TerrainCesiumImpl[] {
if (map instanceof CesiumMap) {
return [new TerrainCesiumImpl(map, this.getImplementationOptions())];
}
return [];
}
/**
* getHeight for coordinates
* @param coords - the height is added to the coordinates in place
*/
async getHeightForWGS84Coordinates(
coords: Coordinate[],
): Promise<Coordinate[]> {
const terrainProvider = await getTerrainProviderForUrl(
this.url,
{
requestVertexNormals: this.requestVertexNormals,
requestWaterMask: this.requestWaterMask,
},
this.headers,
);
return getHeightFromTerrainProvider(
terrainProvider,
coords,
undefined,
coords,
);
}
toJSON(): TerrainOptions {
const config: TerrainOptions = super.toJSON();
const defaultOptions = TerrainLayer.getDefaultOptions();
if (this.requestVertexNormals !== defaultOptions.requestVertexNormals) {
config.requestVertexNormals = this.requestVertexNormals;
}
if (this.requestWaterMask !== defaultOptions.requestWaterMask) {
config.requestWaterMask = this.requestWaterMask;
}
return config;
}
}
layerClassRegistry.registerClass(TerrainLayer.className, TerrainLayer);
export default TerrainLayer;