0

我正在尝试更改使用小册子Mapzen绘制的多边形的颜色。颜色在当前图块中清晰可见,但在其他图块中不那么明显,例如 addTiles()。我应该如何更改三个多边形的参数?

要使代码正常工作,您必须输入 mapzen 密钥。

library(rmapzen)
library(leaflet)

Sys.setenv(MAPZEN_KEY = "mapzen-******")
#https://tarakc02.github.io/rmapzen/#introduction

ucb <- mz_geocode("Via Giovanni Spadolini 7, Milan, Italy")

isos <- mz_isochrone(
  ucb,
  costing_model = mz_costing$auto(),
  contours = mz_contours(c(5, 10, 15)),
  polygons = TRUE
)

leaflet(as_sp(isos)) %>%

 addProviderTiles("CartoDB.DarkMatter") %>%

 addPolygons(color = ~color, weight = 1) %>%

 addLegend(colors = ~color, 
        labels = ~paste(contour, "minutes"),
            title = "Drive times from <br/> Centro Leoni")
4

1 回答 1

0

我意识到应该单独添加多边形,而不是:

leaflet(as_sp(isos))

解决方案:

iso10 <- as_sp(mz_isochrone(
  ucb,
  costing_model = mz_costing$auto(),
  contours = mz_contours(10),
  polygons = TRUE
))
iso30 <- as_sp(mz_isochrone(
  ucb,
  costing_model = mz_costing$auto(),
  contours = mz_contours(30),
  polygons = TRUE
))
iso60 <- as_sp(mz_isochrone(
  ucb,
  costing_model = mz_costing$auto(),
  contours = mz_contours(60),
  polygons = TRUE
))

m = leaflet() %>%
  addProviderTiles("CartoDB.DarkMatter") %>%
  addPolygons(data = iso10, color = "red", fillColor = "red")%>%
  addPolygons(data = iso30, color = "green", fillColor = "green")%>%
  addPolygons(data = iso60, color = "blue", fillColor = "blue")
于 2017-11-10T10:29:41.577 回答