Skip to content

Commit

Permalink
Update fly functions for highlighted and hidden objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Son-HNguyen committed Apr 17, 2024
1 parent 930df72 commit aaf34d2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 41 deletions.
4 changes: 2 additions & 2 deletions 3dwebclient/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,12 @@
</div>

<div class="citydb_long_container" onmouseover="listHighlightedObjects()">
<select id = "citydb_highlightinglist" style="width: 100%;" class="cesium-button" onchange="flyToClickedObject(this)">
<select id = "citydb_highlightinglist" style="width: 100%;" class="cesium-button" onchange="flyToHighlightedObject()">
<option selected="selected" disabled="disabled">Choose highlighted Object</option>
</select>
</div>
<div class="citydb_long_container" onmouseover="listHiddenObjects()">
<select id = "citydb_hiddenlist" style="width: 100%;" class="cesium-button" onchange="flyToClickedObject(this)">
<select id = "citydb_hiddenlist" style="width: 100%;" class="cesium-button" onchange="flyToHiddenObject()">
<option selected="selected" disabled="disabled">Choose hidden Object</option>
</select>
</div>
Expand Down
56 changes: 31 additions & 25 deletions 3dwebclient/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}

Expand All @@ -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() {
Expand Down Expand Up @@ -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();
}
}
}
Expand Down
32 changes: 18 additions & 14 deletions js/3dcitydb-web-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit aaf34d2

Please sign in to comment.