Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 3D Tiles feature picking in Viewer #9121

Merged
merged 5 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
##### Additions :tada:

- Add support for the CSS `line-height` specifier in the `font` property of a `Label`. [#8954](https://github.com/CesiumGS/cesium/pull/8954)
- `Viewer` now has default pick handling for `Cesium3DTileFeature` data and will display its properties in the default Viewer `InfoBox` as well as set `Viewer.selectedEntity` to a transient Entity instance representing the data.
mramato marked this conversation as resolved.
Show resolved Hide resolved

##### Fixes :wrench:

Expand Down
61 changes: 61 additions & 0 deletions Source/Widgets/Viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import SelectionIndicator from "../SelectionIndicator/SelectionIndicator.js";
import subscribeAndEvaluate from "../subscribeAndEvaluate.js";
import Timeline from "../Timeline/Timeline.js";
import VRButton from "../VRButton/VRButton.js";
import Cesium3DTileFeature from "../../Scene/Cesium3DTileFeature.js";

var boundingSphereScratch = new BoundingSphere();

Expand All @@ -53,13 +54,73 @@ function onTimelineScrubfunction(e) {
clock.shouldAnimate = false;
}

function getCesium3DTileFeatureDescription(feature) {
var propertyNames = feature.getPropertyNames();

var html = "";
propertyNames.forEach(function (propertyName) {
var value = feature.getProperty(propertyName);
if (defined(value)) {
html += "<tr><th>" + propertyName + "</th><td>" + value + "</td></tr>";
}
});

if (html.length > 0) {
html =
'<table class="cesium-infoBox-defaultTable"><tbody>' +
html +
"</tbody></table>";
}

return html;
}

function getCesium3DTileFeatureName(feature) {
var i;
var possibleNames = [];
var propertyNames = feature.getPropertyNames();
for (i = 0; i < propertyNames.length; i++) {
var propertyName = propertyNames[i];
if (/^name$/i.test(propertyName)) {
possibleNames[0] = feature.getProperty(propertyName);
} else if (/name/i.test(propertyName)) {
possibleNames[1] = feature.getProperty(propertyName);
} else if (/^title$/i.test(propertyName)) {
possibleNames[2] = feature.getProperty(propertyName);
} else if (/^(id|identifier)$/i.test(propertyName)) {
possibleNames[3] = feature.getProperty(propertyName);
} else if (/element/i.test(propertyName)) {
possibleNames[4] = feature.getProperty(propertyName);
} else if (/(id|identifier)$/i.test(propertyName)) {
possibleNames[5] = feature.getProperty(propertyName);
mramato marked this conversation as resolved.
Show resolved Hide resolved
}
}

var length = possibleNames.length;
for (i = 0; i < length; i++) {
var item = possibleNames[i];
if (defined(item) && item !== "") {
return item;
}
}
return "Unnamed Feature";
}

function pickEntity(viewer, e) {
var picked = viewer.scene.pick(e.position);
if (defined(picked)) {
var id = defaultValue(picked.id, picked.primitive.id);
if (id instanceof Entity) {
return id;
}

if (picked instanceof Cesium3DTileFeature) {
return new Entity({
name: getCesium3DTileFeatureName(picked),
description: getCesium3DTileFeatureDescription(picked),
feature: picked,
mramato marked this conversation as resolved.
Show resolved Hide resolved
});
}
}

// No regular entity picked. Try picking features from imagery layers.
Expand Down