addPmToolbar: Add 'leaflet-pm' Toolbar to a Leaflet 'htmlwidget'

Description Usage Arguments Value Examples

Description

Add 'leaflet-pm' Toolbar to a Leaflet 'htmlwidget'

Usage

1
2
3
addPmToolbar(map = NULL, targetLayerId = NULL, targetGroup = NULL,
  toolbarOptions = pmToolbarOptions(), drawOptions = pmDrawOptions(),
  editOptions = pmEditOptions(), cutOptions = pmCutOptions())

Arguments

map

leaflet map htmlwidget to which the toolbar should be added

targetLayerId

string id of the feature to edit

targetGroup

string name of the group to edit

toolbarOptions

pmToolbarOptions

drawOptions

pmDrawOptions

editOptions

pmEditOptions

cutOptions

pmCutOptions

Value

leaflet htmlwidget

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)
  }

}

Example output



leafpm documentation built on May 2, 2019, 1:27 p.m.