mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Test backgroundsource, favor not making object-functions.
This commit is contained in:
@@ -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()) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user