Leaflet/spec/suites/layer/tile/GridLayerSpec.js
2013-12-02 19:18:08 +02:00

55 lines
1.0 KiB
JavaScript

describe('GridLayer', function () {
var div;
beforeEach(function () {
div = document.createElement('div');
div.style.width = '800px';
div.style.height = '600px';
div.style.visibility = 'hidden';
document.body.appendChild(div);
});
afterEach(function () {
document.body.removeChild(div);
});
it('positions tiles correctly with wrapping and bounding', function () {
var map = L.map(div).setView([0, 0], 1);
var tiles = [];
var grid = L.gridLayer();
grid.createTile = function (coords) {
var tile = document.createElement('div');
tiles.push({coords: coords, tile: tile});
return tile;
};
map.addLayer(grid);
var loaded = {};
for (var i = 0; i < tiles.length; i++) {
var coords = tiles[i].coords,
pos = L.DomUtil.getPosition(tiles[i].tile);
loaded[pos.x + ':' + pos.y] = [coords.x, coords.y];
}
expect(loaded).to.eql({
'144:44': [0, 0],
'400:44': [1, 0],
'144:300': [0, 1],
'400:300': [1, 1],
'-112:44': [1, 0],
'656:44': [0, 0],
'-112:300': [1, 1],
'656:300': [0, 1]
});
});
});