add_path {mapdeck} | R Documentation |
Add Path
Description
The Path Layer takes in lists of coordinate points and renders them as extruded lines with mitering.
Usage
add_path(
map,
data = get_map_data(map),
polyline = NULL,
stroke_colour = NULL,
stroke_width = NULL,
stroke_opacity = NULL,
dash_size = NULL,
dash_gap = NULL,
offset = NULL,
width_units = c("meters", "common", "pixels"),
width_min_pixels = NULL,
width_max_pixels = NULL,
width_scale = 1,
tooltip = NULL,
billboard = FALSE,
layer_id = NULL,
id = NULL,
auto_highlight = FALSE,
highlight_colour = "#AAFFFFFF",
palette = "viridis",
na_colour = "#808080FF",
legend = FALSE,
legend_options = NULL,
legend_format = NULL,
update_view = TRUE,
focus_layer = FALSE,
digits = 6,
transitions = NULL,
brush_radius = NULL,
...
)
Arguments
map |
a mapdeck map object |
data |
data to be used in the layer. All coordinates are expected to be EPSG:4326 (WGS 84) coordinate system |
polyline |
optional column of |
stroke_colour |
variable of |
stroke_width |
width of the stroke in meters. Default 1. |
stroke_opacity |
Either a string specifying the column of |
dash_size |
size of each dash, relative to the width of the stroke |
dash_gap |
size of the gap between dashes, relative to the width of the stroke |
offset |
The offset to draw each path with, relative to the width of the path. Negative offset is to the left hand side, and positive offset is to the right hand side. 0 extrudes the path so that it is centered at the specified coordinates. |
width_units |
The units of the line width, one of 'meters', 'common' or 'pixels'. When zooming in and out, meter sizes scale with the base map, and pixel sizes remain the same on screen. |
width_min_pixels |
The minimum path width in pixels. This can be used to prevent the path from getting too thin when zoomed out. |
width_max_pixels |
The maximum path width in pixels. his prop can be used to prevent the path from getting too thick when zoomed in. |
width_scale |
The path width multiplier that multiplied to all paths. |
tooltip |
variable of |
billboard |
logical indicating if the path always faces the camera (TRUE) or if it always faces up (FALSE) |
layer_id |
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 |
id |
an id value in |
auto_highlight |
logical indicating if the shape under the mouse should auto-highlight |
highlight_colour |
hex string colour to use for highlighting. Must contain the alpha component. |
palette |
string or matrix. String will be one of |
na_colour |
hex string colour to use for NA values |
legend |
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. |
legend_options |
A list of options for controlling the legend. |
legend_format |
A list containing functions to apply to legend values. See section legend |
update_view |
logical indicating if the map should update the bounds to include this layer |
focus_layer |
logical indicating if the map should update the bounds to only include this layer |
digits |
number of digits for rounding coordinates |
transitions |
list specifying the duration of transitions. |
brush_radius |
radius of the brush in metres. Default NULL. If supplied, the arcs will only show if the origin or destination are within the radius of the mouse. If NULL, all arcs are displayed |
... |
|
Details
add_path
supports LINESTRING and MULTILINESTRING sf objects
transitions
The transitions argument lets you specify the time it will take for the shapes to transition from one state to the next. Only works in an interactive environment (Shiny) and on WebGL-2 supported browsers and hardware.
The time is in milliseconds
Available transitions for path
list( path = 0, stroke_colour = 0, stroke_width = 0 )
gradient fill
If a colour is supplied for each coordinate (see examples), the colour along each segment
of the line is gradient-filled. However, if either dash_gap
, dash_size
or
offset
are supplied the the segment is filled with a solid colour, accoding to the
first point on the segment.
data
If the data
is a simple feature object, the geometry column is automatically
detected. If the sf object contains more than one geometry column and you want to use a specific one,
you'll need to set the active geometry using sf::st_geometry( x ) <- "your_column"
,
where "your_column"
is the name of the column you're activating. See ?sf::st_geometry
legend
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 legendtitle - 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.
id
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
Examples
## You need a valid access token from Mapbox
key <- 'abc'
set_token( key )
mapdeck(
style = mapdeck_style("dark")
) %>%
add_path(
data = roads
, stroke_colour = "RIGHT_LOC"
, stroke_width = 20
, layer_id = "path_layer"
, tooltip = "ROAD_NAME"
, auto_highlight = TRUE
, legend = TRUE
)
## Dashed lines
mapdeck(
style = mapdeck_style("dark")
) %>%
add_path(
data = roads
, stroke_colour = "RIGHT_LOC"
, layer_id = "path_layer"
, tooltip = "ROAD_NAME"
, stroke_width = 1
, dash_size = 0.5
, dash_gap = 5
)
## Different dashes per path
sf <- mapdeck::roads
sf$dash_size <- sample(1:5, size = nrow( sf ), replace = TRUE )
sf$dash_gap <- sample(1:5, size = nrow( sf ), replace = TRUE )
mapdeck(
style = mapdeck_style("dark")
) %>%
add_path(
data = sf
, stroke_colour = "RIGHT_LOC"
, layer_id = "path_layer"
, tooltip = "ROAD_NAME"
, dash_size = "dash_size"
, dash_gap = "dash_gap"
)
## Offset lines
sf <- mapdeck::roads
sf$offset <- sample(-10:10, size = nrow( sf ), replace = TRUE )
mapdeck(
style = mapdeck_style("light")
) %>%
add_path(
data = sf
, stroke_colour = "ROAD_NAME"
, offset = "offset"
)
## Multi Coloured line
## You need to supply one colour per coordinate in the sf object
sf_line <- sfheaders::sf_linestring(
obj = data.frame(
id = c(1,1,1,1,1,2,2,2,2,2)
, x = c(0,0,1,1,2,-1,-1,0,0,1)
, y = c(0,1,1,2,2,0,1,1,2,2)
, col = c(1,2,3,4,5,5,4,3,2,1)
)
, x = "x"
, y = "y"
, linestring_id = "id"
, list_columns = "col"
, keep = TRUE
)
mapdeck(
style = mapdeck_style("light")
) %>%
add_path(
data = sf_line
, stroke_colour = "col"
, stroke_width = 50000
)
## If using dashed lines, colours won't be gradient-filled
mapdeck(
style = mapdeck_style("light")
) %>%
add_path(
data = sf_line
, stroke_colour = "col"
, stroke_width = 500
, dash_size = 10
, dash_gap = 10
)