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

addStaticLabels

Add static labels to leaflet or mapview objects


Description

Being a wrapper around addLabelOnlyMarkers, this function provides a smart-and-easy solution to add custom text labels to an existing leaflet or mapview map object.

Usage

addStaticLabels(map, data, label, group = NULL, layerId = NULL, ...)

Arguments

map

A leaflet or mapview object.

data

A sf or Spatial* object used for label placement, defaults to the locations of the first dataset in 'map'.

label

The labels to be placed at the positions indicated by 'data' as character, or any vector that can be coerced to this type.

group

the group of the static labels layer.

layerId

the layerId of the static labels layer.

...

Additional arguments passed to labelOptions.

Value

A labelled leaflet map

Author(s)

Florian Detsch, Lorenzo Busetto

See Also

Examples

## Not run: 
## leaflet label display options
library(leaflet)

lopt = labelOptions(noHide = TRUE,
                    direction = 'top',
                    textOnly = TRUE)

## Add labels on a Leaflet map

indata <- sf::st_read(system.file("shape/nc.shp", package="sf"))

leaflet(indata) %>%
  addProviderTiles("OpenStreetMap") %>%
  addFeatures(.) %>%
  addStaticLabels(., label = indata$NAME)

Modify styling -

leaflet(indata) %>%
  addProviderTiles("OpenStreetMap") %>%
  addFeatures(.) %>%
  addStaticLabels(., label = indata$NAME,
                    style = list("color" = "red", "font-weight" = "bold"))


## End(Not run)

leafem

'leaflet' Extensions for 'mapview'

v0.1.3
MIT + file LICENSE
Authors
Tim Appelhans [cre, aut], Christoph Reudenbach [ctb], Kenton Russell [ctb], Jochen Darley [ctb], Daniel Montague [ctb] (Leaflet.EasyButton plugin), Lorenzo Busetto [ctb], Luigi Ranghetti [ctb], Miles McBain [ctb], Sebastian Gatscha [ctb], Björn Harrtell [ctb] (FlatGeobuf plugin), Daniel Dufour [ctb] (georaster-layer-for-leaflet)
Initial release
2020-07-19

We don't support your browser anymore

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