rajat
rajat

Reputation: 894

Unable to serve.terrain files in cesium sandcastle

I am learning 3d terrain generation using CesiumJS. I generated .terrain files usind Cesium terrain builder and kept them in 'cesium/apps' directory for testing purposes and to avoid CORS issues. Whenever, I try to generate terrain I get error that tile at X:0 Y:0 level 0 as well as tile at X:1 Y:0 level 0 were not found even though I added empty files at the specified locations.

Upvotes: 4

Views: 1957

Answers (1)

Sergiu Dogotaru
Sergiu Dogotaru

Reputation: 395

This is now an older question, but I stumbled upon it throughout my research so I'll detail a bit.

After you've managed to generate your terrain tiles, the most obvious at this time option to serve them is https://github.com/geo-data/cesium-terrain-server. The server is written in Go requires Go to be present on the system. It is build with the intention to ease the development and testing of terrain tiles created with Cesium Terrain Builder tools.

My own objective was to serve .terrain tiles from an Apache server and this turned out to be pretty easy, after inspecting in fiddler what cesium-terrain-server is serving and after finding this exchange of messages (look for Kevin Ring's reply).

Besides CORS, essentially terrain files need to have MIME type application/octet-stream and if gzipped Content-Encoding: gzip. Be careful, only pass the gzip header don't gzip the files served again if they are already gzipped.

In my .htaccess I have the following new lines in place:

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>
<filesMatch "(.*)\.terrain$">
    ForceType application/octet-stream
    Header set Content-Disposition attachment
    Header set Content-Encoding: gzip
</filesMatch>

What I also needed to add is a layer.json file in the root of terrain folder, with the following content:

{
  "tilejson": "2.1.0",
  "format": "heightmap-1.0",
  "version": "1.0.0",
  "scheme": "tms",
  "tiles": ["{z}/{x}/{y}.terrain"]
}

Now everything just works as intended.

Upvotes: 4

Related Questions