Closed cromanpa94 closed 1 year ago
You'll need to update the coordinates in the textInput
objects based on the center of the map:
Do not forget to also update the map if the user updates the coordinates directly:
# UI
textInput("latitude", "Latitude", value = 32.2217),
textInput("longitude", "Longitude" , value = -110.9265)
#Server
observe({
lat <- as.numeric(input$latitude)
lng <- as.numeric(input$longitude)
if (is.na(lat) || is.na(lng)) return()
leafletProxy("map") %>%
setView(lng = lng , lat = lat, zoom = input$scale)
})
The user can move the map around and the textInput
will update accordingly. Note that the map needs to be isolated so it doesn't re-render each time. Here's the relevant commit: https://github.com/cromanpa94/OSM.sf.shiny/commit/00d8ea3578ad2927fd7a6c5cd67ac8a62fdc123b.
Note that when you change the scale, the map will always zoom in to a location in Tucson. This is incorrect and needs to reflect either (1) the center of the map when someone is zooming in or (2) the particular location the user is interested in exploring. This needs to be addressed.