From 28f82755261133f695dba768ba0f49dbe0d9a804 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sat, 1 Dec 2012 14:56:01 -0800 Subject: [PATCH] Eliminate failing tile requests in specs --- js/id/id.js | 2 ++ js/id/renderer/background.js | 64 ++++++++++++++++++------------------ test/spec/Map.js | 9 +++-- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/js/id/id.js b/js/id/id.js index 2257c03d2..9ac5371fa 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -144,6 +144,8 @@ var iD = function(container) { } }); + map.background.source(iD.Background.Bing); + var hash = iD.Hash().map(map); if (!hash.hadHash) { diff --git a/js/id/renderer/background.js b/js/id/renderer/background.js index 3ba427f4a..fdef9449c 100644 --- a/js/id/renderer/background.js +++ b/js/id/renderer/background.js @@ -1,27 +1,6 @@ iD.Background = function() { - var template = 'http://ecn.t{t}.tiles.virtualearth.net/tiles/a{u}.jpeg?g=587&mkt=en-gb&n=z', - tile = d3.geo.tile(), - projection; - - // derive the url of a 'quadkey' style tile from a coordinate object - function tileUrl(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]); - } + var tile = d3.geo.tile(), + projection, source; // derive the tiles onscreen, remove those offscreen and position tiles // correctly for the currentstate of `projection` @@ -35,36 +14,57 @@ iD.Background = function() { return "scale(" + tiles.scale + ")translate(" + tiles.translate + ")"; }) .selectAll("image") - .data(tiles, function(d) { return [d.join(), template].join(); }); + .data(tiles, function(d) { return d; }); image.exit() .remove(); image.enter().append("image") - .attr("xlink:href", tileUrl) + .attr("xlink:href", source) .attr("width", 1) .attr("height", 1) .attr("x", function(d) { return d[0]; }) .attr("y", function(d) { return d[1]; }); } - background.projection = function(p) { + background.projection = function(_) { if (!arguments.length) return projection; - projection = p; + projection = _; return background; }; - background.size = function(size) { + background.size = function(_) { if (!arguments.length) return tile.size(); - tile.size(size); + tile.size(_); return background; }; - background.template = function(x) { - if (!arguments.length) return template; - template = x; + background.source = function(_) { + if (!arguments.length) return source; + source = _; return background; }; return background; }; + +// 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]); +}; diff --git a/test/spec/Map.js b/test/spec/Map.js index 476bcb011..d42d83bf1 100644 --- a/test/spec/Map.js +++ b/test/spec/Map.js @@ -1,14 +1,13 @@ describe('Map', function() { - var map, foo; + var container, map; beforeEach(function() { - foo = document.body.appendChild(document.createElement('div')); - foo.id = 'foo'; - map = iD.Map(d3.select('#foo').node()); + container = d3.select('body').append('div'); + map = iD.Map(container.node()); }); afterEach(function() { - foo.parentNode.removeChild(foo); + container.remove(); }); describe('#zoom', function() {