铯如何将多边形或线

铯如何将多边形或线

本文介绍了铯如何将多边形或线“悬垂"到地形表面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用铯,我想添加多边形或直线来表示地形表面上的属性边界.

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.

足够公平,我实际上没有z/height值-因此,我使用的是 sampleTerrain.js promise方法可根据地形插值高度值.这部分工作正常,我得到了我的身高值.但是那又怎样呢?

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. 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?

唯一考虑的高度值参考是 PolygonOutlineGeometry ,该属性具有良好的外观称为 perPositionHeight .

The only reference to height values being considered is in the PolygonOutlineGeometry, which has a promising looking property called 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..

这是我失败的尝试之一:

Here's one of my unsuccessful attempts:

实体/多边形:

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.

在注释的评论中使用橙色多边形示例.将接受的答案与 sampleTerrain.js 结合起来,我已经能够模拟将多边形覆盖"到地形,其中列出了没有z值的位置,这是一个粗略的示例:

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:

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

});

推荐答案

从1.13版开始,铯现在支持.它们将悬垂在地形上.

As of version 1.13 cesium now supports GroundPrimitives. They will drape over terrain.

它看起来像这样: 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
}));

这篇关于铯如何将多边形或线“悬垂"到地形表面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 16:03