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

draw

Adds a Toolbar to draw shapes/points on the map.


Description

Adds a Toolbar to draw shapes/points on the map.

Removes the draw toolbar

Usage

addDrawToolbar(map, targetLayerId = NULL, targetGroup = NULL,
  position = c("topleft", "topright", "bottomleft", "bottomright"),
  polylineOptions = drawPolylineOptions(),
  polygonOptions = drawPolygonOptions(),
  circleOptions = drawCircleOptions(),
  rectangleOptions = drawRectangleOptions(),
  markerOptions = drawMarkerOptions(),
  circleMarkerOptions = drawCircleMarkerOptions(), editOptions = FALSE,
  singleFeature = FALSE)

removeDrawToolbar(map, clearFeatures = FALSE)

Arguments

map

The map widget.

targetLayerId

An optional layerId of a GeoJSON/TopoJSON layer whose features need to be editable. Used for adding a GeoJSON/TopoJSON layer and then editing the features using the draw plugin.

targetGroup

An optional group name of a Feature Group whose features need to be editable. Used for adding shapes(markers, lines, polygons) and then editing them using the draw plugin. You can either set layerId or group or none but not both.

position

The position where the toolbar should appear.

polylineOptions

See drawPolylineOptions(). Set to FALSE to disable polyline drawing.

polygonOptions

See drawPolygonOptions(). Set to FALSE to disable polygon drawing.

circleOptions

See drawCircleOptions(). Set to FALSE to disable circle drawing.

rectangleOptions

See drawRectangleOptions(). Set to FALSE to disable rectangle drawing.

markerOptions

See drawMarkerOptions(). Set to FALSE to disable marker drawing.

circleMarkerOptions

See drawCircleMarkerOptions(). Set to FALSE to disable circle marker drawing.

editOptions

By default editing is disable. To enable editing pass editToolbarOptions().

singleFeature

When set to TRUE, only one feature can be drawn at a time, the previous ones being removed.

clearFeatures

whether to clear the map of drawn features.

Examples

leaflet() %>%
  setView(0, 0, 2) %>%
  addProviderTiles(providers$CartoDB.Positron) %>%
  addDrawToolbar(
    targetGroup = "draw",
    editOptions = editToolbarOptions(
      selectedPathOptions = selectedPathOptions()
    )
  )  %>%
  addLayersControl(
    overlayGroups = c("draw"),
    options = layersControlOptions(collapsed = FALSE)
  ) %>%
  addStyleEditor()

## for more examples see
# browseURL(system.file("examples/draw.R", package = "leaflet.extras"))

leaflet.extras

Extra Functionality for 'leaflet' Package

v1.0.0
GPL-3 | file LICENSE
Authors
Bhaskar Karambelkar [aut, cre], Barret Schloerke [aut], Bangyou Zheng [ctb] (Leaflet-search and Leaflet-GPS plugin integration), Robin Cura [ctb] (Fixes for Draw Options), Markus Voge [ctb] (Enhancements for Draw Options), Markus Dumke [ctb] (Bounce Marker addition), Mapbox [ctb, cph] (leaflet-omnivore, csv2geojson, and togeojson libraries), Henry Thasler [ctb, cph] (Leaflet.Geodesic library), Dennis Wilhelm [ctb, cph] (Leaflet.StyleEditor library), Kirollos Risk [ctb, cph] (fuse.js library), Tim Wisniewski [ctb, cph] (leaflet-choropleth library), Leaflet [ctb, cph] (leaflet-draw library), Alexander Milevski [ctb, cph] (leaflet-draw-drag library), John Firebaugh [ctb, cph] (leaflet-fullscreen library), Stefano Cudini [ctb, cph] (leaflet-gps library), Johannes Rudolph [ctb, cph] (leaflet-hash library), Per Liedman [ctb, cph] (leaflet-measure-path library), Pavel Shramov [ctb, cph] (leaflet-plugins library), Filip Zavadil [ctb, cph] (leaflet-pulse-icon library), Stefano Cudini [ctb, cph] (leaflet-search library), CliffCloud [ctb, cph] (leaflet-sleep library), Ursudio [ctb, cph] (leaflet-webgl-heatmap library), Maxime Hadjinlian [ctb, cph] (leaflet.BounceMarker library), Vladimir Agafonkin [ctb, cph] (leaflet.heat library), Iván Sánchez Ortega [ctb, cph] (leaflet.tilelayer.pouchdbcached library), Dale Harvey [ctb, cph] (pouchdb-browser library), Mike Bostock [ctb, cph] (topojson library)
Initial release

We don't support your browser anymore

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