# \donttest{
## 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
)
# }
Run the code above in your browser using DataLab