我正在使用 R 包“传单”制作交互式地图。
我想根据缩放级别自动更改可见图层。
例如,我希望放大时多边形图层消失,替换为点图层。像这样:https : //tree-map.nycgovparks.org/
我一直在尝试许多不同的技巧并详细探索“leaflet”和“leaflet.extras”包的帮助,但找不到任何这样做的东西。
我还直接从传单中找到了一些东西,但在 R 下似乎无法重现: 设置传单中图层的缩放级别
我尝试使用markerOptions 中的选项minZoom 和maxZoom,但它似乎没有做我想要的。
这是我的这个例子的代码:
require(spData)
require(leaflet)
require(sf)
# loading shapes of countries from the package spData
data(world)
world <- st_read(system.file("shapes/world.gpkg", package="spData"))
# creating a sf objet with oceanian countries boundaries
oceania <- world[world$continent=="Oceania",]
#loading points events from the quakes dataset
data(quakes)
#Creating a leaflet objet with points and polygons
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addCircleMarkers(lng=quakes$long,
lat=quakes$lat,
col="blue",
radius=3,
stroke=FALSE,
fillOpacity = 0.7,
options = markerOptions(minZoom=15, maxZoom=20)) %>%
addPolygons(data= …Run Code Online (Sandbox Code Playgroud)