pane option for addStarsImage
mtennekes opened this issue ยท 10 comments
Maybe I overlooked it, but there does not seem to be a pane option for addStarsImage?
This is currently not possible because the underlying JS-method addRasterImage
doesnt offer it.
But there is a PR that should fix it: rstudio/leaflet#692
The pane
argument is now available in leaflet 2.2.2 as
addRasterImage
now takes options = gridOptions()
Still does not seem to be passed on correctly. Are you sure pane
is passed on via gridOptions?
library(stars)
library(leaflet)
library(leafem)
tif = system.file("tif/L7_ETMs.tif", package = "stars")
x = read_stars(tif)
leaflet() %>%
addProviderTiles("OpenStreetMap", group = "osm") %>%
addProviderTiles("Esri.WorldImagery", group = "esri") |>
addStarsImage(x, project = TRUE, options = gridOptions(pane = "leaflet-overlay-pane")) |>
addLayersControl(baseGroups = c("osm", "esri"))
(The related tmap issue r-tmap/tmap#882)
Apparently you cannot append a layer to any of leaflets own panes. You will get a browser error like this
Uncaught TypeError: Cannot read properties of undefined (reading 'appendChild')
You have to create a pane frst with addMapPane("name", zIndex = 450)
, then it should work.
This code creates the map below and inside the HTML you can see that the pane exists and the layer is inside.
library(stars)
library(leaflet)
library(leafem)
tif = system.file("tif/L7_ETMs.tif", package = "stars")
x = read_stars(tif)
leaflet() %>%
addMapPane("myspecialpane", zIndex = 450) %>%
addProviderTiles("OpenStreetMap") %>%
addStarsImage(x, project = TRUE, options = gridOptions(pane = "myspecialpane"))
Thx @trafficonese
This example doesn't work on my machine. It added the pane, but it still puts the stars image into the leaflet tile-pane. The new pane remains empty. In Safari inspector:
library(stars)
#> Loading required package: abind
#> Loading required package: sf
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(leaflet)
library(leafem)
sessioninfo::session_info(pkgs = "attached")
#> โ Session info โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#> setting value
#> version R version 4.3.1 (2023-06-16)
#> os macOS Sonoma 14.4.1
#> system aarch64, darwin20
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Europe/Berlin
#> date 2024-06-11
#> pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#>
#> โ Packages โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#> package * version date (UTC) lib source
#> abind * 1.4-5 2016-07-21 [1] CRAN (R 4.3.0)
#> leafem * 0.2.3.9006 2024-06-11 [1] Github (r-spatial/leafem@541e2a6)
#> leaflet * 2.2.2 2024-03-26 [1] CRAN (R 4.3.1)
#> sf * 1.0-16 2024-03-24 [1] CRAN (R 4.3.1)
#> stars * 0.6-5 2024-01-15 [1] Github (r-spatial/stars@666abc7)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
#>
#> โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Created on 2024-06-11 with reprex v2.1.0
I cannot reproduce this. It works in all my browsers also with your package versions..
@tim-salabim Can you reproduce that?
The only difference is I'm using Windows an R 4.4.0 Patched.. but that should not be the issue..
Yes, with R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
I can reproduce this. It works fine with R version 4.4.0 Patched (2024-05-26 r86634) -- "Puppy Cup"
Maybe a similar issue to #77 (comment) ? Although it seems strange that this is related to the R version, it seems like it is the case...
Just installed R 4.4.1. And this issue still persists...
This works for me with R 4.4.1. Are you using the github version of leafem?
Il it can help, I also encountered this problem; all worked fine after installing the github version of leafem (v. โ0.2.3.9006โ). This solved also r-tmap/tmap#882. Tested both on Windows and Ubuntu.