I am using a custom map image. And I have verified my lat, lon bounds via google maps. But when using the code below combined with my image - it sometimes returns a negative number for y based on the different zoom levels - so I end up with an image path of (tile_z_x--y.png)
I am not really sure why this happens. My image is a rectangle - it is taller than it is wide, but I don't see how this would make a difference.
when I log the error - the max number that is returned for bounds.top is 29.1427626 but this is way outside my real bounds.
function loadmap() {
var left = -81.5426684;
var top = 29.0901949;
var right = -81.4901007;
var bottom = 29.1393509;
var centerLon = (left + right) / 2;
var centerLat = (top + bottom) / 2;
var get_my_url = function (bounds) {
var res = this.map.getResolution();
console.warn(this.maxExtent.top);
console.warn(bounds.top);
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 = "tile_" + z + "_" + x + "-" + y + "." + this.type;
var url = this.url;
if (url instanceof Array) {
url = this.selectUrl(path, url);
}
return url + path;
}
var options = {
maxExtent: new OpenLayers.Bounds(-81.5426684, 29.0901949, -81.4901007, 29.1393509),
numZoomLevels: 5,
};
var map = new OpenLayers.Map(
'map',
options
);
var tms = new OpenLayers.Layer.TMS(
'Aerial',
'/maps/output/',
{
type: 'png',
getURL: get_my_url
});
//add a point
var vector = new OpenLayers.Layer.Vector("Polygon Layer");
var point = new OpenLayers.Geometry.Point( centerLon, centerLat);
var pointFeature = new OpenLayers.Feature.Vector(point, null, null);
vector.addFeatures(pointFeature);
map.addLayers([tms,vector]);
map.setCenter([centerLon, centerLat], 2);
}