Title: | Leaflet Map Plugin for Drawing and Editing |
---|---|
Description: | A collection of tools for interactive manipulation of (spatial) data layers on leaflet web maps. Tools include editing of existing layers, creation of new layers through drawing of shapes (points, lines, polygons), deletion of shapes as well as cutting holes into existing shapes. Provides control over options to e.g. prevent self-intersection of polygons and lines or to enable/disable snapping to align shapes. |
Authors: | Kenton Russell [aut, cre], Tim Appelhans [aut], Sumit Kumar [ctb] (Leaflet.pm plugin) |
Maintainer: | Kenton Russell <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-10-27 03:18:49 UTC |
Source: | https://github.com/r-spatial/leafpm |
Add 'leaflet-pm' Toolbar to a Leaflet 'htmlwidget'
addPmToolbar(map = NULL, targetLayerId = NULL, targetGroup = NULL, toolbarOptions = pmToolbarOptions(), drawOptions = pmDrawOptions(), editOptions = pmEditOptions(), cutOptions = pmCutOptions())
addPmToolbar(map = NULL, targetLayerId = NULL, targetGroup = NULL, toolbarOptions = pmToolbarOptions(), drawOptions = pmDrawOptions(), editOptions = pmEditOptions(), cutOptions = pmCutOptions())
map |
|
targetLayerId |
|
targetGroup |
|
toolbarOptions |
|
drawOptions |
|
editOptions |
|
cutOptions |
leaflet
htmlwidget
if(interactive()) { library(leaflet) library(leafpm) # quick example leaflet() %>% addTiles() %>% addPmToolbar() # customizing with options leaflet() %>% addTiles() %>% addPmToolbar( toolbarOptions = pmToolbarOptions(drawMarker = FALSE, position = "topright"), drawOptions = pmDrawOptions(snappable = FALSE, allowSelfIntersection = FALSE), editOptions = pmEditOptions(preventMarkerRemoval = TRUE, draggable = FALSE), cutOptions = pmCutOptions(snappable = FALSE, allowSelfIntersection = FALSE) ) # demonstrate that leaflet.pm can work with holes library(sf) library(leaflet) library(leafpm) outer1 = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE) hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE) hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE) outer2 = matrix(c(11,0,11,1,12,1,12,0,11,0),ncol=2, byrow=TRUE) pts1 = list(outer1, hole1, hole2) pts2 = list(outer2) pl1 = st_sf(geom = st_sfc(st_polygon(pts1))) pl2 = st_sf(geom = st_sfc(st_polygon(pts2))) mpl = st_sf(geom = st_combine(rbind(pl1, pl2))) if(requireNamespace("mapview")) { mapview::mapview(mpl)@map %>% addPmToolbar(targetGroup = "mpl", cutOptions = pmCutOptions(snappable = FALSE)) } else { warning("Please install mapview to run this example", call. = FALSE) } }
if(interactive()) { library(leaflet) library(leafpm) # quick example leaflet() %>% addTiles() %>% addPmToolbar() # customizing with options leaflet() %>% addTiles() %>% addPmToolbar( toolbarOptions = pmToolbarOptions(drawMarker = FALSE, position = "topright"), drawOptions = pmDrawOptions(snappable = FALSE, allowSelfIntersection = FALSE), editOptions = pmEditOptions(preventMarkerRemoval = TRUE, draggable = FALSE), cutOptions = pmCutOptions(snappable = FALSE, allowSelfIntersection = FALSE) ) # demonstrate that leaflet.pm can work with holes library(sf) library(leaflet) library(leafpm) outer1 = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE) hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE) hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE) outer2 = matrix(c(11,0,11,1,12,1,12,0,11,0),ncol=2, byrow=TRUE) pts1 = list(outer1, hole1, hole2) pts2 = list(outer2) pl1 = st_sf(geom = st_sfc(st_polygon(pts1))) pl2 = st_sf(geom = st_sfc(st_polygon(pts2))) mpl = st_sf(geom = st_combine(rbind(pl1, pl2))) if(requireNamespace("mapview")) { mapview::mapview(mpl)@map %>% addPmToolbar(targetGroup = "mpl", cutOptions = pmCutOptions(snappable = FALSE)) } else { warning("Please install mapview to run this example", call. = FALSE) } }
Set Options for 'leaflet.pm' Cut Mode
pmCutOptions(snappable = FALSE, allowSelfIntersection = TRUE, cursorMarker = FALSE)
pmCutOptions(snappable = FALSE, allowSelfIntersection = TRUE, cursorMarker = FALSE)
snappable |
|
allowSelfIntersection |
|
cursorMarker |
|
list
of options
Dependencies for 'leaflet-pm'
pmDependencies()
pmDependencies()
htmltools::htmlDependency
Set Options for 'leaflet.pm' Draw Mode
pmDrawOptions(snappable = TRUE, snapDistance = 20, snapMiddle = TRUE, tooltips = TRUE, cursorMarker = TRUE, finishOn = NULL, allowSelfIntersection = TRUE, templineStyle = list(), hintlineStyle = list(color = "#3388ff", dashArray = "5,5"), markerStyle = list(draggable = TRUE))
pmDrawOptions(snappable = TRUE, snapDistance = 20, snapMiddle = TRUE, tooltips = TRUE, cursorMarker = TRUE, finishOn = NULL, allowSelfIntersection = TRUE, templineStyle = list(), hintlineStyle = list(color = "#3388ff", dashArray = "5,5"), markerStyle = list(draggable = TRUE))
snappable |
|
snapDistance |
|
snapMiddle |
|
tooltips |
|
cursorMarker |
|
finishOn |
|
allowSelfIntersection |
|
templineStyle |
|
hintlineStyle |
|
markerStyle |
|
list
of options
Set Options for 'leaflet.pm' Edit Mode
pmEditOptions(snappable = TRUE, snapDistance = 20, allowSelfIntersection = TRUE, draggable = TRUE, preventMarkerRemoval = FALSE, preventVertexEdit = FALSE)
pmEditOptions(snappable = TRUE, snapDistance = 20, allowSelfIntersection = TRUE, draggable = TRUE, preventMarkerRemoval = FALSE, preventVertexEdit = FALSE)
snappable |
|
snapDistance |
|
allowSelfIntersection |
|
draggable |
|
preventMarkerRemoval |
|
preventVertexEdit |
|
list
of options
Set Options for 'leaflet.pm' Toolbar
pmToolbarOptions(drawMarker = TRUE, drawPolygon = TRUE, drawPolyline = TRUE, drawCircle = TRUE, drawRectangle = TRUE, editMode = TRUE, cutPolygon = TRUE, removalMode = TRUE, position = "topleft")
pmToolbarOptions(drawMarker = TRUE, drawPolygon = TRUE, drawPolyline = TRUE, drawCircle = TRUE, drawRectangle = TRUE, editMode = TRUE, cutPolygon = TRUE, removalMode = TRUE, position = "topleft")
drawMarker |
|
drawPolygon |
|
drawPolyline |
|
drawCircle |
|
drawRectangle |
|
editMode |
|
cutPolygon |
|
removalMode |
|
position |
|
leaflet
htmlwidget with added toolbar
Removes the 'leaflet.pm' toolbar
removePmToolbar(map, clearFeatures = FALSE)
removePmToolbar(map, clearFeatures = FALSE)
map |
|
clearFeatures |
whether to clear the map of drawn features. currently not working |
leaflet
htmlwidget