Learn R Programming

leaflet.extras2 (version 1.1.0)

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

References

https://github.com/hallahan/LeafletPlayback

See Also

Other Playback Functions: playbackOptions(), removePlayback()

Examples

Run this code
# 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))
# }

Run the code above in your browser using DataLab