Created
December 8, 2014 14:34
-
-
Save emackey/ae9484c1569f1197c823 to your computer and use it in GitHub Desktop.
Dynamic position HUD for Cesium Sandcastle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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="Dynamic HUD showing Longitude, Latitude, and Altitude of a selected CZML entity."> | |
<meta name="cesium-sandcastle-labels" content="Showcases, DataSources"> | |
<title>Cesium Demo</title> | |
<script type="text/javascript" src="../Sandcastle-header.js"></script> | |
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.9/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); | |
</style> | |
<div id="cesiumContainer" class="fullSize"></div> | |
<div id="loadingOverlay"><h1>Loading...</h1></div> | |
<div id="toolbar"></div> | |
<script id="cesium_sandcastle_script"> | |
function startup(Cesium) { | |
"use strict"; | |
//Sandcastle_Begin | |
// | |
// USER INSTRUCTIONS: Left-click on any object in the CZML display | |
// to activate a HUD showing Lon, Lat, and Alt. | |
// | |
// Launch Cesium Viewer | |
var viewer = new Cesium.Viewer('cesiumContainer'); | |
viewer.extend(Cesium.viewerEntityMixin); | |
// Load CZML | |
var czmlDataSource = new Cesium.CzmlDataSource(); | |
viewer.dataSources.add(czmlDataSource); | |
czmlDataSource.loadUrl('../../SampleData/simple.czml'); | |
// Create HUD | |
var hud = document.getElementById('toolbar'); | |
hud.setAttribute('style', 'background: rgba(42,42,42,0.9); border-radius: 5px;'); | |
var cartographic = new Cesium.Cartographic(); | |
viewer.clock.onTick.addEventListener(function(clock) { | |
var entity = viewer.selectedEntity; | |
if (!Cesium.defined(entity)) { | |
hud.style.display = 'none'; | |
} else { | |
hud.style.display = 'block'; | |
var position = entity.position.getValue(clock.currentTime); | |
Cesium.Ellipsoid.WGS84.cartesianToCartographic(position, cartographic); | |
hud.innerHTML = | |
'Lon: ' + Cesium.Math.toDegrees(cartographic.longitude).toFixed(3) + ' deg<br/>' + | |
'Lat: ' + Cesium.Math.toDegrees(cartographic.latitude).toFixed(3) + ' deg<br/>' + | |
'Alt: ' + (cartographic.height * 0.001).toFixed(1) + ' km'; | |
} | |
}); | |
//Sandcastle_End | |
Sandcastle.finishedLoading(); | |
} | |
if (typeof Cesium !== "undefined") { | |
startup(Cesium); | |
} else if (typeof require === "function") { | |
require(["Cesium"], startup); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment