Support JOSM style templates. Fixes #1023

This commit is contained in:
Tom MacWright
2013-03-15 16:22:54 -04:00
parent b665770bf1
commit 53121c9842
2 changed files with 11 additions and 2 deletions

View File

@@ -18,7 +18,13 @@ iD.BackgroundSource.template = function(data) {
.replace('{u}', u)
.replace('{x}', coord[0])
.replace('{y}', coord[1])
.replace('{z}', coord[2]);
.replace('{z}', coord[2])
// JOSM style
.replace('{zoom}', coord[2])
.replace(/\{(switch\:[^\}]*)\}/, function(s, r) {
var subdomains = r.split(':')[1].split(',');
return subdomains[coord[2] % subdomains.length];
});
};
generator.data = data;

View File

@@ -39,6 +39,9 @@ describe('iD.Background', function() {
var source = iD.BackgroundSource.template({ template: '{t}/{z}/{x}/{y}', subdomains: ['apples', 'oranges'] });
expect(source([0,1,1])).to.equal('oranges/1/0/1');
});
it('supports josm style templates', function() {
var source = iD.BackgroundSource.template({ template: '{switch:foo,bar}/{zoom}/{x}/{y}' });
expect(source([0,1,1])).to.equal('bar/1/0/1');
});
});
});