Skip to contents

A route is a line that can be animated along a set of points. This function adds a route to the map with a unique identifier and settings for the route's appearance and animation.

Usage

add_route(map, route_id, points, settings = list())

Arguments

map

A toro map object or a map proxy object.

route_id

A unique identifier for the route.

points

A sf object containing the points of the route.

settings

A list of settings for the route (e.g., color, weight).

Value

The map or map proxy object for chaining.

Examples

if(interactive()){
library(shiny)
library(toro)
library(sf)

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
  )
)

ui <- fluidPage(
 tagList(
   mapOutput("map"),
   actionButton("play_route", "Play Route Animation"),
   actionButton("pause_route", "Pause Route Animation"),
   actionButton("remove_route", "Remove Route")
 )
)
server <- function(input, output, session) {
 output$map <- renderMap({
   map() |>
     add_route(route_id = "route_line", points = line_data)
 })

 observe({
   req(input$map_loaded)
   mapProxy("map") |>
     play_route(route_id = "route_line")
 }) |>
   bindEvent(input$play_route)

  observe({
   req(input$map_loaded)
   mapProxy("map") |>
     pause_route(route_id = "route_line")
 }) |>
   bindEvent(input$pause_route)

  observe({
   req(input$map_loaded)
   mapProxy("map") |>
     remove_route(route_id = "route_line")
 }) |>
   bindEvent(input$remove_route)
}
}