Fix for partial caching of layered web tiles.

There is a caching problem with layered web tile sources  (like OpenStreetMap with an OpenSeaMap Overlay). If not all of the layers are loaded successfully, the resulting composite image still gets cached and is not reloaded on the next display. This may happen if one of the layer servers times out. For us this resulted in cached tiles with only the transparent OpenSeaMap layer being displayed for quite some time.
This proposed fix counts the downloaded tile images and checks if all images have been successfully downloaded before adding the composite image to the cache.