I have the following code, which should display a slippy map showing tiles producted by me with mapnik:
Proj4js.defs["EPSG:31258"] = "+proj=tmerc +lat_0=0 +lon_0=13.33333333333333 +k=1 +x_0=450000 +y_0=-5000000 +ellps=bessel +towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232 +units=m +no_defs";
var latLonProj = new OpenLayers.Projection("EPSG:4326");
var salzburgProj = new OpenLayers.Projection("EPSG:31258");
var bounds = new OpenLayers.Bounds(426249,294999,426251,295001);
var maxZoom = 19;
var minZoom = 11;
var map1 = new OpenLayers.Map({
div: "map1",
allOverlays: true,
maxExtent: bounds,
maxResolution: "auto",
projection: salzburgProj,
displayProjection: salzburgProj,
allowSelection: true,
units: 'm',
controls: [new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.Navigation()]
});
var layer1 = new OpenLayers.Layer.XYZ(
"layer",
"tiles/",
{
sphericalMercator: true,
crossOriginKeyword: null,
buffer: 1,
getURL: get_my_url
});
map1.addLayer(layer1);
var center = bounds.getCenterLonLat();
map1.setCenter(center, minZoom);
function get_my_url (bounds) {
var z = this.map.getZoom();
var x = long2tile(bounds.transform(salzburgProj,latLonProj).left, z);
var y = lat2tile(bounds.transform(salzburgProj,latLonProj).top, z);
var path = z + "/" + x + "/" + y + ".png";
var url = this.url;
if (url instanceof Array) {
url = this.selectUrl(path, url);
}
return url + path;
}
function long2tile(lon,zoom){
return (Math.floor((lon+180)/360*Math.pow(2,zoom)));
}
function lat2tile(lat,zoom){
return (Math.floor((1-Math.log(Math.tan(lat*Math.PI/180) + 1/Math.cos(lat*Math.PI/180))/Math.PI)/2 *Math.pow(2,zoom)));
}
I have taken get_my_url() from here (and customized it) and long2tile and lat2tile from here.
The problem is that I do not get the correct tile urls, probably because long2tile() and lat2tile() refers to projection 900913 and not to my salzburg projection 31258.
How can I modify these functions in order to get correct tile urls? Maybe can I use some tuning parameter given in 31258 definition at the top of my source?
Thanks in advance.
