Skip to content

Commit

Permalink
Merge pull request #5738 from openstreetmap/1ec5-wkid
Browse files Browse the repository at this point in the history
Replace wkid/w/s/n/e in WMS URL templates
  • Loading branch information
1ec5 authored Jan 20, 2019
2 parents 2df39c1 + 9e3d49e commit 898b2e3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
30 changes: 25 additions & 5 deletions modules/renderer/background_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 3 additions & 1 deletion test/spec/renderer/background_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 898b2e3

Please sign in to comment.