Good morning. I am asking for feedback on the best approach to drape (or clamp) an image over the terrain.
1. A concise explanation of the problem you're experiencing.
I would like to overlay map images (.jpg, .png, etc) on the terrain. Any thoughts or corrections to my findings are greatly appreciated.
2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.
I have explored three options to drape images on the terrain, but run into problems with each:
A. As a rectangle/polygon material: clamping to terrain only currently works for solid colors, not images. In the example here toggle the terrain on/off to see the effect on the Cesium logo.
var viewer = new Cesium.Viewer('cesiumContainer');
var redRectangle = viewer.entities.add({
name : 'Red translucent rectangle',
rectangle : {
coordinates : Cesium.Rectangle.fromDegrees(-110.0, 20.0, -80.0, 25.0),
material : Cesium.Color.RED.withAlpha(0.5)
}
});
var image = viewer.entities.add({
name : 'Cesium logo',
rectangle : {
coordinates : Cesium.Rectangle.fromDegrees(-110.0, 15.0, -80.0, 20.0),
material : '../images/Cesium_Logo_overlay.png'
}
});
viewer.zoomTo(viewer.entities);
B. As a billboard: image cannot be locked flat nor draped over the terrain model
C. As an imageryLayer: it seems that one loses the flexibility with the baseLayerPicker once imageryLayers are created (otherwise this functions well):
var viewer = new Cesium.Viewer(‘cesiumContainer’, {
imageryProvider : new Cesium.ArcGisMapServerImageryProvider({
url : ‘https://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer’
}),
baseLayerPicker : false
});
var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
url : ‘https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles’,
requestWaterMask : true,
requestVertexNormals : true
});
viewer.terrainProvider = cesiumTerrainProviderMeshes;
var layers = viewer.imageryLayers;
var earth = layers.addImageryProvider(Cesium.createTileMapServiceImageryProvider({
url : 'https://dev.virtualearth.net',
}));
layers.addImageryProvider(new Cesium.SingleTileImageryProvider({
url : '../images/Cesium_Logo_overlay.png',
rectangle : Cesium.Rectangle.fromDegrees(-106.4, 39.6, -106.1, 39.7)
}));
viewer.camera.flyTo({
destination : Cesium.Rectangle.fromDegrees(-106.5, 39.5, -106.0, 39.8)
});
3. Context. Why do you need to do this? We might know a better way to accomplish your goal.
I am building virtual documentaries of battles and want turn on/off historic maps to provide more context for events. For example maps showing trading routes, or on a larger scale maps an army's location, etc
Cheers, erik