Renders flat arcs along the great circle joining pairs of source and target points, specified as longitude/latitude coordinates.
add_greatcircle( map, data = get_map_data(map), layer_id = NULL, origin, destination, id = NULL, stroke_from = NULL, stroke_from_opacity = NULL, stroke_to = NULL, stroke_to_opacity = NULL, stroke_width = NULL, wrap_longitude = FALSE, tooltip = NULL, auto_highlight = FALSE, highlight_colour = "#AAFFFFFF", legend = F, legend_options = NULL, legend_format = NULL, palette = "viridis", na_colour = "#808080FF", update_view = TRUE, focus_layer = FALSE, transitions = NULL, digits = 6 )
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 |
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 |
origin | vector of longitude and latitude columns, and optionally an elevation column,
or an |
destination | vector of longitude and latitude columns, and optionally an elevatino column,
or an |
id | an id value in |
stroke_from | column of |
stroke_from_opacity | Either a string specifying the
column of |
stroke_to | column of |
stroke_to_opacity | Either a string specifying the
column of |
stroke_width | width of the stroke in pixels |
wrap_longitude | logical, whether to automatically wrap longitudes over the 180th antimeridian. |
tooltip | variable of |
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. |
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 |
palette | string or matrix. String will be one of |
na_colour | hex string colour to use for NA values |
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 |
transitions | list specifying the duration of transitions. |
digits | number of digits for rounding coordinates |
add_greatcircle
supports POINT sf objects
MULTIPOINT objects will be treated as single points. That is, if an sf objet has one row with a MULTIPOINT object consisting of two points, this will be expanded to two rows of single POINTs. Therefore, if the origin is a MULTIPOINT of two points, and the destination is a single POINT, the code will error as there will be an uneven number of rows
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{ ## You need a valid access token from Mapbox set_token("MAPBOX_TOKEN") url <- 'https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv' flights <- read.csv(url) flights$id <- seq_len(nrow(flights)) flights$stroke <- sample(1:3, size = nrow(flights), replace = T) flights$info <- paste0("<b>",flights$airport1, " - ", flights$airport2, "</b>") mapdeck( style = mapdeck_style("dark"), pitch = 45 ) %>% add_greatcircle( data = flights , layer_id = "greatcircle_layer" , origin = c("start_lon", "start_lat") , destination = c("end_lon", "end_lat") , stroke_from = "airport1" , stroke_to = "airport2" , stroke_width = "stroke" , tooltip = "info" , auto_highlight = TRUE , legend = T , legend_options = list( stroke_from = list( title = "Origin airport" ), css = "max-height: 100px;") ) mapdeck( style = mapdeck_style("dark")) %>% add_greatcircle( data = flights , layer_id = "greatcircle_layer" , origin = c("start_lon", "start_lat") , destination = c("end_lon", "end_lat") , stroke_from = "airport1" , stroke_to = "airport2" , stroke_width = "stroke" ) ## Using a 2-sfc-column sf object library(sfheaders) sf_flights <- sfheaders::sf_point( flights, x = "start_lon", y = "start_lat", keep = TRUE ) destination <- sfheaders::sfc_point( flights, x = "end_lon", y = "end_lat" ) sf_flights$destination <- destination mapdeck() %>% add_greatcircle( data = sf_flights , origin = 'geometry' , destination = 'destination' , layer_id = 'greatcircles' , stroke_from = "airport1" , stroke_to = "airport2" ) # }