0
我正在學習如何使用R和Leaflet。我幾乎完成了使用加利福尼亞縣的地圖,但我不喜歡我可以在地圖上看到其他州。我想把我的多邊形(縣)周圍的地圖畫出來。我看到類似的問題在其他地方解決,但我不知道如何在代碼中應用所述內容。有人可以檢查這個代碼,並建議我需要添加什麼?將Leaflet視圖的可視部分限制爲多邊形區域
如果你滾動到這個鏈接的底部,你會看到我想要做的。 http://rpubs.com/stefanya/127436
我使用的代碼是:
#loading shapefile
counties <- readOGR("./shapefiles", layer="cb_2014_us_county_20m")
#filtering for only california
counties <- subset(counties, [email protected]$STATEFP=="06")
#making a leaflet map of california counties
leaflet() %>% addTiles() %>% addPolygons(data=counties)
#merging the data into this shapefile
[email protected] = data.frame([email protected], sumByCounty[match([email protected][,"NAME"], sumByCounty[,"NAME"]),])
#set color palette
colorRamp <- colorRamp(c("#2c7fb8","#7fcdbb","#edf8b1"), interpolate = "spline")
palette <- colorNumeric(colorRamp, [email protected]$progress)
leaflet() %>% addProviderTiles("Stamen.TonerLite") %>%
addPolygons(
weight= 2,
stroke = TRUE,
fillOpacity = .65,
data=counties,
color = ~palette(progress),
popup = ~paste("<strong>County:</strong>",NAME,
"<br>",
"<strong>Total Responses:</strong>",sumByCounty,
"<br>",
"<strong>Complete:</strong>",progress,"<strong>%</strong>")
) %>% addLegend(title = "Response <br> Goal Met", pal = palette, values = [email protected]$progress, bins=5, opacity = 1, position="topright", labFormat = labelFormat(suffix = '%'))
一個簡單的解決辦法是建立在其他國家一大多邊形來隱藏他們... – ghybs
你也許可以組成你自己的自定義瓷磚。 https://help.openstreetmap.org/questions/136/how-do-i-render-my-own-maps-for-my-website –
這是鏈接到「類似的問題解決其他地方」:http:///gis.stackexchange.com/questions/73048/how-do-i-clip-osm-basemap-with-a-polygon,因爲它基本上是@ghybs解決方法,並且可以很容易地應用於傳單。 – Spacedman