From 5c6c2713944ef6677b00a29b8b7b25ede49ef866 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 6 Dec 2012 11:12:06 -0500 Subject: [PATCH] Split background sources into background_source --- index.html | 1 + js/id/renderer/background.js | 36 ----------------------------- js/id/renderer/background_source.js | 36 +++++++++++++++++++++++++++++ test/index.html | 1 + 4 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 js/id/renderer/background_source.js diff --git a/index.html b/index.html index c468ca7a0..38a17504b 100644 --- a/index.html +++ b/index.html @@ -30,6 +30,7 @@ + diff --git a/js/id/renderer/background.js b/js/id/renderer/background.js index cb5ade511..92d1f2464 100644 --- a/js/id/renderer/background.js +++ b/js/id/renderer/background.js @@ -63,39 +63,3 @@ iD.Background = function() { return background; }; -iD.BackgroundSource = {}; - -// derive the url of a 'quadkey' style tile from a coordinate object -iD.BackgroundSource.template = function(template, subdomains) { - 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 = subdomains ? - subdomains[coord[2] % subdomains.length] : ''; - return template - .replace('{t}', t) - .replace('{u}', u) - .replace('{x}', coord[0]) - .replace('{y}', coord[1]) - .replace('{z}', coord[2]); - }; -}; - -iD.BackgroundSource.Bing = iD.BackgroundSource.template( - 'http://ecn.t{t}.tiles.virtualearth.net/tiles/a{u}.jpeg?g=587&mkt=en-gb&n=z', - [0, 1, 2, 3]); - -iD.BackgroundSource.Tiger2012 = iD.BackgroundSource.template( - 'http://{t}.tile.openstreetmap.us/tiger2012_roads_expanded/{z}/{x}/{y}.png', - ['a', 'b', 'c']); - -iD.BackgroundSource.OSM = iD.BackgroundSource.template( - 'http://{t}.tile.openstreetmap.org/{z}/{x}/{y}.png', - ['a', 'b', 'c']); diff --git a/js/id/renderer/background_source.js b/js/id/renderer/background_source.js new file mode 100644 index 000000000..8e7f6e019 --- /dev/null +++ b/js/id/renderer/background_source.js @@ -0,0 +1,36 @@ +iD.BackgroundSource = {}; + +// derive the url of a 'quadkey' style tile from a coordinate object +iD.BackgroundSource.template = function(template, subdomains) { + 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 = subdomains ? + subdomains[coord[2] % subdomains.length] : ''; + return template + .replace('{t}', t) + .replace('{u}', u) + .replace('{x}', coord[0]) + .replace('{y}', coord[1]) + .replace('{z}', coord[2]); + }; +}; + +iD.BackgroundSource.Bing = iD.BackgroundSource.template( + 'http://ecn.t{t}.tiles.virtualearth.net/tiles/a{u}.jpeg?g=587&mkt=en-gb&n=z', + [0, 1, 2, 3]); + +iD.BackgroundSource.Tiger2012 = iD.BackgroundSource.template( + 'http://{t}.tile.openstreetmap.us/tiger2012_roads_expanded/{z}/{x}/{y}.png', + ['a', 'b', 'c']); + +iD.BackgroundSource.OSM = iD.BackgroundSource.template( + 'http://{t}.tile.openstreetmap.org/{z}/{x}/{y}.png', + ['a', 'b', 'c']); diff --git a/test/index.html b/test/index.html index 5f681b444..f5234875f 100644 --- a/test/index.html +++ b/test/index.html @@ -33,6 +33,7 @@ +