Skip to contents

Show or hide a scale control on the map

Usage

toggle_scale_control(proxy, id = "scale_control", show = TRUE)

Arguments

proxy

The map proxy object created by mapProxy().

id

Unique identifier of the scale control to toggle. Default is "scale_control".

show

Logical indicating whether to show or hide the control. Default is TRUE.

Value

The map proxy object for chaining.

Examples

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

ui <- fluidPage(
  tagList(
    mapOutput("map"),
    checkboxInput("show_scale", "Show scale control", value = TRUE)
  )
)
server <- function(input, output, session) {
  output$map <- renderMap({
    map() |> add_scale_control()
  })

  observe({
    req(input$map_loaded)
    mapProxy("map") |>
      toggle_scale_control(show = input$show_scale)
  }) |>
    bindEvent(input$show_scale)
}
}