SymbolixAU / mapdeck

R interface to Deck.gl and Mapbox
https://symbolixau.github.io/mapdeck/articles/mapdeck.html
362 stars 40 forks source link

clear_bitmap() not working #367

Closed Zekiye-Y closed 1 year ago

Zekiye-Y commented 1 year ago

Describe the bug Using add_bitmap to add an image overlay to a map however the clear_bitmap() function does not seem to work and the bitmap will not clear unless refreshed.

To Reproduce

library(shiny)
library(mapdeck)
library(shinyWidgets)

set_token(ADD MAPDECK TOKEN HERE)

shinyApp(
  ui =   fluidPage(
    title = "Bitmap Test",
    fluidRow(
      column(
        # Main Window
        10,
        mapdeckOutput("map", height = '800', width = '101%'),
      )
    ),
    column(
      2,
      fluidRow(
        column(
          3,
          switchInput("bitmap_switch", 
                      value = F,
                      size = "small")
        ),
        column(
          9,
          style = "margin-left: 14px;
                           margin-right: -14px;",
          HTML(paste0("<h4><b>Bitmap Layer</b></h4>"))
        )
      ),

    )
  ),
  server = function(input, output, session) {

    map <- reactive({  
      mapdeck(style = mapdeck_style("streets"),
              location = c(-122.3, 37.8), 
              zoom = 10)
    })

    output$map <- renderMapdeck({
      map()
    })

    observeEvent(input$bitmap_switch, {
      if(input$bitmap_switch){
        mapdeck_update(map_id = "map") %>%
          add_bitmap(
            layer_id = "bitmap",
            image = paste0(
              'https://raw.githubusercontent.com/uber-common/deck.gl-data/master/',
              'website/sf-districts.png')
            , bounds = c(-122.519, 37.7045, -122.355, 37.829)
          )
      }
      else{
        mapdeck_update(map_id = 'map') %>%
          clear_bitmap(layer_id = "bitmap")
      }
    })

  }
)

Expected behaviour When the bitmap layer is turned off using the switch Input button, the bitmap layer should trigger the clear_bitmap() function however it does not remove the bitmap layer

Screenshots image

Versions


R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.utf8  LC_CTYPE=English_Australia.utf8    LC_MONETARY=English_Australia.utf8 LC_NUMERIC=C                       LC_TIME=English_Australia.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shinyWidgets_0.7.6 mapdeck_0.3.40004  shiny_1.7.4       

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10       rstudioapi_0.14   magrittr_2.0.3    xtable_1.8-4      R6_2.5.1          rlang_1.1.0       fastmap_1.1.0     tools_4.2.2       cli_3.6.0         jquerylib_0.1.4   withr_2.5.0      
[12] htmltools_0.5.4   ellipsis_0.3.2    yaml_2.3.6        digest_0.6.31     lifecycle_1.0.3   later_1.3.0       htmlwidgets_1.6.2 sass_0.4.4        promises_1.2.0.1  memoise_2.0.1     cachem_1.0.6 
``` `
dcooley commented 1 year ago

Thanks for the report - should now be fixed on the master branch

Zekiye-VAP commented 1 year ago

Thank you!