r-spatial / mapview

Interactive viewing of spatial data in R
https://r-spatial.github.io/mapview/
GNU General Public License v3.0
519 stars 90 forks source link

Lines between nearest neighbours (from st_connect) are not shown on map #483

Open marekie opened 5 months ago

marekie commented 5 months ago

Using the data from a question on SO, I cannot reproduce the outcome in this answer as the lines between the points are not plotted. I am running R version 4.4.0 Patched (2024-05-26 r86634 ucrt) and mapview_2.11.2.9000.

person_location <-
structure(list(id = c(1, 2, 3, 4, 5), longitude = c(-76.67707, 
-76.44519, -76.69402, -76.68936, -76.58341), latitude = c(39.399754, 
39.285084, 39.36958, 39.369907, 39.357994)), class = "data.frame", row.names = c(NA, 
-5L))

building_location <-
structure(list(id = c(1, 2, 3, 4, 5, 6, 7, 8, 9), longitude = c(-76.624393, 
-76.457246, -76.711729, -76.631249, -76.566742, -76.683106, -76.530232, 
-76.598582, -76.691287), latitude = c(39.246464, 39.336996, 39.242936, 
39.289103, 39.286271, 39.35447, 39.332398, 39.344642, 39.292849
)), class = "data.frame", row.names = c(NA, -9L))

person_location <- person_location %>%
  st_as_sf(coords = c('longitude', 'latitude')) %>%
  st_set_crs(4326)

building_location <- building_location %>%
  st_as_sf(coords = c('longitude', 'latitude')) %>%
  st_set_crs(4326)

st_connect(person_location, building_location) %>% 
  mapview::mapview() +
  mapview::mapview(person_location, color = 'green', col.regions = 'green') + 
  mapview::mapview(building_location, color = 'black', col.regions = 'black')

2024-05-28 11_07_44-Window

tim-salabim commented 5 months ago

Works for me under Linux

image

> sessionInfo()
R version 4.4.0 Patched (2024-05-26 r86634)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=de_DE.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=de_DE.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Berlin
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] nngeo_0.4.8         sf_1.0-16           mapview_2.11.2.9000

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.8          compiler_4.4.0          Rcpp_1.0.12            
 [4] parallel_4.4.0          leaflet_2.2.2           jquerylib_0.1.4        
 [7] scales_1.3.0            png_0.1-8               yaml_2.3.8             
[10] fastmap_1.2.0           lattice_0.22-6          R6_2.5.1               
[13] classInt_0.4-10         satellite_1.0.5         knitr_1.46             
[16] htmlwidgets_1.6.4       leaflet.providers_2.0.0 units_0.8-5            
[19] stars_0.6-5             munsell_0.5.1           DBI_1.2.2              
[22] rlang_1.1.3             sp_2.1-4                terra_1.7-78           
[25] xfun_0.44               cli_3.6.2               magrittr_2.0.3         
[28] class_7.3-22            crosstalk_1.2.1         digest_0.6.35          
[31] grid_4.4.0              leafem_0.2.3.9001       rstudioapi_0.16.0      
[34] geojsonsf_2.0.3         base64enc_0.1-3         lifecycle_1.0.4        
[37] KernSmooth_2.23-22      data.table_1.15.4       proxy_0.4-27           
[40] evaluate_0.23           glue_1.7.0              farver_2.1.2           
[43] raster_3.6-26           codetools_0.2-20        abind_1.4-5            
[46] stats4_4.4.0            colorspace_2.1-0        e1071_1.7-14           
[49] rmarkdown_2.27          tools_4.4.0             htmltools_0.5.8.1  

Do you see any errors in the browser console?

gisma commented 5 months ago

I run in the same issue and the browser throws:

Uncaught (in promise) TypeError: Cannot read properties of null (reading '0')
    at updateStyle (fgb.js:251:24)
    at style (fgb.js:108:24)
    at e._setLayerStyle (leaflet.js:5:83506)
    at e.resetStyle (leaflet.js:5:83321)
    at e.addData (leaflet.js:5:83177)
    at e.initialize (leaflet.js:5:82862)
    at new e (leaflet.js:5:14525)
    at Object.Kt (leaflet.js:5:13500)
    at handleResult (fgb.js:103:21)

However I can fix it setting mapviewOptions(fgb = FALSE)


> sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: TUXEDO OS 2

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=de_DE.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=de_DE.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=de_DE.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Berlin
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] mapview_2.11.2.9000 nngeo_0.4.8         sf_1.0-16           dplyr_1.1.4        

loaded via a namespace (and not attached):
 [1] utf8_1.2.4              generics_0.1.3          bspm_0.5.7             
 [4] class_7.3-22            KernSmooth_2.23-22      lattice_0.22-6         
 [7] digest_0.6.35           magrittr_2.0.3          grid_4.3.3             
[10] fastmap_1.1.1           jsonlite_1.8.8          processx_3.8.4         
[13] pkgbuild_1.4.4          e1071_1.7-14            DBI_1.2.2              
[16] ps_1.7.6                fansi_1.0.6             crosstalk_1.2.1        
[19] scales_1.3.0            brew_1.0-10             jquerylib_0.1.4        
[22] codetools_0.2-20        cli_3.6.2               rlang_1.1.3            
[25] leafpop_0.1.0           units_0.8-5             munsell_0.5.1          
[28] base64enc_0.1-3         remotes_2.5.0           tools_4.3.3            
[31] raster_3.6-26           uuid_1.2-0              colorspace_2.1-0       
[34] curl_5.2.1              vctrs_0.6.5             R6_2.5.1               
[37] png_0.1-8               stats4_4.3.3            proxy_0.4-27           
[40] lifecycle_1.0.4         classInt_0.4-10         leaflet_2.2.2          
[43] leaflet.providers_2.0.0 htmlwidgets_1.6.4       pkgconfig_2.0.3        
[46] desc_1.4.3              callr_3.7.6             terra_1.7-71           
[49] pillar_1.9.0            data.table_1.15.4       glue_1.7.0             
[52] Rcpp_1.0.12             systemfonts_1.0.6       tibble_3.2.1           
[55] tidyselect_1.2.1        rstudioapi_0.16.0       farver_2.1.1           
[58] htmltools_0.5.8.1       svglite_2.1.3           leafem_0.2.3           
[61] satellite_1.0.5         compiler_4.3.3          sp_2.1-4  
tim-salabim commented 5 months ago

Thanks @gisma ! Does it help to update leafem to the latest github version?

gisma commented 5 months ago

@tim-salabim yep updating leafemto the current github version works fine.

tim-salabim commented 5 months ago

Ok, thanks! I'll see when I can get it released.