Skip to contents

Hide a layer from the map

Usage

hide_layer(proxy, layer_id)

Arguments

proxy

The map proxy object created by mapProxy().

layer_id

The ID of the layer to hide.

Value

The map proxy object for chaining.

Note

This does not remove the layer, it only hides it from view.

Examples

if(interactive()){
library(shiny)
library(sf)
library(toro)

data(quakes)
quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326)

ui <- fluidPage(
 tagList(
   mapOutput("map"),
   actionButton("show_layer", "Show Layer"),
   actionButton("hide_layer", "Hide Layer")
 )
)
server <- function(input, output, session) {
 output$map <- renderMap({
   map() |>
     add_circle_layer(
       id = "quakes",
       source = quakes_data
     )
 })

 observe({
   mapProxy("map") |>
     show_layer(layer_id = "quakes")
 }) |>
   bindEvent(input$show_layer)

 observe({
   mapProxy("map") |>
     hide_layer(layer_id = "quakes")
 }) |>
   bindEvent(input$hide_layer)
}
}