Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pane option for addStarsImage #58

Closed
mtennekes opened this issue May 10, 2022 · 10 comments
Closed

pane option for addStarsImage #58

mtennekes opened this issue May 10, 2022 · 10 comments

Comments

@mtennekes
Copy link

Maybe I overlooked it, but there does not seem to be a pane option for addStarsImage?

@trafficonese
Copy link
Contributor

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

@trafficonese
Copy link
Contributor

The pane argument is now available in leaflet 2.2.2 as
addRasterImage now takes options = gridOptions()

@mtennekes
Copy link
Author

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)

@trafficonese
Copy link
Contributor

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"))

image

@mtennekes
Copy link
Author

mtennekes commented Jun 11, 2024

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:

Screenshot 2024-06-11 at 22 26 38
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

@trafficonese
Copy link
Contributor

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..

@tim-salabim
Copy link
Member

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...

@mtennekes
Copy link
Author

Just installed R 4.4.1. And this issue still persists...

@tim-salabim
Copy link
Member

This works for me with R 4.4.1. Are you using the github version of leafem?

@ranghetti
Copy link
Contributor

ranghetti commented Sep 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants