addDivicon {leaflet.extras2} | R Documentation |
Add DivIcon Markers to a Leaflet Map
Description
Adds customizable DivIcon markers to a Leaflet map. The function can accept either spatial data (lines or points) in the form of a Simple Feature (sf) object or numeric vectors for latitude and longitude coordinates. It allows for the application of custom HTML content and CSS classes to each marker, providing high flexibility in marker design.
Usage
addDivicon(
map,
lng = NULL,
lat = NULL,
layerId = NULL,
group = NULL,
popup = NULL,
popupOptions = NULL,
label = NULL,
labelOptions = NULL,
className = NULL,
html = NULL,
options = markerOptions(),
clusterOptions = NULL,
clusterId = NULL,
divOptions = list(),
data = getMapData(map)
)
Arguments
map |
the map to add awesome Markers to. |
lng |
a numeric vector of longitudes, or a one-sided formula of the form
|
lat |
a vector of latitudes or a formula (similar to the |
layerId |
the layer id |
group |
the name of the group the newly created layers should belong to
(for |
popup |
a character vector of the HTML content for the popups (you are
recommended to escape the text using |
popupOptions |
A Vector of |
label |
a character vector of the HTML content for the labels |
labelOptions |
A Vector of |
className |
A single CSS class or a vector of CSS classes. |
html |
A single HTML string or a vector of HTML strings. |
options |
a list of extra options for tile layers, popups, paths (circles, rectangles, polygons, ...), or other map elements |
clusterOptions |
if not |
clusterId |
the id for the marker cluster layer |
divOptions |
A list of extra options for Leaflet DivIcon. |
data |
the data object from which the argument values are derived; by
default, it is the |
Value
The modified Leaflet map object.
Examples
library(sf)
library(leaflet)
library(leaflet.extras2)
# Sample data
df <- sf::st_as_sf(atlStorms2005)
df <- suppressWarnings(st_cast(df, "POINT"))
df <- df[sample(1:nrow(df), 50, replace = FALSE), ]
df$classes <- sample(x = c("myclass1", "myclass2", "myclass3"), nrow(df), replace = TRUE)
df$ID <- paste0("ID_", 1:nrow(df))
leaflet() %>%
addTiles() %>%
addDivicon(
data = df,
html = ~ paste0(
'<div class="custom-html">',
'<div class="title">', Name, "</div>",
'<div class="subtitle">MaxWind: ', MaxWind, "</div>",
"</div>"
),
label = ~Name,
layerId = ~ID,
group = "Divicons",
popup = ~ paste(
"ID: ", ID, "<br>",
"Name: ", Name, "<br>",
"MaxWind:", MaxWind, "<br>",
"MinPress:", MinPress
),
options = markerOptions(draggable = TRUE)
)