javascript - 我想在铯屏底部获取鼠标的经纬度高度

标签 javascript location cesiumjs

现在使用下面的 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;
    }
});

谢谢你的帮助

最佳答案

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

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

Working SandCastle link

HTML

<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>

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;
    }
});

关于javascript - 我想在铯屏底部获取鼠标的经纬度高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52342073/

相关文章:

javascript - 如何使用 jQuery 在单击相应按钮时淡入多个隐藏的 div?

安卓GPS路由系统

javascript - 使用 Cesium Js 通过搜索框查找对象

javascript - Cesium 如何在放大/缩小时缩放多边形以匹配 Lat-Lon 位置

ios - 位置搜索结果叠加

cesiumjs - 铯表面上方的折线弧

javascript - 获取配置 JSON 的主干和最佳实践

php 爆炸在 javascript 模板中不起作用

javascript - 网站倒计时js

java - 位置跟踪服务会减慢应用程序速度