From 25557cac1265916625e8d29f1b3473d6a7b88315 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 4 Dec 2012 18:13:23 -0500 Subject: [PATCH] Fine-tune zoom and center, make them properly match up with other maps --- js/id/renderer/background.js | 39 +++++++++++++++++++----------------- js/id/renderer/map.js | 7 ++++--- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/js/id/renderer/background.js b/js/id/renderer/background.js index 4032148ba..160f75424 100644 --- a/js/id/renderer/background.js +++ b/js/id/renderer/background.js @@ -62,22 +62,25 @@ iD.Background = function() { }; // derive the url of a 'quadkey' style tile from a coordinate object -iD.Background.Bing = function (coord) { - var template = 'http://ecn.t{t}.tiles.virtualearth.net/tiles/a{u}.jpeg?g=587&mkt=en-gb&n=z', - u = ''; - for (var zoom = coord[2]; zoom > 0; zoom--) { - var byte = 0; - var mask = 1 << (zoom - 1); - if ((coord[0] & mask) !== 0) byte++; - if ((coord[1] & mask) !== 0) byte += 2; - u += byte.toString(); - } - // distribute requests against multiple domains - var t = coord[2] % 5; - return template - .replace('{t}', t) - .replace('{u}', u) - .replace('{x}', coord[0]) - .replace('{y}', coord[1]) - .replace('{z}', coord[2]); +iD.Background.template = function(template) { + return function(coord) { + var u = ''; + for (var zoom = coord[2]; zoom > 0; zoom--) { + var byte = 0; + var mask = 1 << (zoom - 1); + if ((coord[0] & mask) !== 0) byte++; + if ((coord[1] & mask) !== 0) byte += 2; + u += byte.toString(); + } + // distribute requests against multiple domains + var t = coord[2] % 5; + return template + .replace('{t}', t) + .replace('{u}', u) + .replace('{x}', coord[0]) + .replace('{y}', coord[1]) + .replace('{z}', coord[2]); + }; }; + +iD.Background.Bing = iD.Background.template('http://ecn.t{t}.tiles.virtualearth.net/tiles/a{u}.jpeg?g=587&mkt=en-gb&n=z'); diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index 318129b4f..7638c98e6 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -444,9 +444,9 @@ iD.Map = function() { map.zoom = function(z) { if (!arguments.length) { - return Math.max(Math.log(projection.scale()) / Math.log(2) - 7, 0); + return Math.max(Math.log(projection.scale()) / Math.LN2 - 8, 0); } - var scale = 256 * Math.pow(2, z - 1), + var scale = 256 * Math.pow(2, z), center = pxCenter(), l = pointLocation(center); projection.scale(scale); @@ -482,7 +482,8 @@ iD.Map = function() { c = pxCenter(), ll = projection(loc); projection.translate([ - t[0] - ll[0] + c[0], t[1] - ll[1] + c[1]]); + t[0] - ll[0] + c[0], + t[1] - ll[1] + (c[1] /2)]); zoom.translate(projection.translate()); return redraw(); }