add_polygon_layer: Add a polygon layer to the deckgl widget

View source: R/layers_polygon-layer.R

add_polygon_layerR Documentation

Add a polygon layer to the deckgl widget

Description

The PolygonLayer renders filled and/or stroked polygons.

Usage

add_polygon_layer(
  deckgl,
  data = NULL,
  properties = list(),
  ...,
  id = "polygon-layer"
)

Arguments

deckgl

A deckgl widget object.

data

The url to fetch data from or a data object.

properties

A named list of properties with names corresponding to the properties defined in the deckgl-api-reference for the given layer class. The properties parameter can also be an empty list. In this case all props must be passed as named arguments.

...

Named arguments that will be added to the properties object. Identical parameters are overwritten.

id

The unique id of the layer.

See Also

https://deck.gl/#/documentation/deckgl-api-reference/layers/polygon-layer

Examples

## @knitr polygon-layer
sample_data <- paste0(
  "https://raw.githubusercontent.com/",
  "uber-common/deck.gl-data/",
  "master/website/sf-zipcodes.json"
)

properties <- list(
  pickable = TRUE,
  stroked = TRUE,
  filled = TRUE,
  wireframe = TRUE,
  lineWidthMinPixels = 1,
  getPolygon = ~contour,
  getElevation = JS("d => d.population / d.area / 10"),
  getFillColor = JS("d => [d.population / d.area / 60, 140, 0]"),
  getLineColor = c(80, 80, 80),
  getLineWidth = 1,
  tooltip = "{{zipcode}}<br/>Population: {{population}}"
)

deck <- deckgl(zoom = 11, pitch = 25) %>%
  add_polygon_layer(data = sample_data, properties = properties) %>%
  add_basemap() %>%
  add_control("Polygon Layer")

if (interactive()) deck

crazycapivara/deckgl documentation built on March 29, 2023, 4:10 a.m.