# \donttest{
set_token( "MAPBOX_TOKEN")
sf <- city_trail
mapdeck(
style = mapdeck_style("dark")
) %>%
add_trips(
data = sf
, animation_speed = 500
, trail_length = 500
, stroke_colour = "#FFFFFF"
, stroke_width = 25
)
## Multi-coloured trips
## requires a colour for each coordiante
## In this example I'm assining the elevation (z) value
## to a new column
df <- sfheaders::sf_to_df( city_trail )
df$colour <- df$z
sf <- sfheaders::sf_linestring(
obj = df
, x = "x"
, y = "y"
, z = "z"
, m = "m"
, keep = TRUE
, list_column = "colour"
)
mapdeck(
style = mapdeck_style("light")
) %>%
add_trips(
data = sf
, animation_speed = 1000
, trail_length = 1000
, stroke_colour = "colour"
, stroke_width = 50
, legend = TRUE
)
## New York Taxi Trips
json <- jsonify::from_json(
"https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/trips/trips.json"
)
lens <- vapply( json$segments, nrow, 1L )
mat <- do.call( rbind, json$segments )
df <- setNames( as.data.frame( mat ), c("x","y","m") )
idx <- rep( seq_along( lens ), times = lens )
df$vendor <- rep( json$vendor, times = lens )
df$z <- 0 ## z column is required in SF object
df$idx <- idx
## Using the timestamp as a colour
df$timestamp <- df$m
sf_line <- sfheaders::sf_linestring(
obj = df
, x = "x"
, y = "y"
, z = "z"
, m = "m"
, linestring_id = "idx"
, keep = TRUE
, list_column = "timestamp"
)
mapdeck(
style = mapdeck_style("dark")
) %>%
add_trips(
data = sf_line
, stroke_colour = "timestamp"
, animation_speed = 1000
, trail_length = 1000
, palette = colourvalues::get_palette("viridis")[100:256, ]
)
# }
Run the code above in your browser using DataLab