-
Notifications
You must be signed in to change notification settings - Fork 28
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
Allow addFeatures to work on leaflet_proxy object #2
Conversation
If the data layer provided in addFeature is not 4326, it is automatically reprojected
Also allows usage on leaflet_proxy objects, and without the `data` argument in leaflet piepes
required by addstaticlabels
- Copy makeLabels, getGeometryType, getLayerNamesFromMap (needed for addstaticlabels and addextent to work) - Slightly modify combineExtent to allow calls such as `mapview() + viewExtent(indata)`
add new functions and author
- also, modify addExtent to work on leaflet/leaflet_proxy object - also, modify addExtent to work on leaflet pipes such as leaflet(indata) %>% addExtent()
allows both `mapview(trails, native.crs = TRUE) %>% addStaticLabels()` and `leaflet(trails) %>% addFeatures()` to work properly.
the test was previously failing due to regex not recognised - using the "o" argument simplifies the check
was not used
to pass checks on devtools, need "methods" in imports and mapview in suggests
Thanks @lbusett !! |
Thanks for considering merging! Concerning reprojection, I see your point, though I liked the possibility to have auto-reprojection in leaflet pipes, and I feel that it is a bit counterintuitive that with the current version these work: indata <- sf::st_read(system.file("shape/nc.shp", package="sf")) %>%
sf::st_transform(3035)
mapview(indata) %>% addStaticLabels()
mapview(indata) %>% addFeatures()
mapview(indata) %>% addExtent() while these do not : indata <- sf::st_read(system.file("shape/nc.shp", package="sf")) %>%
sf::st_transform(3035)
leaflet(indata) %>% addStaticLabels()
leaflet(indata) %>% addFeatures()
leaflet(indata) %>% addExtent() However, it's no big deal and I'll just have to remember to reproject as needed in case I want to use Consider however that removing the auto-reprojection in addStaticLabels is somewhat of a breaking change. Infact, it leads this "use case" in r-spatial/mapview#161: leaflet() %>%
addTiles() %>%
addPolylines(data = st_transform(trails, 4326)) %>%
addStaticLabels(trails) to fail, while it was previously working. HTH, Lorenzo |
Thanks for these thoughts @lbusett, however I still think that in leafem we should not auto-reproject. leaflet makes it very clear that every data should be in epsg:4326 so all |
Understood. Concerning Warnings, > leaflet(indata) %>% addFeatures()
Warning message:
sf layer has inconsistent datum (+proj=longlat +datum=NAD27 +no_defs).
Need '+proj=longlat +datum=WGS84' I'd think it should throw an error instead, in these situations, but it is a |
Currently,
leafem::addFeatures
does not work on leaflet_proxy objects, because it expects only aleaflet
object as input. This PR simply modifiesleafem::garnishMap
so that it works also onleaflet_proxy
maps.It also slightly modifies
leafem::addFeatures
so that if the data layer provided in addFeature is not 4326, it is automatically reprojected (this for "coherence" with mapView, where I think layers are automatically reprojected).Below, I report an example of a shiny app using
addFeatures
with aleafletProxy
map, which works with the implemented changes.HTH.