【发布时间】:2016-06-26 01:12:12
【问题描述】:
我正在寻找一个 Cesium Guru 来帮助我找到我需要的东西。我是 Cesium 的新手,但我一直在使用教程和一些我继承的现有代码。
在我的 Cesium 应用程序中,我输入我的地址,然后视图会放大到我的街道。耶!然后我拉近一点,这样我就可以在我的房子周围画一个多边形。现有的代码很好地做到了这一点。但是当我缩小然后再次放大时,我的多边形不会与我家的经纬度位置保持一致。
Cesium 是否包含将像素缩放到经纬度坐标的实用程序 还是我需要使用类似的工具 distanceToBoundingSphere(boundingSphere) 并自己计算?一世 只想要 x,y 坐标;我根本不在乎身高。
我一直在查看演示和教程,但到目前为止还没有找到我想找的东西。也许我找到了一些接近的东西,但我知道的还不够多,不知道我是否找到了它。救命!
=============================代码=============== ====================
收集多边形的位置:
单次单击仅捕获该点的坐标并在用户将鼠标拖动到新点时绘制一条折线。因此,一堆折线和每个点的坐标集合。
positionHandler.setInputAction(function (click) {
cartesian = scene.camera.pickEllipsoid(click.position, ellipsoid);
if (cartesian) {
var setCartographic = ellipsoid.cartesianToCartographic(cartesian);
asset.latlonalt.push(
Cesium.Math.toDegrees(setCartographic.latitude).toFixed(15),
Cesium.Math.toDegrees(setCartographic.longitude).toFixed(15),
Cesium.Math.toDegrees(setCartographic.height).toFixed(15)
);
lla.push(Cesium.Math.toDegrees(setCartographic.longitude), Cesium.Math.toDegrees(setCartographic.latitude));
if (lla.length >= 4) {
self.loggingMessage((lla.length / 2) + ' Points Added');
}
Cesium.sampleTerrain(terrainProvider, 11, [cartographic])
.then(function (updatedPositions) {
asset.latlonalt[2] = updatedPositions[0].height;
stage = 1;
});
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
然后,doubleClick 会获取在 singleClick 函数中捕获的坐标并调用 self.createAsset('add',asset) 来创建多边形。
positionHandler.setInputAction(function (doubleClick){
if (asset.shape == 'Polygon') {
var len = asset.latlonalt.length;
if(len > 9) {
asset.rad = (len / 3);
console.log("Creating Asset");
self.loggingMessage("Creating Asset");
socket.emit('newElement', asset.cType, asset);
self.createAsset('add', asset);
viewer.entities.remove(entity);
viewer.entities.remove(newCircle);
viewer.entities.remove(newPolygon);
viewer.entities.remove(newOutline);
positionHandler = positionHandler && positionHandler.destroy();
}else{
console.log('3+ Positions Required');
loggingMessage('3+ Positions Required.');
}
}
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)
创建多边形:
var newPolygon = viewer.entities.add({
name : asset.id,
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray(vertices),
material : rgba[0],
outline : true,
outlineColor : rgba[1]
}
});
var newLabel = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(asset.latlonalt[1], asset.latlonalt[0], 1000),
name: asset.id,
label: {
text: asset.name,
font : '16px Helvetica'
}
});
var newPoint = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(asset.latlonalt[1], asset.latlonalt[0], 0),
name: asset.id,
point : {
pixelSize : 5,
color : Cesium.Color.RED,
outlineColor : Cesium.Color.RED,
outlineWidth : 2
}
});
self.currentGeometry[asset.id] = {shape: newPolygon, label: newLabel, point: newPoint};
看起来我们正在使用地形(我认为)。
我应该对哪些数字感兴趣:
收集坐标时,只有第一个z不为零:
我采用该值并填充其他 z 值:
现在我已经添加了 z 值,在 createAsset 方法中出现了一些错误。我需要跟踪该问题以查看结果。现在,它看起来像这样:
真的很大,轮廓没有被删除。
【问题讨论】:
-
欢迎来到铯,露西小姐。您的应用是否偶然使用了 Terrain?如果是这样,您可能会在适当的高度看到您的房子,但在零高度(WGS84 参考高度)处绘制了一个多边形。这种“地下多边形”通常会随着相机的移动而漂移。
-
没错!我可以移动相机并放大或缩小,直到多边形与我的房子相匹配,当我移动地球时,多边形会远离我的房子。如果你所说的地形是指树木、汽车、草和其他东西,那么是的,它一定是使用地形。好的。我将对此进行更多研究。也许你可以给我一个答案,我会给你分数。 :-)
-
等一下...代码只考虑了 x,y 坐标。你是说只需添加 z 坐标,我的多边形就会留在我的房子里吗?
-
“使用地形”我的意思是,如果您靠近一些山脉,并将相机向地平线倾斜,您会看到山脉垂直向上,而不是山脉平放在 WGS84 椭球上的照片。如果是前者(3D 山脉),那么是的,地形正在使用中,即使在平坦区域,您也必须将多边形定位在非零高度。我看到你添加了对
sampleTerrain的调用,这解决了问题吗? -
我相信我们正在使用地形。我能做的最好的就是屏幕帽。不,我没有添加 sampleTerrrain(它已经存在)。但我开始看到可能是什么问题。当它只收集坐标时,我不知道他为什么在该方法(第一个代码块)中使用 sampleTerrain。即使在 sampleTerrain 方法中 updatedPositions[0].height 是正确的,z 值似乎也不会被填充。也许我们应该在实际创建多边形的代码中使用 sampleTerrain(第三个代码块)。我在顶点数组上填充 z 值。
标签: javascript node.js cesium