mapview (version 2.7.0)

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 mapview object.

See Also

addLabelOnlyMarkers.

Examples

Run this code
# NOT RUN {
## leaflet label display options
library(leaflet)

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

## point labels
m1 = mapview(breweries)
l1 = addStaticLabels(m1,
                     label = breweries$number.of.types,
                     labelOptions = lopt)
l1

## polygon centroid labels
m2 = mapview(franconia)
l2 = addStaticLabels(m2,
                     label = franconia$NAME_ASCI,
                     labelOptions = lopt)
l2

## custom labels
m3 = m2 + m1
l3 = addStaticLabels(m3,
                     data = franconia,
                     label = franconia$NAME_ASCI,
                     labelOptions = lopt)
l3
# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace