Learn R Programming

toro (version 0.1.0)

add_fill_layer: Add a fill layer to a map or map proxy

Description

Add a fill layer to a map or map proxy

Usage

add_fill_layer(
  map,
  id,
  source,
  paint = NULL,
  layout = NULL,
  popup_column = NULL,
  hover_column = NULL,
  can_cluster = FALSE,
  under_id = NULL,
  filter = NULL,
  ...
)

Value

The updated map object with the fill layer added.

Arguments

map

The map object or map proxy to which the layer will be added.

id

A unique identifier for the layer.

source

The data source for the layer, if not a GeoJSON, it will be converted.

paint

A list of paint options for styling the layer. See get_paint_options() for defaults and options.

layout

A list of layout options for the layer. See get_layout_options() for defaults and options.

popup_column

The column name to use for popups. Default is NULL.

hover_column

The column name to use for hover effects. Default is NULL.

can_cluster

Whether the layer can be clustered. Default is FALSE.

under_id

The ID of an layer already on the map to place this layer under. Default is NULL.

filter

A filter expression to apply to the layer. Default is NULL. See get_layer_filter() for more details on how to create filter expressions.

...

Additional arguments to include in the layer definition.

  • clusterOptions: A list of options for clustering, if can_cluster is TRUE. See the cluster vignette for details on available options.

Examples

Run this code
# Load libraries
library(dplyr)
library(spData)
library(sf)

nz_data <- spData::nz |>
  dplyr::rename(geometry = geom) |>
  sf::st_transform(4326)

map() |>
 add_fill_layer(
   id = "nz_regions",
   source = nz_data,
   hover_column = "Name"
 )

map() |>
 add_fill_layer(
   id = "nz_regions",
   source = nz_data,
   hover_column = "Name",
   paint = get_paint_options(
     "fill",
     options = list(
       colour = "#a3b18a",
       opacity = 0.3,
       outline_colour = "#588157"
     )
   )
 )

Run the code above in your browser using DataLab