I'm trying to add constraining boundaries to the Zooming and Panning behaviors I've implemented for Unveil.js (http://github.com/michael/unveil). With boundaries enabled you shouldn't be able to pan outside the scene boundaries and the zoomlevel (=scale) shouldn't ever become lower than 1.0. As a result you shouldn't be able to pan at all if you're at zoomlevel 1.0.
You can see the un-constrained behavior at the stacks example: dejavis.org/stacks. Use the mousewheel to zoom. You're able to wipe the blocks out the screen or infinitely shrink them, which should be avoided.
The really hard problem is that zooming relative to mouse pointer also causes the viewport to move out of place. So checking the boundaries during panning is not enough. I'd have to find a smart way to zoom back to 100% when using the Mouswheel (without doing dirty jumps). Photoshop seems to have solved this problem when zooming a picture.
I've absolutely no idea how I should solve this. Very frustrating. :/
I'm using a Matrix to store the current View transformation which is manipulated repeatedly. Here's the implementation code for Zooming and Panning behaviors.
http://github.com/michael/unveil/blob/master/src/scene/behaviors.js
Thanks for any ideas. :)
Cheers,
Michael