]> git.openstreetmap.org Git - rails.git/blobdiff - public/javascripts/map.js
Add a flag to allow the API to be placed in read-only mode.
[rails.git] / public / javascripts / map.js
index 4ba66b03fb2b36b19bb74c06668b7036fdfef235..71f5b8ff8be18845881b77dab4db62fc4c53e2ae 100644 (file)
@@ -8,7 +8,7 @@ function createMap(divName, centre, zoom) {
    }
 
    map = new OpenLayers.Map(divName,
-                            { maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
+                            { maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
                               numZoomLevels: 19,
                               maxResolution: 156543,
                               units: 'm',
@@ -16,12 +16,12 @@ function createMap(divName, centre, zoom) {
 
    var mapnik = new OpenLayers.Layer.TMS("Mapnik",
                                          "http://tile.openstreetmap.org/",
-                                         { type: 'png', getURL: getTileURL });
+                                         { type: 'png', getURL: getTileURL, displayOutsideMaxExtent: true });
    map.addLayer(mapnik);
 
    var osmarender = new OpenLayers.Layer.TMS("Osmarender",
                                              "http://dev.openstreetmap.org/~ojw/Tiles/tile.php/",
-                                             { type: 'png', getURL: getTileURL });
+                                             { type: 'png', getURL: getTileURL, displayOutsideMaxExtent: true });
    map.addLayer(osmarender);
 
    map.addControl(new OpenLayers.Control.LayerSwitcher());
@@ -35,8 +35,18 @@ function getTileURL(bounds) {
    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 limit = Math.pow(2, z);
 
-   return this.url + z + "/" + x + "/" + y + "." + this.type;
+   if (y < 0 || y >= limit)
+   {
+     return null;
+   }
+   else
+   {
+     x = ((x % limit) + limit) % limit;
+
+     return this.url + z + "/" + x + "/" + y + "." + this.type;
+   }
 }
 
 function addMarkerToMap(position, icon, description) {
@@ -89,16 +99,15 @@ function removeMarkerFromMap(marker){
 function mercatorToLonLat(merc) {
    var lon = (merc.lon / 20037508.34) * 180;
    var lat = (merc.lat / 20037508.34) * 180;
-   var PI = 3.14159265358979323846;
 
-   lat = 180/PI * (2 * Math.atan(Math.exp(lat * PI / 180)) - PI / 2);
+   lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
 
    return new OpenLayers.LonLat(lon, lat);
 }
 
 function lonLatToMercator(ll) {
    var lon = ll.lon * 20037508.34 / 180;
-   var lat = Math.log(Math.tan((90 + ll.lat) * PI / 360)) / (PI / 180);
+   var lat = Math.log(Math.tan((90 + ll.lat) * Math.PI / 360)) / (Math.PI / 180);
 
    lat = lat * 20037508.34 / 180;