diff --git a/public/js/appCesium.js b/public/js/appCesium.js index c32da2298dd25602b5be478336b3f2f39c52886e..b522842bfdcb898ffa4e94003fafb73a370fcd28 100644 --- a/public/js/appCesium.js +++ b/public/js/appCesium.js @@ -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 - * @returns {undefined} undefined + * @returns {Object} The tileset dataset */ -const loadTiles = function (urlTiles) { - const tileset = new Cesium.Cesium3DTileset({ +const createBuildingTileset = function (urlTiles) { + return new Cesium.Cesium3DTileset({ 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 .zoomTo( tileset, new Cesium.HeadingPitchRange( 0.0, -0.5, - tileset.boundingSphere.radius / 0.5 + buildingTileset.boundingSphere.radius / 0.5 ) ) .otherwise(function (err) { @@ -59,11 +79,8 @@ const loadTiles = function (urlTiles) { * @returns {undefined} undefined */ const loadNonDetailedBuilding225 = function () { - // Paths to data sources - const URL_3DTILES = "data_3d/3dtiles/1_full/tileset.json"; - - // Tileset with all buildings - loadTiles(URL_3DTILES); + // 3D tileset with all buildings + loadTiles(nonDetailedBuilding225Tileset); }; /** @@ -93,12 +110,11 @@ const gltfLoad = function (gltfUrl, gltfId) { * @returns {undefined} undefined */ const loadDetailedBuilding225 = function () { - // Paths to data sources - const URL_3DTILES = "data_3d/3dtiles/2_partial/tileset.json"; + // Path to glTF data source const URL_GLTF = "data_3d/gltf"; // Tileset without building 225 - loadTiles(URL_3DTILES); + loadTiles(detailedBuilding225Tileset); // Load Building 225 gltfLoad(URL_GLTF, "bosch_si225_3");