# --------------------------------------------------
# 6) Leaflet map
# --------------------------------------------------
m <- leaflet(options = leafletOptions(preferCanvas = TRUE)) %>%
  addProviderTiles(providers$CartoDB.Positron) %>%

  # All 2010 tracts
  addPolygons(
    data = tracts_2010_ll,
    group = "All 2010 Tracts",
    fill = FALSE,
    color = "#bdbdbd",
    weight = 0.6,
    opacity = 0.7,
    popup = ~paste0("<b>2010 GEOID:</b> ", geoid)
  ) %>%

  # All 2020 tracts
  addPolygons(
    data = tracts_2020_ll,
    group = "All 2020 Tracts",
    fill = FALSE,
    color = "#9ecae1",
    weight = 0.6,
    opacity = 0.7,
    popup = ~paste0("<b>2020 GEOID:</b> ", geoid)
  ) %>%

  # 2020 PBC service area tracts
  addPolygons(
    data = service_area_2020_ll,
    group = "2020 PBC Service Area Tracts",
    fillColor = "#fb8b24",
    fillOpacity = 0.25,
    color = "#fb8b24",
    weight = 2,
    opacity = 1,
    popup = ~paste0(
      "<b>2020 GEOID:</b> ", geoid, "<br>",
      "<b>Status:</b> ", match_status
    )
  ) %>%

  # matched 2010 tracts
  addPolygons(
    data = service_area_2010_matched_ll,
    group = "Matched 2010 Tracts",
    fillColor = "#2a9d8f",
    fillOpacity = 0.30,
    color = "#2a9d8f",
    weight = 2,
    opacity = 1,
    popup = ~paste0(
      "<b>2010 GEOID:</b> ", geoid, "<br>",
      "<b>Status:</b> ", match_status
    )
  ) %>%

  # unmatched 2020 tracts
  addPolygons(
    data = service_area_2020_unmatched_ll,
    group = "Unmatched 2020 Tracts",
    fillColor = "#d62828",
    fillOpacity = 0.55,
    color = "#d62828",
    weight = 2.5,
    opacity = 1,
    popup = ~paste0(
      "<b>2020 GEOID:</b> ", geoid, "<br>",
      "<b>Status:</b> ", match_status
    )
  ) %>%

  # outlines
  addPolylines(
    data = service_area_2020_outline_ll,
    group = "2020 PBC Outline",
    color = "#fb8b24",
    weight = 3,
    opacity = 1
  ) %>%

  addPolylines(
    data = service_area_2010_matched_outline_ll,
    group = "Matched 2010 Outline",
    color = "#2a9d8f",
    weight = 3,
    opacity = 1,
    dashArray = "6,6"
  ) %>%

  addLayersControl(
    overlayGroups = c(
      "All 2010 Tracts",
      "All 2020 Tracts",
      "2020 PBC Service Area Tracts",
      "Matched 2010 Tracts",
      "Unmatched 2020 Tracts",
      "2020 PBC Outline",
      "Matched 2010 Outline"
    ),
    options = layersControlOptions(collapsed = FALSE)
  ) %>%

  hideGroup("All 2010 Tracts") %>%
  hideGroup("All 2020 Tracts")

m