Skip to content

Commit

Permalink
Fix terain provider config after Cesium upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Flowm committed Dec 25, 2023
1 parent d23f540 commit 4ac6e99
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/components/Satvis.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<div class="toolbarTitle">
Terrain
</div>
<label v-for="name in cc.terrainProviders" :key="name" class="toolbarSwitch">
<label v-for="name in cc.terrainProviderNames" :key="name" class="toolbarSwitch">
<input v-model="terrainProvider" type="radio" :value="name">
<span class="slider"></span>
{{ name }}
Expand Down
60 changes: 33 additions & 27 deletions src/modules/CesiumController.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export class CesiumController {
window.cc = this;

// CesiumController config
this.terrainProviders = ["None", "Maptiler"];
this.sceneModes = ["3D", "2D", "Columbus"];
this.cameraModes = ["Fixed", "Inertial"];

Expand Down Expand Up @@ -166,6 +165,21 @@ export class CesiumController {
base: false,
},
};
this.terrainProviders = {
None: {
create: () => new Cesium.EllipsoidTerrainProvider(),
},
Maptiler: {
create: () => Cesium.CesiumTerrainProvider.fromUrl("https://api.maptiler.com/tiles/terrain-quantized-mesh/?key=tiHE8Ed08u6ZoFjbE32Z", {
credit: "<a href=\"https://www.maptiler.com/copyright/\" target=\"_blank\">© MapTiler</a> <a href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\">© OpenStreetMap contributors</a>",
requestVertexNormals: true,
}),
},
ArcGIS: {
create: () => Cesium.ArcGISTiledElevationTerrainProvider.fromUrl("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"),
visible: false,
},
};
}

preloadReferenceFrameData() {
Expand Down Expand Up @@ -222,6 +236,24 @@ export class CesiumController {
return layer;
}

get terrainProviderNames() {
return Object.entries(this.terrainProviders).filter(([, val]) => val.visible ?? true).map(([key]) => key);
}

set terrainProvider(terrainProviderName) {
this.updateTerrainProvider(terrainProviderName);
}

async updateTerrainProvider(terrainProviderName) {
if (!this.terrainProviderNames.includes(terrainProviderName)) {
console.error("Unknown terrain provider");
return;
}

const provider = await this.terrainProviders[terrainProviderName].create();
this.viewer.terrainProvider = provider;
}

set sceneMode(sceneMode) {
switch (sceneMode) {
case "3D":
Expand All @@ -238,32 +270,6 @@ export class CesiumController {
}
}

set terrainProvider(terrainProviderName) {
if (!this.terrainProviders.includes(terrainProviderName)) {
return;
}

switch (terrainProviderName) {
case "None":
this.viewer.terrainProvider = new Cesium.EllipsoidTerrainProvider();
break;
case "Maptiler":
this.viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
url: "https://api.maptiler.com/tiles/terrain-quantized-mesh/?key=tiHE8Ed08u6ZoFjbE32Z",
credit: "<a href=\"https://www.maptiler.com/copyright/\" target=\"_blank\">© MapTiler</a> <a href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\">© OpenStreetMap contributors</a>",
requestVertexNormals: true,
});
break;
case "ArcGIS":
this.viewer.terrainProvider = new Cesium.ArcGISTiledElevationTerrainProvider({
url: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer",
});
break;
default:
console.error("Unknown terrain provider");
}
}

jumpTo(location) {
switch (location) {
case "Everest": {
Expand Down

0 comments on commit 4ac6e99

Please sign in to comment.