I am trying to create a game that allows the user to edit a raster map using Cesium for Unity.
The only way I am able do it is to make the raster available via WMS (using geoserver) and then, in Unity, to add a CesiumWebMapServiceRasterOverlay pointing to localhost. This works fine.
When the user clicks on the map, the Unity coordinates are converted and I am able to edit the relevant pixel on the raster file. Then I call cesiumWebMapServiceRasterOverlay.Refresh() to see the changes in the game. The problem when refreshing is all the WMS tiles reload (They disappear and appear again) and this makes the user experience really bad.
I have tried to load two CesiumWebMapServiceRasterOverlay, both with the same maps, one in the background and another in front with the editable version of the map, hoping that when Refresh is called on the editable WMS, the one in the back would show up so the user does not see the tiles disappearing, but this is not happening.
I have also tried to add a transparent map as the editable map on top of the raster map, but the raster maps just disappears.
Is it just not possible to add two WMS on the same location?
I have also tried to upload the raster map to Cesium ION and to use a CesiumIonRasterOverlay to be used as a background, but the resolution I get when zoomed in is very bad.
Any idea about how to solve this would be much appreciated.
Is it just not possible to add two WMS on the same location?
Adding two WMS overlays should work. There was a bug with it prior to v1.3.0, though, so make sure you’re on the latest version (v1.4.0).
I have also tried to upload the raster map to Cesium ION and to use a CesiumIonRasterOverlay to be used as a background, but the resolution I get when zoomed in is very bad.
Can you show us what you mean here? Cesium ion certainly shouldn’t be losing imagery resolution.
Any idea about how to solve this would be much appreciated.
I’m guessing you don’t really want to use a WMS for this. Under the hood, in cesium-native, there’s an abstract class called RasterOverlay. By deriving from that class, you can provide per-tile images any way you like. There’s no need for them to come from a server. But you’ll definitely need to write C++ code to take advantage of this, and probably modify the Cesium for Unity plugin itself.
Refreshing an already-loaded image is not explicitly supported. But raster tiles are mapped to geometry tiles by a class called RasterMappedTo3DTile. It has a “ready” image and a “loading” image. To do your updates, you probably just need to keep the ready image in place while creating a new loading image. This isn’t directly achievable with the public API, but it’s probably not crazy to extend it to allow this.
I guess in short, you’re pretty far off the beaten path here. So you’re going to need to make some modifications to the core pieces of Cesium for Unity and cesium-native in order to do this optimally. It’s possible, but probably challenging.
I can confirm that upgrading to v1.4.0 fixes the problem with the two overlapping WMS.
Here are two images so you can see the difference when zoomed in. In the CesiumWebMapServiceRasterOverlay I increased the Maximum Level to 25. In the CesiumIonRasterOverlay I increased the Maximum texture size but nothing changed.
Having a WMS layer in the background and refreshing only the second layer with edited parts is not the optimal solution, but it is still a big improvement. I will have a look at the RasterMappedTo3DTile class and see what I can do. Thanks a lot for the tips.
Ok, I see. The resolution in those two screenshots is identical. The only difference is that your WMS is doing nearest-neighbor intepolation while Cesium ion is doing linear interpolation. So you can see the hard pixel edges with the WMS, while the ion images are smoothed out.