addStaticLabels | R Documentation |
leaflet
or mapview
objectsBeing 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.
addStaticLabels(map, data, label, group = NULL, layerId = NULL, ...)
map |
A |
data |
A |
label |
The labels to be placed at the positions indicated by 'data' as
|
group |
the group of the static labels layer. |
layerId |
the layerId of the static labels layer. |
... |
Additional arguments passed to
|
A labelled leaflet map
Florian Detsch, Lorenzo Busetto
addLabelOnlyMarkers
.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.