Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

select geometries to map #6

Open
ehesch opened this issue Jun 10, 2021 · 2 comments
Open

select geometries to map #6

ehesch opened this issue Jun 10, 2021 · 2 comments

Comments

@ehesch
Copy link
Contributor

ehesch commented Jun 10, 2021

The challenge is that ideally, I’d like the user to have options (either a button or layers that can be turned on/off) to choose if they want to:
Map (+ download/graph/table) all metro tracts
Map (+ download/graph/table) corridors, which are essentially bundles of a few tracts
Map (+ download/graph/table) corridor walksheds, which are larger bundles of tracts
Optional, but nice: Overlay polygons of the corridors themselves (smaller than tracts), just for context. No need to attach any data to those in themselves.

@carogeo yes! All of these things can be done :) breaking up into 2 comments here:

Overlay polygons

  1. the easiest is to overlay corridor polygons; if you check out the msp branch, the mod_map_overview.R file shows how you can overlay extra information (in this case, transit stops)
 #### regional specific other data layers
      addMapPane("trans", zIndex = 431) %>%
      addCircles(
        # Markers(
        data = trans_stops,
        group = "Active transit stops",
        radius = 20,
        fill = T,
        stroke = TRUE,
        weight = 2,
        color = "black", #councilR::colors$transitRed,
        fillColor = "black",# councilR::colors$transitRed,
        options = pathOptions(pane = "trans")
      ) %>%
      # groupOptions(
      #   group = "Active transit stops",
      #   zoomLevels = 13:20
      # ) %>%
      
      hideGroup("Active transit stops") %>%
      
      ### add layer control
      addLayersControl(
        position = "bottomright",
        baseGroups = c(
          "Carto Positron",
          "Stamen Toner",
          "Aerial Imagery"
        ),
        overlayGroups = c(
          "EVA Scores",
          "Active transit stops"
        ),
        options = layersControlOptions(collapsed = T)
      ) 

You'll note that I did addCircles but you can just as easily addPolygons. The zIndex makes sure that the layer will be on top of others. The commented out groupOptions would automatically turn on the layer if you zoomed in on the map. Make sure to update the addLayersControl if you change names, add overlays, etc.

@ehesch
Copy link
Contributor Author

ehesch commented Jun 10, 2021

Map/dl/etc specific geographies

@carogeo, as I'm thinking about it now, I think the easiest way to go about this would be to add a "radiobutton" option. I think it could be intuitive to add it immediately under the map description, but not interfere with the sidebarpanel?

If this seems like the way to go, I'd recommend making a new module (for instance golem::add_module("geo_selection")). in the UI of that module, put the radio buttons. something like this:

 radioButtons(
        ns("input_geo"),
        label = h4("Choose geography to map"),
        choices = c("tract", "corridor", "corridor walkshed"),
        selected = c("tract")
      )

In the server of the module "save" the user input as a reactive value. Kind of like what is happening in the mod_map_selections.R file.

  input_values <- reactiveValues() # start with an empty reactiveValues object.
  
  observeEvent(input$input_distance,{ 
    input_values$selected_distance <- input$input_distance})
  
  return(input_values)

Then in the app_server.R file, you'll want to be sure to save the geography input - something like this:

map_selections <- callModule(mod_geo_selection_server, "geo_selection_ui_1")

And you'll also want to make sure that the modules which will need the geography selection (mod_plot_tract, mod_download_scores, mod_table, map_utils, maybe others ) get the map_selections imported (so kind of like how tract_selections and map_utils are happening here in the app_server.R file (also do the same in the server part of the individual modules):

callModule(mod_plot_tract_server, "plot_tract_ui_1",
             tract_selections = tract_selections,
             map_util = map_util)

The mod_map_utils.R file currently saves the tract that a user would click on. So that should get updated too...I'd probably use an if else statement with the geo_selection being an input into the function - so something like if (geo_selection == "tract") {do the tract thing} else if (geo_selection == "corridor") {do a corridor thing} else if (geo_selection == "walkshed") {do the walkshed thing}.

And then finally you'll get to the mod_map_overview.R which I don't think would need any updating, actually! Because it pulls the geometry from the map_util$map_data2!

Give it a try, and let me know if you'd like me to have a look. If you're unsure of pushing something to GitHub and breaking your code that works, it can always be nice to start a new branch (here "geoselection") or something which can be linked to a specific issue. If you break the new branch, you'll always be able to abandon it!

Screen Shot 2021-06-10 at 4 48 39 PM

@carogeo
Copy link

carogeo commented Jun 29, 2021

@ehesch These options both seem great, thank you!

In the main branch of my fork, I added corridors as polygons. Any thoughts for how to best add EVA data for these? I'd like to either:

  • Merge a "corridor" column onto the EVA data, and then conditionally 'group_by(corridor)' rather than group_by(tract_string) in mod_map_utils when the user clicks on a corridor rather than a tract. Or,
  • Set up an entirely new dataset for this pane, if necessary. The challenge here is having the new dataset 'listen' to the map selections and save the correct info to create the plots and tables.

Alternatively, I also attempted to create geo selection radio buttons, in the geography_selections branch. I ran into a similar roadblock of how best to integrate a new module and new data into the current app structure.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants