OverlayView class
google.maps
. OverlayView
class
You can implement this class if you want to display custom types of overlay objects on the map.
Inherit from this class by setting your overlay's prototype: MyOverlay.prototype = new google.maps.OverlayView();
. The OverlayView
constructor is guaranteed to be an empty function.
You must implement three methods: onAdd()
, draw()
, and onRemove()
.
- In the
onAdd()
method, you should create DOM objects and append them as children of the panes. - In the
draw()
method, you should position these elements. - In the
onRemove()
method, you should remove the objects from the DOM.
setMap()
with a valid Map
object to trigger the call to the onAdd()
method and setMap(null)
in order to trigger the onRemove()
method. The setMap()
method can be called at the time of construction or at any point afterward when the overlay should be re-shown after removing. The draw()
method will then be called whenever a map property changes that could change the position of the element, such as zoom, center, or map type. This class extends MVCObject
.
Access by calling const {OverlayView} = await google.maps.importLibrary("maps")
or const {OverlayView} = await google.maps.importLibrary("streetView")
.
See Libraries in the Maps JavaScript API
.
Constructor |
|
---|---|
OverlayView
|
OverlayView()
Parameters: None
Creates an
OverlayView
. |
Static Methods
preventMapHitsAndGesturesFrom(element)
-
element
:Element
preventMapHitsFrom(element)
-
element
:Element
Methods
draw()
getPanes()
MapPanes
|null
onAdd
is called by the API.getProjection()
MapCanvasProjection
MapCanvasProjection
object associated with this OverlayView
. The projection is not initialized until onAdd
is called by the API.onAdd()
onRemove()
setMap(map)
-
map
:Map | StreetViewPanorama optional
The map or panorama. Ifnull
, the layer will be removed.
MapPanes interface
google.maps
. MapPanes
interface
Properties |
|
---|---|
floatPane
|
Type:
Element
This pane contains the info window. It is above all map overlays. (Pane 4).
|
mapPane
|
Type:
Element
This pane is the lowest pane and is above the tiles. It does not receive DOM events. (Pane 0).
|
markerLayer
|
Type:
Element
This pane contains markers. It does not receive DOM events. (Pane 2).
|
overlayLayer
|
Type:
Element
This pane contains polylines, polygons, ground overlays and tile layer overlays. It does not receive DOM events. (Pane 1).
|
overlayMouseTarget
|
Type:
Element
This pane contains elements that receive DOM events. (Pane 3).
|
MapCanvasProjection interface
google.maps
. MapCanvasProjection
interface
This object is made available to the OverlayView
from within the draw method. It is not guaranteed to be initialized until draw is called.
Methods
fromLatLngToContainerPixel(latLng)
-
latLng
:LatLng | LatLngLiteral
Point
|null
fromLatLngToDivPixel(latLng)
-
latLng
:LatLng | LatLngLiteral optional
Point
|null
getVisibleRegion()
VisibleRegion
|null
null
if the map has no size. Returns null
if the OverlayView is on a StreetViewPanorama.getWorldWidth()
number