addFgb {leafem} | R Documentation |
Add a flatgeobuf file to leaflet map
Description
flatgeobuf is a performant binary geo-spatial file format suitable for
serving large data. For more details see
https://github.com/flatgeobuf/flatgeobuf and the respective
documentation for the GDAL/OGR driver at
https://gdal.org/drivers/vector/flatgeobuf.html.
In contrast to classical ways of serving data from R onto a leaflet map,
flatgeobuf can stream the data chunk by chunk so that rendering of the map
is more or less instantaneous. The map is responsive while data is still
loading so that popup queries, zooming and panning will work even
though not all data has been rendered yet. This makes for a rather pleasant
user experience as we don't have to wait for all data to be added to the map
before interacting with it.
Usage
addFgb(
map,
file = NULL,
url = NULL,
layerId = NULL,
group = NULL,
popup = NULL,
label = NULL,
radius = 10,
stroke = TRUE,
color = "#03F",
weight = 5,
opacity = 0.5,
fill = FALSE,
fillColor = NULL,
fillOpacity = 0.2,
dashArray = NULL,
options = NULL,
className = NULL,
scale = scaleOptions(),
minZoom = NULL,
maxZoom = 52,
...
)
Arguments
map |
a mapview or leaflet object. |
file |
file path to the .fgb file to be added to |
url |
url of the data to be added to |
layerId |
the layer id. |
group |
the group name for the file to be added to |
popup |
either a logical of whether to show the feature properties (fields) in popups or the name of the field to show in popups. |
label |
name of the field to be shown as a tooltip. |
radius |
the size of the circle markers. |
stroke |
whether to draw stroke along the path (e.g. the borders of polygons or circles). |
color |
stroke color. |
weight |
stroke width in pixels. |
opacity |
stroke opacity. |
fill |
whether to fill the path with |
fillColor |
fill color. If set, |
fillOpacity |
fill opacity. |
dashArray |
a string that defines the stroke dash pattern. |
options |
a list of extra options for tile layers, popups, paths (circles, rectangles, polygons, ...), or other map elements. |
className |
optional class name for the popup (table). Can be used to define css for the popup. |
scale |
named list with instructions on how to scale radius, width, opacity, fillOpacity if those are to be mapped to an attribute column. |
minZoom |
minimum zoom level at which data should be rendered. |
maxZoom |
maximum zoom level at which data should be rendered. |
... |
currently not used. |
Examples
if (interactive()) {
library(leaflet)
library(leafem)
# via URL
url = "https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/3.0.1/test/data/UScounties.fgb"
leaflet() %>%
addTiles() %>%
leafem:::addFgb(
url = url
, group = "counties"
, label = "NAME"
, popup = TRUE
, fill = TRUE
, fillColor = "blue"
, fillOpacity = 0.6
, color = "black"
, weight = 1
) %>%
addLayersControl(overlayGroups = c("counties")) %>%
addMouseCoordinates() %>%
setView(lng = -105.644, lat = 51.618, zoom = 3)
}