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

本文详细介绍了地图覆盖物API的功能,包括多边形(GPolygon)、折线(GPolyline)和地面覆盖物(GGroundOverlay)等各类覆盖物的创建、使用方法及属性设置。涵盖了构造函数、工厂方法、事件监听等功能,并提供了关于图标(GIcon)、点(GPoint)、尺寸(GSize)等基本元素的定义。

class GPolyline

This is a map overlay that draws a polyline on the map, using the vector drawing facilities of the browser if they are available, or an image overlay from Google servers otherwise.

Constructor

ConstructorDescription
GPolyline(latlngs, color?, weight?, opacity?, opts?)Creates a polyline from an array of vertices. The color is given as a string that contains the color in hexadecimal numeric HTML style, i.e. #RRGGBB. The weight is the width of the line in pixels. The opacity is given as a number between 0 and 1. The line will be antialiased and semitransparent.

Factory Methods

Factory MethodsReturn ValueDescription
fromEncoded(color?, weight?, opacity?, points, zoomFactor, levels, numLevels)GPolylineCreates a polyline from encoded strings of aggregated points and levels. color is a string that contains a hexadecimal numeric HTML style, i.e. #RRGGBB. weight is the width of the line in pixels. opacity is a number between 0 and 1. points is a string containing the encoded latitude and longitude coordinates. levels is a string containing the encoded polyline zoom level groups. numLevels is the number of zoom levels contained in the encoded levels string. zoomFactor is the magnification between adjacent sets of zoom levels in the encoded levels string. Together, these two values determine the precision of the levels within an encoded polyline. The line will be antialiased and semitransparent. (Since 2.63)

Methods

MethodsReturn ValueDescription
getVertexCount()NumberReturns the number of vertices in the polyline. (Since 2.46)
getVertex(index)GLatLngReturns the vertex with the given index in the polyline. (Since 2.46)
getLength()NumberReturns the length (in meters) of the polyline along the surface of a spherical Earth. (Since 2.85)
getBounds()GLatLngBoundsReturns the bounds for this polyline. (Since 2.85)
hide()noneHides the polyline if it is both currently visible and GPolyline.supportsHide() returns true. Note that this function triggers the event GPolyline.visibilitychanged in case the polyline is currently visible. (Since 2.87)
isHidden()BooleanReturns true if the polyline is currently hidden. Otherwise returns false. (Since 2.87)
show()noneShows the polyline if it is currently hidden. Note that this function triggers the event GPolyline.visibilitychanged in case the polyline is currently hidden. (Since 2.87)
supportsHide()BooleanReturns true if GPolyline.hide() is supported in the current environment for GPolyline objects. Otherwise returns false. (Since 2.87)

Events

EventsArgumentsDescription
removenoneThis event is fired when the polyline is removed from the map, using GMap2.removeOverlay() or GMap2.clearOverlays().
visibilitychangedisVisibleThis event is fired when the visibility state of the polyline toggles from visible to hidden or vice versa. The isVisible argument reflects the state of the polyline after completion of this visibility state. (Since 2.87)
clicklatlngThis event is fired when the polyline is clicked. Note that this event also subsequently triggers a "click" event on the map, where the polyline is passed as the overlay argument within that event. (Since 2.88)

class GPolylineOptions

Instances of this class are used in GPolyline's constructor. 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
clickable BooleanToggles whether or not the polyline is clickable. The default value for this option is true, i.e. if the option is not specified, the polyline will be clickable. (Since 2.91)
geodesic BooleanRender each edge of the polyline as a geodesic (a segment of a "great circle"). A geodesic is the shortest path between two points along the surface of the Earth. (Since 2.84)

class GPolygon

This is very similar to a GPolyline, except that you can additionally specify a fill color and opacity.

Constructor

ConstructorDescription
GPolygon(points, strokeColor?, strokeWeight?, strokeOpacity?, fillColor?, fillOpacity?, opts?)Creates a polygon from an array of vertices. The colors are given as a string that contains the color in hexadecimal numeric HTML style, i.e. #RRGGBB. The weight is the width of the line in pixels. The opacities is given as a number between 0 and 1. The line will be antialiased and semitransparent. (Since 2.69)

Factory Methods

Factory MethodsReturn ValueDescription
fromEncoded(polylines, fill?, color?, opacity?, outline?)GPolygonCreates a polygon (consisting of a number of polylines) from encoded strings of aggregated points and levels. polylines contains an associative array of constituent polylines, encoded in the same format as described in the GPolyline.fromEncoded documentation. fill specifies whether to fill in the polygon with a certain color. opacity and outline specifies whether to stroke the polygon with the polyline's color, weight and opacity. In case multiple values are specified in polylines, the first polyline's values are taken. (Since 2.78)

Methods

MethodsReturn ValueDescription
getVertexCount()NumberReturns the number of vertices in the polygon. (Since 2.69)
getVertex(index)GLatLngReturns the vertex with the given index in the polygon. (Since 2.69)
getArea()NumberReturns the area (in square meters) of the polygon, assuming a spherical Earth. (Since 2.85)
getBounds()GLatLngBoundsReturns the bounds for this polygon. (Since 2.85)
hide()noneHides the polygon if it is both currently visible and GPolygon.supportsHide returns true. Note that this function triggers the event GPolygon.visibilitychanged in case the polygon is currently visible. (Since 2.87)
isHidden()BooleanReturns true if the polygon is currently hidden. Otherwise returns false. (Since 2.87)
show()noneShows the polygon if it is currently hidden. Note that this function triggers the event GPolygon.visibilitychanged in case the polygon is currently hidden. (Since 2.87)
supportsHide()BooleanReturns true if GPolygon.hide() is supported in the current environment for GPolygon objects. Otherwise returns false. (Since 2.87)

Events

EventsArgumentsDescription
removenoneThis event is fired when the polygon is removed from the map, using GMap2.removeOverlay() or GMap2.clearOverlays().
visibilitychangedisVisibleThis event is fired when the visibility state of the polygon toggles from visible to hidden or vice versa. The isVisible argument reflects the state of the polygon after completion of this visibility state. (Since 2.87)
clicklatlngThis event is fired when the polygon is clicked. Note that this event also subsequently triggers a "click" event on the map, where the polygon is passed as the overlay argument within that event. (Since 2.88>)

class GPolygonOptions

Instances of this class are used in GPolygon's constructor. 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
clickable BooleanToggles whether or not the polygon is clickable. The default value for this option is true, i.e. if the option is not specified, the polygon will be clickable. (Since 2.91)

class GGroundOverlay

This object creates a rectangular image overlay on the map, whose boundaries are defined by GLatLngBounds.

Constructor

ConstructorDescription
GGroundOverlay(imageUrl, bounds)Creates a ground overlay from an image URL and its bounds. (Since 2.79)

Methods

MethodsReturn ValueDescription
hide()noneHides the ground overlay if it is currently visible. Note that this function triggers the event GGroundOverlay.visibilitychanged in case the ground overlay is currently visible. (Since 2.87)
isHidden()BooleanReturns true if the ground overlay is currently hidden. Otherwise returns false. (Since 2.87)
show()noneShows the ground overlay if it is currently hidden. Note that this function triggers the event GGroundOverlay.visibilitychanged in case the ground overlay is currently hidden. (Since 2.87)
supportsHide()BooleanAlways returns true. (Since 2.87)

Events

EventsArgumentsDescription
visibilitychangedisVisibleThis event is fired when the visibility state of the ground overlay toggles from visible to hidden or vice versa. The isVisible argument reflects the state of the ground overlay after completion of this visibility state. (Since 2.77)

class GIcon

An icon specifies the images used to display a GMarker on the map. For browser compatibility reasons, specifying an icon is actually quite complex. Note that you can use the default Maps icon G_DEFAULT_ICON if you don't want to specify your own.

Constructor

ConstructorDescription
GIcon(copy?, image?)Creates a new icon object. If another icon is given in the optional copy argument, its properties are copied, otherwise they are left empty. The optional argument image sets the value of the image property.

Constants

ConstantsDescription
G_DEFAULT_ICONThe default icon used by markers.

Properties

PropertiesTypeDescription
image StringThe foreground image URL of the icon.
shadow StringThe shadow image URL of the icon.
iconSize GSizeThe pixel size of the foreground image of the icon.
shadowSize GSizeThe pixel size of the shadow image.
iconAnchor GPointThe pixel coordinate relative to the top left corner of the icon image at which this icon is anchored to the map.
infoWindowAnchor GPointThe pixel coordinate relative to the top left corner of the icon image at which the info window is anchored to this icon.
printImage StringThe URL of the foreground icon image used for printed maps. It must be the same size as the main icon image given by image.
mozPrintImage StringThe URL of the foreground icon image used for printed maps in Firefox/Mozilla. It must be the same size as the main icon image given by image.
printShadow StringThe URL of the shadow image used for printed maps. It should be a GIF image since most browsers cannot print PNG images.
transparent StringThe URL of a virtually transparent version of the foreground icon image used to capture click events in Internet Explorer. This image should be a 24-bit PNG version of the main icon image with 1% opacity, but the same shape and size as the main icon.
imageMap Array of NumberAn array of integers representing the x/y coordinates of the image map we should use to specify the clickable part of the icon image in browsers other than Internet Explorer.
maxHeight IntegerSpecifies the distance in pixels in which a marker will visually "rise" vertically when dragged. (Since 2.79)
dragCrossImage StringSpecifies the cross image URL when an icon is dragged. (Since 2.79)
dragCrossSize GSizeSpecifies the pixel size of the cross image when an icon is dragged. (Since 2.79)
dragCrossAnchor GPointSpecifies the pixel coordinate offsets (relative to the iconAnchor) of the cross image when an icon is dragged. (Since 2.79)

