shanX
文章31
标签17
分类9
Cesium billboard贴地形表

Cesium billboard贴地形表

==============

获取点击位置高程的方法,cartographic 中包含:

  • longitude 经度
  • latitude 维度
  • height 高程
let ray = viewer.camera.getPickRay(movement.position);
let earthPosition = viewer.scene.globe.pick(ray, viewer.scene);
let cartographic = Cesium.Cartographic.fromCartesian(earthPosition);

billboard 贴地形表

billboard: {
              image: locationMark,
              heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
              horizontalOrigin: Cesium.HorizontalOrigin.CENTER, // //相对于对象的原点(注意是原点的位置)的水平位置
              verticalOrigin: Cesium.VerticalOrigin.BOTTOM //相对于对象的原点的垂直位置,BOTTOM时锚点在下,对象在上
}

结合使用,点击添加图标

if (flag) {
    viewer.screenSpaceEventHandler.setInputAction(function (movement) {
        let ray = viewer.camera.getPickRay(movement.position);
        let earthPosition = viewer.scene.globe.pick(ray, viewer.scene);
        let cartographic = Cesium.Cartographic.fromCartesian(earthPosition);
        let billboard = new Cesium.Entity({
            name: 'Draw-Handler-point',
            position: Cesium.Cartesian3.fromDegrees(
                Cesium.Math.toDegrees(cartographic.longitude),
                Cesium.Math.toDegrees(cartographic.latitude),
                cartographic.height
            ),
            billboard: {
                image: location4, // default: undefined
                width: 30, // default: undefined
                height: 40, // default: undefined
            },
        });
        viewer.entities.add(billboard);
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
} else {
    viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK); //移除事件
}
本文作者:shanX
本文链接:https://rhymexmove.github.io/2021/08/31/7ba201dda6cb/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可