问题描述
我想在GeoJSON中绘制一个多边形(由Cesium定义,在下面的示例中为蓝色)。
我正在考虑在按下“开始绘制”按钮后将连续的鼠标单击捕获到阵列中。每次单击都必须给出wgs84坐标的三元组(lon,lat,lat),该坐标必须限制在多边形上。
但是我有两个主要问题:
- 我不知道如何在Cesium中捕获鼠标事件。
- 如果知道的话,我该如何将点击点约束为在多边形定义的数学平面上 上(实际上,每个2D显示器上的像素可以对应于2D显示器经过的3D直线的任何点)?这可能涉及交点的计算。
如果可以简化事情,我可以从多边形中构建一个glTF资产来替换它。
相机是固定的。
这是我的出发点:
var viewer = new Cesium.Viewer("cesiumContainer");
// The geojson deFinition of the polygon to draw onto:
const poly = {
"type": "FeatureCollection","name": "Mypolygon","crs": {
"type": "name","properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},"features": [
{
"type": "Feature","properties": {},"geometry": {
"type": "polygon","coordinates": [
[[ 10.746500009923748,48.314700009648320,500 ],[ 10.747500009924019,48.315700009648104,[ 10.747038310965864,48.315905422444722,550 ],[ 10.746038315853207,48.314905418639555,[ 10.746500009923748,500 ]]
]
}
}
]
};
const polygon = viewer.dataSources.add(Cesium.GeoJsonDataSource.load(poly,{
stroke: Cesium.Color.BLUE,fill: new Cesium.Color(0.2,0.2,1,0.2),strokeWidth: 3
}));
const camera = viewer.scene.camera;
camera.setView({
destination: Cesium.Cartesian3.fromdegrees(10.748176,48.314773,590),orientation: {
heading : Cesium.Math.toradians(302),pitch : Cesium.Math.toradians(-32),roll : Cesium.Math.toradians(0)
}
});
https://sandcastle.cesium.com/
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)