将clusterOptions与addPolygons或addRasterImage一起使用时,不呈现传单addMarkers

时间:2019-04-03 20:55:53

标签: r r-leaflet leaflet.markercluster

我有一个工作传单地图,显示了使用clusterOptions聚类的几个标记。 我想添加地形数据和一些边框shapefile作为背景而不是默认图块。 但是,如果在同一地图上使用addRasterImage(或addPolygons),则不会渲染带有clusterOptions的addMarkers。

除了addTiles之外,还使用addRasterImage,而不是用addRasterImage替换addTiles,可以正确渲染标记簇。但是,这不是解决方案,因为出于美观和资源的原因,我不想使用图块。

library(leaflet)

# this works
leaflet(quakes) %>% 
  setView( lat=-23, lng=180, zoom=6) %>%
  addTiles() %>%
  addMarkers(~long, ~lat)


# this doesn't work, only shows polygons... if anything
leaflet(quakes) %>% 
  setView( lat=-23, lng=180, zoom=6) %>%
  addMarkers(~long, ~lat, clusterOptions = TRUE) %>%
  addPolygons(lng = ~long, lat = ~lat, fill = F, weight = 1.5, color = "gray", opacity = 0.9, fillOpacity = 0)


# this works (takes a while), but I don't want to use tiles :(
leaflet(quakes) %>% 
  setView( lat=-23, lng=180, zoom=6) %>%
  addTiles() %>%
  addMarkers(~long, ~lat, clusterOptions = TRUE) %>%
  addPolygons(lng = ~long, lat = ~lat, fill = F, weight = 1.5, color = "gray", opacity = 0.9, fillOpacity = 0)

1 个答案:

答案 0 :(得分:0)

该问题是由于clusterOptions = TRUE选项所致。如果将其删除,地图将起作用:

leaflet(quakes) %>% 
  setView( lat=-23, lng=180, zoom=6) %>%
  addPolygons(lng = ~long, lat = ~lat, fill = F, weight = 1.5, color = "gray", opacity = 0.9, fillOpacity = 0) %>%
  addMarkers(~long, ~lat) 

我不知道为什么必须使用图块才能启用此选项,但我想它与绘制多边形以将稳定群集映射到图块有关

enter image description here