class GPoint

A GPoint represents a point on the map by its pixel coordinates. Notice that in v2, it doesn't represent a point on the earth by its geographical coordinates anymore. Geographical coordinates are now represented by GLatLng.

In the map coordinate system, the x coordinate increases to the left, and the y coordinate increases downwards.

Notice that while the two parameters of a GPoint are accessible as properties x and y, it is better to never modify them, but to create a new object with different paramaters instead.

Constructor

ConstructorDescription
GPoint(x, y)Creates a GPoint object.

Properties

PropertiesTypeDescription
x Number x coordinate, increases to the left.
y Number y coordinate, increases downwards.

Methods

MethodsReturn ValueDescription
equals(other)BooleanReturns true iff the other point has equal coordinates.
toString()StringReturns a string that contains the x and y coordinates, in this order, separated by a comma.

class GSize

A GSize is the size in pixels of a rectangular area of the map. The size object has two parameters, width and height. Width is a difference in the x-coordinate; height is a difference in the y-coordinate, of points.

Notice that while the two parameters of a GSize are accessible as properties width and height, it is better to never modify them, but to create a new object with different paramaters instead.

Constructor

ConstructorDescription
GSize(width, height)Creates a GSize object.

Properties

PropertiesTypeDescription
width NumberThe width parameter.
height NumberThe height parameter.

Methods

MethodsReturn ValueDescription
equals(other)BooleanReturns true iff the other size has exactly equal components.
toString()StringReturns a string that contains the wdith and height parameter, in this order, separated by a comma.

class GBounds

GBounds is a rectangular area of the map in pixel coordinates. Notice that a rectangle in geographical coordinates is represented by a GLatLngBounds object.

Constructor

ConstructorDescription
GBounds(points)Constructs a rectangle that contains all the given points.

Properties

PropertiesTypeDescription
minX NumberThe x coordinate of the left edge of the rectangle.
minY NumberThe y coordinate of the top edge of the rectangle.
maxX NumberThe x coordinate of the right edge of the rectangle.
maxY NumberThe y coordinate of the bottom edge of the rectangle.

Methods

MethodsReturn ValueDescription
toString()StringReturns a string that contains the coordinates of the upper left and the lower right corner points of the box, in this order, separated by comma, surrounded by parentheses.
mid()GPointReturns the pixel coordinates of the center of the rectangular area. (Since 2.88)
min()GPointReturns the pixel coordinates of the upper left corner of the rectangular area.
max()GPointReturns the pixel coordinates of the lower right corner of the rectangular area.
containsBounds(other)BooleanReturns true if the passed rectangular area is entirely contained in this rectangular area.
containsPoint(point)BooleanReturns true if the rectangular area (inclusively) contains the pixel coordinates. (Since 2.88)
extend(point)noneEnlarges this box so that the point is also contained in this box.

class GLatLng

GLatLng is a point in geographical coordinates longitude and latitude.

Notice that although usual map projections associate longitude with the x-coordinate of the map, and latitude with the y-coordinate, the latitude cooridnate is always written first, followed by the longitude, as it is custom in cartography.

Notice also that you cannot modify the coordinates of a GLatLng. If you want to compute another point, you have to create a new one.

Constructor

ConstructorDescription
GLatLng(lat, lng, unbounded?)Notice the ordering of latitude and longitude. If the unbounded flag is true, then the numbers will be used as passed, otherwise latitude will be clamped to lie between -90 degrees and +90 degrees, and longitude will be wrapped to lie between -180 degrees and +180 degrees.

Methods

MethodsReturn ValueDescription
lat()NumberReturns the latitude coordinate in degrees, as a number between -90 and +90. If the unbounded flag was set in the constructor, this coordinate can be outside this interval.
lng()NumberReturns the longitude coordinate in degrees, as a number between -180 and +180. If the unbounded flag was set in the constructor, this coordinate can be outside this interval.
latRadians()NumberReturns the latitude coordinate in radians, as a number between -PI/2 and +PI/2. If the unbounded flag was set in the constructor, this coordinate can be outside this interval.
lngRadians()NumberReturns the longitude coordinate in radians, as a number between -PI and +PI. If the unbounded flag was set in the constructor, this coordinate can be outside this interval.
equals(other)BooleanReturns true iff the other size has equal components, within certain roundoff margins.
distanceFrom(other)NumberReturns the distance, in meters, from this point to the given point. The earth is approximated as a sphere, hence the distance could be off by as much as 0.3%. See below. (Deprecated since 2.89)
distanceFrom(other, radius?)NumberReturns the distance, in meters, from this point to the given point. By default, this distance is calculated given the default equatorial earth radius of 6378137 meters. The earth is approximated as a sphere, hence the distance could be off as much as 0.3%, especially in the polar extremes. You may also pass an optional radius argument to calculate distances between GLatLng coordinates on spheres of a different radius than earth. (Since 2.89)
toUrlValue()StringThis version of the method has been deprecated in favor of the revised version (shown below) which passes an optional precision parameter. (Deprecated since 2.78)
toUrlValue(precision?)StringReturns a string that represents this point in a format suitable for use as a URL parameter value, separated by a comma, without whitespace. By default, precision is returned to 6 digits, which corresponds to a resolution to 4 inches/ 11 centimeters. An optional precision parameter allows you to specify a lower precision to reduce server load. Note: prior to 2.78, this precision parameter was not available. (Since 2.78)

Properties

These properties exist for backwards compatibility with v1 event handler functions only. They should not be used.

These properties mirror the return values of the lng() and lat() accessor methods and they allow a GLatLng to appear in places where a GPoint is expected by a v1 client. This is necessary where GLatLng appears in event details (i.e. in arguments of event handler functions). In contrast to method wrappers, it is impossible in the current infrastructure to create event wrappers.

PropertiesTypeDescription
x NumberDeprecated.
y NumberDeprecated.

class GLatLngBounds

A GLatLngBounds instance represents a rectangle in geographical coordinates, including one that crosses the 180 degrees meridian.

Constructor

ConstructorDescription
GLatLngBounds(sw?, ne?)Constructs a rectangle from the points at its south-west and north-east corners.

Methods

MethodsReturn ValueDescription
equals(other)BooleanReturns true iff all parameters in this rectangle are equal to the parameters of the other, within a certain roundoff margin.
contains(latlng)BooleanReturns true iff the geographical coordinates of the point lie within this rectangle. (Deprecated since 2.88)
containsLatLng(latlng)BooleanReturns true iff the geographical coordinates of the point lie within this rectangle. (Since 2.88)
intersects(other)BooleanWhat the name says.
containsBounds(other)BooleanWhat the name says.
extend(latlng)noneEnlarges this rectangle such that it contains the given point. In longitude direction, it is enlarged in the smaller of the two possible ways. If both are equal, it is enlarged at the eastern boundary.
getSouthWest()GLatLngReturns the point at the south-west corner of the rectangle.
getNorthEast()GLatLngReturns the point at the north-east corner of the rectangle.
toSpan()GLatLngReturns a GLatLng whose cordinates represent the size of this rectangle.
isFullLat()BooleanReturns true if this rectangle extends from the south pole to the north pole.
isFullLng()BooleanReturns true if this rectangle extends fully around the earth in the longitude direction.
isEmpty()BooleanReturns true if this rectangle is empty.
getCenter()GLatLngReturns the point at the center of the rectangle. (Since 2.52)

interface GControl

This interface is implemented by all controls. You can implement it in order to provide a custom control for the map. Controls are added to the map using the GMap2.addControl() method.

In contrast to overlays, which are positioned relative to the map, controls are positioned relative to the map view, i.e. they don't move when the map moves.

Constructor

ConstructorDescription
GControl(printable?, selectable?)Creates the prototype instance for a new control class. Flag printable indicates that the control should be visible in the print output of the map. Flag selectable indicates that the control will contain text that should be selectable.

Methods

These methods will be called by the map when the control is added to the map using GMap2.addControl(). Thus, these methods will not be called by you, but they will be implemented by you.

MethodsReturn ValueDescription
printable()BooleanReturns to the map if the control should be printable.
selectable()BooleanReturns to the map if the control contains selectable text.
initialize(map)NodeWill be called by the map so the control can initialize itself. The control will use the method GMap2.getContainer() to get hold of the DOM element that contains the map, and add itself to it. It returns the added element.
getDefaultPosition()GControlPositionReturns to the map the position in the map view at which the control appears by default. This will be overridden by the second argument to GMap2.addControl().

