[英]Cesium - using camera to scale a polygon to match Lat-Lon positions while zoom-in/zoom-out
[英]Cesium - drawing polygon using camera Lat-Lon-Alt positions
这个问题与这两个有关:
我要从摄像机获取lat-lon-alt位置的示例代码位于黄金标准中,该标准似乎已经烘焙到现有的摄像机控制器中 。 使用此代码,我可以从相机的距离检索纬度-纬度位置,以获取几乎与所选原始纬度位置和地球表面上方高度完全相同的值。 完善!
所有示例和文档都显示了使用度数或度数点创建的多边形。
怎么办? 也许我缺少了一些东西,但我的意图是能够使用特定的x,y,z坐标创建多边形,以便在放大,缩小和缩小时多边形将“粘贴”到我房屋的顶部相机运动。 现在我有了这些值,用这些值绘制多边形的秘密是什么?
仅供参考,这些是我目前拥有的价值:
=========================新信息======================== ====
redPolygon的代码有效:
var redPolygon = viewer.entities.add({
name : 'Red polygon on surface',
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0,
-115.0, 32.0,
-102.0, 31.0,
-102.0, 35.0,
-102.0, 35.0]),
material : Cesium.Color.RED
}
});
viewer.flyTo(redPolygon);
bluePolygon的代码不起作用:
var bluePolygon = viewer.entities.add({
name : 'Blue polygon on surface',
polygon : {
//hierarchy: collection.latlonalt,
hierarchy: Cesium.Cartesian3.fromArray(collection.latlonalt),
material : Cesium.Color.BLUE
}
});
viewer.flyTo(bluePolygon);
如果我使用hierarchy: collection.latlonalt,
则会收到以下错误:
因此,我将代码更改为hierarchy: Cesium.Cartesian3.fromArray(collection.latlonalt),
其中collection.latlonalt是我的Cartesian3数组:
但是什么也没画。 没有错误。 这是我在控制台中看到的:
只是为了测试,我尝试将z位置添加到redPolygon并将.fromDegreesArray更改为.fromArray,如下所示:
var redPolygon = viewer.entities.add({
name : 'Red polygon on surface',
polygon : {
hierarchy : Cesium.Cartesian3.fromArray([-115.0, 37.0, 10.0,
-115.0, 32.0, 10.0,
-102.0, 31.0, 10.0,
-102.0, 35.0, 10.0,
-102.0, 35.0, 10.0]),
material : Cesium.Color.RED
}
});
viewer.flyTo(redPolygon);
那也不起作用。
Cesium具有Polygon Demo使用的诸如Cartesian3.fromDegreesArray
类的辅助函数,但是,由于您已经掌握了实际的Cartesian3值,因此不需要这些辅助函数。
例如,多边形演示代码如下所示:
var redPolygon = viewer.entities.add({
name : 'Red polygon on surface',
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0,
-115.0, 32.0,
-107.0, 33.0,
-102.0, 31.0,
-102.0, 35.0]),
material : Cesium.Color.RED
}
});
在上面的代码中,在这种情况下, fromDegreesArray
仅获取5个lot / lan值对的列表,并将它们转换为具有Cartesian3
类的5个实例的JavaScript数组。 然后,将这个5个笛卡尔3的数组作为hierarchy
的值存储在面定义中。 如果在运行时检查该定义,则会发现原始的lon / lat值已被舍弃,这要归功于helper函数,由实际的Cartesian3代替。
因此,在您的代码中,您需要一个到目前为止用户已单击的Cartesian3数组。 这从一个空数组开始,并且您至少需要收集三次单击,然后将每次单击转换为Cartesian3(如您在上述问题中显示的那样),然后将该值push
入数组。 一旦数组累积了3次或更多点击,您就可以将该数组作为多边形定义的hierarchy
字段传递。
通过这种方式,您避免了调用fromDegreesArray
因为您的点击处理程序正在做更详细的工作,以收集每次点击的确切笛卡尔位置。 如果相机在两次单击之间移动,则每次单击时都必须进行这种收集。 因此,数组“进行中”必须在两次单击之间保留下来,直到收集到所有点击并可以创建多边形为止。
编辑 :这是我要描述的代码结构的示例。 我这里没有显示实际的单击处理程序,因为您似乎已经从鼠标单击中得到了Cartesian3值。 相反,我展示了三个用于创建多边形的值。
var viewer = new Cesium.Viewer('cesiumContainer');
// Create an empty array of click positions at the start.
var clickPositions = [];
// When the first mouse click is received, convert to Cartesian3, and push it into the array.
var click1 = new Cesium.Cartesian3(-2155350.2, -4622163.4, 3817393.1);
clickPositions.push(click1);
// Later, more mouse clicks are received and pushed into the array.
var click2 = new Cesium.Cartesian3(-2288079.8, -4906803.1, 3360431.4);
clickPositions.push(click2);
var click3 = new Cesium.Cartesian3(-1087466.8, -5116129.4, 3637866.9);
clickPositions.push(click3);
// Finally, draw the polygon.
var redPolygon = viewer.entities.add({
name : 'Red polygon on surface',
polygon : {
hierarchy : clickPositions,
material : Cesium.Color.RED
}
});
请注意,将clickPositions
分配给hierarchy
时没有任何clickPositions
。 这里的Cartesian3值数组已经是Cesium所需的形式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.