CUT /FILL Analysis in cesium

var tileAvailability = that._viewer.terrainProvider.availability;

var maxLevel = 0;
var minHeight = 15000;

for (var i = 0; i < this._positions.length; i++) {
  var cartographic = Cesium.Cartographic.fromCartesian(this._positions[i]);
  var height = this._scene.globe.getHeight(cartographic);

  if (minHeight > height) minHeight = height;

  var level = tileAvailability.computeMaximumLevelAtPosition(cartographic);

  if (maxLevel < level) maxLevel = level;

where I am getting tileAvailability is undefined.

Hi @Bikash_Ranjan_Mallic , What are you assigning in this and that ? It seems like you are getting error on retrieving height of terrain at certain location. You should go with sampleTerrainMostDetailed to calculate terrain height.

It would be easy to understand with the help of sandcastle example.

  • Regards

Hi @Jacky

I am using cut fill analysis and not getting terrain availability method which is undefined.

It’s not easy to understand the issue without study the source code. Cut/Fill Analysis is not the inbuilt feature in cesiumjs. Please create a sandcastle example or share the source code.

There can be one reason, you are trying to get terrainProvider availability before it gets ready. Check the documentation for detail.

Check this sandcastle link.

As per your code, it should be like:

that._viewer.terrainProvider.readyPromise.then(function(isReady){
  var tileAvailability  = that._viewer.terrainProvider.availability;
        console.log(tileAvailability);
});
  • Best Regards,
  • Yash

Dear @Jacky

I am using Geoserver terrain provider to create terrain from geoserver wms services.

_.prototype.computeCutVolume = function () {
// var tileAvailability = this._cesiumViewer.terrainProvider.availability;
//var tileAvailability = that._viewer.terrainProvider.availability;
//TileAvailability;
this._cesiumViewer.terrainProvider.readyPromise.then(function (isReady) {
var tileAvailability = this._cesiumViewer.terrainProvider.availability;
console.log(tileAvailability);
});
var maxLevel = 0;
var minHeight = 15000;

for (var i = 0; i < this._positions.length; i++) {
  var cartographic = Cesium.Cartographic.fromCartesian(this._positions[i]);
  var height = this._scene.globe.getHeight(cartographic);

  if (minHeight > height) minHeight = height;

  var level = tileAvailability.computeMaximumLevelAtPosition(cartographic); //api or wcs

  if (maxLevel < level) maxLevel = level;
}

//var granularity =  Math.PI/ Math.pow(2, maxLevel);
var granularity = Math.PI / Math.pow(2, 11);

granularity = granularity / 64;

var polygonGeometry = new Cesium.PolygonGeometry.fromPositions({
  positions: this._positions,
  vertexFormat: Cesium.PerInstanceColorAppearance.FLAT_VERTEX_FORMAT,
  granularity: granularity,
});

mycode

You are not getting tileAvailability object in console log? You should put all your codes inside the Promise callback function.