0
votes

I am just learning leaflet. I am able to add a polygon made of many other polygons. I would like to add a label to each polygon. The label I would like to add is mabsurvey@data$ID. There are 33 polygons and labels.

This is my attempt:

  leaflet(as.data.frame(position)) %>%
      addTiles() %>%
      addPolygons(data = mabsurvey, color = 'grey', opacity = 0.4,label=~mabsurvey@data$ID) %>%
      addPolygons(data = accessareas, fill=F,color = 'black', opacity = 0.5) %>%
      addPolygons(data = accessareas_c, fill=F,color = 'black', opacity = 0.8) %>%
      addCircles(lng = ~long, lat = ~lat, color="red")
1

1 Answers

0
votes
leaflet(as.data.frame(position)) %>%
  addTiles() %>%
  addPolygons(data = mabsurvey, color = 'grey', opacity = 0.4,popup=paste("Stratum:",mabsurvey@data$STRATA2,"<br>")) %>%
  addPolygons(data = accessareas, fill=F,color = 'black', opacity = 0.5) %>%
  addPolygons(data = accessareas_c, fill=F,color = 'black', opacity = 0.8) %>%
  addCircles(lng = ~long, lat = ~lat, color="red")