From d7bf010f0b8e30e291ed8193fcc52d7f8fe118fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Lal?= Date: Sat, 10 Aug 2013 17:11:43 +0200 Subject: [PATCH] test Map#setMaxBounds and Map#panInsideBounds --- spec/suites/map/MapSpec.js | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 00da85d8..747ce256 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -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 () {