You can always go back to where you came from with DragZoomControl v1.1

Friday, August 10, 2007 at 5:42:00 PM

I'd like to thank Pamela for inviting me to post on this blog, and especially for encouraging me to join the Open Source library. I would encourage anyone out there to talk to her if you've written code which may be useful to the Maps API development community.

When Andre Lewis' DragZoomControl was introduced on this blog a few months ago, I was eager to use it in my own Google Maps API app. But I soon thought to myself, "Hey, wouldn't it be nice to able to back out from where the zoom had centered the map?" I looked into DragZoomControl's options and realized that I could implement a back button just by using the many callbacks available. So I did. Then Pamela saw my extension and asked me to put it in the OS library so it'd be available for all developers. So here we are today.

While coding the back button functionality, a few decisions needed to be made. I decided that the function should restore the map context (including map type) to the state prior to the last DragZoom, and that if successive DragZooms are done, then the function should take you back one step at a time (undoing the DragZooms in reverse order).

The simple example below shows the basic function. If you click the magnifying glass button on the map, you will initiate a DragZoom. Click and drag your mouse to create a rectangle and then release the mouse button - the map will zoom in to your rectangle. This is the standard DragZoom functionality. But what you will see on the map now is a new button below the first. This is the back button - click on it to restore the map to its prior state.

Now try several DragZooms in succession, drilling down to a particular area (maybe Central Park). After any number of zoom-ins, you can start clicking the back button and the map will go back in reverse order through all the steps you took.

Want to add a back button to your drag zoom? You can grab the new code from the 1.1/src folder, or wait two weeks for it to be pushed into the release directory. You can also read through a full set of examples or the class reference. As always, you can post in the developer forum with questions or suggestions.