class GControlPosition

This class described the position of a control in the map view. It consists of a corner relative to where the control is postioned, and an offset that determines this position. It can be passed as optional argument position to the method GMap2.addControl(), and it is returned from method GControl.getDefaultPosition().

Constructor

ConstructorDescription
GControlPosition(anchor, offset)Creates a specification for a control position.

enum GControlAnchor

Constants

ConstantsDescription
G_ANCHOR_TOP_RIGHTThe control will be anchored in the top right corner of the map.
G_ANCHOR_TOP_LEFTThe control will be anchored in the top left corner of the map.
G_ANCHOR_BOTTOM_RIGHTThe control will be anchored in the bottom right corner of the map.
G_ANCHOR_BOTTOM_LEFTThe control will be anchored in the bottom left corner of the map.

class GControl

These implementations of interface GControl are available.

Constructor

ConstructorDescription
GSmallMapControl()Creates a control with buttons to pan in four directions, and zoom in and zoom out.
GLargeMapControl()Creates a control with buttons to pan in four directions, and zoom in and zoom out, and a zoom slider.
GSmallZoomControl()Creates a control with buttons to zoom in and zoom out.
GScaleControl()Creates a control that displays the map scale.
GMapTypeControl()Creates a control with buttons to switch between map types.
GOverviewMapControl()Creates a collapsible overview mini-map in the corner of the main map for reference location and navigation (through dragging). The GOverviewMapControl creates an overview map with a one-pixel black border.

class GMapType

Google provides some predefined map types - this class is used to define custom ones. In order to show them on the map, use the GMap2 constructor, or the GMap2.addMapType() method. See also GTileLayerOverlay to add to (rather than entirely replace) the map's tile layers.

This class can also be subclassed. Constructor arguments can be omitted if instantiated as a prototype. A subclass constructor must invoke the GMapType constructor using call().

Constructor

ConstructorDescription
GMapType(layers, projection, name, opts?)Constructs a map type with the given tile layers, projection, name, and optional parameters.

Methods

These methods are mostly called by the map that this maptype is passed to, but some methods may also be called from outside the map, e.g. getBoundsZoomLevel().

MethodsReturn ValueDescription
getSpanZoomLevel(center, span, viewSize)NumberReturns to the map the zoom level at which the map section defined by center and span fits into the map view of the given size in pixels.
getBoundsZoomLevel(bounds, viewSize)noneReturns to the map the zoom level at which the map section defined by bounds fits into the map view of the given size in pixels.
getName(short?)StringReturns to the map the name of the map type to be used as the button label in the GMapTypeControl.
getProjection()GProjectionReturns to the map the projection of this map type.
getTileSize()NumberReturns to the map the map tile size in pixels of this map type. The tiles are assumed to be quadratic. All tile layers have the same tile size.
getTileLayers()Array of GTileLayerReturns to the map the array of tile layers.
getMinimumResolution()NumberReturns to the map the lowest zoom level at which this map type is defined.
getMaximumResolution()NumberReturns to the map the highest zoom level at which this map type is defined.
getTextColor()StringReturns to the map the color that is best used for text that is overlaid on the map. Used for the color of the text of the copyright message displayed by the copyroght control.
getLinkColor()StringReturns to the map the color that is best used for a hyperlink that is overlaid on the map. Used for the color of the link to the terms of use displayed by the copyroght control.
getErrorMessage()StringReturns to the map the error message that is displayed in areas or on zoom level where this map type doesn't have map tiles.
getCopyrights(bounds, zoom)Array of StringReturns to the map the copyright messages appropriate for the region described by bounds at the given zoom level. This is used by the copyright message on the map.
getUrlArg()StringReturns to the map a value that is used as a URL paramater value to identify this map type in permalinks to the current map view. This is currently only used by the maps application.
getAlt()StringReturns to the map the alternative text of this map type. (Since 2.86)

Constants

ConstantsDescription
G_NORMAL_MAPThis is the normal street map type.
G_SATELLITE_MAPThis map type shows Google Earth satellite images.
G_HYBRID_MAPThis map type shows transparent street maps over Google Earth satellite images.
G_DEFAULT_MAP_TYPESAn array of all three predefined map types described above.

Events

EventsArgumentsDescription
newcopyrightcopyrightThis event is fired when a new copyright is added to the copyright collection of one of the tile layers contained in this map type.

class GMapTypeOptions

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

Properties

PropertiesTypeDescription
shortName StringSets the short name of the map type that is returned from GMapType.getName(true). Default is the same as the name.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值