tmap icon indicating copy to clipboard operation
tmap copied to clipboard

tm_popup

Open olivroy opened this issue 2 years ago • 14 comments

Hi @mtennekes ,

I started looking into transitioning to v4 in my previous code. I think I ran into a bug.

  • Missing id hovering.
  • The popup doesn't show id as 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

image

v3.3-4 : id showing when hovering + shows as bold on top of the popup

image

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 image

In v4, currently, has borders, size is not passed correctly. image

I also like that the legend background in view was a bit transparent, could this be added back?

olivroy avatar Mar 28 '24 19:03 olivroy

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:

  • hover Also used for the popup title
  • id Only used for interactive features, e.g. shiny (via layerId)
  • 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 ?

mtennekes avatar Apr 11 '24 08:04 mtennekes

qtm improved, please check @olivroy still a to do: redirect ... arguments such as symbols.title.size

mtennekes avatar Apr 11 '24 10:04 mtennekes

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

olivroy avatar Apr 11 '24 11:04 olivroy

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).

mtennekes avatar Apr 11 '24 11:04 mtennekes

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..

olivroy avatar Apr 11 '24 12:04 olivroy

@mtennekes have you consider having just one argument that accepts a function (e.g., tm_popup())?

Nowosad avatar Apr 11 '24 12:04 Nowosad

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) where TRUE means 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 when id != ""?

mtennekes avatar Apr 11 '24 14:04 mtennekes

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.

tim-salabim avatar Apr 11 '24 14:04 tim-salabim

Am I correct in assuming that tm_popup() does not exist (yet)? I can't seem to find it in the repo

tim-salabim avatar Apr 11 '24 14:04 tim-salabim

@tim-salabim yep -- it is still an idea

Nowosad avatar Apr 11 '24 15:04 Nowosad

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.

mtennekes avatar Jun 25 '24 14:06 mtennekes

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.

tim-salabim avatar Jun 26 '24 17:06 tim-salabim