The background to the question is as follows:
I have a shiny app that presents data on a leaflet map. That data can be filtered and presented in different ways. However, when the user zooms in and/or moves the map, and THEN filters the data, the map will revert back to the initial map view:
output$mymap <- renderLeaflet({
leaflet() %>%
setView(lng = 0, lat = 30, zoom = 4) %>% #setting the view over ~ center of North America
addTiles(options = providerTileOptions(noWrap = TRUE))
})
What I am looking for is some way of returning the position of the map such that when the data is updated in a proxy leaflet function I can set the view as well. The following is what I'm trying to achieve (I've made up a move equivalent of input$mymap_click
).
observeEvent(input$mymap_move, {
move <- input$mymap_move
mlat <- move$lat
mlon <- move$lon
mzoom <- move$zoom
leafletProxy('mymap') %>%
setView(lng = mlng, lat = mlat, zoom = mzoom) %>%
addMarkers(data = data.join,
lat = data.join$a.lat,
lng = data.join$a.lon,
icon = icon.func[data.join$SYMBOL_CODE],
popup = data.join$ANCHOR)
})