From aaf34d215ceeaaafe19c50f351be7ff276ed12ed Mon Sep 17 00:00:00 2001 From: "Son H. Nguyen" Date: Wed, 17 Apr 2024 18:11:58 +0200 Subject: [PATCH] Update fly functions for highlighted and hidden objects --- 3dwebclient/index.html | 4 +-- 3dwebclient/script.js | 56 +++++++++++++++++++++++------------------- js/3dcitydb-web-map.js | 32 +++++++++++++----------- 3 files changed, 51 insertions(+), 41 deletions(-) diff --git a/3dwebclient/index.html b/3dwebclient/index.html index 18349da6..91a63234 100644 --- a/3dwebclient/index.html +++ b/3dwebclient/index.html @@ -528,12 +528,12 @@
-
-
diff --git a/3dwebclient/script.js b/3dwebclient/script.js index 91045b36..9959dc95 100644 --- a/3dwebclient/script.js +++ b/3dwebclient/script.js @@ -422,31 +422,37 @@ function inspectTileStatus() { }, 200); } +let highlightedIdObjects = {}; + function listHighlightedObjects() { - var highlightingListElement = document.getElementById("citydb_highlightinglist"); + const highlightingListElement = document.getElementById("citydb_highlightinglist"); emptySelectBox(highlightingListElement, function () { - var highlightedObjects = webMap.getAllHighlightedObjects(); - for (var i = 0; i < highlightedObjects.length; i++) { + highlightedIdObjects = webMap.getAllHighlightedObjects(); + for (let key in highlightedIdObjects) { var option = document.createElement("option"); - option.text = highlightedObjects[i]; + option.text = key; + option.value = key; highlightingListElement.add(option); - highlightingListElement.selectedIndex = 0; } + highlightingListElement.selectedIndex = 0; }); } +let hiddenIdObjects = {}; + function listHiddenObjects() { - var hidddenListElement = document.getElementById("citydb_hiddenlist"); + const hidddenListElement = document.getElementById("citydb_hiddenlist"); emptySelectBox(hidddenListElement, function () { - var hiddenObjects = webMap.getAllHiddenObjects(); - for (var i = 0; i < hiddenObjects.length; i++) { + hiddenIdObjects = webMap.getAllHiddenObjects(); + for (let key in hiddenIdObjects) { var option = document.createElement("option"); - option.text = hiddenObjects[i]; + option.text = key; + option.value = key; hidddenListElement.add(option); - hidddenListElement.selectedIndex = 0; } + hidddenListElement.selectedIndex = 0; }); } @@ -458,21 +464,22 @@ function emptySelectBox(selectElement, callback) { callback(); } -function flyToClickedObject(obj) { - // The web client stores clicked or ctrlclicked entities in a dictionary clickedEntities with {id, entity} as KVP. - // The function flyTo from Cesium Viewer will be first employed to fly to the selected entity. - // NOTE: This flyTo function will fail if the target entity has been unloaded (e.g. user has moved camera away). - // In this case, the function zoomToObjectById shall be used instead. - // NOTE: This zoomToObjectById function requires a JSON file containing the IDs and coordinates of objects. - cesiumViewer.flyTo(clickedEntities[obj.value]).then(function (result) { - if (!result) { - zoomToObjectById(obj.value); - } - }).otherwise(function (error) { - zoomToObjectById(obj.value); +function flyToHighlightedObject() { + const highlightingListElement = document.getElementById("citydb_highlightinglist"); + const selectedValue = highlightingListElement.value; + let feature = highlightedIdObjects[selectedValue]; + cesiumViewer.camera.flyToBoundingSphere(feature._storedBoundingSphere, { + orientation: feature._storedOrientation }); +} - obj.selectedIndex = 0; +function flyToHiddenObject() { + const hidddenListElement = document.getElementById("citydb_hiddenlist"); + const selectedValue = hidddenListElement.value; + let feature = hiddenIdObjects[selectedValue]; + cesiumViewer.camera.flyToBoundingSphere(feature._storedBoundingSphere, { + orientation: feature._storedOrientation + }); } function saveLayerSettings() { @@ -796,8 +803,7 @@ function hideSelectedObjects() { var objectIds; for (var i = 0; i < layers.length; i++) { if (layers[i].active) { - objectIds = Object.keys(layers[i].highlightedObjects); - layers[i].hideObjects(objectIds); + layers[i].hideSelected(); } } } diff --git a/js/3dcitydb-web-map.js b/js/3dcitydb-web-map.js index fd052fc1..fb004361 100644 --- a/js/3dcitydb-web-map.js +++ b/js/3dcitydb-web-map.js @@ -280,34 +280,38 @@ }; /** - * get highlighted objects from all layers + * get highlighted objects from active layer * @returns {Array} */ WebMap3DCityDB.prototype.getAllHighlightedObjects = function () { - var results = []; - var count = 0; - var layers = this._layers; + let scope = this; + var results = {}; + var layers = scope._layers; for (var i = 0; i < layers.length; i++) { - var curLayer = this._layers[i]; - for (var obj in curLayer._highlightedObjects) { - results[count++] = obj; + var curLayer = scope._layers[i]; + if (!curLayer.active) continue; + let highlightedObjects = curLayer.getAllHighlightedObjects(); + for (var key in highlightedObjects) { + results[key] = highlightedObjects[key]; } } return results; }; /** - * get hidden objects from all layers + * get hidden objects from active layer * @returns {Array} */ WebMap3DCityDB.prototype.getAllHiddenObjects = function () { - var results = []; - var count = 0; - var layers = this._layers; + let scope = this; + var results = {}; + var layers = scope._layers; for (var i = 0; i < layers.length; i++) { - var curLayer = this._layers[i]; - for (var j = 0; j < curLayer._hiddenObjects.length; j++) { - results[count++] = curLayer._hiddenObjects[j]; + var curLayer = scope._layers[i]; + if (!curLayer.active) continue; + let hiddenObjects = curLayer.getAllHiddenObjects(); + for (var key in hiddenObjects) { + results[key] = hiddenObjects[key]; } } return results;