qfes / rdeck

Deck.gl widget for R
https://qfes.github.io/rdeck
MIT License
98 stars 0 forks source link

May I know how I can create the icon layer? #67

Closed RealCoChenchao closed 2 years ago

anthonynorth commented 2 years ago

This layer has almost no documentation.

This layer works similarly to the text & scatter plot layers, but each feature is rendered as a raster icon. You'll need the following icon-specific parameters for rendering icons:

An example using spData::cycle_hire with deck.gl example icons:

library(rdeck)

icon_atlas <- "https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/icon-atlas.png"
icon_mapping <- jsonlite::fromJSON("https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/icon-atlas.json")

# ensure loaded
spData::cycle_hire

cycle_hire <- spData::cycle_hire |>
  dplyr::mutate(
    # name of icon in atlas
    icon = dplyr::if_else(
      # randomly assign icons to features
      runif(dplyr::n()) > 0.9,
      "marker-warning",
      "marker"
    )
  )

rdeck(initial_bounds = cycle_hire) |>
  add_icon_layer(
    name = "cycle hire",
    data = cycle_hire,
    get_position = sf_column(),
    size_scale = 30,
    get_color = scale_color_linear(nbikes),

    # icon params
    get_icon = icon,
    icon_atlas = icon_atlas,
    icon_mapping = icon_mapping,

    # interactivity
    pickable = TRUE,
    auto_highlight = TRUE,
    tooltip = tidyselect::everything()
  )

image

edit: clarity