Skip to contents

The LeafletSlider plugin enables you to dynamically add and remove Markers/Lines on a map by using a JQuery UI slider.

Usage

addTimeslider(
  map,
  data,
  radius = 10,
  stroke = TRUE,
  color = "#03F",
  weight = 5,
  opacity = 0.5,
  fill = TRUE,
  fillColor = color,
  fillOpacity = 0.2,
  dashArray = NULL,
  popup = NULL,
  popupOptions = NULL,
  label = NULL,
  labelOptions = NULL,
  ordertime = TRUE,
  options = timesliderOptions()
)

Arguments

map

a map widget

data

data must be a Simple Feature collection of type POINT or LINESTRING with a column of class Date or POSIXct.

radius

a numeric vector of radii for the circles; it can also be a one-sided formula, in which case the radius values are derived from the data (units in meters for circles, and pixels for circle markers)

stroke

whether to draw stroke along the path (e.g. the borders of polygons or circles)

color

stroke color

weight

stroke width in pixels

opacity

stroke opacity (or layer opacity for tile layers)

fill

whether to fill the path with color (e.g. filling on polygons or circles)

fillColor

fill color

fillOpacity

fill opacity

dashArray

a string that defines the stroke dash pattern

popup

a character vector of the HTML content for the popups (you are recommended to escape the text using htmlEscape() for security reasons)

popupOptions

A Vector of popupOptions to provide popups

label

a character vector of the HTML content for the labels

labelOptions

A Vector of labelOptions to provide label options for each label. Default NULL

ordertime

boolean value indicating whether to order the data by the time column. The slider will adopt the order of the timestamps. The default is TRUE.

options

List of additional options. See timesliderOptions

Value

the new map object

See also

Other Timeslider Functions: removeTimeslider(), timesliderOptions()

Examples

library(leaflet)
library(leaflet.extras2)
library(sf)

data <- sf::st_as_sf(leaflet::atlStorms2005[1, ])
data <- st_cast(data, "POINT")
#> Warning: repeating attributes for all sub-geometries for which they may not be constant
data$time <- as.POSIXct(
  seq.POSIXt(Sys.time() - 1000, Sys.time(), length.out = nrow(data))
)

leaflet() %>%
  addTiles() %>%
  addTimeslider(
    data = data,
    options = timesliderOptions(
      position = "topright",
      timeAttribute = "time",
      range = TRUE
    )
  ) %>%
  setView(-72, 22, 4)