sampleTerrainMostDetailed problem

1. A concise explanation of the problem you're experiencing.
I'm using Cesium 1.30. When I attempt to use sampleTerrainMostDetailed I get the following error "sampleTerrainMostDetailed requires a terrain provider that has tile availability. My terrain provider is an instance of CesiumTerrainProvider, the format is HeightMap

This might have been fixed in a later version. Can you try upgrading and see if that fixes it?

var terrainProvider = Cesium.createWorldTerrain();

pos-------> is a catographic array, u Need to pass it as an argument

function updateHeights(terrainProvider, pos)

{

var promise = Cesium.sampleTerrainMostDetailed(terrainProvider, pos);

return Cesium.when(promise, function(updatedPositions)

{

});

}

I think this is the optimal solution for getting terrain heights…

You can check array after calling the updateHeights() function.

console.log(pos)----> u could check whether heights are updated or not.

Are you saying that I need to create it using Cesium.createWorldTerrain? I have my own data I was trying to use. I created the provider using Cesium.CesiumTerrainProvider.

I tested with Cesium 1.51, but get the same error.
"sampleTerrainMostDetailed requires a terrain provider that has tile availability"

Thanks,
  Tony

Tony,

As the error says, your tileset must provide availability. That means the “available” property of the terrain provider must not be undefined. Otherwise sampleTerrainMostDetailed can’t tell which tells exist, so it can’t request the most detailed ones in an area. For CesiumTerrainProvider, this means your layer.json must include the “available” property. Here’s an example of one that does:

http://www.ga.gov.au/terrain/terrain/layer.json

Each element in the “available” array is for a level of the tile hierarchy. i.e. the 0th element is for level 0, the 1st element is for level 1, etc. Each element itself is an array of rectangles of tiles that exist at that level. startX/startY/endX/endY specify the range of tile indices within that level that exist. The values are inclusive.

Kevin

Thanks for the info, but the link you provided doesn't work for me. Do you know where else I can find a sample layer.json?

Thanks,
  Tony

The link works for me. It’s a pretty short JSON so I posted it below:

{
  "tilejson": "2.1.0",
  "format": "heightmap-1.0",
  "version": "1.1.0",
  "scheme": "tms",
  "tiles": ["{z}/{x}/{y}.terrain?v={version}"],
  "attribution": "© Commonwealth of Australia (Geoscience Australia) 2014, Data: SIO, NOAA, U.S. Navy, NGA, GEBCO, Geoscience Australia",
  "projection": "EPSG:4326",
  "bounds": [-180.0,-90.0,180.0,90.0],
  "available": [[{"startX":0,"startY":0,"endX":1,"endY":0}],[{"startX":0,"startY":0,"endX":3,"endY":1}],[{"startX":0,"startY":0,"endX":7,"endY":3}],[{"startX":0,"startY":0,"endX":15,"endY":7}],[{"startX":0,"startY":0,"endX":31,"endY":15}],[{"startX":0,"startY":0,"endX":63,"endY":31}],[{"startX":0,"startY":0,"endX":127,"endY":63}],[{"startX":0,"startY":0,"endX":255,"endY":127}],[{"startX":0,"startY":0,"endX":511,"endY":255}],[{"startX":0,"startY":0,"endX":1023,"endY":511}],[{"startX":1666,"startY":261,"endX":1900,"endY":455}],[{"startX":3333,"startY":523,"endX":3800,"endY":910}],[{"startX":6667,"startY":1046,"endX":7600,"endY":1820}],[{"startX":13334,"startY":2093,"endX":15200,"endY":3640}]]
}

``

You can also look at the CesiumTerrainProvider source to see what it’s doing with the availability and all that:

https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/CesiumTerrainProvider.js#L267-L276

Thanks, I tried looking at CesiumTerrainProvider.js, but couldn't figure out what the availability variable is supposed to consist of.

Is it not documented anywhere? Is there not a tool that generates it out there?

Thanks,
  Tony

Hi Tony,

My explanation above is probably the best documentation of it available. Is something unclear? Here it is again:

Each element in the “available” array is for a level of the tile hierarchy. i.e. the 0th element is for level 0, the 1st element is for level 1, etc. Each element itself is an array of rectangles of tiles that exist at that level. startX/startY/endX/endY specify the range of tile indices within that level that exist. The values are inclusive.

Tools that generate terrain generate this available property as well. Certainly Cesium Ion does. If you’re generating your own terrain tiles, though, you’ll need to generate this as well in order for sampleTerrainMostDetailed to work.

Kevin

Oh, I didn't see your explanation above. Yes, that is what I was looking for.

Thanks,
  Tony

Hi,
it is possible to have a terrain which covers only an AOI and which starts at a zoom level > 0.
In other terms, is this kind of layer.json valid (note the first levels are empty) :

{
    "tilejson": "2.1.0",
    "format": "quantized-mesh-1.0",
    "version": "1.1.0",
    "scheme": "tms",
    "tiles": [
        "{z}/{x}/{y}.terrain?v={version}"
    ],
    "attribution": "",
    "projection": "EPSG:3857",
    "bounds": [
        -180.0,
        -90.0,
        180.0,
        90.0
    ],
    "minzoom": 5,
    "maxzoom": 18,
    "available": [
        [],
        [],
        [],
        [],
        [],
        [
            {
                "startX": 32,
                "startY": 42,
                "endX": 32,
                "endY": 42
            }
        ],
        [
            {
                "startX": 65,
                "startY": 84,
                "endX": 65,
                "endY": 84
            }
        ],
        [
            {
                "startX": 131,
                "startY": 168,
                "endX": 131,
                "endY": 168
            }
        ],
        [
            {
                "startX": 262,
                "startY": 336,
                "endX": 262,
                "endY": 336
            }
        ],
        [
            {
                "startX": 524,
                "startY": 672,
                "endX": 524,
                "endY": 672
            }
        ],
        [
            {
                "startX": 1048,
                "startY": 1345,
                "endX": 1048,
                "endY": 1345
            }
        ],
        [
            {
                "startX": 2097,
                "startY": 2691,
                "endX": 2097,
                "endY": 2691
            }
        ],
        [
            {
                "startX": 4194,
                "startY": 5382,
                "endX": 4195,
                "endY": 5383
            }
        ],
        [
            {
                "startX": 8389,
                "startY": 10765,
                "endX": 8391,
                "endY": 10767
            }
        ],
        [
            {
                "startX": 16779,
                "startY": 21530,
                "endX": 16783,
                "endY": 21534
            }
        ],
        [
            {
                "startX": 33558,
                "startY": 43060,
                "endX": 33566,
                "endY": 43069
            }
        ],
        [
            {
                "startX": 67116,
                "startY": 86121,
                "endX": 67133,
                "endY": 86139
            }
        ],
        [
            {
                "startX": 134232,
                "startY": 172243,
                "endX": 134267,
                "endY": 172278
            }
        ]
    ]
}```