使用此脚本,我将显示具有三个等时线的地图。我希望地图具有包含每个等时线/多边形表示的最大时间的标签。
我应该如何在 addPolygons() 部分引用空间数据框 (iso1/2/3)?
在下面的三个 addPolygons() 中的每一个中,我都尝试了不同的方法,但没有运气:((尽管脚本仍然有效)。
library(osrm)
library(leaflet)
library(viridisLite)
# Making isochrones
iso1 = osrmIsochrone(loc = c(9.2,45.5),
breaks = seq(from = 0,
to = 45,
by = 5),
res=75)
iso2 = osrmIsochrone(loc = c(12.51182,41.92631),
breaks = seq(from = 0,
to = 45,
by = 15),
res=100)
iso3 = osrmIsochrone(loc = c(11.25581,43.76956),
breaks = seq(from = 0,
to = 45,
by = 15),
res=100)
# colors for leaflet
vir = viridis(9)
# palette
pal1 <- colorNumeric(
palette = vir,
domain = iso1@data$id)
pal2 <- colorNumeric(
palette = "Blues",
domain = iso2@data$id)
pal3 <- colorNumeric(
palette = "Reds",
domain = iso3@data$id)
# Plotting interactive map using spdf
leaflet()%>%
addTiles("http://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", attribution = 'Google')%>%
addPolygons(data = iso1,
fill = TRUE,
fillOpacity = 0.7,
fillColor = ~pal1(id),stroke = FALSE, label = iso1@data$max)%>%
addPolygons(data = iso2,
fill = TRUE,
fillOpacity = 0.7,
fillColor = ~pal2(id),stroke = FALSE, label = ~max)%>%
addPolygons(data = iso3,
fill = TRUE,
fillOpacity = 0.7,
fillColor = ~pal3(id),stroke = FALSE, label = ~iso3@data$max)