[OSM-dev] Tileserver restricted to a region, anyone?
Stefano Salvador
stefano.salvador at gmail.com
Mon Feb 7 10:12:36 GMT 2011
> I am looking for either (a) an OpenLayers layer/code/configuration that will
> automatically direct requests for tiles outside a given area to another
> tileserver or (b) a mod_tile patch or clever Apache config snippet to do the
> redirects.
Openlayers permits to overwrite the base method to access tiles in a
layer, e.g. in the properties list of the layer you pass a method to
getURL property, In this method you can implement the logic you like.
I do that for loading a paticular TMS service schema, here a snippet of code:
var layer = new OpenLayers.Layer.TMS( "layer", "", {
type: 'png', getURL: getTMSURL, alpha: true, numZoomLevels: 7, zoomOffset: 7
});
function getTMSURL(bounds) {
var res = this.map.getResolution();
var x = Math.round((bounds.left - this.maxExtent.left) / (res *
this.tileSize.w));
var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res *
this.tileSize.h));
var z = this.map.getZoom() + this.options.numZoomLevels;
if (mapBounds.intersectsBounds( bounds ) && z >= mapMinZoom && z <=
mapMaxZoom ) {
return this.url + '/tms/' + z + "/" + x + "/" + y + "." + this.type;
} else {
return "/images/none.png";
}
}
hope this helps,
Stefano
More information about the dev
mailing list