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

addScaleBar

Add or remove a scale bar


Description

Uses Leaflet's built-in scale bar feature to add a scale bar.

Usage

addScaleBar(
  map,
  position = c("topright", "bottomright", "bottomleft", "topleft"),
  options = scaleBarOptions()
)

scaleBarOptions(
  maxWidth = 100,
  metric = TRUE,
  imperial = TRUE,
  updateWhenIdle = TRUE
)

removeScaleBar(map)

Arguments

map

the map to add the scale bar to

position

position of control: "topleft", "topright", "bottomleft", or "bottomright"

options

a list of additional options, intended to be provided by a call to scaleBarOptions

maxWidth

maximum width of the control in pixels (default 100)

metric

if TRUE (the default), show a scale bar in metric units (m/km)

imperial

if TRUE (the default), show a scale bar in imperial units (ft/mi)

updateWhenIdle

if FALSE (the default), the scale bar is always up-to-date (updated on move). If TRUE, the control is updated on moveend.

Examples

leaflet() %>%
  addTiles() %>%
  addScaleBar()

leaflet

Create Interactive Web Maps with the JavaScript 'Leaflet' Library

v2.0.4.1
GPL-3
Authors
Joe Cheng [aut, cre], Bhaskar Karambelkar [aut], Yihui Xie [aut], Hadley Wickham [ctb], Kenton Russell [ctb], Kent Johnson [ctb], Barret Schloerke [ctb], jQuery Foundation and contributors [ctb, cph] (jQuery library), Vladimir Agafonkin [ctb, cph] (Leaflet library), CloudMade [cph] (Leaflet library), Leaflet contributors [ctb] (Leaflet library), Brandon Copeland [ctb, cph] (leaflet-measure plugin), Joerg Dietrich [ctb, cph] (Leaflet.Terminator plugin), Benjamin Becquet [ctb, cph] (Leaflet.MagnifyingGlass plugin), Norkart AS [ctb, cph] (Leaflet.MiniMap plugin), L. Voogdt [ctb, cph] (Leaflet.awesome-markers plugin), Daniel Montague [ctb, cph] (Leaflet.EasyButton plugin), Kartena AB [ctb, cph] (Proj4Leaflet plugin), Robert Kajic [ctb, cph] (leaflet-locationfilter plugin), Mapbox [ctb, cph] (leaflet-omnivore plugin), Michael Bostock [ctb, cph] (topojson), RStudio [cph]
Initial release

We don't support your browser anymore

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