Adds monitoring-location markers and the same interactive chart, CSV, and
attribute popups used by edr_map() to an existing Leaflet widget. This is
useful for composing station observations over a gridded coverage map:
start with edr_map(grid) and add one or more station groups.
Usage
edr_add_stations(
map,
locations,
data = NULL,
popup = c("plot+csv", "plot", "csv", "table", "all"),
location_col = "coverage_id",
id_col = NULL,
label_col = NULL,
parameter = NULL,
plot_width = 7,
plot_height = 3.5,
plot_dpi = 72,
marker_radius = 6,
matched_color = "#2C7FB8",
unmatched_color = "#BBBBBB",
show_unmatched = TRUE,
legend = TRUE,
max_match_distance = NULL,
group = "Stations",
fit = FALSE
)Arguments
- map
A
leaflethtmlwidget, typically returned byedr_map().- locations
An
sfobject fromedr_locations(), anedr_responsewrapping GeoJSON, or a GeoJSONFeatureCollection.- data
Optional station observations: a tidy tibble with a location-id column, a named list of tibbles keyed by feature id, or
NULLfor attribute-only popups.- popup
One of
"plot+csv"(default),"plot","csv","table", or"all".- location_col
Column in
datacarrying the location id whendatais a single tibble. Default"coverage_id".- id_col
Column in
locationsto join on. IfNULL, the function looks for"id"then"_id"then the first character column.- label_col
Column in
locationsused for the popup heading. IfNULL, tries"name","locationName","title", then the detected id column.- parameter
Optional character vector restricting the rows of
dataused in popups. Filtered rows also determine whether a station is marked as having data.- plot_width, plot_height
Popup chart dimensions in inches. Display size in pixels is
plot_width * plot_dpibyplot_height * plot_dpi, with a larger minimum size for readable interactive popups.- plot_dpi
Display dots-per-inch for popup charts. Default 72; bump to 90+ if popups look small on hi-DPI displays.
- marker_radius
Marker radius in pixels for stations that have time-series data. Data-less stations are drawn one pixel smaller.
- matched_color
Marker colour for stations that joined to a coverage in
data. Default deep blue.- unmatched_color
Marker colour for stations without data (only relevant when
datais supplied andshow_unmatched = TRUE). Default light grey.- show_unmatched
If
TRUE(default), data-less stations are drawn inunmatched_colorso the user can see the full station network. Set toFALSEto drop them entirely. Ignored whendataisNULL.- legend
If
TRUE(default), add a legend distinguishing stations with data from those without. Suppressed automatically when there are no unmatched markers to label.- max_match_distance
Optional maximum coordinate distance for spatially matching
datarows withx/ycolumns to stations. Units are those of the station coordinates.NULL(default) keeps the nearest-station fallback unlimited.- group
Optional Leaflet layer-group name. The default,
"Stations", makes the added markers available toleaflet::addLayersControl(). PassNULLto retain the status groups used by a standalone station map ("Has data"and"No data in window").- fit
If
TRUE, fit the map to the added station extent. Defaults toFALSEso adding stations does not replace an existing coverage extent.