GZoom enhancements

Nov 21, 2006 by Andre

I added a few things to GZoom today. What's new:

  • GZoom now works on maps that move or are resized on the page
  • new "Sticky" mode -- can stay in zoom mode for multiple zooms
  • more flexible zoom button, can use images, arbitrary text, etc.
  • tested and confirmed to work with GMaps new Marker Manager
  • you can specify optional callback functions for the following events: buttonClick,dragStart,dragging,dragEnd

See the GZoom original post, the new example, or read on for details of what's updated. Or just grab the new code:

gzoom.js -- right-click --> save as
gzoom_uncompressed.js -- right-click --> save as

Read on much more detail . . .

Advanced usage

The GZoom constructor takes three optional arguments, all three of which are hashes of key-value pairs. All three are optional, but if you want to include one, you need to include the previous hashes too, even if they are empty:

oMap.addControl(new GZoomControl({},{},{bStickyZoom:true}));

First Hash: Visual options for the overlay

The first optional hash you can pass to the GZoom constructor allows you to customize the overlay which goes over the map when you activate GZoom. The hash recognizes three keys:

  • sColor: the color of the transparent veil which is put over the map when you click "zoom...". Use a standard hex value for this. Defaults to #000.
  • nOpacity: the opacity of the veil -- a value from 0 to 1, with one 1 being totally opaque. Defaults to .2
  • sBorder: the border of the area which you drag on the map. Takes a three-part string, just as if you were specifying a border in CSS. Defaults to "2px solid blue". If you specify this value, you must provide a three-part string in the same format.
Here's an example with all three properties specified:
oMap.addControl(new GZoomControl({sColor:'#FFF',nOpacity:.4,sBorder:'1px solid yellow'}));

Second Hash: Other Options

The second hash allows you to set the following options:

Key Description Default
sButtonHTML The HTML in the "zoom" button in normal, un-activated state 'zoom ...'
oButtonStartingStyle A hash of css styles for the zoom button which are common to both un-activated and activated state {'52px',border:'1px solid black',padding:'0px 5px 1px 5px'}
oButtonStyle A hash of css styles for the zoom button which will be applied when the button is in un-activated state. {background:'#FFF'}
sButtonZoomingHTML HTML which is placed in the zoom button when the button is activated. 'Drag a region on the map'
oButtonZoomingStyle A hash of css styles for the zoom button which will be applied when the button is activated. {background:'#FF0'}
nOverlayRemoveMS number of milliseconds to wait before removing the rectangle indicating the zoomed-in area after the zoom has happened. 6000
bStickyZoom Whether or not the control stays in "zoom mode" until turned off. When true, the user can zoom repeatedly, until clicking on the zoom button again to turn zoom mode off. false
bForceCheckResize If you modify the dimensions of the map by altering the css of its containing div, you need to call map.checkResize() to alert the map that its dimensions have changed. If for some reason you'll not able to do this, setting bForceCheckResize=true will force GZoom to call checkResize on the map whenever the GZoom control is clicked. Bottom line: you shouldn't need to set this to true, and if you do it's because your code isn't doing something it should. false

Third Hash: Callbacks

The third hash allows you to set callback functions for various GZoom events:

