pngtile: fix multiple bugs with region-link centering
authorTero Marttila <terom@qmsk.net>
Sat, 04 Oct 2014 03:28:57 +0300
changeset 175 16ab69a5569a
parent 174 58c9e2de0dd4
child 176 ad32cf3a25fa
pngtile: fix multiple bugs with region-link centering
pngtile/tile.py
static/pngtile/map.js
--- a/pngtile/tile.py	Sat Oct 04 03:03:17 2014 +0300
+++ b/pngtile/tile.py	Sat Oct 04 03:28:57 2014 +0300
@@ -43,7 +43,7 @@
         Scale value about center by zoom.
     """
 
-    return scale(val, zoom) - dim / 2
+    return scale(val - dim / 2, zoom)
 
 class TileApplication (pngtile.application.PNGTileApplication):
     # age in seconds for caching an unknown-mtime image for revalidates
--- a/static/pngtile/map.js	Sat Oct 04 03:03:17 2014 +0300
+++ b/static/pngtile/map.js	Sat Oct 04 03:28:57 2014 +0300
@@ -26,12 +26,16 @@
         var map_zoom = map.getZoom();
         var size = map.getSize();
         
+        var x = (+map_center.lng) * Math.pow(2, map_config.tile_zoom);
+        var y = (-map_center.lat) * Math.pow(2, map_config.tile_zoom);
+        var zoom = map_config.tile_zoom - map_zoom;
+
         var state = {
             w: size.x,
             h: size.y,
-            x: (+map_center.lng) << map_config.tile_zoom,
-            y: (-map_center.lat) << map_config.tile_zoom,
-            z: map_config.tile_zoom - map_zoom,
+            x: x >> zoom,
+            y: y >> zoom,
+            z: zoom
         };
 
         var url = L.Util.template(this.options.url, L.extend(state, this.options));