1

Hi I am trying to have multiple layers to a map in Leaflet R while leaving the markers as the top most layer. I tried using bringToFront() in highlightOptions() for the addCircleMarkers option but they get moved to the bottom most layer whenever I change the layer using addLayersControl().

Suggestions?

renderLeaflet(

leaflet()%>%
  addTiles()%>%
  addPolygons(data = district_shapes, 
              weight = 1,
              fillColor = "blue",
              fillOpacity = .25,
              label = labels,
              group = "School District"
              ) %>%
  addPolygons(data = district_shapes, 
              weight = 1,
              fillColor =~frl_pal(district_shapes$FRL),
              fillOpacity = .7,
              label = labels,
              popup = frl_label,
              group = "Free and Reduced Lunch"
              ) %>%
  addPolygons(data = district_shapes, 
              weight = 1,
              fillColor =~avgIncome_pal(district_shapes$Avg_Household_Income),
              fillOpacity = .7,
              label = labels,
              group = "Average Household Income"
              ) %>%
  addLayersControl(
    baseGroup = c("School District","Free and Reduced Lunch", "Average Household Income"),
    options = layersControlOptions(collapsed = TRUE)
  )%>%
  addCircleMarkers(
    lng = ~Longitude ,
    lat = ~Latitude,
    data = charter_year_filter(),
    label = ~Account_Name,
    color = ~Color,
    popup = sprintf("<strong><u>%s</u></strong><br/>%s <br/>%s <br/>%s <br/>%s",
                  charter_geo$Account_Name, 
                  charter_geo$Site1, 
                  charter_geo$Site2,
                  charter_geo$Site3, 
                  charter_geo$Site4)%>% lapply(htmltools::HTML),
    stroke = T,
    options = highlightOptions(bringToFront = T),
    opacity = 1,
    fillOpacity = .5,
    fill = T,
    clusterOptions = markerClusterOptions()
  )
)
OK_Sooner
  • 131
  • 1
  • 1
  • 7

0 Answers0