This library adds a drag zoom capability to a V3 Google map.
When drag zoom is enabled, holding down a designated hot key (shift | ctrl | alt)
while dragging a box around an area of interest will zoom the map in to that area when
the mouse button is released. Optionally, a visual control can also be supplied for turning
a drag zoom operation on and off.
Only one line of code is needed: google.maps.Map.enableKeyDragZoom();
NOTE: Do not use Ctrl as the hot key with Google Maps JavaScript API V3 since, unlike with V2, it causes a context menu to appear when running on the Macintosh.
Note that if the map's container has a border around it, the border widths must be specified in pixel units (or as thin, medium, or thick). This is required because of an MSIE limitation.
NL: 2009-05-28: initial port to core API V3.
NL: 2009-11-02: added a temp fix for -moz-transform for FF3.5.x using code from Paul Kulchenko (http://notebook.kulchenko.com/maps/gridmove).
NL: 2010-02-02: added a fix for IE flickering on divs onmousemove, caused by scroll value when get mouse position.
GL: 2010-06-15: added a visual control option.
For a description and examples of how to use this library, check out the how-to.
This class represents a drag zoom object for a map. The object is activated by holding down the hot key
or by turning on the visual control.
This object is created when google.maps.Map.enableKeyDragZoom
is called; it cannot be created directly.
Use google.maps.Map.getDragZoomObject
to gain access to this object in order to attach event listeners.
Events | Arguments | Description |
---|---|---|
activate |
None |
This event is fired when the hot key is pressed. |
deactivate |
bnds:LatLngBounds |
This event is fired when the hot key is released. The parameter passed is the geographic bounds of the selected area immediately before the hot key was released. |
drag |
southwestPixel:Point, northeastPixel:Point, prj:MapCanvasProjection |
This event is fired repeatedly while the user drags a box across the area of interest.
The southwest and northeast point are passed as parameters of type google.maps.Point
(for performance reasons), relative to the map container. Also passed is the projection object
so that the event listener, if necessary, can convert the pixel positions to geographic
coordinates using google.maps.MapCanvasProjection.fromContainerPixelToLatLng . |
dragend |
bnds:LatLngBounds |
This event is fired when the drag operation ends. The parameter passed is the geographic bounds of the selected area. Note that this event is not fired if the hot key is released before the drag operation ends. |
dragstart |
latlng:LatLng |
This event is fired when the drag operation begins. The parameter passed is the geographic position of the starting point. |
These are new methods added to the Google Maps JavaScript API V3's Map class.
Methods | Return Value | Description |
---|---|---|
disableKeyDragZoom() |
None |
Disables drag zoom. |
enableKeyDragZoom(opt_zoomOpts:KeyDragZoomOptions) |
None |
Enables drag zoom. The user can zoom to an area of interest by holding down the hot key
(shift | ctrl | alt ) while dragging a box around the area or by turning
on the visual control then dragging a box around the area. |
getDragZoomObject() |
DragZoom |
Returns the DragZoom object which is created when google.maps.Map.enableKeyDragZoom is called.
With this object you can use google.maps.event.addListener to attach event listeners
for the "activate", "deactivate", "dragstart", "drag", and "dragend" events. |
keyDragZoomEnabled() |
boolean |
Returns true if the drag zoom feature has been enabled. |
This class represents the optional parameter passed into google.maps.Map.enableKeyDragZoom
. There is no constructor for this class. Instead, this class is instantiated as a javascript object literal.
Properties | Type | Description |
---|---|---|
boxStyle |
Object |
An object literal defining the CSS styles of the zoom box.
Border widths must be specified in pixel units (or as thin, medium, or thick). The default value is {border: "4px solid #736AFF"} . |
key |
string |
The hot key to hold down to activate a drag zoom, shift | ctrl | alt .
NOTE: Do not use Ctrl as the hot key with Google Maps JavaScript API V3 since, unlike with V2,
it causes a context menu to appear when running on the Macintosh. Also note that the
alt hot key refers to the Option key on a Macintosh. The default value is "shift" . |
noZoom |
boolean |
A flag indicating whether to disable zooming after an area is
selected. Set this to true to allow KeyDragZoom to be used as a simple area
selection tool. The default value is false . |
veilStyle |
Object |
An object literal defining the CSS styles of the veil pane which covers the map when a drag
zoom is activated. The previous name for this property was paneStyle but the use
of this name is now deprecated. The default value is {backgroundColor: "gray", opacity: 0.25, cursor: "crosshair"} . |
visualClass |
string |
The name of the CSS class defining the styles for the visual
control. To prevent the visual control from being printed, set this property to the name of
a class, defined inside a @media print rule, which sets the CSS
display style to none . The default value is "" . |
visualEnabled |
boolean |
A flag indicating whether a visual control is to be used. The default value is false . |
visualPosition |
ControlPosition |
The position of the visual control. The default value is google.maps.ControlPosition.LEFT_TOP . |
visualPositionIndex |
number |
The index of the visual control.
The index is for controlling the placement of the control relative to other controls at the
position given by visualPosition ; controls with a lower index are placed first.
Use a negative value to place the control before any default controls. No index is
generally required. The default value is null . |
visualPositionOffset |
Size |
The width and height values
provided by this property are the offsets (in pixels) from the location at which the control
would normally be drawn to the desired drawing location. The default value is google.maps.Size(35, 0) . |
visualSize |
Size |
The width and height values provided by
this property are the size (in pixels) of each of the images within visualSprite . The default value is google.maps.Size(20, 20) . |
visualSprite |
String |
The URL of the sprite image used for showing the visual control in the on, off, and hot
(i.e., when the mouse is over the control) states. The three images within the sprite must
be the same size and arranged in on-hot-off order in a single row with no spaces between images. The default value is "http://maps.gstatic.com/mapfiles/ftr/controls/dragzoom_btn.png" . |
visualTips |
Object |
An object literal defining the help tips that appear when
the mouse moves over the visual control. The off property is the tip to be shown
when the control is off and the on property is the tip to be shown when the
control is on. The default value is {off: "Turn on drag zoom mode", on: "Turn off drag zoom mode"} . |