measure-path: Enables measuring of length of polylines and areas of...

enableMeasurePathR Documentation

Enables measuring of length of polylines and areas of polygons

Description

Enables measuring of length of polylines and areas of polygons

Options for measure-path

Adds a toolbar to enable/disable measuring path distances/areas

Usage

enableMeasurePath(map)

measurePathOptions(
  showOnHover = FALSE,
  minPixelDistance = 30,
  showDistances = TRUE,
  showArea = TRUE,
  imperial = FALSE
)

addMeasurePathToolbar(map, options = measurePathOptions(), group = NULL)

Arguments

map

The map widget.

showOnHover

If TRUE, the measurements will only show when the user hovers the cursor over the path.

minPixelDistance

The minimum length a line segment in the feature must have for a measurement to be added.

showDistances

If FALSE, doesn't show distances along line segments of of a polyline/polygon.

showArea

If FALSE, doesn't show areas of a polyline/polygon.

imperial

If TRUE the distances/areas will be shown in imperial units.

options

The measurePathOptions.

group

A character vector specifying the group(s) of layers for measurements. If 'group' is 'NULL' (default), measurements apply to all layers. For a single group or multiple groups, measurements apply only to matching layers.

Examples


geoJson <- readr::read_file(
  "https://rawgit.com/benbalter/dc-maps/master/maps/ward-2012.geojson"
)

leaflet() %>%
  addTiles() %>%
  setView(-77.0369, 38.9072, 11) %>%
  addBootstrapDependency() %>%
  enableMeasurePath() %>%
  addGeoJSONChoropleth(
    geoJson,
    valueProperty = "AREASQMI",
    scale = c("white", "red"),
    mode = "q",
    steps = 4,
    padding = c(0.2, 0),
    labelProperty = "NAME",
    popupProperty = propstoHTMLTable(
      props = c("NAME", "AREASQMI", "REP_NAME", "WEB_URL", "REP_PHONE", "REP_EMAIL", "REP_OFFICE"),
      table.attrs = list(class = "table table-striped table-bordered"),
      drop.na = TRUE
    ),
    color = "#ffffff", weight = 1, fillOpacity = 0.7,
    highlightOptions = highlightOptions(
      weight = 2, color = "#000000",
      fillOpacity = 1, opacity = 1,
      bringToFront = TRUE, sendToBack = TRUE
    ),
    pathOptions = pathOptions(
      showMeasurements = TRUE,
      measurementOptions = measurePathOptions(imperial = TRUE)
    )
  )


leaflet() %>%
  addTiles() %>%
  addCircles(lng = c(10, 20), lat = c(50, 60), group = "Group 1") %>%
  addCircles(lng = c(15, 25), lat = c(55, 65), group = "Group 2") %>%
  addMeasurePathToolbar(group = "Group 1") # Enable measurements for "Group 1" only

bhaskarvk/leaflet.extras documentation built on Jan. 17, 2025, 2:29 a.m.