我有一个多边形,我可以使用addPolygons完美地添加到传单,但我试图给它一个layerId,所以我可以在以后删除它。我不能使用clearShape()因为我有超过1层。所以我想使用removeShape(layerId)。但是当我将layerId添加到addPolygon时,它不再显示多边形。我的脚本的相关部分是:
colorData <- region2@data[, "contP"]
colorData[colorData == 0] <- NA
pal <- colorNumeric(c("lightblue1", "steelblue3", "blue", "green","green3","green4",
"yellow","gold","darkorange","red","red2","red4","magenta","purple1"), c(0,30),
na.color = "transparent")
leafletProxy("map") %>%
# removeImage("colorRaster") %>%
# removeShape("colorLegend") %>%
addPolygons(data=region2, weight = 1, color = "black", fillColor = pal(colorData), fillOpacity = 0.5, layerId="colorLegend2") %>%
addLegend("bottomleft", pal=pal, values=c(0,30), title="Mean P", layerId="colorLegend")
有关为何会发生这种情况的任何提示?