簡體   English   中英

並非所有 SpatialLine 都顯示在帶有 addPolylines 的 Leaflet 中

[英]Not all SpatialLines displaying in Leaflet with addPolylines

我正在使用R-Shiny開發一個網絡應用程序。

我的問題是並非SpatialLinesDataFrame (SLDF) 中的所有行都顯示在Leaflet地圖中。 歡迎大家提出意見。 數據集存儲在這里

我的代碼:

#convert raster layer (ras) to SLDF
rtc <- rasterToContour(ras)

leaflet() %>%
addPolylines(data=rtc, group="contour", layerId="contour_pr",noClip = TRUE)

結果:

Leaflet只顯示內部輪廓線

在此處輸入圖片說明

或者,使用 R 繪圖函數( plot(rtc) )顯示所有線條在此處輸入圖片說明

版本信息:

R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.1 LTS
other attached packages:
[1] igraph_1.2.2 rgeos_0.3-25 bindrcpp_0.2.2 ggplot2_3.1.0 withr_2.1.2
[6] labeling_0.3 V8_1.5 RColorBrewer_1.1-2 stringr_1.3.1 ncdf4_1.16
[11] yaml_2.2.0 data.table_1.11.4 mapview_2.5.0 sf_0.6-3 DT_0.4
[16] geometa_0.3-0 rgdal_1.3-6 raster_2.6-7 sp_1.3-1 dplyr_0.7.6
[21] plyr_1.8.4 leaflet.extras_1.0.0 leaflet_2.0.2 shinyBS_0.61 
shinyjs_1.0
[26] shinydashboard_0.7.0 shiny_1.1.0

有兩種方法可以解決這個問題。

  1. 如果您想一次添加它們,您應該將SpatialLinesDataFrame添加為leaflet函數中的數據集(示例 1 )。
  2. 更難看,但也可以單獨添加它們(示例 2 )。

示例 1

leaflet(data=rtc) %>% addTiles() %>% addPolylines()

示例 2

map <- leaflet() %>% addTiles()
for( level in rtc$level){
  map <- addPolylines(map, data=subset(rtc, level==level))
}
# to show the map
map

結果

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM