test Map#setMaxBounds and Map#panInsideBounds

This commit is contained in:
Jérémy Lal 2013-08-10 17:11:43 +02:00
parent 2974cacff4
commit d7bf010f0b

View File

@ -139,6 +139,46 @@ describe("Map", function () {
});
});
describe('#setMaxBounds', function() {
it("aligns pixel-wise map view center with maxBounds center if it cannot move view bounds inside maxBounds (#1908)", function() {
var container = map.getContainer();
// large view, cannot fit within maxBounds
container.style.width = container.style.height = "1000px";
document.body.appendChild(container);
// maxBounds
var bounds = L.latLngBounds([51.5, -0.05], [51.55, 0.05]);
map.setMaxBounds(bounds, {animate: false});
// set view outside
map.setView(L.latLng([53.0, 0.15]), 12, {animate: false});
// get center of bounds in pixels
var boundsCenter = map.project(bounds.getCenter());
boundsCenter = {x: Math.round(boundsCenter.x), y: Math.round(boundsCenter.y)};
expect(map.project(map.getCenter())).to.eql(boundsCenter);
document.body.removeChild(container);
});
it("moves map view within maxBounds by changing one coordinate", function() {
var container = map.getContainer();
// small view, can fit within maxBounds
container.style.width = container.style.height = "200px";
document.body.appendChild(container);
// maxBounds
var bounds = L.latLngBounds([51, -0.2], [52, 0.2]);
map.setMaxBounds(bounds, {animate: false});
// set view outside maxBounds on one direction only
// leaves untouched the other coordinate (that is not already centered)
var initCenter = [53.0, 0.1];
map.setView(L.latLng(initCenter), 16, {animate: false});
// one pixel coordinate hasn't changed, the other has
var pixelCenter = map.project(map.getCenter());
var pixelInit = map.project(initCenter);
expect(pixelCenter.x).to.eql(Math.round(pixelInit.x));
expect(pixelCenter.y).not.to.eql(Math.round(pixelInit.y));
// the view is inside the bounds
expect(bounds.contains(map.getBounds())).to.be(true);
document.body.removeChild(container);
});
});
describe("#getMinZoom and #getMaxZoom", function () {
describe('#getMinZoom', function () {
it('returns 0 if not set by Map options or TileLayer options', function () {