Skip to content

Commit

Permalink
wrap tileBounds if noWrap is false by @Fyeah (#4908)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanSanchez authored and perliedman committed Sep 12, 2016
1 parent 8b32527 commit 63fd4ed
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
72 changes: 72 additions & 0 deletions spec/suites/layer/tile/GridLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,4 +816,76 @@ describe('GridLayer', function () {
clock.tick(250);
});
});

describe("nowrap option", function () {
it("When false, uses same coords at zoom 0 for all tiles", function (done) {

var grid = L.gridLayer({
attribution: 'Grid Layer',
tileSize: L.point(256, 256),
noWrap: false
});
var loadedTileKeys = [];

grid.createTile = function (coords) {
loadedTileKeys.push(coords.x + ':' + coords.y + ':' + coords.z);
return document.createElement('div');
};

map.addLayer(grid).setView([0, 0], 0);

grid.on('load', function () {
expect(loadedTileKeys).to.eql(["0:0:0", "0:0:0", "0:0:0", "0:0:0", "0:0:0"]);
done();
});
});

it("When true, uses different coords at zoom level 0 for all tiles", function (done) {

var grid = L.gridLayer({
attribution: 'Grid Layer',
tileSize: L.point(256, 256),
noWrap: true
});
var loadedTileKeys = [];

grid.createTile = function (coords) {
loadedTileKeys.push(coords.x + ':' + coords.y + ':' + coords.z);
return document.createElement('div');
};

map.addLayer(grid).setView([0, 0], 0);

grid.on('load', function () {
expect(loadedTileKeys).to.eql(['0:0:0', '-1:0:0', '1:0:0', '-2:0:0', '2:0:0']);
done();
});
});

it("When true and with bounds, loads just one tile at zoom level 0", function (done) {

var grid = L.gridLayer({
attribution: 'Grid Layer',
tileSize: L.point(256, 256),
bounds: [[-90, -180], [90, 180]],
noWrap: true
});
var loadedTileKeys = [];

grid.createTile = function (coords) {
loadedTileKeys.push(coords.x + ':' + coords.y + ':' + coords.z);
return document.createElement('div');
};

map.addLayer(grid).setView([0, 0], 0);

grid.on('load', function () {
expect(loadedTileKeys).to.eql(['0:0:0']);
done();
});
});
});



});
9 changes: 7 additions & 2 deletions src/layer/tile/GridLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,13 @@ L.GridLayer = L.Layer.extend({
nwPoint = coords.scaleBy(tileSize),
sePoint = nwPoint.add(tileSize),

nw = map.wrapLatLng(map.unproject(nwPoint, coords.z)),
se = map.wrapLatLng(map.unproject(sePoint, coords.z));
nw = map.unproject(nwPoint, coords.z),
se = map.unproject(sePoint, coords.z);

if (!this.options.noWrap) {
nw = map.wrapLatLng(nw);
se = map.wrapLatLng(se);
}

return new L.LatLngBounds(nw, se);
},
Expand Down

0 comments on commit 63fd4ed

Please sign in to comment.