-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mapdeck_view() doesn't use current viewState properties #382
Comments
Thanks for the PR - now merged |
Something in this commit causes the map to freeze, so I've reverted to the commit before this. |
something else was wrong so I've fully reverted this |
Hi @dcooley, first of all apologies for those half-baked PRs. This time I'll share my thoughts first. I've been digging about the intended behaviour of deck.gl when using either initialViewState or viewState props. Here are some of my interpretations of what's going on when using the
In order to avoid fully overwriting the viewState, the initialViewState prop could be set in window[map_id + 'map'].setProps({
initialViewState: {
...window[map_id + 'map'].viewState,
[map_id]: {
longitude: currentLon,
latitude: currentLat,
zoom: currentZoom,
maxZoom: currentMaxZoom,
minZoom: currentMinZoom,
maxPitch: currentMaxPitch,
minPitch: currentMinPitch,
pitch: currentPitch,
bearing: currentBearing,
transitionInterpolator: transition === "fly" ? new deck.FlyToInterpolator() : new deck.LinearInterpolator(),
transitionDuration: duration,
controller: true}
}
}); As such, the current viewState for the map_id could be retrieved using viewManager.getViewState(), as follows: currentViewState = window[map_id + 'map'].viewManager?.getViewState(map_id) || window[map_id + 'map'].viewState;
I hope this helps! |
Thanks for the extra detail. And I've been meaining to revisit the I'll try and set some time aside next week to look at this in more detail. |
reprex for this: library(shiny)
library(sinydashboard)
set_token(secret::get_secret("MAPBOX"))
ui <- shinydashboard::dashboardPage(
header = shinydashboard::dashboardHeader()
, sidebar = shinydashboard::dashboardSidebar(
shiny::actionButton(inputId = "viewState", label = "Pitch")
)
, body = shinydashboard::dashboardBody(
mapdeck::mapdeckOutput(
outputId = "map"
)
)
)
server <- function(input, output, session) {
observeEvent({input$viewState},{
mapdeck::mapdeck_update(map_id = "map") %>%
mapdeck::mapdeck_view(pitch = 45)
})
output$map <- mapdeck::renderMapdeck({
mapdeck::mapdeck() %>%
mapdeck::add_scatterplot(
data = capitals
)
})
}
shiny::shinyApp(ui, server) |
@hdmm3 I've finally managed to look at this again and added a potential solution to the branch Notes:
|
Hi @dcooley, I just tested your commit in my project and it seems to be working perfectly. Let me know if you would like me to run any additional tests. |
great - I think it's now working as intended so I'll merge into master |
I've been trying to use
mapdeck_view()
to individually update some map parameters, like the bearing or zoom level. However, after manually zooming, dragging, tilting, if I call something likemapdeck_view(pitch = 45)
the rest of the viewState parameters will be reset to the latest values programmatically defined for the viewState, instead of the current values.After a quick inspection, I noticed that the underlying function here is getting the current lon, lat, pitch, bearing, zoom, etc, directly from the
viewState
whose values don't seem to change when interacting with the map. The current values seem to be nested insideviewState.map
instead. So for instance retrieving the current pitch could be done through:I'll submit a PR for this issue.
The text was updated successfully, but these errors were encountered: