All pastes #1983499 Raw Edit

Someone

public text v1 · immutable
#1983499 ·published 2010-11-06 09:38 UTC
rendered paste body
diff -Nur osm_vanilla/OpenLayers-2.10/lib//OpenLayers/Layer/XYZ.js OpenLayers-2.10/lib//OpenLayers/Layer/XYZ.js
--- osm_vanilla/OpenLayers-2.10/lib//OpenLayers/Layer/XYZ.js	2010-09-02 23:43:25.000000000 +0200
+++ OpenLayers-2.10/lib//OpenLayers/Layer/XYZ.js	2010-11-06 00:20:55.571034709 +0100
@@ -53,15 +53,16 @@
      * options - {Object} Hashtable of extra options to tag onto the layer
      */
     initialize: function(name, url, options) {
+        factor = 1.48607709750566893424;
         if (options && options.sphericalMercator || this.sphericalMercator) {
             options = OpenLayers.Util.extend({
                 maxExtent: new OpenLayers.Bounds(
-                    -128 * 156543.0339,
-                    -128 * 156543.0339,
-                    128 * 156543.0339,
-                    128 * 156543.0339
+                    -128 * 156543.0339 * factor,
+                    -128 * 156543.0339 * factor,
+                    128 * 156543.0339 * factor,
+                    128 * 156543.0339 * factor
                 ),
-                maxResolution: 156543.0339,
+                maxResolution: 156543.0339 * factor,
                 numZoomLevels: 19,
                 units: "m",
                 projection: "EPSG:900913"
@@ -110,9 +111,18 @@
      */
     getURL: function (bounds) {
         var res = this.map.getResolution();
-        var x = Math.round((bounds.left - this.maxExtent.left) 
+        var f = 1.48607709750566893424;
+
+
+        // TODO: why exactly is bounds incorrect?
+
+        var left = f * Math.sqrt(1/f) * (bounds.left - this.maxExtent.left/f) + (this.maxExtent.left);
+
+
+        var x = Math.round((left - this.maxExtent.left) 
             / (res * this.tileSize.w));
-        var y = Math.round((this.maxExtent.top - bounds.top) 
+        var top = - (f / Math.sqrt(f)) * ((this.maxExtent.top/f) - bounds.top) + this.maxExtent.top;
+        var y = Math.round((this.maxExtent.top - top) 
             / (res * this.tileSize.h));
         var z = this.map.getZoom() + this.zoomOffset;