SymbolixAU / mapdeck

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

Support for updating pitch/zoom/bearing without specifying the location #375

Closed hdmm3 closed 11 months ago

hdmm3 commented 1 year ago

I was trying to update the map view using mapdeck_view in my shiny app to change the pitch, without changing the location like this:

mapdeck_update(map_id = "map") %>%
          mapdeck_view(pitch = 60, transition = "linear", duration = 500)

However, doing this throws console errors in the browser and freezes/crashes the map. Assuming this behaviour wasn't considered for mapdeck_view, would it be possible to add it? Alternatively, is there a workaround to do this?

I'm using the latest Github version of the package.

dcooley commented 1 year ago

I think this is related to https://github.com/SymbolixAU/mapdeck/issues/373 - will fully test when that's resolved

dcooley commented 11 months ago

reader: not solved by #373


example:

library(shiny)
library(shinydashboard)
library(mapdeck)
set_token(secret::get_secret("MAPBOX"))

ui <- dashboardPage(
    dashboardHeader()
    , dashboardSidebar(
        shiny::actionButton(
            inputId = "btn"
            , label = "update view"
        )
    )
    , dashboardBody(
        mapdeckOutput(
            width = "100%"
            , height = "800px"
            , outputId = "map"
        )
    )
)

server <- function(input, output) {

    output$map <- renderMapdeck({
        mapdeck(style = mapdeck_style("light"))
    })

    observeEvent(input$btn, {
        mapdeck_update(map_id = "map") %>%
            mapdeck_view(pitch = 60, transition = "linear", duration = 500)
    })

}

shinyApp(ui = ui, server = server)
dcooley commented 11 months ago

needed to check for empty location array (as well as null)