r-spatial / leafpop

Include Tables, Images and Graphs in Leaflet Popups
Other
113 stars 15 forks source link

quest Guidance on popupGraph Function #30

Closed szr0613 closed 12 months ago

szr0613 commented 1 year ago

HI, I wanted to implement a multi-level popup window of the map, such as province-city-county-township, but I found that the windows were out of order when I was nesting the popup. Could you please tell me how to set it correctly?I have attached my code at the end of the article. I am looking forward to your reply.Thanks in advance.

township

tmaptl<- vector("list",1580) for(i in 1:1580){ names(tmaptl)[i]<-paste("tmapt",substr(tmap@data$code[i],1,9),sep="") tmaptl[[i]]<-tmapl[[i]]%>% leaflet() %>% addPolygons()%>% addMarkers(lng=hdata[hdata$townid==tmapl[[i]]$town,]$long,lat=hdata[hdata$townid==tmapl[[i]]$town,]$lat)%>%
amap() }

county

rtmaptl<- vector("list",117) for(i in 1:117){ names(rtmaptl)[i]<-paste("rtmapt",substr(rmap@data$XZQH[i],1,6),sep="") rtmaptl[[i]]<-rtmapl[[i]]%>% leaflet() %>% addPolygons()%>% addCircleMarkers(as.numeric(rtmapl[[i]]$long),as.numeric(rtmapl[[i]]$lat),popup=popupGraph(tmaptl[which(substr(names(tmaptl),6,11)==substr(names(rtmapl)[i],6,11))],type = "html") )%>% amap() }

city

crmaptl<- vector("list",11) for(i in 1:11){ names(crmaptl)[i]<-paste("crmapt",substr(cmap@data$id[i],1,4),sep="") crmaptl[[i]]<-crmapl[[i]]%>% leaflet() %>% addPolygons()%>% addCircleMarkers(lng=crmapl[[i]]$long,lat=crmapl[[i]]$lat,popup=popupGraph(rtmaptl[which(substr(names(rtmaptl),7,10)==substr(names(crmapl)[i],6,9))],type = "html"))%>% amap() }

province

scmapft<-scmapf%>% leaflet() %>% addPolygons() %>% addCircleMarkers(lng=scmapf$cp1,lat=scmapf$cp2, popup = popupGraph(crmaptl,type = "html"))%>% amap()