mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
Support JOSM style templates. Fixes #1023
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user