Created
July 14, 2015 01:45
-
-
Save mramato/a5e403379c4989313545 to your computer and use it in GitHub Desktop.
A simple Cesium example of drawing a label at the horizon point.
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
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