Skip to content

Instantly share code, notes, and snippets.

@mramato
Created July 14, 2015 01:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mramato/a5e403379c4989313545 to your computer and use it in GitHub Desktop.
Save mramato/a5e403379c4989313545 to your computer and use it in GitHub Desktop.
A simple Cesium example of drawing a label at the horizon point.
var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;
var ellipsoid = scene.globe.ellipsoid;
var entity = viewer.entities.add({
label : {
show : true,
outlineColor: Cesium.Color.BLACK,
verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
style : Cesium.LabelStyle.FILL_AND_OUTLINE
}
});
function updateHorizonPoint(){
var canvas = viewer.canvas;
var height = canvas.height;
var width = Math.floor(canvas.width/2);
for(var i = 0; i < height; i++) {
var cartesian = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(width, i), ellipsoid);
if (cartesian) {
if(i === 0){
//Sky not visible
entity.label.show = false;
return;
}
var cartographic = ellipsoid.cartesianToCartographic(cartesian);
var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2);
var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2);
entity.position = cartesian;
entity.label.show = true;
entity.label.text = '(' + longitudeString + ', ' + latitudeString + ')';
return;
}
}
entity.label.show = false;
}
scene.preRender.addEventListener(updateHorizonPoint);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment