Skip to content

GmapsContextMenu

Matthew Wright edited this page Jan 2, 2021 · 4 revisions

Description

A GmapsContextMenu displays clickable text options in a popup window above the mouse right click location. The content area (options) is configured with JSON. While it is based on an InfoWindow, it does not have a tapered stem.

Typically you will attach a context menu to a map, but you can also attach context menus to circles, markers, and other shapes.

GmapsContextMenu class

GmapsContextMenu class

An overlay that looks like a bubble and is often connected to the map or a marker.

Constructor

Constructor Detail
GmapsContextMenu GmapsContextMenu([map, settings])

Parameters:
  • map: google.maps.Map required
  • settings: GmapsContextMenu settings optional

Methods

Method Detail
registerFor([mapOrShape]) Arguments:
  • mapOrShape: Map, Marker, or Shape required
Registers the element for both opening and closing the context menu
registerOpenFor([mapOrShape]) Arguments:
  • mapOrShape: Map, Marker, or Shape required
Registers the element to open the context menu on rightclick
registerCloseFor([mapOrShape]) Arguments:
  • mapOrShape: Map, Marker, or Shape required
Registers the element to close the context menu on click
updateOptions() Arguments:
  • None
Rebuilds the context menu content
close() Arguments:
  • None
Closes the context menu

GmapsContextMenu settings

Object used to define the properties that can be set on a GmapsContextMenu.

Property Detail
registerOpenForMap Type: boolean optional
Default: true

Whether this context menu should be opened by the map on rightclick.
registerCloseForMap Type: boolean optional
Default: true

Whether this context menu should be closed by the map on click.
options Type Array[GmapsContextMenu option]

Options displayed in the context menu.

GmapsContextMenu option

Object to customize a clickable text option displayed in the GmapsContextMenu.

Property Detail
text Type: boolean required

The text displayed for the menu item.
showWhen Type: function() optional

A function returning boolean for whether to display this option on right click
onclick Type: function(latLng) required

A function with an argument that returns {lat, lng} for the position the context menu is opened when the option is clicked.

GmapsContext object

Meta object that stores each of the GmapsContextMenus and provides additional option(s).

GmapsContext.setSetting("setting", "value");
Setting Detail
registerCloseForEverything Type: boolean optional
Default: true

Registers every GmapsContextMenu made to be closed on click by every map, marker, shape referenced in every other GmapsContextMenu. When enabled, this allows every open context menu to close when a click occurs outside every open context menu.