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

tm_minimap() not working unless leaflet is loaded #231

Closed
mtennekes opened this issue Jul 13, 2018 · 2 comments
Closed

tm_minimap() not working unless leaflet is loaded #231

mtennekes opened this issue Jul 13, 2018 · 2 comments

Comments

@mtennekes
Copy link
Member

Just before going to submit tmap(tools) 2.0 to CRAN, I found this bug:

library(tmap)
qtm()  # shortcut for tm_basemap() + tm_minimap(), which automatically switches to view mode

throws this error, while

library(tmap)
library(leaflet)
qtm()

works.

The call traceback of the error is:

Error in tiles %in% providers : object 'providers' not found 
8.
tiles %in% providers 
7.
(function (map, position = "bottomright", width = 150, height = 150, 
    collapsedWidth = 19, collapsedHeight = 19, zoomLevelOffset = -5, 
    zoomLevelFixed = FALSE, centerFixed = FALSE, zoomAnimation = FALSE, 
    toggleDisplay = FALSE, autoToggleDisplay = FALSE, minimized = FALSE,  ... 
6.
do.call(addMiniMap, c(list(map = lf), mmargs)) at view_tmap.R#653
5.
view_tmap(x, shps = list(dummy = NULL)) at print_tmap.R#120
4.
print_shortcut(x, interactive, args, knit) at print_tmap.R#341
3.
print_tmap(x = x, vp = vp, return.asp = return.asp, mode = mode, 
    show = show, knit = knit, options = options, ...) at print_tmap.R#40
2.
print.tmap(x) 
1.
function (x, ...) 
UseMethod("print")(x) 

The list object providers is not exported by leaflet (i.e. it is not in its NAMESPACE), but made accessible with this dirty (but working) hack:

utils::globalVariables(c("providers")) # To make R CMD Check happy

See https://github.com/rstudio/leaflet/blob/master/R/plugin-minimap.R#L1. Therefore, the providers object can be accessed with leaflet::providers.

Does anyone has a clue how to use addMinimap inside a package? It is called here: https://github.com/mtennekes/tmap/blob/master/R/view_tmap.R#L653 @tim-salabim : do you use minimaps or the providers object in mapview?

@tim-salabim
Copy link

Nope for both. Minimap is neat but doesn't really add any value for quick layer inspection. Regarding providers, I call addProviderTiles("XXX") directly, e.g. "CartoDB.Positron"

@mtennekes
Copy link
Member Author

I think it's a nice feature, especially in unfamiliar areas.

I made a pull request in leaflet, as you can see above. For now, a message "please load leaflet" is shown when tm_minimap doesn't work. Also I changed the default value of qtm.minimap to FALSE.

schloerke referenced this issue in rstudio/leaflet Nov 1, 2018
* to make it accessible within other packages (see https://github.com/mtennekes/tmap/issues/231)

* add minimap fix to NEWS

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

No branches or pull requests

2 participants