Add a contextmenu to the map or markers/vector layers.
addContextmenu(map)
a map widget object created from leaflet
A leaflet map object
This function is only used to include the required JavaScript and CSS bindings and to set up some Shiny event handlers.
The contextmenu for
the map must be defined in
leafletOptions
.
the markers/vector layers must be defined
in markerOptions
or
pathOptions
.
When a contextmenu is selected, a Shiny input with the
ID "MAPID_contextmenu_select"
is set (`MAPID` refers to the map's id).
If the selected contextmenu item is triggered from:
the map, the returned list contains the text
of
the item.
the markers, the returned list also contains the
layerId
, group
, lat
,
lng
and label
.
the vector layers, the returned list also contains the
layerId
, group
and label
.
Other Contextmenu Functions:
addItemContextmenu()
,
context_mapmenuItems()
,
context_markermenuItems()
,
context_menuItem()
,
disableContextmenu()
,
enableContextmenu()
,
hideContextmenu()
,
insertItemContextmenu()
,
mapmenuItems()
,
markermenuItems()
,
menuItem()
,
removeItemContextmenu()
,
removeallItemsContextmenu()
,
setDisabledContextmenu()
,
showContextmenu()
library(leaflet)
leaflet(options = leafletOptions(
contextmenu = TRUE,
contextmenuWidth = 200,
contextmenuItems =
context_mapmenuItems(
context_menuItem("Zoom Out", "function(e) {this.zoomOut()}", disabled=FALSE),
"-",
context_menuItem("Zoom In", "function(e) {this.zoomIn()}")))) %>%
addTiles(group = "base") %>%
addContextmenu() %>%
addMarkers(data = breweries91, label = ~brewery,
layerId = ~founded, group = "marker",
options = markerOptions(
contextmenu = TRUE,
contextmenuWidth = 200,
contextmenuItems =
context_markermenuItems(
context_menuItem(text = "Show Marker Coords",
callback = "function(e) {alert(e.latlng);}",
index = 1)
)
))