Add a source to the map
Arguments
- map
The map or map proxy object.
- source_id
The ID for the source.
- data
The data for the source, typically in GeoJSON format.
- type
The type of the source. Default is
"geojson". Other options include"vector"or"raster".- cluster
Whether to enable clustering for this source. Default is
FALSE.- ...
Additional arguments to in pass directly to the JS addSource function. Documentation for this can be found on the MapLibre GL JS docs.
id: Alternative to
source_idfor backward compatibility. If bothsource_idandidare provided,source_idwill take precedence.
Note
If you add a source directly in an add layer function, the source ID will
be automatically generated as source-{layer-id}.
Examples
# Load libraries
library(sf)
# Prepare data
data(quakes)
quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326)
# Display the source on map
map() |>
add_source(
source_id = "my_source",
data = sf::st_as_sf(quakes_data, coords = c("long", "lat"), crs = 4326)
) |>
add_circle_layer(id = "quakes", source = "my_source")
