[GIS] Unable to serve Cesium Terrain files

3dcesiumgeoserverjavascriptterrain

I am trying to generate 3d Terrain.
I am serving the terrain files at localhost:8081

Here is the Cesium Code

var viewer = new Cesium.Viewer('cesiumContainer', {
    baseLayerPicker : false,
    terrainProvider : new Cesium.CesiumTerrainProvider({
        url : 'localhost:8081'
    })
});

I get the following error:

An error occurred in "CesiumTerrainProvider": An error occurred while accessing localhost:8081/layer.json.

This is my layer.json file and i have given appropriate access permissions:

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

Best Answer

Try putting http:// on the front of the URL:

var viewer = new Cesium.Viewer('cesiumContainer', {
    baseLayerPicker : false,
    terrainProvider : new Cesium.CesiumTerrainProvider({
        url : 'http://localhost:8081'
    })
});

Also, if Cesium itself is not served from port 8081 locally, then you will need to enable CORS on your 8081 server, to work around the same-origin policy in the browser.

Related Question