铯路径到地形:连接2点的线在地形下方 [英] Cesium path onto terrain: line connecting 2 points goes under the terrain
问题描述
我有一条随着时间的流逝的道路. 我使用Cesium.sampleTerrain获取位置高程并将其悬垂在地形上. 问题是,即使所有点都在地形上,连接2个点的线有时也会在地形下. 如何在地形上同时悬垂连接线?
I have a path moving over time. I use Cesium.sampleTerrain to get positions elevation and drape them on the terrain. The problem is that, even if all points are on the terrain, the line connecting 2 points sometimes goes under the terrain. How can I do to drape also connecting lines on the terrain?
这是我的代码:
var promise = Cesium.sampleTerrain(terrainProvider, 14, positions);
Cesium.when(promise, function(updatedPositions) {
var cartesianPositions = Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray(updatedPositions);
var sample = new Cesium.SampledPositionProperty();
sample.setInterpolationOptions({
interpolationDegree : 3,
interpolationAlgorithm : Cesium.HermitePolynomialApproximation
});
$(cartesianPositions).each(function(index, cartPosition) {
var time = Cesium.JulianDate.addSeconds(start, index*10, new Cesium.JulianDate());
sample.addSample(time, cartPosition);
})
var target = viewer.entities.add({
position: sample,
path: {
resolution: 60,
material:Cesium.Color.BLUE,
width: 4,
trailTime: 422*10,
leadTime: 0
}
});
});
推荐答案
就像马修说的那样; Cesium当前不支持在地形上悬垂的折线"类型 entity .
So like Matthew says; Cesium doesn't currently support a 'polyline' type entity with draping over terrain.
如果您发现Entity API不能满足您的需求,则可能值得深入研究较低级别的Primitives API,以获得更好的控制权-更具体地说,是
If you find that the Entity API isn't giving you what you need, it might be worth digging into the lower-level Primitives API to gain finer control - more specifically the GroundPrimitive geometry.
在其他人中; GroundPrimitives当前支持 CorridorGeometry .
Among others; GroundPrimitives currently support the CorridorGeometry.
我没有在Cesium中进行时态数据绘图的经验,但是我建议您考虑使用这种方法,而不是异步承诺方法,该方法(IMO)似乎更多是由于缺乏GroundPrimitive类型的解决方案而引起的.时间.
I have no experience with temporal data plotting within Cesium, but I would suggest you consider this approach rather than the async promise approach, which (IMO) seems like more of a hack born from the absence of a GroundPrimitive-type solution at the time.
下面是一个实际的GroundPrimitive示例(请注意,我们不需要任何z值):
Here's a crude example of a GroundPrimitive in action (note we don't need any z values):
var viewer = new Cesium.Viewer('cesiumContainer');
var corridorInstance = new Cesium.GeometryInstance({
geometry : new Cesium.CorridorGeometry({
vertexFormat : Cesium.VertexFormat.POSITION_ONLY,
positions : Cesium.Cartesian3.fromDegreesArray([
-122.26, 46.15,
-122.12, 46.26,
]),
width : 100
}),
id : 'myCorridor',
attributes : {
color : new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)
}
});
var corridorPrimitive = new Cesium.GroundPrimitive({
geometryInstance : corridorInstance
});
viewer.scene.primitives.add(corridorPrimitive);
viewer.camera.setView({
destination: Cesium.Cartesian3.fromDegrees(-122.19, 46.20, 10000.0)
});
哪个会给你这个:
这篇关于铯路径到地形:连接2点的线在地形下方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!