set_style function

Update the style of a map

Update the style of a map

set_style(map, style, config = NULL, diff = TRUE)

Arguments

  • map: A map object created by the mapboxgl or maplibre function, or a proxy object.
  • style: The new style URL to be applied to the map.
  • config: A named list of options to be passed to the style config.
  • diff: A boolean that attempts a diff-based update rather than re-drawing the full style. Not available for all styles.

Returns

The modified map object.

Examples

## Not run: map <- mapboxgl( style = mapbox_style("streets"), center = c(-74.006, 40.7128), zoom = 10, access_token = "your_mapbox_access_token" ) # Update the map style in a Shiny app observeEvent(input$change_style, { mapboxgl_proxy("map", session) %>% set_style(mapbox_style("dark"), config = list(showLabels = FALSE), diff = TRUE) }) ## End(Not run)
  • Maintainer: Kyle Walker
  • License: MIT + file LICENSE
  • Last published: 2025-03-18