简体   繁体   English

铯如何将多边形或线条“悬垂”到地形表面上

[英]Cesium how to 'drape' a polygon or line onto terrain surface

So, I'm using cesium and I want to add a polygon or line to represent a property boundary on a terrain surface. 所以,我正在使用铯,我想添加一个多边形或线来表示地形表面上的属性边界。

My polygon works fine on the flat/Ellipsoid surface, unfortunately however the polygon doesn't automagically drape over the surface when the terrain layer is shown. 我的多边形在平面/椭圆体表面上工作正常,但不幸的是,当显示地形图层时,多边形不会自动覆盖表面。

Fair enough, I don't actually have the z/height values - so I'm using the sampleTerrain.js promise method to interpolate the height values based on the terrain. 很公平,我实际上没有z / height值 - 所以我使用sampleTerrain.js promise方法根据地形插入高度值。 This part works fine, I get my height values. 这部分工作正常,我得到我的身高值。 But then what? 但那又怎样?

I've tried creating a polygon entity with my height-laden positions, but to no avail - it just ignores the height values. 我尝试用我的高度位置创建一个多边形实体,但无济于事 - 它只是忽略了高度值。 When I read the docs , I can really see any reference to height values being ingested - all the "positions" array are two dimensional? 当我阅读文档时 ,我真的可以看到任何对摄取高度值的引用 - 所有“位置”数组都是二维的?

The only reference to height values being considered is in the PolygonOutlineGeometry , which has a promising looking property called perPositionHeight . 对要考虑的高度值的唯一引用是在PolygonOutlineGeometry中 ,它具有一个看起来很有前途的属性perPositionHeight

This is essentially what I want - I don't want to set the height of the whole poly, I want every points height value to be used.. 这基本上就是我想要的 - 我不想设置整个poly的高度,我想要使用每个点的高度值。

Here's one of my unsuccessful attempts: 这是我不成功的尝试之一:

Entity/Polygon: 实体/多边形:

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),
   }
});


Bottom line: I just want a polygon or polyline entity that sits nicely on the surface of the terrain. 底线:我只想要一个多边形或折线实体,它可以很好地放置在地形表面上。

EDIT: 编辑:

Using the Orange Polygon example in the comments of the accepted answer combined with sampleTerrain.js , I've been able to simulate 'draping' a polygon onto terrain, with a list of positions that did not have z values, here's a crude example: 在接受的答案的注释中使用橙色多边形示例sampleTerrain.js相结合,我已经能够模拟将多边形“悬垂”到地形上,并且列出了没有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);   

});

As of version 1.13 cesium now supports GroundPrimitives . 从版本1.13开始,cesium现在支持GroundPrimitives They will drape over terrain. 他们将覆盖地形。

It looks like this: http://cesiumjs.org/images/2015/09-01/groundPrimitives.gif 它看起来像这样: http//cesiumjs.org/images/2015/09-01/groundPrimitives.gif

This the example Cesium gives: 这个示例Cesium给出:

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
}));

Cesium does not support vector data on terrain yet. Cesium尚不支持地形上的矢量数据。 It is being actively worked on and most features should start to appear in Cesium 1.10 which will be out on June 1st. 它正在积极开展工作,大多数功能应该开始出现在6月1日的Cesium 1.10中。 Anything that doesn't make that release should be in 1.11 on July 1st. 任何不能发布的内容应该是7月1日的1.11。

For Polygons specifically, you can follow along with the GitHub pull request: https://github.com/AnalyticalGraphicsInc/cesium/pull/2618 对于Polygons,您可以按照GitHub拉取请求进行操作: https//github.com/AnalyticalGraphicsInc/cesium/pull/2618

For Billboards and Labels, check out: https://github.com/AnalyticalGraphicsInc/cesium/pull/2653 对于Billboards和Labels,请查看: https//github.com/AnalyticalGraphicsInc/cesium/pull/2653

Polylines haven't been started yet but will be as soon as the above two are finished. 折线还没有开始,但一旦上述两个完成,将立即开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM