Skip to contents

Manually specify icons, labels, and colours to add an Icon legend to a map. Useful in conjunction with magicIcons() to communicate the meaning of icons/colours.

Usage

addIconLegend(
  map,
  icons,
  labels,
  colors = "black",
  title = NULL,
  library = "fontawesome",
  position = c("topright", "bottomright", "bottomleft", "topleft"),
  layerId = NULL,
  className = "info legend",
  data = leaflet::getMapData(map)
)

Arguments

map

a map widget object created from leaflet()

icons

Name of the icons, passed to fontawesome::fa() or bsicons::bs_icon(). A full list of available icons can be found using fontawesome::fa_metadata(), https://icons.getbootstrap.com/ or https://ionic.io/ionicons.

labels

Labels for each icon; should be the same length as icons.

colors

Colours to use for each icon. If length(colors) == 1L it is recycled for all icons. Otherwise should be the same length as icons.

title

the legend title; optional.

library

One of "fontawesome", "bootstrap", or "ionicons", defining the icon library of interest. Defaults to "fontawesome".

position

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

layerId

the layer id

className

extra CSS classes to append to the control, space separated

data

the data object from which the argument values are derived; by default, it is the data object provided to leaflet() initially, but can be overridden

Value

a leaflet widget

Examples

library(leaflet)
addIconLegend(
  map = leaflet(),
  icons = c("beer", "school"),
  labels = c("Pub", "University"),
  colors = c("red", "blue"),
  title = "Student Hangout"
)