Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

addContextmenu

Add contextmenu Plugin


Description

Add a contextmenu to the map or markers/vector layers.

Usage

addContextmenu(map)

Arguments

map

a map widget object created from leaflet

Details

This function is only used to include the required JavaScript and CSS bindings and to set up some Shiny event handlers.

Contextmenu initialization

The contextmenu for

Contextmenu selection

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 containts 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.

Value

A leaflet map object

References

See Also

Examples

library(leaflet)
leaflet(options = leafletOptions(
    contextmenu = TRUE,
    contextmenuWidth = 200,
    contextmenuItems =
     mapmenuItems(
       menuItem("Zoom Out", "function(e) {this.zoomOut()}", disabled=FALSE),
       "-",
       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 =
              markermenuItems(
                menuItem(text = "Show Marker Coords",
                         callback = "function(e) {alert(e.latlng);}",
                         index = 1)
              )
          ))

leaflet.extras2

Extra Functionality for 'leaflet' Package

v1.1.0
GPL-3 | file LICENSE
Authors
Gatscha Sebastian [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.