Skip to contents

Create a layer

Usage

Layer(type, id, source = NULL, paint = NULL, layout = NULL, ...)

Arguments

type

The type of the layer.

id

The unique ID of the layer

source

The name (unique ID) of a source or a source object to be used for the layer.

paint

The paint properties of the layer.

layout

The layout properties of the layer.

...

Additional layer options

Examples

library(maplibre)

earthquakes_source <- list(
  type = "geojson",
  data = "https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"
)

earthquakes_layer <- Layer(
  id = "earthquakes",
  type = "circle",
  source = earthquakes_source,
  paint = list("circle-color" = "yellow", "circle-radius" = 2)
)

# Adds a tooltip that appears when hovering over it

maplibre() |>
  add_layer(earthquakes_layer) |>
  add_tooltip("earthquakes", prop = "mag")
# Adds a popup that appears when clicking on the layer maplibre() |> add_layer(earthquakes_layer) |> add_popup("earthquakes", prop = "mag")