我想使用addLayersControl小部件将图层添加到现有地图中,但我一直在获取以下信息:警告:调度错误:缺少参数“ map”,没有default(server)和参数“ map”,其中显示屏上没有默认错误。我希望能够在地图的不同图层之间切换。我尝试过包括getMapdata函数,但仍然无法在各层之间切换。可复制的代码:
#loading shape files
mp<-readOGR(
dsn="merge",
layer="m1")
treat<- readOGR(dsn="Wastewater treatment plants map",
layer="Nk_Sewer_Treatment")
output$leaf<-renderLeaflet({
leaflet(mp) %>%
#Initializing the map
setView(lng=36.092245, lat=-00.292115,zoom=15)%>%
#Base map
#Add default OpenStreetMap map tiles
addTiles(group = "default1")%>%
addProviderTiles("Esri.NatGeoWorldMap",group = "default")%>%
addProviderTiles("CartoDB.Positron",group = "custom")%>%
addPolygons(
data = mp,
fillColor = "blue",
weight = 1, smoothFactor = 0.5,
opacity = 1.0, fillOpacity = 1.0,
highlightOptions = highlightOptions(
weight = 2,
color = "red",
fillOpacity = 0.7,
bringToFront = TRUE
),
label =~LIA,
popup = ~paste("<strong>Area Type:</strong>",AreaTyp,
"<br>",
"<strong>Piped Water On Plot:</strong>",PpdWtrP,"%",
"<br>",
"<strong>Water Source On Plot:</strong>",WtrSrOP,"%",
"<br>",
"<strong>Flash Toilets:</strong>",FlshTlt,"%",
"<br>",
"<strong>Other Improved:</strong>",OthrImp,"%",
"<br>",
"<strong>Unimproved:</strong>",Unmprvd,"%",
"<br>",
"<strong>Open Defecation:</strong>",OpnDfct,"%",
"<br>",
"<strong>Population Per km2:</strong>",PpDnsty
)
)
#Overlay map
addPolygons(
data = treat,
fillColor = "red",
weight = 1, smoothFactor = 0.5,
opacity = 1.0, fillOpacity = 1.0,
group = "basepoly",
)
#add control widget
addLayersControl(
baseGroups = c("default1","default","custom"),
overlayGroups = c("basepoly"),
options = layersControlOptions(collapsed = FALSE)
)
})