Leaflet: allow options for addRasterImage

Created on 24 Apr 2018  路  4Comments  路  Source: rstudio/leaflet

Thanks for the recent update! It really brings some great new features. One feature I have been exploiting is map pane definition to control layer order in a map, e.g. points always on top of polygons.

This works great:

library(leaflet)
library(mapview) # for the data

leaflet() %>%
  addTiles() %>%
  addPolygons(data = franconia, 
              group = "polygons",
              opacity = 1,
              fillOpacity = 1,
              options = leafletOptions(pane = "tilePane")) %>%
  addCircleMarkers(data = breweries,
                   group = "points",
                   color = "black",
                   fillColor = "black",
                   options = leafletOptions(pane = "overlayPane")) %>%
  addLayersControl(overlayGroups = c("polygons", "points"))

However, this does not work for addRasterImage (throughing error unused argument (options = leafletOptions(pane = "overlayPane"))).

leaflet() %>%
  addTiles() %>%
  addRasterImage(poppendorf[[4]], 
                 project = TRUE,
                 options = leafletOptions(pane = "overlayPane"))

If I understand correctly, addRasterImage uses L.GridLayer for the image rendering which has an option to specify the pane.

It would be great of we could add an options argument to addRasterImage so we can define which pane it should be rendered in. There are situations where you'd want an image to overlay vector features.

Related to this, we have freshly implemented a method to create custom map panes in a leaflet map following this tutorial. The relevant js code is here and the R functions are here.
I think this is general enough to have this in leaflet rather than mapview and I am more than happy to migrate this over for the next CRAN release (until then, I'd prefer to keep it in mapview, where it will be part of the next CRAN release).
Let me know if you are interested in migrating this to leaflet.

For completeness, here is where we specify the panes for use in mapview such that by default points overlay lines overlay polygons.

Thanks again for the great work you've put into leaflet recently!!

v2.1 release

Most helpful comment

Looks like the option feature in addRasterImage is not available?
Any clue?

All 4 comments

Hi @tim-salabim

This has been exposed in #524. Has not been merged yet (waiting for CLA) and is set for next release.

Let me know how it works for you!.

devtools::install_github("rstudio/leaflet#524")

Going to make a new issue for the panes. I think it'd be great to have in leaflet, as it is a Leaflet.js library feature. Will mark for next release!

Yes, with the above PR it works as expected! Closing here as expected in next release. Thanks

Looks like the option feature in addRasterImage is not available?
Any clue?

Was this page helpful?
0 / 5 - 0 ratings