Commit c2322910 authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

New function: create 3d tileset

Refactor logic of creating a 3d tilset into a new function
parent fb213f5c
...@@ -19,24 +19,44 @@ const viewer = new Cesium.Viewer("cesiumGlobeContainer", { ...@@ -19,24 +19,44 @@ const viewer = new Cesium.Viewer("cesiumGlobeContainer", {
}); });
/** /**
* Load and zoom to the extents of 3DTiles * Add a tileset containing buildings
*
* @param {String} urlTiles URL of the 3DTiles to be loaded * @param {String} urlTiles URL of the 3DTiles to be loaded
* @returns {undefined} undefined * @returns {Object} The tileset dataset
*/ */
const loadTiles = function (urlTiles) { const createBuildingTileset = function (urlTiles) {
const tileset = new Cesium.Cesium3DTileset({ return new Cesium.Cesium3DTileset({
url: urlTiles, url: urlTiles,
}); });
viewer.scene.primitives.add(tileset); };
tileset.readyPromise.then(function () { // 3D tileset with all buildings
const nonDetailedBuilding225Tileset = createBuildingTileset(
"data_3d/3dtiles/1_full/tileset.json"
);
// 3D tileset with all buildings except Bau 225
const detailedBuilding225Tileset = createBuildingTileset(
"data_3d/3dtiles/2_partial/tileset.json"
);
/**
* Load and zoom to the extents of 3DTiles
* @param {Object} buildingTileset The 3D tileset to be loaded
* @returns {undefined} undefined
*/
const loadTiles = function (buildingTileset) {
// Add the tileset to the viewer
viewer.scene.primitives.add(buildingTileset);
buildingTileset.readyPromise.then(function () {
viewer viewer
.zoomTo( .zoomTo(
tileset, tileset,
new Cesium.HeadingPitchRange( new Cesium.HeadingPitchRange(
0.0, 0.0,
-0.5, -0.5,
tileset.boundingSphere.radius / 0.5 buildingTileset.boundingSphere.radius / 0.5
) )
) )
.otherwise(function (err) { .otherwise(function (err) {
...@@ -59,11 +79,8 @@ const loadTiles = function (urlTiles) { ...@@ -59,11 +79,8 @@ const loadTiles = function (urlTiles) {
* @returns {undefined} undefined * @returns {undefined} undefined
*/ */
const loadNonDetailedBuilding225 = function () { const loadNonDetailedBuilding225 = function () {
// Paths to data sources // 3D tileset with all buildings
const URL_3DTILES = "data_3d/3dtiles/1_full/tileset.json"; loadTiles(nonDetailedBuilding225Tileset);
// Tileset with all buildings
loadTiles(URL_3DTILES);
}; };
/** /**
...@@ -93,12 +110,11 @@ const gltfLoad = function (gltfUrl, gltfId) { ...@@ -93,12 +110,11 @@ const gltfLoad = function (gltfUrl, gltfId) {
* @returns {undefined} undefined * @returns {undefined} undefined
*/ */
const loadDetailedBuilding225 = function () { const loadDetailedBuilding225 = function () {
// Paths to data sources // Path to glTF data source
const URL_3DTILES = "data_3d/3dtiles/2_partial/tileset.json";
const URL_GLTF = "data_3d/gltf"; const URL_GLTF = "data_3d/gltf";
// Tileset without building 225 // Tileset without building 225
loadTiles(URL_3DTILES); loadTiles(detailedBuilding225Tileset);
// Load Building 225 // Load Building 225
gltfLoad(URL_GLTF, "bosch_si225_3"); gltfLoad(URL_GLTF, "bosch_si225_3");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment