A lightweight Go server for hosting CesiumJS terrain tilesets. Serves filesystem-based terrain tiles for use with CesiumTerrainProvider, with optional Memcached caching and Docker support.
Built for use with tilesets created by Cesium Terrain Builder.
go get github.com/brickhouse-tech/cesium-terrain-server/cmd/cesium-terrain-serverOr use Docker:
docker pull brickhouse-tech/cesium-terrain-serverGiven a terrain tileset at /data/tilesets/terrain/srtm/:
cesium-terrain-server -dir /data/tilesets/terrain -port 8080Tiles are then available at http://localhost:8080/tilesets/srtm/ — point your CesiumTerrainProvider there.
cesium-terrain-server [options]
-dir="." Root directory containing tileset directories
-port=8000 Server port
-base-terrain-url="/tilesets" URL prefix for all tilesets
-cache-limit=1.00MB Max resource size for caching (supports kB, MB, GB, TB)
-memcached="" Memcached address for tile caching (e.g. localhost:11211)
-web-dir="" Directory for serving static files
-log-level=notice Log level: crit, err, notice, debug
-no-request-log=false Suppress client request logging
Just drop tileset directories under your root dir. For example:
/data/tilesets/terrain/
├── srtm/ → http://localhost:8080/tilesets/srtm/
├── lidar/ → http://localhost:8080/tilesets/lidar/
└── custom/ → http://localhost:8080/tilesets/custom/
CesiumTerrainProvider requires a layer.json file. If one exists in your tileset root, it's served as-is. Otherwise, the server returns a sensible default.
Cesium requires both 0/0/0.terrain and 0/1/0.terrain. If one is missing (common when your dataset doesn't cross the prime meridian), the server returns a blank tile automatically.
Use with a reverse proxy (e.g. Nginx) for production caching:
cesium-terrain-server -dir /data/tilesets/terrain -memcached memcache.me.org:11211Example Nginx configuration
server {
listen 80;
server_name localhost;
root /var/www/app;
index index.html;
location /tilesets/ {
set $memcached_key "tiles$request_uri";
memcached_pass memcached:11211;
error_page 404 502 504 = @fallback;
add_header Access-Control-Allow-Origin "*";
location ~* \.terrain$ {
add_header Content-Encoding gzip;
}
}
location @fallback {
proxy_pass http://tiles:8000;
proxy_set_header X-Memcache-Key $memcached_key;
}
}# Build from source
make
# Build Docker image
make docker-localRequires Go with GOPATH, GOROOT, and GOBIN set. See the Makefile for details.
Please report bugs via the GitHub issue tracker. Pull requests welcome!
If you find this project useful, consider sponsoring @brickhouse-tech to support ongoing maintenance and development. ❤️
Originally created by Homme Zwaagstra at GeoData.