[Pkg-javascript-commits] [leaflet] 128/301: test Map#setMaxBounds and Map#panInsideBounds
Jonas Smedegaard
js at moszumanska.debian.org
Mon Jan 27 22:22:46 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository leaflet.
commit d7bf010f0b8e30e291ed8193fcc52d7f8fe118fd
Author: Jérémy Lal <kapouer at melix.org>
Date: Sat Aug 10 17:11:43 2013 +0200
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 00da85d..747ce25 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 () {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet.git
More information about the Pkg-javascript-commits
mailing list