callback name Description callback arguments
buttonClick called when the GZoom is activated by clicking on the "zoom" button. none
dragStart called when the user starts to drag a rectangle x,y -- the PIXEL values, relative to the upper-left-hand corner of the map, where the user began dragging. See the GMaps API if you need to translate this into latitude/longitude
dragging called repeatedly while the user is dragging startX,startY, currentX,currentY -- the PIXEL values of the start of the drag, and the current drag point, respectively.
dragEnd called when the user releases the mouse button, after dragging the rectangle NW LatLng, NE LatLng, SE LatLng, SW LatLng, NW GPoint, NE GPoint, SE GPoint, SW GPoint -- eight params in all, the first four describe latitude/longitudes; the second four describe pixels coordinates on the map. Either set can be used (depending on whether you need pixels or latitude/longitudes to determine the rectangle that was zoomed in upon.

An Example with Some Advanced Features

This example customizes the overlay (first hash), provides some of the additional options (second hash), and all of the callbacks (third hash): see example. The GZoom instantiation code:

  map.addControl(new GZoomControl(
		/* first set of options is for the visual overlay.*/
		{
			nOpacity:.2,
			sBorder:"2px solid red"
		},
		/* second set of options is for everything else */
		{
			sButtonHTML:"<img src="/img/spacer.gif"> 

Using an image for the button instead of text

The example above demonstrates how to substitute an image for text on the GZoom button. Basically, use the sButtonHTML and sButtonZoomingHTML arguments (in the second hash) to specify images rather than text. You can put any valid html in these arguments, even a combination of images and text. Just make sure you set the width and height of the button (through the oButtonStartingStyle) as appropriate for the look of the button. If you need to the shape/background etc. of the button to change when activated, you can set styles in the oButtonZoomingStyle argument.

Comments

1

wouter addink on Dec 13

Hi,
I like your GZoom, but I have problems when using it on a window-centered map in MSIE, like:

If you click the zoom control, the map is darkened right in mozilla, but the darkened area starts at the center in MSIE (v6). In a div without a centered style it is ok.
Any idea how I could fix this?

Wouter

2

wouter addink on Dec 13

see my previous post:
this works (but perhaps not in all browsers):

So the problem is when using style="text-align: center" on the div containing the map

Wouter

3

Tony Montana on Jan 24

Hi, I am having trouble adding the zoom feature to my map. Could someone help me?
I also cant figure out how to make the map auto scale across the page.
I also want to add scroll mouse zoom and a mini map in a corner.
this is the page I am working on:

www.nqccs.com.au/vitamin2.htm

4

Andre Lewis on Jan 25

Tony, you should try to get the built-in zoom control added to the map first. The mini-map is just another control, you can add it like anything else. For help on this stuff, try groups.google.com/group/Google-Maps-API

The scroll wheel isn't supported in the maps API, only on maps.google.com -- for now at least

5

Donald Curry on Mar 09

This is very cool! I am wondering how one could take this and grab all markers that fall within the zoom window? That way, I could have the users zoom in a certain area and display the details of all markers that fall inside the zoom area in a grid. This would be EXTREMELY useful!

6

Jeff Pendergrass on Jun 06

Question about font: I notice the word 'Zoom' is in a different font (Courier, I think) from the Google font (Arial, I think). How would one go about fixing this?

7

Andre on Jul 26

Jeff: you can define styles for the zoom control in the initialization call. See the API for details.

8

Minh Phan on Feb 24

Hi, I like this GZoomControl,
Just a question, if I want to reset the map,
How can I remove the bounding box?

Thanks

Post a comment

Stay in Touch

spacer
spacer
Recommend me at WWR -->

Last Five Posts

Rails on Ruby 1.9.1 in production: just do it
RubyMine + Snow Leopard
Business lessons learned
Load Averages, Explained
git remote branch

My Book

Available now from Apress

Categories

  • Ajax
  • Entrepreneurial
  • Gadgets
  • GeoKit
  • Google
  • Google Maps
  • How-to
  • Javascript
    • Prototype
    • jQuery
  • Misc
  • MySQL
  • Open source
  • OpenID
  • PlaceShout
  • Railsconf
  • Ruby
  • Ruby on Rails
  • SEO
  • Scout
  • ShapeWiki
  • Sinatra
  • Speaking / writing
  • Tools
    • JSLog
  • Usability
  • Web
  • Web 2.0
  • Wifi Cafes
  • git
  • iphone
  • system

My WiFi site

Top cities: San Francisco WiFi; Portland WiFi; Charlotte WiFi

 
This is so filters can reject the spam-bots. Thanks!
 
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.