@smartmaps/smartmaps-gl / ContextMenu
Class: ContextMenu
An ContextMenu that offers the user an additional way to interact with the map.
Remarks
- can be activated/disabled with the contextmenu option MapOptions
Examples
contextmenu: {
contextmenuItems: [ {
action: 'centerMap',
label: 'Center map here',
handler: (coords, map) => map.setCenter(coords)
},
{
action: 'addMarker',
label: 'Add Marker',
handler: (coords, map) => new Marker().setLngLat(coords).addTo(map)
}]
}
map.addControl( new ContextMenu({
contextmenuItems: [ {
action: 'zoomIn',
label: `${icons.zoomIn} Zoom in`,
handler: (_, map: Map) => map.zoomIn()
},
{
action: 'zoomOut',
label: `${icons.zoomOut} Zoom out`,
handler: (_, map: Map) => map.zoomOut()
}],
}));
Constructors
Constructor
new ContextMenu(
map,options?):ContextMenu
Parameters
map
the map instance which the control will be added to
options?
the control's options
Returns
ContextMenu
Methods
addItem()
addItem(
options):void
Adds a new menu item to the context menu
Parameters
options
The menu item options
Returns
void
hide()
hide():
void
Hides the context menu
Returns
void
removeAllItems()
removeAllItems():
void
Removes all menu items from the context menu
Returns
void
removeItem()
removeItem(
action):void
Removes a menu item from the context menu
Parameters
action
string
The action of the menu item to remove
Returns
void