function getMapClickPosition() {
if (!window.SuperMap3D) SuperMap3D = Cesium
var HoldMap = viewer
var handler = new SuperMap3D.ScreenSpaceEventHandler(HoldMap.scene.canvas);
handler.setInputAction(function (e) {
//首先移除之前添加的点
HoldMap.entities.removeAll();
//获取点击位置笛卡尔坐标
HoldMap.scene.pickPositionAsync(e.position).then((position) => {
//将笛卡尔坐标转化为经纬度坐标
var cartographic = SuperMap3D.Cartographic.fromCartesian(position);
var longitude = SuperMap3D.Math.toDegrees(cartographic.longitude);
var latitude = SuperMap3D.Math.toDegrees(cartographic.latitude);
var height = cartographic.height;
var pos = {
longitude,
latitude,
height,
}
console.log(pos);
if (height < 0) {
height = 0;
}
//在点击位置添加对应点
HoldMap.entities.add(new SuperMap3D.Entity({
point: new SuperMap3D.PointGraphics({
color: new SuperMap3D.Color(1, 1, 0),
pixelSize: 10,
outlineColor: new SuperMap3D.Color(0, 1, 1)
}),
position: SuperMap3D.Cartesian3.fromDegrees(longitude, latitude, height + 0.5)
}));
})
}, SuperMap3D.ScreenSpaceEventType.LEFT_CLICK);
}
GIS Cesium 点击获取位置(经纬度高度)
最新推荐文章于 2024-07-04 00:59:27 发布