datadiversitylab / BarrioMap

https://viz.datascience.arizona.edu/barriomap/
MIT License
0 stars 1 forks source link

Enable dynamic view #1

Closed cromanpa94 closed 1 year ago

cromanpa94 commented 1 year ago

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.

cromanpa94 commented 1 year ago

You'll need to update the coordinates in the textInput objects based on the center of the map:

https://stackoverflow.com/questions/60606516/how-do-i-return-the-position-of-a-leaflet-map-in-shiny-once-its-been-moved-by-t

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)
  })
cromanpa94 commented 1 year ago

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.