3

i am using cesium on my gwt project and i am using cesium-terrain-server for terrain. (Not cesium-gwt , devoloping my own code with jsni) My problem : i am creating graphic on terrain (polygon , polyline) , when i navigate on map , graphics are moving from its position. is there any way to immobilize them on the point(s) which i selected before ?

example code :

    var polygon = new Cesium.PolygonGraphics({
                   fill : true;
                   material : Cesium.Color.BLUE.withAlpha(0.5),
                   outline : true,
                   hierarchy :{
                       positions: cartesian3s
                   }
                 })

then i am adding polygon as entity to cesium viewers entities.

hkn
  • 371
  • 1
  • 14
  • Can you show the code when you add polygon to entity? – Tomislav Muic Oct 27 '15 at 14:19
  • @Tomislav Muic firstly i create an entity `var entity = new Cesium.Entity()` then i set polygon to entity `entity.polygon = polygon` lastly i am adding it to my viewer `viewer.enties.add(entity)` – hkn Oct 28 '15 at 06:37

1 Answers1

3

If graphics appear to "move" or slide around when navigating a map with terrain on it, that typically means the graphics in question are being drawn underneath the terrain (on the WGS84 ellipsoid itself), and are showing through the terrain. There's a bit of an optical illusion where the eye doesn't understand that it's seeing through a mountain or the ground itself to some graphics far underneath. It's only when the camera moves that it becomes visually apparent that something is wrong. If you want the graphics to appear stationary, they must be at the correct altitude for the terrain they're on.

The ability to drape polygons on terrain was added in Cesium 1.3 and has been asked about elsewhere on SO. But it looks like this capability has not been added to the Entity API as of yet, so your current options are (a) if on flat terrain, sample the height at a point and move the polygon to that height, or (b) skip the Entity API layer and use graphics primitives, specifically the GroundPrimitive to render the polygon draped on terrain.

Community
  • 1
  • 1
emackey
  • 11,818
  • 2
  • 38
  • 58
  • thanks for your answer , actually i tried to set height or extrudedHeight but it didnt work. i get height value from one my cartesian3 array which i used to draw polygon. – hkn Oct 28 '15 at 06:18
  • Try loading the [GeoJSON Demo](http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=GeoJSON%20and%20TopoJSON.html&label=Showcases) and click the `Custom styling` button at the top of the 3D window, for an example of working extrudedHeight. If you still can't get it working, please ask a new question about this topic specifically. Thanks! – emackey Oct 28 '15 at 13:54
  • 1
    Actually sampleTerrain fixed my problem its not draping shapes on terrain but it prevents shapes to move when camera move . @emackey thank you true answer – hkn Oct 29 '15 at 10:40