From 731df3ce413bba1c3a161877aa9119a25cb06198 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Wed, 5 Dec 2012 17:34:47 -0500 Subject: [PATCH] Test backgroundsource, favor not making object-functions. --- js/id/id.js | 2 +- js/id/renderer/background.js | 7 +++++-- js/id/renderer/map.js | 10 ++++++++-- test/spec/renderer/background.js | 18 ++++++++++++------ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/js/id/id.js b/js/id/id.js index 453536636..34c6a6b3c 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -7,7 +7,7 @@ window.iD = function(container) { .history(history), controller = iD.Controller(map, history); - map.background.source(iD.Background.Bing); + map.background.source(iD.BackgroundSource.Bing); function editor() { if (!iD.supported()) { diff --git a/js/id/renderer/background.js b/js/id/renderer/background.js index 160f75424..c42182058 100644 --- a/js/id/renderer/background.js +++ b/js/id/renderer/background.js @@ -61,8 +61,10 @@ iD.Background = function() { return background; }; +iD.BackgroundSource = {}; + // derive the url of a 'quadkey' style tile from a coordinate object -iD.Background.template = function(template) { +iD.BackgroundSource.template = function(template) { return function(coord) { var u = ''; for (var zoom = coord[2]; zoom > 0; zoom--) { @@ -83,4 +85,5 @@ iD.Background.template = function(template) { }; }; -iD.Background.Bing = iD.Background.template('http://ecn.t{t}.tiles.virtualearth.net/tiles/a{u}.jpeg?g=587&mkt=en-gb&n=z'); +iD.BackgroundSource.Bing = iD.BackgroundSource.template( + 'http://ecn.t{t}.tiles.virtualearth.net/tiles/a{u}.jpeg?g=587&mkt=en-gb&n=z'); diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index dcaf8e089..0f359fe16 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -54,6 +54,7 @@ iD.Map = function() { class_area = iD.Style.styleClasses('area'), class_casing = iD.Style.styleClasses('casing'), transformProp = iD.util.prefix() + 'transform', + support3d = iD.util.prefix() === 'O', supersurface, surface, defs, tilegroup, r, g, alength; function map() { @@ -304,8 +305,13 @@ iD.Map = function() { if (!translateStart) translateStart = d3.event.translate.slice(); var a = d3.event.translate, b = translateStart; - surface.style(transformProp, - 'translate3d(' + ~~(a[0] - b[0]) + 'px,' + ~~(a[1] - b[1]) + 'px, 0px)'); + if (support3d) { + surface.style(transformProp, + 'translate3d(' + ~~(a[0] - b[0]) + 'px,' + ~~(a[1] - b[1]) + 'px, 0px)'); + } else { + surface.style(transformProp, + 'translate(' + ~~(a[0] - b[0]) + 'px,' + ~~(a[1] - b[1]) + 'px)'); + } } else { redraw(); translateStart = null; diff --git a/test/spec/renderer/background.js b/test/spec/renderer/background.js index 42bc221e7..110d7786f 100644 --- a/test/spec/renderer/background.js +++ b/test/spec/renderer/background.js @@ -3,8 +3,7 @@ describe('Background', function() { beforeEach(function() { d = d3.select(document.createElement('div')); - c = iD.Background() - .projection(d3.geo.mercator()); + c = iD.Background().projection(d3.geo.mercator()); d.call(c); }); @@ -23,14 +22,21 @@ describe('Background', function() { }); it('#source', function() { - expect(c.source(iD.Background.Bing)).to.equal(c); - expect(c.source()).to.equal(iD.Background.Bing); + expect(c.source(iD.BackgroundSource.Bing)).to.equal(c); + expect(c.source()).to.equal(iD.BackgroundSource.Bing); }); }); - describe('iD.Background.Bing', function() { + describe('iD.BackgroundSource.Bing', function() { it('generates tiles', function() { - expect(iD.Background.Bing([0,0,0])).to.equal('http://ecn.t0.tiles.virtualearth.net/tiles/a.jpeg?g=587&mkt=en-gb&n=z'); + expect(iD.BackgroundSource.Bing([0,0,0])).to.equal('http://ecn.t0.tiles.virtualearth.net/tiles/a.jpeg?g=587&mkt=en-gb&n=z'); + }); + }); + + describe('iD.BackgroundSource.Template', function() { + it('generates a tile-generating source', function() { + var source = iD.BackgroundSource.template('{z}/{x}/{y}'); + expect(source([0,1,2])).to.equal('2/0/1'); }); });