-
Notifications
You must be signed in to change notification settings - Fork 122
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
WebGL not compatible with projected shapes in view mode / tm_basemap(NULL) didn't disable basemaps #972
Comments
Thx for bringing this up! FYI: the default options for tmap are mode-specific. The mode-specific options are accessible via There is an option called Apart from the current bug, should we use NULL or NA? One should be used for "not specified, just use the default" and the other for "non-existent". I would propose:
This is also the behaviour in tmap3. This question is also relevant for visual variables: tm_shape(World) +
tm_polygons(fill = NA) could/should use the default fill color for polygons (default is grey, but theme dependent)
should not fill the polygons Does this make sense @barryrowlingson @Nowosad @Robinlovelace @gilbertocamara ? |
I think I only suggested the opposite sense for NA and NULL to keep compatibility with what happens already with basemaps! But if there's other places they are used then keeping consistent meanings is probably better. |
Makes sense and sounds good to me 👍 |
For the context, I added examples of the current behavior. The question: wouldn't this change impact many existing code bases? library(tmap)
data(World)
tm_shape(World) +
tm_polygons() tm_shape(World) +
tm_polygons(fill = NA) tm_shape(World) +
tm_polygons(fill = NULL)
#> Error in val[[1]]: subscript out of bounds |
Do you mean with the existing v4 code bases? I've checked with v3: tm_shape(World) +
tm_polygons() tm_shape(World) +
tm_polygons(col = NA) tm_shape(World) +
tm_polygons(col = NULL)
#> Warning message: In rep(x, length.out = nx) : 'x' is NULL so the result will be NULL
|
👍🏻 Ok, now I understand the need for the consistency here (I've been using tmap4 for so long that I do not remember the old ways of doing things) |
As a clarification, when you say "tmap4" does that mean version 3.99.xxx as is the current master branch? Or is that the last ever 3.x version? There is a v4 branch with somewhat older changes, but the instructions for "Installation of tmap (version 4) is straightforward:" seem to get master from github. |
Yes that's correct. v4 is on the main branch. |
I don't see a "main" branch, only a "master" branch and a "v4" branch... I'm assuming the "v4" branch is stale in some sense, that the "master" branch is the latest tmap version 4 code base, and that someone didn't change all their "master" branches to "main" :) |
|
Correct. I just deleted it to avoid others getting confused, thanks for the nudge. |
Done! FYI (for developers), see tmap_options("value.const", "value.blank") The option Visual variables# default fill (grey)
tm_shape(World) +
tm_polygons(fill = NA)
# default no fill
tm_shape(World) +
tm_polygons(fill = NULL)
# default fill (grey), no borders
tm_shape(World) +
tm_polygons(fill = NA, lwd = NULL) Basemaps# Default basemap(s)
tm_shape(World) +
tm_polygons() +
tm_basemap()
# Other basemap
(tm = tm_shape(World) +
tm_polygons() +
tm_basemap("OpenStreetMap"))
# Adding another aux layer (tm_grid) and removing basemaps
(tm2 = tm +
tm_grid() +
tm_basemap(NULL))
# Add basemap again
tm2 +
tm_basemap() Please test carefully (as we are close to CRAN submission). I haven't update the docs yet. Feel free to do so (PRs welcome) |
I've tried it, and there seems to be an issue for a non-global case: library(tmap)
# works fine
(tm = tm_shape(NLD_dist) +
tm_polygons() +
tm_basemap("OpenStreetMap"))
# works not fine
(tm2 = tm +
tm_grid() +
tm_basemap(NULL)) |
@mtennekes the issue is in the view mode: library(tmap)
tmap_mode("view")
# works fine
(tm = tm_shape(NLD_dist) +
tm_polygons() +
tm_basemap("OpenStreetMap"))
# works not fine (cannot see the polygons)
(tm2 = tm +
tm_grid() +
tm_basemap(NULL)) |
Funny. It seems to be an issue with
Glad this is not a major bug (bad timing:-)) |
Nope. Apparently projected shapes in view mode don't work with WebGL enabled (which is the default for large shapes, and
So still a bug, bug minor, and probably something upstream @tim-salabim does leafgl work with projected shapes and L.CRS.Simple? |
Yeah, seems like it's not compatible with Here's a minimal reprex library(leaflet)
library(leafgl)
library (tmap)
library(sf)
data("NLD_dist")
leaflet(options = leafletOptions(
crs = leafletCRS(crsClass = "L.CRS.Simple")
, minZoom = -1000
)) |>
addGlPolygons(data = st_cast(NLD_dist, "POLYGON")) |
Help page for
tm_basemap
says:Use ‘NULL’ in ‘tm_basemap()’ to disable basemaps.
But in both plot and view mode I still get an ESRI base map. I would expect to not see a basemap. Obvious fix is
to not have the tm_basemap() call if you don't want a basemap, but that's harder to do if the basemap is driven
by a variable, eg
tm_basemap(whichone) + tm_shape(...) + ...
Ideally I think
tm_basemap
should be able to specify with arguments no basemap, the default basemap, or aspecific basemap. To preserve backward compatibility I suggest:
tm_basemap()
: adds default basemaptm_basemap(NULL)
: adds default basemap, change documentation to clarifytm_basemap(NA)
: no basemap, think of it as a "missing value".tm_basemap(xyz)
: add basemap for provider xyz, xyz may also be NULL or NA to get behaviour as above.Having no
tm_basemap
in a map would also remain the current behaviour which I think is default basemap in view mode, no basemap in plot mode. But I don't know if this minor inconsistency is worth preserving going forward...The text was updated successfully, but these errors were encountered: