Google Maps API Reference——Google 地图 API 文档之七-2

GMap2构造选项详解
本文详细介绍了GMap2构造选项类GMapOptions的使用方法,包括如何设置地图大小、地图类型、拖动光标等属性。同时,还介绍了GMapPane常量,用于定义覆盖物在地图上的层级关系,并探讨了GKeyboardHandler类提供的键盘事件处理功能。

class GMapOptions

This class represents optional arguments to the GMap2 constructor. It has no constructor, but is instantiated as an object literal.

Properties

PropertiesTypeDescription
size GSizeSets the size in pixels of the map. The container that is passed to the map constructor will be resized to the given size. By default, the map will assume the size of its container.
mapTypes Array of GMapTypeArray of map types to be used by this map. By default, G_DEFAULT_MAP_TYPES is used. You can use this option to restrict the set of predefined map types that is displayed on the map, or to pass your own map types to the map. See also GMap2.addMapType().
draggableCursor StringThe cursor to display when the map is draggable. (Since 2.59)
draggingCursor StringThe cursor to display while dragging the map. (Since 2.59)

enum GMapPane

These constants define the layering system that is used by overlay to display themselves on the map. There are different layers for icons, shadows, the info window, the shadow on the info window, and transparent mouse event catching objects.

You need to use this type if you subclass from GOverlay.

Constants

ConstantsDescription
G_MAP_MAP_PANEThis pane is still below the shadows of the markers, directly on top of the map. It contains for instance the polylines.
G_MAP_MARKER_SHADOW_PANEThis pane contains the shadows of the markers. It is below the markers.
G_MAP_MARKER_PANEThis pane contains the markers.
G_MAP_FLOAT_SHADOW_PANEThis pane contains the shadow of the info window. It is above the G_MAP_MARKER_PANE, so that markers can be in the shadow of the info window.
G_MAP_MARKER_MOUSE_TARGET_PANEThis pane contains transparent elements that receive DOM mouse events for the markers. Is is above the G_MAP_FLOAT_SHADOW_PANE, so that markers in the shadow of the info window can be clickable.
G_MAP_FLOAT_PANEThis pane contains the info window. It is above everything else on the map.

class GKeyboardHandler

Instantiate this class to add keyboard bindings to a map. The key bindings are the same as for the maps application.

Key(s)Action
up, down, left, rightMoves the map continuously while the key is pressed. Two keys can be pressed simultaneously in order to move diagonally.
page down, page up, home, endPans the map by 3/4 its size in the corresponding direction, with a nice animation. This corresponds to the arrow buttons in the GLargeMapControl and the GSmallMapControl.
+, -Zooms one level in or out, respectively. This corresponds to the + and - buttons in the GLargeMapControl and the GSmallMapControl.

Constructor

ConstructorDescription
GKeyboardHandler(map)Installs keyboard event handler for the map passed as argument.

interface GOverlay

This interface is implemented by the GMarker, GPolyline, GTileLayerOverlay and GInfoWindow classes in the maps API library. You can implement it if you want to display custom types of overlay objects on the map. An instance of GOverlay can be put on the map with the method GMap2.addOverlay(). The map will then call the method GOverlay.initialize() on the overlay instance to display itself on the map initially. Whenever the map display changes, the map will call GOverlay.redraw() so that the overlay can reposition itself if necessary. The overlay instance can use the method GMap2.getPane() to get hold of one or more DOM container elements to attach itself to.

Constructor

ConstructorDescription
GOverlay()This constructor creates dummy implementations for the methods. Still, when inheriting from this class, your derived class constructor should call this constructor for completeness.

Static Methods

Static MethodsReturn ValueDescription
getZIndex(latitude)NumberReturns a CSS z-index value for a given latitude. It computes a z index such that overlays further south are on top of overlays further north, thus creating the 3D appearance of marker overlays.

Abstract Methods

Abstract MethodsReturn ValueDescription
initialize(map)noneCalled by the map after the overlay is added to the map using GMap2.addOverlay(). The overlay object can draw itself into the different panes of the map that can be obtained using GMap2.getPane().
remove()noneCalled by the map after the overlay is removed from the map using GMap2.removeOverlay() or GMap2.clearOverlays(). The overlay must remove itself from the map panes here.
copy()GOverlayReturns an uninitialized copy of itself that can be added to the map.
redraw(force)noneCalled by the map when the map display has changed. The argument force will be true if the zoom level or the pixel offset of the map view has changed, so that the pixel coordinates need to be recomputed.

class GInfoWindow

GInfoWindow has no constructor. It is created by the map and accessed by its method GMap2.getInfoWindow().

Methods

MethodsReturn ValueDescription
selectTab(index)noneSelects the tab with the given index. This has the same effect as clicking on the corresponding tab.
hide()noneMakes the info window invisible. NOTE: This doesn't close the info window. It can be made visible again using show().
show()noneMakes the info window visible if its currently invisible.
isHidden()BooleanReturns true iff the info window is hidden. This includes the state that it's closed.
reset(point, tabs, size, offset?, selectedTab?)noneResets the state of the info window. Each argument may be null and then its value will not be changed from the current value.
getPoint()GLatLngReturns the geographical point at which the info window is anchored. The tip of the window points to this point on the map, modulo the pixel offset.
getPixelOffset()GSizeReturns the offset, in pixels, of the tip of the info window from the point on the map at whose geographical coordinates the info window is anchored.
getSelectedTab()NumberReturns the index, starting at 0, of the current selected tab.
getTabs()Array of GInfoWindowTabsReturns the array of tabs in this info window. (Since 2.59)
getContentContainers()Array of NodeReturns the array of DOM nodes that hold the content of the tabs of this info window. (Since 2.59)

Events

EventsArgumentsDescription
closeclicknoneThis event is fired when the info window close button is clicked. An event handler for this event can implement to close the info window, by calling the GMap2.closeInfoWindow() method.

class GInfoWindowTab

An array of instances of this class can be passed as the tabs argument to the methods GMap2.openInfoWindowTabs(), GMap2.openInfoWindowTabsHtml(), GMarker.openInfoWindowTabs(), GMarker.openInfoWindowTabsHtml(), and the GMarker.bindInfoWindow*() variants. If the array contains more than one element, the info window will be shown with tabs. Every InfoWindowTab object contains two items: content defines the content of the info window when the tab is selected, and label defines the label of the tab. The properties are passed as arguments to the constructor. For the openInfoWindowTabs() methods, content is a DOM Node. For the methods openInfoWindowTabsHtml(), content is a string that contains HTML text.

Constructor

ConstructorDescription
GInfoWindowTab(label, content)Creates an info window tab data structure that can be passed in the tabs argument to openInfoWindowTabs*() methods.

class GInfoWindowOptions

Instances of this class are used in the opts? argument to the methods openInfoWindow(), openInfoWindowHtml(), openInfoWindowTabs(), openInfoWindowTabsHtml(), the bindInfoWindow*() variants, and showMapBlowup() of classes GMap2 and GMarker. There is no constructor for this class. Instead, this class is instantiated as javascript object literal.

Properties

As the name of this class indicates, all properties are optional.

PropertiesTypeDescription
selectedTab NumberSelects the tab with the given index, starting at 0, instead of the first tab (with index 0).
maxWidth NumberMaximum width of the info window content, in pixels.
noCloseOnClick BooleanIndicates whether or not the info window should close for a click on the map that was not on a marker. If set to true, the info window will not close when the map is clicked. The default value is false. (Since 2.83)
onOpenFn FunctionFunction is called after the info window is opened and the content is displayed.
onCloseFn FunctionFunction is called when the info window is closed.
zoomLevel NumberPertinent for showMapBlowup() only. The zoom level of the blowup map in the info window.
mapType GMapTypePertinent for showMapBlowup() only. The map type of the blowup map in the info window.

class GMarker

A GMarker marks a position on the map. It implements the GOverlay interface and thus is added to the map using the GMap2.addOverlay() method.

A marker object has a point, which is the geographical position where the marker is anchored on the map, and an icon. If the icon is not set in the constructor, the default icon G_DEFAULT_ICON is used.

After it is added to a map, the info window of that map can be opened through the marker. The marker object will fire mouse events and infowindow events.

Constructor

ConstructorDescription
GMarker(point, icon?, inert?)Creates a marker at the passed point of either GPoint or GLatLng with icon or the G_DEFAULT_ICON. If the inert flag is true, then the marker is not clickable and will not fire any events. (Deprecated since 2.50)
GMarker(latlng, opts?)Creates a marker at the latlng with options specified in GMarkerOptions. By default markers are clickable & have the default icon G_DEFAULT_ICON. (Since 2.50)

Methods

Before these methods can be invoked, the marker must be added to a map.

MethodsReturn ValueDescription
openInfoWindow(content, opts?)noneOpens the map info window over the icon of the marker. The content of the info window is given as a DOM node. Only option GInfoWindowOptions.maxWidth is applicable.
openInfoWindowHtml(content, opts?)noneOpens the map info window over the icon of the marker. The content of the info window is given as a string that contains HTML text. Only option GInfoWindowOptions.maxWidth is applicable.
openInfoWindowTabs(tabs, opts?)noneOpens the tabbed map info window over the icon of the marker. The content of the info window is given as an array of tabs that contain the tab content as DOM nodes. Only options GInfoWindowOptions.maxWidth and InfoWindowOptions.selectedTab are applicable.
openInfoWindowTabsHtml(tabs, opts?)noneOpens the tabbed map info window over the icon of the marker. The content of the info window is given as an array of tabs that contain the tab content as Strings that contain HTML text. Only options InfoWindowOptions.maxWidth and InfoWindowOptions.selectedTab are applicable.
bindInfoWindow(content, opts?)noneBinds the given DOM node to this marker. The content within this node will be automatically displayed in the info window when the marker is clicked. Pass content as null to unbind. (Since 2.85)
bindInfoWindowHtml(content, opts?)noneBinds the given HTML to this marker. The HTML content will be automatically displayed in the info window when the marker is clicked. Pass content as null to unbind. (Since 2.85)
bindInfoWindowTabs(tabs, opts?)noneBinds the given GInfoWindowTabs (provided as DOM nodes) to this marker. The content within these tabs' nodes will be automatically displayed in the info window when the marker is clicked. Pass tabs as null to unbind. (Since 2.85)
bindInfoWindowTabsHtml(tabs, opts?)noneBinds the given GInfoWindowTabs (provided as strings of HTML) to this marker. The HTML content within these tabs will be automatically displayed in the info window when the marker is clicked. Pass tabs as null to unbind. (Since 2.85)
closeInfoWindow()noneCloses the info window only if it belongs to this marker. (Since 2.85)
showMapBlowup(opts?)noneOpens the map info window over the icon of the marker. The content of the info window is a closeup map around the marker position. Only options InfoWindowOptions.zoomLevel and InfoWindowOptions.mapType are applicable.
getIcon()GIconReturns the icon of this marker, as set by the constructor.
getTitle()StringReturns the title of this marker, as set by the constructor via the GMarkerOptions.title property. Returns undefined if no title is passed in. (Since 2.85)
getPoint()GLatLngReturns the geographical coordinates at which this marker is anchored, as set by the constructor or by setPoint(). (Deprecated since 2.88)
getLatLng()GLatLngReturns the geographical coordinates at which this marker is anchored, as set by the constructor or by setLatLng(). (Since 2.88)
setPoint(point)noneSets the geographical coordinates of the point at which this marker is anchored. (Deprecated since 2.88)
setLatLng(point)noneSets the geographical coordinates of the point at which this marker is anchored. (Since 2.88)
enableDragging()noneEnables the marker to be dragged and dropped around the map. To function, the marker must have been initialized with GMarkerOptions.draggable = true.
disableDragging()noneDisables the marker from being dragged and dropped around the map.
draggable()BooleanReturns true if the marker has been initialized via the constructor using GMarkerOptions.draggable = true. Otherwise, returns false.
draggingEnabled()BooleanReturns true if the marker is currently enabled for the user to drag on the map.
setImage(url)none Requests the image specified by the url to be set as the foreground image for this marker. Note that neither the print image nor the shadow image are adjusted. Therefore this method is primarily intended to implement highlighting or dimming effects, rather than drastic changes in marker's appearances. (Since 2.75)
hide()noneHides the marker if it is currently visible. Note that this function triggers the event GMarker.visibilitychanged in case the marker is currently visible. (Since 2.77)
show()noneShows the marker if it is currently hidden. Note that this function triggers the event GMarker.visibilitychanged in case the marker is currently hidden. (Since 2.77)
isHidden()BooleanReturns true if the marker is currently hidden. Otherwise returns false. (Since 2.77)

Events

All these events fire only if the marker is not inert (see constructor).

EventsArgumentsDescription
clicknoneThis event is fired when the marker icon was clicked. Notice that this event will also fire for the map, with the marker passed as the first argument to the event handler there.
dblclicknoneThis event is fired when the marker icon was double-clicked. Notice that this event will not fire for the map, because the map centers on double-click as a hardwired behavior.
mousedownnoneThis event is fired when the DOM mousedown event is fired on the marker icon. Notice that the marker will stop the mousedown DOM event, so that it doesn't cause the map to start dragging.
mouseupnoneThis event is fired for the DOM mouseup on the marker. Notice that the marker will not stop the mousedown DOM event, because it will not confuse the drag handler of the map.
mouseovernoneThis event is fired when the mouse enters the area of the marker icon.
mouseoutnoneThis event is fired when the mouse leaves the area of the marker icon.
infowindowopennoneThis event is fired when the info window of the map was opened through this marker.
infowindowbeforeclosenoneThis event is fired before the info window of the map that was opened through this marker is closed. (Since 2.83)
infowindowclosenoneThis event is fired when the info window of the map that was opened through this marker is closed. This happens when either the info window was closed, or when it was opened on another marker, or on the map. The event infowindowbeforeclose is fired before this event.
removenoneThis event is fired when the marker is removed from the map, using GMap2.removeOverlay() or GMap2.clearOverlays().
dragstartnoneIf the marker is enabled for dragging, this event is fired when the marker dragging begins.
dragnoneIf the marker is enabled for dragging, this event is fired when the marker is being dragged.
dragendnoneIf the marker is enabled for dragging, this event is fired when the marker ceases to be dragged.
visibilitychangedisVisibleThis event is fired when the visibility of the marker is changed (i.e. the visibility is flipped from visible to hidden or vice-versa). isVisible refers to the state of the marker after the visibility change has happened. (Since 2.77)

class GMarkerOptions

Instances of this class are used in the opts? argument to the constructor of the GMarker class. There is no constructor for this class. Instead, this class is instantiated as a javascript object literal.

Properties

As the name of this class indicates, all properties are optional.

PropertiesTypeDescription
icon GIconChooses the Icon for this class. If not specified, G_DEFAULT_ICON is used. (Since 2.50)
dragCrossMove BooleanWhen dragging markers normally, the marker floats up and away from the cursor. Setting this value to true keeps the marker underneath the cursor, and moves the cross downwards instead. The default value for this option is false. (Since 2.63)
title StringThis string will appear as tooltip on the marker, i.e. it will work just as the title attribute on HTML elements. (Since 2.50)
clickable BooleanToggles whether or not the marker is clickable. Markers that are not clickable or draggable are inert, consume less resources and do not respond to any events. The default value for this option is true, i.e. if the option is not specified, the marker will be clickable. (Since 2.50)
draggable BooleanToggles whether or not the marker will be draggable by users. Markers set up to be dragged require more resources to set up than markers that are clickable. Any marker that is draggable is also clickable, bouncy and auto-pan enabled by default. The default value for this option is false. (Since 2.61)
bouncy BooleanToggles whether or not the marker should bounce up and down after it finishes dragging. The default value for this option is false. (Since 2.61)
bounceGravity NumberWhen finishing dragging, this number is used to define the acceleration rate of the marker during the bounce down to earth. The default value for this option is 1. (Since 2.61)
autoPan BooleanAuto-pan the map as you drag the marker near the edge. If the marker is draggable the default value for this option is true. (Since 2.87)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值