From fa2d04dfe749ee7d31477158d5daedfeb03e7c33 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Fri, 30 Nov 2012 17:25:48 -0500 Subject: [PATCH] Support other tilesets, xyz tiles, etc. Fixes #130 --- index.html | 4 +++- js/id/id.js | 2 ++ js/id/renderer/map.js | 1 + js/id/renderer/tiles.js | 17 +++++++++++++++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index ba5386c81..44d5fb8b2 100644 --- a/index.html +++ b/index.html @@ -50,6 +50,8 @@
- + diff --git a/js/id/id.js b/js/id/id.js index 1e90953e1..fab9fdd1d 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -149,6 +149,8 @@ var iD = function(container) { d3.select('.user').call(iD.userpanel(connection) .on('logout', connection.logout) .on('login', connection.authenticate)); + + return map; }; iD.supported = function() { diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index 3d0d66b2c..885444643 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -510,6 +510,7 @@ iD.Map = function(elem, connection) { map.selectEntity = selectEntity; + map.tileclient = tileclient; map.center = center; map.centre = center; map.getZoom = getZoom; diff --git a/js/id/renderer/tiles.js b/js/id/renderer/tiles.js index 8987e1d48..d9bbadfa9 100644 --- a/js/id/renderer/tiles.js +++ b/js/id/renderer/tiles.js @@ -1,5 +1,6 @@ iD.Tiles = function(selection, projection) { var t = {}, + template = 'http://ecn.t{t}.tiles.virtualearth.net/tiles/a{u}.jpeg?g=587&mkt=en-gb&n=z', tile = d3.geo.tile(); // derive the url of a 'quadkey' style tile from a coordinate object @@ -14,7 +15,12 @@ iD.Tiles = function(selection, projection) { } // distribute requests against multiple domains var t = coord[2] % 5; - return 'http://ecn.t' + t + '.tiles.virtualearth.net/tiles/a' + u + '.jpeg?g=587&mkt=en-gb&n=z'; + return template + .replace('{t}', t) + .replace('{u}', u) + .replace('{x}', coord[0]) + .replace('{y}', coord[1]) + .replace('{z}', coord[2]); } // derive the tiles onscreen, remove those offscreen and position tiles @@ -29,7 +35,7 @@ iD.Tiles = function(selection, projection) { return "scale(" + tiles.scale + ")translate(" + tiles.translate + ")"; }) .selectAll("image") - .data(tiles, function(d) { return d; }); + .data(tiles, function(d) { return [d.join(), template].join(); }); image.exit() .remove(); @@ -48,6 +54,13 @@ iD.Tiles = function(selection, projection) { return t; } + t.template = function(x) { + if (!arguments.length) return template; + template = x; + redraw(); + return t; + }; + t.setSize = setSize; t.redraw = redraw;