Move scaleExtent into background sources

This commit is contained in:
Tom MacWright
2012-12-06 16:10:44 -05:00
parent 9006a746be
commit 7f6a06f9bb
3 changed files with 16 additions and 20 deletions
+5 -13
View File
@@ -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;
};
+10 -5
View File
@@ -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]);
+1 -2
View File
@@ -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'),