2015-04-28 37 views
14

所以,我使用銫,我想添加一個多邊形或線來表示屬性邊界在地形表面上。銫如何'懸垂'多邊形或線條到地形表面

我的多邊形在平面/橢球體表面上工作正常,但不幸的是,當顯示地形圖層時,多邊形不會自動懸垂在表面上。

夠公平的,我實際上沒有z /高度值 - 所以我使用了sampleTerrain.js承諾方法來插入基於地形的高度值。這部分工作正常,我得到我的身高值。但那又如何?

我試着創建一個多邊形實體與我的身高負載的立場,但無濟於事 - 它只是忽略了身高值。 When I read the docs,我真的可以看到任何參考高度值被攝入 - 所有的「職位」數組是二維的?

正在考慮的高度值的唯一參考是PolygonOutlineGeometry,它具有看起來很有希望的屬性perPositionHeight

這基本上是我想要的東西 - 我並不想集全聚的高度,我想使用的每個點的高度值..

這裏是我的不成功的嘗試之一:

實體/多邊形:

var entity = viewer.entities.add({ 
    polygon : { 
     hierarchy : cartesianPositions, //array of positions with z values 
     outline : true, 
     outlineColor : Cesium.Color.RED, 
     outlineWidth : 9, 
     material : Cesium.Color.BLUE.withAlpha(0.0), 
    } 
}); 


底線:我只想要一個多邊形或折線實體它很好地坐在地形的表面上。

編輯:

使用公認的答案與sampleTerrain.js結合的評論Orange Polygon example,我已經能夠模擬「立體裁剪」多邊形地形上,有沒有這個位置的列表z值,這裏有個粗略的例子:

var positions = []; // xy position array  

var cesiumTerrainProvider = new Cesium.CesiumTerrainProvider({ 
    url : '//assets.agi.com/stk-terrain/world' 
}); 
viewer.terrainProvider = cesiumTerrainProvider; 

// go off and sample the terrain layer to get interpolated z values for each position.. 
var promise = Cesium.sampleTerrain(cesiumTerrainProvider, 11, positions); 
Cesium.when(promise, function(updatedPositions) { 

    var cartesianPositions = Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray(updatedPositions); 

     var entity = viewer.entities.add({ 
      polygon : { 
        hierarchy : cartesianPositions, 
        outline : true, 
        outlineColor : Cesium.Color.RED, 
        outlineWidth : 9, 
        perPositionHeight: true, 
        material : Cesium.Color.BLUE.withAlpha(0.0), 
      } 
     }); 

    viewer.flyTo(entity); 

}); 
+0

,爲什麼你有'阿爾法(0.0)'如果你想看到的多邊形?根據[Cesium spec](http://cesiumjs.org/Cesium/Build/Documentation/Color.html)0.0是_zero intensity_ –

+0

我故意隱藏了多邊形的表面,因爲我對邊界更感興趣,哪些*是*可見的。這與我的問題無關。 – danwild

+0

我使用相同的代碼,但部分路徑段仍處於地面。有人知道原因嗎? – sabrina

回答

8

從版本1.13開始,銫現在支持GroundPrimitives。他們將懸垂在地形上。

它看起來像這樣:http://cesiumjs.org/images/2015/09-01/groundPrimitives.gif

這個例子給出了銫:

var rectangleInstance = new Cesium.GeometryInstance({ 
    geometry : new Cesium.RectangleGeometry({ 
    rectangle : Cesium.Rectangle.fromDegrees(-140.0, 30.0, -100.0, 40.0) 
    }), 
    id : 'rectangle', 
    attributes : { 
    color : new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5) 
    } 
}); 
scene.primitives.add(new Cesium.GroundPrimitive({ 
    geometryInstance : rectangleInstance 
})); 
+0

它也可能使用GroundPrimitives也用於路徑?這是我的代碼: VAR目標= viewer.entities.add({ 位置:樣品, 路徑:{ 分辨率:60, 材料:Cesium.Color.BLUE, 寬度:4, trailTime:360, 引用次數:0 } }); 其中sampe是一個Cesium.SampledPositionProperty,所​​以路徑隨着時間的推移而延伸。 如何在地形上鋪設路徑? – sabrina

+0

您需要使用原始類型並將其添加到scene.primitives集合中。看起來你正在創建一個實體。 – Zac

+0

@emackey有沒有使用CZML實現這一點的方法? – Slaiyer

5

銫並不支持地形上的矢量數據。它正在積極開展工作,大部分功能應該開始出現在將於6月1日發佈的Cesium 1.10中。任何不能釋放的東西都應該在7月1日1.11。

多邊形具體情況,你可以用拉GitHub的請求一起如下:https://github.com/AnalyticalGraphicsInc/cesium/pull/2618

廣告牌和標籤,請上網:https://github.com/AnalyticalGraphicsInc/cesium/pull/2653

折線都尚未開始,但將盡快會以上兩項完成。

+0

好吧,沒有正式的支持但 - 但sampleTerrain.js存在的事實告訴我,一定有辦法做到這一點,當然?如果銫無法處理三維空間中的點,爲什麼有人會在開放層上使用銫? – danwild

+0

我的歉意,我誤解了你的問題。要使用位置的高度值,請將perPositionHeight屬性設置爲true。在這個例子中的橙色多邊形做你想要的:http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Polygon.html&label=Geometries –

+0

我會補充說,我們添加的是將矢量數據直接放在地形上,即如同鋪設在地面上一樣。設置perPositionHeight不會使多邊形符合地形,它只會將高度提高到指定的高度,以便您可以在空中使用多邊形。 –

相關問題