Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

addPlayback

Add Playback to Leaflet


Description

The LeafletPlayback plugin provides the ability to replay GPS Points in the form of POINT Simple Features. Rather than simply animating a marker along a polyline, the speed of the animation is synchronized to a clock. The playback functionality is similar to a video player; you can start and stop playback or change the playback speed.

Usage

addPlayback(
  map,
  data,
  time = "time",
  icon = NULL,
  pathOpts = pathOptions(),
  options = playbackOptions()
)

Arguments

map

a map widget

data

data must be a POINT Simple Feature or a list of POINT Simple Feature's with a time column.

time

The column name of the time column. Default is "time".

icon

an icon which can be created with makeIcon

pathOpts

style the CircleMarkers with pathOptions

options

List of additional options. See playbackOptions

Value

the new map object

Note

If used in Shiny, you can listen to 2 events

  • 'map-ID'+"_pb_mouseover"

  • 'map-ID'+"_pb_click"

References

See Also

Other Playback Functions: playbackOptions(), removePlayback()

Examples

## Not run: 
library(leaflet)
library(leaflet.extras2)
library(sf)

## Single Elements
data <- sf::st_as_sf(leaflet::atlStorms2005[1,])
data <- st_cast(data, "POINT")
data$time = as.POSIXct(
  seq.POSIXt(Sys.time() - 1000, Sys.time(), length.out = nrow(data)))

leaflet() %>%
  addTiles() %>%
  addPlayback(data = data,
              options = playbackOptions(radius = 3),
              pathOpts = pathOptions(weight = 5))


## Multiple Elements
data <- sf::st_as_sf(leaflet::atlStorms2005[1:5,])
data$Name <- as.character(data$Name)
data <- st_cast(data, "POINT")
data <- split(data, f = data$Name)
lapply(1:length(data), function(x) {
  data[[x]]$time <<- as.POSIXct(
    seq.POSIXt(Sys.time() - 1000, Sys.time(), length.out = nrow(data[[x]])))
})

leaflet() %>%
  addTiles() %>%
  addPlayback(data = data,
              options = playbackOptions(radius = 3,
                                        color = c("red","green","blue",
                                                  "orange","yellow")),
              pathOpts = pathOptions(weight = 5))

## End(Not run)

leaflet.extras2

Extra Functionality for 'leaflet' Package

v1.1.0
GPL-3 | file LICENSE
Authors
Gatscha Sebastian [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.