diff --git a/js/id/renderer/background.js b/js/id/renderer/background.js index 8bacbf019..275a6f2dc 100644 --- a/js/id/renderer/background.js +++ b/js/id/renderer/background.js @@ -1,6 +1,5 @@ iD.Background = function() { var tile = d3.geo.tile(), - scaleExtent = [0, 20], projection, cache = {}, transformProp = iD.util.prefixProperty('Transform'), @@ -17,8 +16,7 @@ iD.Background = function() { } function upZoom(t, distance) { - var az = atZoom(t, distance), - tiles = []; + var az = atZoom(t, distance), tiles = []; for (var x = 0; x < 2; x++) { for (var y = 0; y < 2; y++) { var up = [az[0] + x, az[1] + y, az[2]]; @@ -34,15 +32,16 @@ iD.Background = function() { function background() { var tiles = tile .scale(projection.scale()) + .scaleExtent(source.scaleExtent || [0, 17]) .translate(projection.translate())(), + scaleExtent = tile.scaleExtent(), z = Math.max(Math.log(projection.scale()) / Math.log(2) - 8, 0), rz = Math.max(scaleExtent[0], Math.min(scaleExtent[1], Math.floor(z))), ts = 256 * Math.pow(2, z - rz), tile_origin = [ projection.scale() / 2 - projection.translate()[0], - projection.scale() / 2 - projection.translate()[1]]; - - var ups = {}; + projection.scale() / 2 - projection.translate()[1]], + ups = {}; tiles.forEach(function(d) { d.push(source(d)); @@ -108,12 +107,5 @@ iD.Background = function() { return background; }; - background.scaleExtent = function(_) { - if (!arguments.length) return tile.scaleExtent(); - tile.scaleExtent(_); - return background; - }; - return background; }; - diff --git a/js/id/renderer/background_source.js b/js/id/renderer/background_source.js index 8e7f6e019..dffe5e9ec 100644 --- a/js/id/renderer/background_source.js +++ b/js/id/renderer/background_source.js @@ -1,8 +1,9 @@ iD.BackgroundSource = {}; // derive the url of a 'quadkey' style tile from a coordinate object -iD.BackgroundSource.template = function(template, subdomains) { - return function(coord) { +iD.BackgroundSource.template = function(template, subdomains, scaleExtent) { + scaleExtent = scaleExtent || [0, 18]; + var generator = function(coord) { var u = ''; for (var zoom = coord[2]; zoom > 0; zoom--) { var byte = 0; @@ -21,16 +22,20 @@ iD.BackgroundSource.template = function(template, subdomains) { .replace('{y}', coord[1]) .replace('{z}', coord[2]); }; + + generator.scaleExtent = scaleExtent; + + return generator; }; 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]); + [0, 1, 2, 3], [0, 20]); iD.BackgroundSource.Tiger2012 = iD.BackgroundSource.template( 'http://{t}.tile.openstreetmap.us/tiger2012_roads_expanded/{z}/{x}/{y}.png', - ['a', 'b', 'c']); + ['a', 'b', 'c'], [0, 17]); iD.BackgroundSource.OSM = iD.BackgroundSource.template( 'http://{t}.tile.openstreetmap.org/{z}/{x}/{y}.png', - ['a', 'b', 'c']); + ['a', 'b', 'c'], [0, 18]); diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index 9f5e4e6c8..4e678aefa 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -45,8 +45,7 @@ iD.Map = function() { dragging = undefined; }), background = iD.Background() - .projection(projection) - .scaleExtent([0, 20]), + .projection(projection), class_stroke = iD.Style.styleClasses('stroke'), class_fill = iD.Style.styleClasses('stroke'), class_area = iD.Style.styleClasses('area'),