Last chance! 50% off unlimited learning
Sale ends in
Adds a Toolbar to draw shapes/points on the map.
Removes the draw toolbar
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,
toolbar = NULL,
handlers = NULL,
edittoolbar = NULL,
edithandlers = NULL,
drag = TRUE
)removeDrawToolbar(map, clearFeatures = FALSE)
The map widget.
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.
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.
The position where the toolbar should appear.
See drawPolylineOptions
(). Set to FALSE to disable polyline drawing.
See drawPolygonOptions
(). Set to FALSE to disable polygon drawing.
See drawCircleOptions
(). Set to FALSE to disable circle drawing.
See drawRectangleOptions
(). Set to FALSE to disable rectangle drawing.
See drawMarkerOptions
(). Set to FALSE to disable marker drawing.
See drawCircleMarkerOptions
(). Set to FALSE to disable circle marker drawing.
By default editing is disable. To enable editing pass editToolbarOptions
().
When set to TRUE, only one feature can be drawn at a time, the previous ones being removed.
See toolbarOptions
. Set to NULL
to take Leaflets default values.
See handlersOptions
. Set to NULL
to take Leaflets default values.
See edittoolbarOptions
. Set to NULL
to take Leaflets default values.
See edithandlersOptions
. Set to NULL
to take Leaflets default values.
When set to TRUE
, the drawn features will be draggable during editing, utilizing
the Leaflet.Draw.Drag
plugin. Otherwise, this library will not be included.
whether to clear the map of drawn features.
The drawn features emit events upon mouse interaction.
Event names follow the pattern: input$MAPID_LAYERCATEGORY_EVENTNAME
,
where LAYERCATEGORY
can be one of:
marker
shape
polyline
Similarly, for EVENTNAME
, valid values are:
click
mouseover
mouseout
See the provided example for usage:
browseURL(system.file("examples/shiny/draw-events/draw_mouse_events.R",
package = "leaflet.extras"))
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"))
# browseURL(system.file("examples/shiny/draw-events/app.R",
# package = "leaflet.extras"))
# browseURL(system.file("examples/shiny/draw-events/draw_mouse_events.R",
# package = "leaflet.extras"))
Run the code above in your browser using DataLab