var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;
var handler;
var label;
var ellipsoid = scene.globe.ellipsoid;
var labels = scene.primitives.add(new Cesium.LabelCollection());
label = labels.add();
// Mouse over the globe to see the cartographic position
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
var cartesian = scene.camera.pickEllipsoid(movement.endPosition, ellipsoid);
if (cartesian) {
var cartographic = ellipsoid.cartesianToCartographic(cartesian);
label.show = true;
label.text = '(' + Cesium.Math.toDegrees(cartographic.longitude).toFixed(2) + ', ' + Cesium.Math.toDegrees(cartographic.latitude).toFixed(2) + ')';
label.position = cartesian;
} else {
label.text = '';
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
转载于:https://my.oschina.net/victorzhan/blog/349075