-
Notifications
You must be signed in to change notification settings - Fork 416
/
Copy pathTerrainLayer.js
67 lines (62 loc) · 1.98 KB
/
TerrainLayer.js
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
/*
* Copyright 2022, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import Layers from '../../../../utils/cesium/Layers';
import * as Cesium from 'cesium';
import GeoServerBILTerrainProvider from '../../../../utils/cesium/GeoServerBILTerrainProvider';
import WMSUtils from '../../../../utils/cesium/WMSUtils';
function cesiumOptionsMapping(config) {
return {
url: config.url,
credit: config?.options?.credit,
ellipsoid: config?.options?.ellipsoid,
requestMetadata: config?.options?.requestMetadata,
requestWaterMask: config?.options?.requestWaterMask,
requestVertexNormals: config?.options?.requestVertexNormals
};
}
const createLayer = (config, map) => {
map.terrainProvider = undefined;
let terrainProvider;
switch (config.provider) {
case 'wms': {
terrainProvider = new GeoServerBILTerrainProvider(WMSUtils.wmsToCesiumOptionsBIL(config));
break;
}
case 'cesium': {
terrainProvider = new Cesium.CesiumTerrainProvider(cesiumOptionsMapping(config));
break;
}
case 'ellipsoid': {
terrainProvider = new Cesium.EllipsoidTerrainProvider();
break;
}
default:
terrainProvider = new Cesium.EllipsoidTerrainProvider();
break;
}
map.terrainProvider = terrainProvider;
return {
detached: true,
terrainProvider,
remove: () => {
map.terrainProvider = new Cesium.EllipsoidTerrainProvider();
}
};
};
const updateLayer = (layer, newOptions, oldOptions, map) => {
if (newOptions.securityToken !== oldOptions.securityToken
|| oldOptions.credits !== newOptions.credits
|| oldOptions.provider !== newOptions.provider) {
return createLayer(newOptions, map);
}
return null;
};
Layers.registerType('terrain', {
create: createLayer,
update: updateLayer
});