Deep Zoom - Restricting the Zoom Level

If you have used the Deep Zoom Composer to generate a Silverlight project, then one thing you may notice is that your users can zoom out so far that they can't see anything!  It is actually quite easy to lose the image completely and not be able to get back to seeing anything.  Alternatively you may want to restrict how far they can zoom in too, so they don't start to see "blocky" images.

A simple fix for this is to modify the Zoom method in Page.Xaml.cs with the following:

 

public void Zoom(double zoom, Point pointToZoom)
        {
            bool zoomingIn = zoom > 1;
            bool zoomingOut = zoom < 1;
            double minViewportWidth = 0.05;
            double maxViewportWidth = 1;

            if (msi.ViewportWidth < minViewportWidth && zoomingIn)
            {
                return;
            }

            if (msi.ViewportWidth > maxViewportWidth && zoomingOut)
            {
                return;
            }

            Point logicalPoint = this.msi.ElementToLogicalPoint(pointToZoom);
            this.msi.ZoomAboutLogicalPoint(zoom, logicalPoint.X, logicalPoint.Y);
            
        }

 

This still allows users who are quick with the mouse wheel to take effect of the spring zoom and go a little further than defined but it does offers a simple solution to a common problem.

 

Cheers

 

Ian

Technorati Tags: ,

posted @ Saturday, August 16, 2008 7:58 AM

Print

Comments on this entry:

# re: Deep Zoom - Restricting the Zoom Level

Left by lutz at 8/18/2008 11:02 PM
Gravatar
Actually, this doesn't necessarily look good if you do it this way. Since you only check the value on zoom, you may go past your bounds before the next time you zoom and check things. that results in popping when the user flicks the wheel fast.

I propose another solution on my page.

# re: Deep Zoom - Restricting the Zoom Level

Left by Ian Blackburn at 8/19/2008 8:00 PM
Gravatar
Thanks Lutz - that is a great sample that solves the issue I mentioned and you highlighted.

Cheers

Ian

# wmvqkbia

Left by wmvqkbia at 9/22/2008 11:17 AM
Gravatar
wmvqkbia
Comments have been closed on this topic.