我想在铯屏幕底部获得鼠标的纬度经度高度

Ash*_*hra 6 javascript location cesium

现在使用下面的 javascript,我得到了鼠标指针上的经纬度值。我怎样才能让它像在谷歌地球中一样出现在铯屏幕的底部。

viewer.entities.add({
    id: 'mou',
    label: {
        // position : Cesium.Cartesian2.ZERO, 
        show: true;
    }
});
viewer.scene.canvas.addEventListener('mousemove', function(e) {
    var entity = viewer.entities.getById('mou');
    var ellipsoid = viewer.scene.globe.ellipsoid;
    // Mouse over the globe to see the cartographic position 
    var cartesian = viewer.camera.pickEllipsoid(new Cesium.Cartesian3(e.clientX, e.clientY), ellipsoid);
    if (cartesian) {
        var cartographic = ellipsoid.cartesianToCartographic(cartesian);
        var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(10);
        var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(10);
        entity.position = cartesian;
        entity.label.show = true;
        entity.label.font_style = 84;
        //entity.position= Cesium.Cartesian2.ZERO; 
        entity.label.text = '(' + longitudeString + ', ' + latitudeString + ')';
        var result = latitudeString(45);
        document.getElementById("demo").innerHTML = result;
    } else {
        entity.label.show = false;
    }
});
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

vis*_*man 6

我假设你可能在 Sandcastle 中运行这个?在这种情况下,站点样式使得添加额外的 div 变得有点困难。但如果你将它们绝对定位并给出一个高的 z-index,你可以使 div 出现在 CesiumViewer 容器的顶部。

此外,实体“mou”标签对象中的分号错位还存在一些问题。并且您尝试使用 latitudeString 作为函数调用。

工作沙堡链接

超文本标记语言

<style>
    @import url(../templates/bucket.css);
</style>
<div id="demo" style="z-index: 2000; position: absolute; height:100px; width:200px; right: 10px; bottom: 0px; text-color: white"></div>

<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
Run Code Online (Sandbox Code Playgroud)

JavaScript

viewer.entities.add({
    id: 'mou',
    label: {
        // position : Cesium.Cartesian2.ZERO, 
        show: true   // Removed semicolon here
    }
});
viewer.scene.canvas.addEventListener('mousemove', function(e) {
    var entity = viewer.entities.getById('mou');
    var ellipsoid = viewer.scene.globe.ellipsoid;
    // Mouse over the globe to see the cartographic position 
    var cartesian = viewer.camera.pickEllipsoid(new Cesium.Cartesian3(e.clientX, e.clientY), ellipsoid);
    if (cartesian) {
        var cartographic = ellipsoid.cartesianToCartographic(cartesian);
        var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(10);
        var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(10);
        entity.position = cartesian;
        entity.label.show = true;
        entity.label.font_style = 84;
        //entity.position= Cesium.Cartesian2.ZERO; 
        entity.label.text = '(' + longitudeString + ', ' + latitudeString + ')';
        var result = entity.label.text;  // We can reuse this
        document.getElementById("demo").innerHTML = result;
    } else {
        entity.label.show = false;
    }
});
Run Code Online (Sandbox Code Playgroud)