I am new to Cesium (and javascript)
I have problems to show a polygon when WorldTerrain is selected.
This is my code:
var viewer = new Cesium.Viewer('cesiumContainer',{
terrainProvider : Cesium.createWorldTerrain()
}
);
var polyBlue= new Cesium.GeoJsonDataSource.load('braunschweig_hillerse/groundrisk_polygons_subset0_0.geojson');
polyBlue.then(
function(polyBlue) {
var polys_entities = polyBlue.entities.values;
for (var i=0; i<polys_entities.length; i++)
{
var entity = polys_entities[i];
var cartesianPositions = polys_entities[i].polygon.hierarchy;
var cartographicPositions = viewer.scene.globe.ellipsoid.cartesianArrayToCartographicArray(cartesianPositions._value.positions);
var positions=cartographicPositions;
var promise = Cesium.sampleTerrainMostDetailed(viewer.terrainProvider, positions);
Cesium.when(promise, function(updatePos){
updatedPos = ;
for (var j=0; j<positions.length; j++)
{
updatedPos.push(positions[j].longitude);
updatedPos.push(positions[j].latitude);
updatedPos.push(positions[j].height);
}
entity.polygon.hierarchy = Cesium.Cartesian3.fromRadiansArrayHeights(updatedPos);
entity.polygon.perPositionHeight = true;
entity.polygon.material = Cesium.Color.BLUE;
});
}
viewer.dataSources.add(polyBlue);
}
);
viewer.zoomTo(polyBlue);
var redPolygon = viewer.entities.add({
name : 'Red polygon on surface',
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray([ 10.51542928902906, 52.282576680786995,
10.51360289533807, 52.283340457479895,
10.506454502841559, 52.287258065060719,
10.506384657594938, 52.287307830839133 ,
10.506724121428361, 52.287491515158628 ,
10.507292056871016, 52.287079208668018 ,
10.50814087110892, 52.287028718589156 ,
10.50944165754134, 52.286649028335773 ,
10.511402209744249, 52.286920392423589,
10.512307139954732, 52.287488924617122,
10.512659788726039, 52.287851342544101,
10.512587524063067, 52.288884919379619,
10.514887515894781, 52.288714540362456,
10.516034142302827, 52.288290360082605,
10.516382511476439, 52.288796862699478 ,
10.516607475013146, 52.28891832323152,
10.518938678050964, 52.289034916457396,
10.518656542648899, 52.287880824536927 ,
10.516741456550458, 52.287638218263737,
10.51736756377977, 52.286776988722131 ,
10.517179622359482, 52.286700370146377,
10.516195628614165, 52.286630199576415,
10.515963675356858, 52.286535532208028,
10.515863528024767, 52.285156562017654,
10.515888526663229, 52.284952587890814,
10.516031218583566, 52.284867855978028,
10.517606299902435, 52.284907773873243 ,
10.517769012471801, 52.284866973472461,
10.515599728958165, 52.282670196291889,
10.515465987013249, 52.282640950763842,
10.51542928902906, 52.282576680786995 ]),
material : Cesium.Color.RED
}
});
The coordinates read from geoJson file are nearly the same as the ones in "redPolygon".
When I choose Terrain "WGS84", both polygons are shown; the blue one above the red one.
When I choose Terrain "WorldTerrain", the blue one isn't shown correctly, only parts of it, while the red one is ok.
I have two questions:
1. Why is the blue one not shown correctly?
2. Why need the coordinates of the red one not to be changed? If the one of the blue are not changed when "World Terrain", it does not show up at all.
Thanks in advance for help.