tm_popup
Hi @mtennekes ,
I started looking into transitioning to v4 in my previous code. I think I ran into a bug.
- Missing
idhovering. - The popup doesn't show
idas bold on top of the popup either - Also the layers is "uncovered" by default. Before, it was hidden
devtools::load_all()
tmap_mode("view")
data("NLD_muni") # only needed for v3
NLD_muni |>
tm_shape() +
tm_polygons(
id = "code"
)
v4 : nothing when hovering and no title on top of the popup
v3.3-4 : id showing when hovering + shows as bold on top of the popup
Thanks
other issues
# search query for OpenStreetMap nominatim
tmap_mode("view")
qtm("Amsterdam")
#> Error in tm_view(bbox = "Amsterdam")
#> Unused argument (bbox = "Amsterdam")
Does not focus on China
qtm(metro, bbox = "China")
v4 doesn`t respect borders = NULL
qtm(World, borders = NULL) +
qtm(metro, symbols.size = "pop2010",
symbols.title.size= "Metropolitan Areas",
symbols.id= "name",
format = "World")
In v3
In v4, currently, has borders, size is not passed correctly.
I also like that the legend background in view was a bit transparent, could this be added back?
This is discussed earlier, but great to bring it up again because this is not settled yet.
#749: suggestion to disable hovering by default #764: further discussion of possibilities
Current status: each layer has four related arguments:
-
hoverAlso used for the popup title -
idOnly used for interactive features, e.g. shiny (vialayerId) -
popup.vars -
popup.format
What do you think? Suggestions more than welcome.
NLD_muni |>
tm_shape() +
tm_polygons(
hover = "name",
popup.vars = c("code", "name", "population")
)
To do's: layer selection collapse (default) and fix bbox focus
I've made the legend background deliberately solid, for two reasons: to make it consistent with plot mode, and to make sure that what is shown in the legend (symbols) are exactly the same as the features in the map they represent. However, in some cases I also prefer a bit transparency. What are your thoughts on this @Nowosad ?
qtm improved, please check @olivroy
still a to do: redirect ... arguments such as symbols.title.size
I would agree that hovering and id should not be enabled by default.
However, if id is supplied, hocering could be enabled, and also having the bold title on top of the popup
What do you think of the different variations: id, hover, label, ... ? Currently we only use id for layer reference, but in v3 we also used it for labeling.
The difficulty is the fact that we often want to specify a few things at once (e.g. hovering label, popup title, and layer reference id), but in some cases we explicitly want to separate things (e.g. country name for labeling and iso a3 code for reference ids).
good idea!
# defaults
id = "" # not shown by default
popup.title = id # id by default
hover = FALSE # by default if id is not supplied
what do you think?
In v3 layer id was via name if I remember correctly..
@mtennekes have you consider having just one argument that accepts a function (e.g., tm_popup())?
So bringing this together we have:
tm_shape(World) +
tm_polygons(fill = "economy",
id = "iso_a3",
popup = tm_popup(title = "name", vars = c("economy", "income_grp")),
hover = FALSE)
Defaults:
-
id = "" -
popup = tm_popup(title = id, vars = TRUE)whereTRUEmeans all variables. In v3 this was different: vars consisted of all data variables that were visualised, and all variables if no data was visualised. What do you prefer? - hover =
FALSE, also whenid != ""?
Just in case people forgot, there's leafpop::popupTable which does pretty much all of this, apart from the popup title... It also allows to supply a cssName which you could use to style the popups (like we do in mapview). Let me know if there is interest in expanding functionality to provide what is needed for tmap.
Am I correct in assuming that tm_popup() does not exist (yet)? I can't seem to find it in the repo
@tim-salabim yep -- it is still an idea
Done
So now each (vector) layer (so tm_polygons, tm_lines and tm_symbols use four arguments:
-
popup.vars -
popup.format -
id -
hover
Hover is FALSE by default unless id is defined.
Let me know it all works as expected.
@tim-salabim Thanks for this suggestion! The current implementation of the popups is direct migration from tmap3, and is quite basic, so no css support etc. We can upgrade with using leafpop. Is it possible to add a popup title, or is there a way to implement this without too much effort?
It has low-priority, so for now I'm closing this issue.
Please reopen if there are still bugs.
Adding support for a pop-up title shouldn't be hard to implement. I'll look into it at some stage, but also for me, this has low priority.