
Last chance! 50% off unlimited learning
Sale ends in
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.
addPlayback(
map,
data,
time = "time",
icon = NULL,
pathOpts = pathOptions(),
options = playbackOptions()
)
a map widget
data must be a POINT Simple Feature or a list of POINT Simple Feature's with a time column. It can also be a JSON string which must be in a specific form. See the Details for further information.
The column name of the time column. Default is "time"
.
an icon which can be created with makeIcon
style the CircleMarkers with
pathOptions
List of additional options. See playbackOptions
the new map
object
If data is a JSON string, it must have the following form:
{ "type": "Feature", "geometry": { "type": "MultiPoint", "coordinates": [ [-123.2653968, 44.54962188], [-123.26542599, 44.54951009] ] }, "properties": { "time": [1366067072000, 1366067074000] } }
Other Playback Functions:
playbackOptions()
,
removePlayback()
# 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