The Trips Layer takes an sf object with Z (elevation) and M (time) attributes and renders it as animated trips

  data = get_map_data(map),
  stroke_colour = NULL,
  stroke_width = NULL,
  opacity = 0.3,
  palette = "viridis",
  trail_length = 180,
  start_time = get_m_range_start(data),
  end_time = get_m_range_end(data),
  animation_speed = 30,
  layer_id = NULL,
  legend = FALSE,
  legend_options = NULL,
  legend_format = NULL,
  digits = 6



a mapdeck map object


sf object with XYZM dimensions.


variable of data or hex colour for the stroke.


width of the stroke in meters. Default 1.


single value in [0,1]


string or matrix. String will be one of colourvalues::colour_palettes(). A matrix must have at least 5 rows, and 3 or 4 columns of values between [0, 255], where the 4th column represents the alpha. You can use a named list to specify a different palette for different colour options (where available), e.g. list(fill_colour = "viridis", stroke_colour = "inferno")


how long it takes for the trail to completely fade out (in same units as timestamps )


the minimum timestamp


the maximum timestamp


speed of animation


single value specifying an id for the layer. Use this value to distinguish between shape layers of the same type. Layers with the same id are likely to conflict and not plot correctly


either a logical indiciating if the legend(s) should be displayed, or a named list indicating which colour attributes should be included in the legend.


A list of options for controlling the legend.


A list containing functions to apply to legend values. See section legend


number of digits for rounding coordinates


add_trips supports LINESTRING and MULTILINESTRING sf objects


The legend_options can be used to control the appearance of the legend. This should be a named list, where the names are one of

  • css - a string of valid css for controlling the appearance of the legend

  • title - a string to use for the title of the legend

  • digits - number to round the legend values to

If the layer allows different fill and stroke colours, you can use different options for each. See examples in add_arc.

The legend_format can be used to control the format of the values in the legend. This should be a named list, where the names are one of

  • fill_colour

  • stroke_colour

depending on which type of colouring the layer supports.

The list elements must be functions to apply to the values in the legend.


The id is returned to your R session from an interactive shiny environment by observing layer clicks. This is useful for returning the data.frame row relating to the cliked shape.

From within a shiny server you would typically use observeEvent({input$map_arc_click}), where 'map' is the map_id supplied to mapdeckOutput(), and 'arc' is the layer you are clicking on


# \donttest{ set_token( "MAPBOX_TOKEN") sf <- city_trail mapdeck( location = c(145, -37.8) , zoom = 10 , style = mapdeck_style("dark") ) %>% add_trips( data = sf , animation_speed = 2000 , trail_length = 1000 , stroke_colour = "#FFFFFF" )
#> trips is an experimental layer and the function may change without warning
# }