Add Deck.gl ScatterplotLayer to a mapgl::maplibre() or mapgl::mapboxgl() map using blazing fast nanoarrow::write_nanoarrow() data transfer.
Source: R/addGeoArrowScatterplotLayer.R
addGeoArrowScatterplotLayer.RdAdd Deck.gl ScatterplotLayer to a mapgl::maplibre() or mapgl::mapboxgl() map
using blazing fast nanoarrow::write_nanoarrow() data transfer.
Usage
addGeoArrowScatterplotLayer(
map,
data,
file,
url,
layer_id = "scatter",
geom_column_name = "geometry",
popup = NULL,
tooltip = NULL,
render_options = renderOptions(),
data_accessors = dataAccessors(),
popup_options = popupOptions(),
tooltip_options = tooltipOptions(),
...
)Arguments
- map
the
mapgl::maplibre()ormapgl::mapboxgl()map to add the layer to.- data
a sf
(MULTI)POINTobject.- file
a valid local file path to a
geoarroworgeoparquetfile to be added to the map. Ignored ifdatais supplied.- url
a URL to a remotely hosted
geoarroworgeoparquetfile to be added to the map. Ignored ifdataorfileis supplied.- layer_id
the layer id.
- geom_column_name
the name of the geometry column of the sf object. It is inferred automatically if only one is present.
- popup
should a popup be contructed? If
TRUE, will create a popup fromm all available attributes of the feature. Can also be a character vector of column names, on which case the popup will include only those columns. If a single character is supplied, then this will be shown for all features. IfNULL(deafult) orFALSE, no popup will be shown.- tooltip
should a tooltip be contructed? If
TRUE, will create a tooltip fromm all available attributes of the feature. Can also be a character vector of column names, on which case the tooltip will include only those columns. If a single character is supplied, then this will be shown for all features. IfNULL(deafult) orFALSE, no tooltip will be shown.- render_options
a list of renderOptions
- data_accessors
a list of dataAccessors
- popup_options
a list of popupOptions
- tooltip_options
a list of tooltipOptions
- ...
can be used to pass additional props and parameters to the deck.gl instance. See Details for more info.
Details
... can be used to pass additional props and parameters to the deck.gl instance
for fine-tuning rendering behaviour. For example, we can pass a list called
parameters with settings that control the GPU pipeline of the deck.gl instance.
See https://luma.gl/docs/api-reference/core/parameters for a list of
available prarmeters.
By default, all deck.gl layers passed to a maplibre() map will be drawn on
top of existing ones. It is, however, possible to inject layers into the
existing maplibre (base) layer stack by using
render_options = renderOptions(beforeId = "<some-existing-layer-id>")
which will plot the current layer underneath "<some-existing-layer-id>".
See below for an example.
Examples
library(wk)
library(mapgl)
style_positron = "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
m = maplibre(style = style_positron)
## single wk POINT
pt = wkt("POINT (0 0)")
m |>
addGeoArrowScatterplotLayer(
data = pt
, layer_id = "wk_point"
)
## wk POINT data frame
n = 5e3
pts = xy(
x = runif(n, -180, 180)
, y = runif(n, -50, 50)
, crs = 4326
)
dat = data.frame(
id = 1:length(pts)
, geometry = pts
)
dat$fillColor = sample(hcl.colors(n, alpha = sample(seq(0, 1, length.out = n))))
dat$lineColor = sample(
hcl.colors(n, alpha = sample(seq(0, 1, length.out = n)), palette = "inferno")
)
dat$radius = sample.int(15, nrow(dat), replace = TRUE)
dat$lineWidth = sample.int(5, nrow(dat), replace = TRUE)
m = maplibre(
style = style_positron
) |>
add_navigation_control(visualize_pitch = TRUE) |>
add_globe_control()
m |>
addGeoArrowScatterplotLayer(
data = dat
, layer_id = "wk-points-layer"
, geom_column_name = "geometry"
, render_options = renderOptions()
, data_accessors = dataAccessors(
getRadius = "radius"
, getFillColor = "fillColor"
, getLineWidth = "lineWidth"
, getLineColor = "lineColor"
)
, popup = TRUE
, popup_options = popupOptions(anchor = "bottom-right")
, tooltip = TRUE
, tooltip_options = tooltipOptions(anchor = "top-left")
)
## same as above, but using `beforeId` to inject layer into base layer stack
m |>
addGeoArrowScatterplotLayer(
data = dat
, layer_id = "wk-points-layer-before-water"
, geom_column_name = "geometry"
, render_options = renderOptions(beforeId = "water")
, data_accessors = dataAccessors(
getRadius = "radius"
, getFillColor = "fillColor"
, getLineWidth = "lineWidth"
, getLineColor = "lineColor"
)
, popup = TRUE
, popup_options = popupOptions(anchor = "bottom-right")
, tooltip = FALSE
, tooltip_options = tooltipOptions(anchor = "top-left")
)
## remote parquet file
## paste url together so CRAN check doesn't complain
base_url = "https://raw.githubusercontent.com/geoarrow/"
data_url = "geoarrow-data/v0.2.0/natural-earth/files/natural-earth_cities_native.parquet"
url = paste0(base_url, data_url)
m |>
addGeoArrowScatterplotLayer(
url = url
, layer_id = "parquet-layer"
, geom_column_name = "geometry"
, data_accessors = dataAccessors(
getRadius = 10
, getFillColor = '#ff000090'
, getLineColor = '#000000ff'
)
, tooltip = TRUE
)