Skip to content

Fix #190#191

Open
danielvartan wants to merge 1 commit intowalkerke:mainfrom
danielvartan:fix/hide_controls
Open

Fix #190#191
danielvartan wants to merge 1 commit intowalkerke:mainfrom
danielvartan:fix/hide_controls

Conversation

@danielvartan
Copy link
Copy Markdown
Contributor

Closes #190

Problem

  • save_map() triggers screenshot preparation once the map object is available.
  • For PMTiles maps, source-related setup can delay completion of initial style setup.
  • Control hiding could occur too early, and controls added shortly after were captured in the final image.

Changes

  • Updated screenshot flow to wait for initial style setup completion before applying screenshot options.
  • Added a readiness wait helper in the widget screenshot module.
  • Kept timeout safeguards so screenshot calls do not block indefinitely.
  • Kept existing restore logic for map state after capture.

Result

hide_controls = TRUE now behaves consistently for:

  • maps without PMTiles sources
  • maps with PMTiles sources

Test

library(mapgl)

map <- 
  maplibre(
    bounds = c(-73.99045, -33.75118, -28.84764, 5.271841)
  ) |>
  add_pmtiles_source(
    id = "state_boundaries",
    url = "https://tiles.pmtiles.com.br/geobr/read_state/code-all-year-2020-simplified-TRUE-min_zoom-2-max_zoom-10.pmtiles"
  ) |>
  add_fill_layer(
    id = "fill",
    source = "state_boundaries",
    source_layer = "read_state",
    fill_color = "blue"
  ) |>
  add_navigation_control()

map |>
  save_map(
    filename = "pmtiles_map.png",
    hide_controls = TRUE
  )
pmtiles_map

Copilot AI review requested due to automatic review settings April 5, 2026 04:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses an intermittent save_map(hide_controls = TRUE) behavior where controls could still appear in exported screenshots when PMTiles sources delay completion of initial style setup.

Changes:

  • Added a helper to wait for completion of the widget’s initial style setup (via the widget’s _initialStyleLoaded flag) before applying screenshot-hiding options.
  • Updated screenshot preparation flow to apply screenshot options only after that readiness wait, while retaining existing timeouts to avoid indefinite blocking.
  • Made screenshot-state restoration in the error path conditional on state having been applied.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

save_map(hide_controls = TRUE) does not reliably hide controls when using add_pmtiles_source()

2 participants