From 53121c9842e6f5f5fa356f40a2c37bcaaf8fed49 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Fri, 15 Mar 2013 16:22:54 -0400 Subject: [PATCH] Support JOSM style templates. Fixes #1023 --- js/id/renderer/background_source.js | 8 +++++++- test/spec/renderer/background.js | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/js/id/renderer/background_source.js b/js/id/renderer/background_source.js index 2df4d676c..c3a493c6b 100644 --- a/js/id/renderer/background_source.js +++ b/js/id/renderer/background_source.js @@ -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; diff --git a/test/spec/renderer/background.js b/test/spec/renderer/background.js index 52c825d06..d155814e3 100644 --- a/test/spec/renderer/background.js +++ b/test/spec/renderer/background.js @@ -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'); + }); }); - });