[GIS] OpenLayers.Layer.XYZ keep previous tile if zoom with no tile

openlayers-2

I've got an OpenLayers web application with a custom XYZ layer which downloads tiles from the server itself:

OpenLayers.Layer.MOBAC_OSMDROID_ZIP = OpenLayers.Class(
          OpenLayers.Layer.XYZ, {
              name: "tiles base",
              transitionEffect: "resize",
              sphericalMercator: true,
              url: '../map/${z}/${x}/${y}.png',
              [...]
          });

The funny thing here is that I can use MOBAC to download selected parts of OpenStreetMap and serve them from my website. So far, so good.

The problem is: obviously I do not want to download the whole world from OpenStreetMap, but only, for example, zoom levels 0 and 1 for the world, 2-4 for Europe, 5-7 for Spain and so on. Then, when I am zooming in to Spain I get the right tiles. But if I move outside Spain, I just get the damn pink "no-tile" image. I can easily remove such no-image with the .olImageLoadError CSS class… but it still does not show a map.

What I would like is: if there is no tile, use the previous tile, scaled. This way you will probably have an overview of where you are when there are no specific tiles for such level.

Any idea? Is something like this included in OpenLayers? Any idea to implement it myself?

Since the "resize" effect does not remove the old tiles for a while, maybe keeping them "forever" would work…

Best Answer

If you want to have different zoom levels for different extents, you have to define three layers with corresponding maxExtent, minScale and maxScale.

Otherwise you need to implement a server-side solution, e.g. a small script that delivers the scaled tiles.

Anyway, I don't recommend to upscale the map tiles, since this won't look nice. It's probably better and easier to get generalized map data (e.g. from Natural Earth) and use a WMS, that provides the tiles.