Leaflet/spec/suites/layer/tile/GridLayerSpec.js
2013-12-13 18:01:06 -05:00

71 lines
1.5 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);
});
describe('#redraw', function () {
it('can be called before map.setView', function () {
var map = L.map(div),
grid = L.gridLayer().addTo(map);
expect(grid.redraw()).to.equal(grid);
});
});
describe('#setOpacity', function () {
it('can be called before map.setView', function () {
var map = L.map(div),
grid = L.gridLayer().addTo(map);
expect(grid.setOpacity(0.5)).to.equal(grid);
});
});
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]
});
});
});