From 478696a189baf30e76e40c9738be5a3dd2ebf5fe Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 28 Feb 2013 15:57:37 -0500 Subject: [PATCH] Offsets are now relative to zoom level --- js/id/renderer/background.js | 15 ++++++++++----- js/id/ui/layerswitcher.js | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/js/id/renderer/background.js b/js/id/renderer/background.js index 8a14dc0f3..2336ee0c0 100644 --- a/js/id/renderer/background.js +++ b/js/id/renderer/background.js @@ -78,6 +78,11 @@ iD.Background = function() { return cache[r[3]] !== false; }); + var pixeloffset = [ + Math.round(offset[0] * Math.pow(2, z)), + Math.round(offset[1] * Math.pow(2, z)) + ]; + function load(d) { cache[d[3]] = true; d3.select(this) @@ -97,8 +102,8 @@ iD.Background = function() { var _ts = tileSize[0] * Math.pow(2, z - d[2]); var scale = tileSizeAtZoom(d, z); return 'translate(' + - (Math.round((d[0] * _ts) - tile_origin[0]) + offset[0]) + 'px,' + - (Math.round((d[1] * _ts) - tile_origin[1]) + offset[1]) + 'px)' + + (Math.round((d[0] * _ts) - tile_origin[0]) + pixeloffset[0]) + 'px,' + + (Math.round((d[1] * _ts) - tile_origin[1]) + pixeloffset[1]) + 'px)' + 'scale(' + scale + ',' + scale + ')'; } @@ -134,9 +139,9 @@ iD.Background = function() { return background; }; - background.nudge = function(_) { - offset[0] += _[0]; - offset[1] += _[1]; + background.nudge = function(_, zoomlevel) { + offset[0] += _[0] / Math.pow(2, zoomlevel); + offset[1] += _[1] / Math.pow(2, zoomlevel); return background; }; diff --git a/js/id/ui/layerswitcher.js b/js/id/ui/layerswitcher.js index 5c6c57ff4..955c66938 100644 --- a/js/id/ui/layerswitcher.js +++ b/js/id/ui/layerswitcher.js @@ -174,7 +174,7 @@ iD.ui.LayerSwitcher = function(context) { ['bottom', [0, 1]]]; function nudge(d) { - context.background().nudge(d[1]); + context.background().nudge(d[1], context.map().zoom()); context.redraw(); }