Skip to content

Commit

Permalink
Do not calculate inverted y coords for CRSes with infinite: true
Browse files Browse the repository at this point in the history
Fixes #4338
  • Loading branch information
jieter committed Mar 22, 2016
1 parent 73c8242 commit ccaf632
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
20 changes: 20 additions & 0 deletions spec/suites/layer/tile/TileLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,26 @@ describe('TileLayer', function () {
});
});

it('Does not replace {-y} on map with infinite CRS', function () {
var simplediv = document.createElement('div');
simplediv.style.width = '400px';
simplediv.style.height = '400px';
simplediv.style.visibility = 'hidden';

document.body.appendChild(simplediv);
var simpleMap = L.map(simplediv, {
crs: L.CRS.Simple
}).setView([0, 0], 5);
var layer = L.tileLayer('http://example.com/{z}/{-y}/{x}.png');

expect(function () {
layer.addTo(simpleMap);
}).to.throwError('No value provided for variable {-y}');

simpleMap.remove();
document.body.removeChild(simplediv);
});

it('replaces {s} with [abc] by default', function () {
var layer = L.tileLayer('http://{s}.example.com/{z}/{-y}/{x}.png').addTo(map);

Expand Down
18 changes: 12 additions & 6 deletions src/layer/tile/TileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,22 @@ L.TileLayer = L.GridLayer.extend({
},

getTileUrl: function (coords) {
var invertedY = this._globalTileRange.max.y - coords.y;

return L.Util.template(this._url, L.extend({
var data = {
r: L.Browser.retina ? '@2x' : '',
s: this._getSubdomain(coords),
x: coords.x,
y: this.options.tms ? invertedY : coords.y,
'-y': invertedY,
y: coords.y,
z: this._getZoomForUrl()
}, this.options));
};
if (this._map && !this._map.options.crs.infinite) {
var invertedY = this._globalTileRange.max.y - coords.y;
if (this.options.tms) {
data['y'] = invertedY;
}
data['-y'] = invertedY;
}

return L.Util.template(this._url, L.extend(data, this.options));
},

_tileOnLoad: function (done, tile) {
Expand Down

0 comments on commit ccaf632

Please sign in to comment.