Skip to contents

Adds play/pause/stop buttons to control route animations on the map. Optionally includes a speed control slider for adjusting animation speed.

Usage

add_animation_controls(
  map,
  route_id = NULL,
  position = "top-right",
  panel_id = NULL,
  buttons = c("play", "pause"),
  button_icons = list(),
  button_text = list(play = "Play", pause = "Pause", stop = "Stop"),
  include_speed_control = FALSE,
  speed_values = c(0.5, 1, 2),
  speed_labels = c("Slow", "Normal", "Fast"),
  settings = list()
)

Arguments

map

A toro map object or a map proxy object.

route_id

Optional route ID to control. If NULL, controls all routes.

position

Position of the controls on the map. Default is "top-right".

panel_id

Optional control panel ID to add controls to instead of map.

buttons

Character vector of buttons to include. Options: "play", "pause", "stop". Default is c("play", "pause").

button_icons

Optional named list of custom icons for the buttons. Names should match button names (e.g., list(play = ..., pause = ..., stop = ...)). Each value can be an inline SVG string, a local PNG or SVG file path (automatically converted to a data URI), or plain text to use as the button label. NULL entries fall back to the default icon.

button_text

Optional named list of custom text labels for the buttons. Names should match button names (e.g., list(play = "Start", pause = "Hold", stop = "End")). This allows you to customize the text shown on the buttons, which can be used in combination with or instead of custom icons. If no name is provided for a button, no text will be shown.

include_speed_control

Logical. Whether to include a speed control slider. Default is FALSE.

speed_values

Numeric vector of speed values for the speed slider. Default is c(0.5, 1, 2) for slow, normal, and fast speeds.

speed_labels

Character vector of labels for speed values. Default is c("Slow", "Normal", "Fast").

settings

A list of additional settings for the controls.

Value

The map or map proxy object for chaining.

Examples

library(sf)
#> Linking to GEOS 3.14.1, GDAL 3.12.1, PROJ 9.7.1; sf_use_s2() is TRUE
library(toro)

line_data <- sf::st_sf(
  id = 1,
  geometry = sf::st_sfc(
    sf::st_linestring(
      cbind(c(172.2041, 163.9383), c(-32.56960, -46.43999))
    ),
    crs = 4326
  )
)

map() |>
  add_route(route_id = "route_line", points = line_data) |>
  add_animation_controls(
    route_id = "route_line",
    include_speed_control = TRUE,
    button_icons = list(play = "\u25b6", pause = "\u23f8", stop = "\u23f9"),
    button_text = list() # Remove labels, show only icons
  )