Using Custom Tile Sources / Google-like Tile Layer Support
If you have tiles which are set up according to the 'Google' tile schema -- that is, based on x,y,z and starting in the upper left corner of the world -- you can load these tiles with the TMS layer with a slightly modified get_url function. (Note that in the past there was a 'LikeGoogle' layer in SVN -- this is the appropriate replacement for that code/functionality.)
First, define a getURL function that you want to use: it should accept a bounds as an argument, and will look something like this:
function get_my_url (bounds) {
var res = this.map.getResolution();
var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
var z = this.map.getZoom();
var path = z + "/" + x + "/" + y + "." + this.type;
var url = this.url;
if (url instanceof Array) {
url = this.selectUrl(path, url);
}
return url + path;
}
Then, when creating your TMS layer, pass in options like:
new OpenLayers.Layer.TMS("Name", "http://example.com/", { 'type':'png', 'getURL':get_my_url });
This will cause the getURL function to be overridden by your function, thus requesting your inverted google-like tiles instead of standard TMS tiles.
Note that the map configuration options for a Google-like layer should be:
{
maxExtent: new OpenLayers.Bounds(-20037508.3427892,-20037508.3427892,20037508.3427892,20037508.3427892),
numZoomLevels:18,
maxResolution:156543.0339,
units:'m',
projection: "EPSG:900913",
displayProjection: new OpenLayers.Projection("EPSG:4326")
}
To transform from WGS84 long/lat to mercator-projected meters as in the setCenter example:
var lonLat = new OpenLayers.LonLat(-100, 40) ; lonLat.transform(map.displayProjection,map.getProjectionObject()); map.setCenter(lonLat, 5);
This would center the map on WGS84 coordinates long -100 lat 40 at zoom level 5.
Note: Projection.js is available as "trunk" code until 2.6 becomes stable.
