diff --git a/modules/renderer/background_source.js b/modules/renderer/background_source.js index 9d4440961..174df4884 100644 --- a/modules/renderer/background_source.js +++ b/modules/renderer/background_source.js @@ -124,13 +124,33 @@ export function rendererBackgroundSource(data) { } }).bind(this); + var tileSize = this.tileSize; + var projection = this.projection; var minXmaxY = tileToProjectedCoords(coord[0], coord[1], coord[2]); var maxXminY = tileToProjectedCoords(coord[0]+1, coord[1]+1, coord[2]); - return template - .replace('{width}', this.tileSize) - .replace('{height}', this.tileSize) - .replace('{proj}', this.projection) - .replace('{bbox}', minXmaxY.x + ',' + maxXminY.y + ',' + maxXminY.x + ',' + minXmaxY.y); + return template.replace(/\{(\w+)\}/g, function (token, key) { + switch (key) { + case 'width': + case 'height': + return tileSize; + case 'proj': + return projection; + case 'wkid': + return projection.replace(/^EPSG:/, ''); + case 'bbox': + return minXmaxY.x + ',' + maxXminY.y + ',' + maxXminY.x + ',' + minXmaxY.y; + case 'w': + return minXmaxY.x; + case 's': + return maxXminY.y; + case 'n': + return maxXminY.x; + case 'e': + return minXmaxY.y; + default: + return token; + } + }); } return template .replace('{x}', coord[0]) diff --git a/test/spec/renderer/background_source.js b/test/spec/renderer/background_source.js index 2289676a4..96d4161bf 100644 --- a/test/spec/renderer/background_source.js +++ b/test/spec/renderer/background_source.js @@ -16,11 +16,13 @@ describe('iD.rendererBackgroundSource', function() { var source = iD.rendererBackgroundSource({ type: 'wms', projection: 'EPSG:3857', - template: 'SRS={proj}&FORMAT=image/jpeg&WIDTH={width}&HEIGHT={height}&BBOX={bbox}' + template: 'SRS={proj}&imageSR={wkid}&bboxSR={wkid}&FORMAT=image/jpeg&WIDTH={width}&HEIGHT={height}&BBOX={bbox}' }); var result = iD.utilStringQs(source.url([0,1,2])); expect(result.SRS).to.equal('EPSG:3857'); + expect(result.imageSR).to.equal('3857'); + expect(result.bboxSR).to.equal('3857'); expect(result.FORMAT).to.equal('image/jpeg'); expect(result.WIDTH).to.equal('256'); expect(result.HEIGHT).to.equal('256');