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

adding nyc picking demo #5525

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
184 changes: 184 additions & 0 deletions Apps/Sandcastle/gallery/3D Tiles Feature Picking.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> <!-- Use Chrome Frame in IE -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Interact with sample 3D Tiles tilesets.">
<meta name="cesium-sandcastle-labels" content="3D Tiles">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);
#toolbar {
background: rgba(42, 42, 42, 0.8);
padding: 4px;
border-radius: 4px;
}
#toolbar .header {
font-weight: bold;
padding-top: 5px;
padding-bottom: 5px;
}
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
// A simple demo of 3D Tiles feature picking with
// hover and select behavior.
var viewer = new Cesium.Viewer('cesiumContainer');

// Set the initial camera view to look at Manhattan
var initialPosition = Cesium.Cartesian3.fromDegrees(-74.01881302800248, 40.69114333714821, 753);
var initialOrientation = new Cesium.HeadingPitchRoll.fromDegrees(21.27879878293835, -21.34390550872461, 0.0716951918898415);
viewer.scene.camera.setView({
destination: initialPosition,
orientation: {
heading: initialOrientation.heading,
pitch: initialOrientation.pitch,
roll: initialOrientation.roll
},
endTransform: Cesium.Matrix4.IDENTITY
});

// Load the NYC buildings tileset
var city = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url: 'https://cesiumjs.org/NewYork/3DTilesGml',
maximumScreenSpaceError: 16 // default value
}));

//HTML overlay for showing building name on mouseover.
var nameOverlay = document.createElement('div');
viewer.container.appendChild(nameOverlay);
nameOverlay.className = 'backdrop';
nameOverlay.style.display = 'none';
nameOverlay.style.position = 'absolute';
nameOverlay.style.bottom = '0';
nameOverlay.style.left = '0';
nameOverlay.style['pointer-events'] = 'none';
nameOverlay.style.padding = '4px';
nameOverlay.style.backgroundColor = 'black';

// Information about the currently selected building.
var selected = {
building: undefined, // a Cesium3DTileFeature
originalColor: new Cesium.Color()
};

// Information about the currently highlighted building.
var highlighted = {
building: undefined, // a Cesium3DTileFeature
originalColor: new Cesium.Color()
};

// An entity object which will hold info about the currently selected feature
// for infobox display
var selectedEntity = new Cesium.Entity();

// Color a building yellow on hover.
viewer.screenSpaceEventHandler.setInputAction(function onMouseMove(movement) {

// If a building was previously highlighted, undo the highlight.
if (Cesium.defined(highlighted.building)) {
// Restore original color to building that is no longer highlighted
// This assignment is necessary to work with the set property
highlighted.building.color = Cesium.Color.clone(highlighted.originalColor, highlighted.building.color);
highlighted.building = undefined;
}

// Pick a new building, a Cesium3DTileFeature
var pickedBuilding = viewer.scene.pick(movement.endPosition);
if (!Cesium.defined(pickedBuilding)) {
nameOverlay.style.display = 'none';
return;
}

// A building was picked, so show it's overlay content
nameOverlay.style.display = 'block';
nameOverlay.style.bottom = viewer.canvas.clientHeight - movement.endPosition.y + 'px';
nameOverlay.style.left = movement.endPosition.x + 'px';
var name = pickedBuilding.getProperty('name');
if (!Cesium.defined(name)) {
name = pickedBuilding.getProperty('id');
}
nameOverlay.textContent = name;

// Highlight the building if it's not already selected.
if (pickedBuilding !== selected.building) {
highlighted.building = pickedBuilding;
Cesium.Color.clone(pickedBuilding.color, highlighted.originalColor);
pickedBuilding.color = Cesium.Color.clone(Cesium.Color.YELLOW, pickedBuilding.color);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

// Color a building on selection and show metadata in the InfoBox.
var clickHandler = viewer.screenSpaceEventHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {
if (Cesium.defined(selected.building)) {
// Restore original color to building that is no longer selected
// This assignment is necessary to work with the set property
selected.building.color = Cesium.Color.clone(selected.originalColor, selected.building.color);
selected.building = undefined;
}

// Pick a Cesium3DTileFeature
var pickedBuilding = viewer.scene.pick(movement.position);
if (!Cesium.defined(pickedBuilding)) {
clickHandler(movement);
return;
}

// Select the building if it's not already selected
if (selected.building === pickedBuilding) {
return;
}
selected.building = pickedBuilding;

// Save the selected building's original color
if (pickedBuilding === highlighted.building) {
// If building is highlighted grab its actual original color
Cesium.Color.clone(highlighted.originalColor, selected.originalColor);
highlighted.building = undefined;
}
else {
Cesium.Color.clone(pickedBuilding.color, selected.originalColor);
}

// Highlight newly selected building
pickedBuilding.color = Cesium.Color.clone(Cesium.Color.LIME, pickedBuilding.color);

// Set building infobox description
var featureName = pickedBuilding.getProperty('name');
selectedEntity.name = featureName;
selectedEntity.description = 'Loading <div class="cesium-infoBox-loading"></div>';
viewer.selectedEntity = selectedEntity;
selectedEntity.description = '<table class="cesium-infoBox-defaultTable"><tbody>' +
'<tr><th>BIN</th><td>' + pickedBuilding.getProperty('BIN') + '</td></tr>' +
'<tr><th>DOITT ID</th><td>' + pickedBuilding.getProperty('DOITT_ID') + '</td></tr>' +
'<tr><th>SOURCE ID</th><td>' + pickedBuilding.getProperty('SOURCE_ID') + '</td></tr>' +
'</tbody></table>';
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.