I added a few things to GZoom today. What's new:
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 asRead on much more detail . . .
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}));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:
oMap.addControl(new GZoomControl({sColor:'#FFF',nOpacity:.4,sBorder:'1px solid yellow'}));
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 |
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. |
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
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
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
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
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
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!
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?
Andre on Jul 26
Jeff: you can define styles for the zoom control in the initialization call. See the API for details.
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
Last Five Posts
RubyMine + Snow Leopard
Business lessons learned
Load Averages, Explained
git remote branch
My Book
Categories
My WiFi site
Top cities: San Francisco WiFi; Portland WiFi; Charlotte WiFi
button activated second google example
for its contents. This is a safe-cache copy of the original web site.