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

In mode = "view", could tm_credits use leaflet::addTiles() #806

Open
olivroy opened this issue Oct 25, 2023 · 4 comments
Open

In mode = "view", could tm_credits use leaflet::addTiles() #806

olivroy opened this issue Oct 25, 2023 · 4 comments
Labels
view View mode issues

Comments

@olivroy
Copy link
Contributor

olivroy commented Oct 25, 2023

I sometimes use (in v3)

library(tmap) # tmap v3.3.4
data(World, package = "tmap")
tmap_mode("view")
my_map <- tm_shape(World) +
  tm_polygons(title = "the title of my map", col = "area") +
  tm_basemap("OpenStreetMap") + tm_layout("title of my map") 

my_map

my_map |> 
  tmap_leaflet() |> 
  leaflet::addTiles(attributions = "Last update in October 2023")

Could this be equivalent as

my_map <- tm_shape(World) +
  tm_polygons(title = "the title of my map", col = "area") +
  tm_basemap("OpenStreetMap") + tm_layout("title of my map")  +
  tm_credits("Last update in October 2023")

Thanks

Apologies if this already exists in v4. I just wanted to type it quickly.

@olivroy olivroy changed the title In interactive, could tm_credit use leaflet::addTiles() In mode = "view", could tm_credit use leaflet::addTiles() Oct 31, 2023
@mtennekes
Copy link
Member

Good point, this should be done in v4.

In R-leaflet, the attributions are collected via the addTiles and addWMSTiles calls, and are placed in the HTML as follows:

<div class="leaflet-bottom leaflet-right">
  <div class="leaflet-control-attribution leaflet-control">
    <a href="https://leafletjs.com" title="A JS library for interactive maps">Leaflet</a> | Attribution A | Attribution B
  </div>
</div>

So in tmap we could collect all the tm_credits text, concatenate to credits_text, and pass it on via a dummy tile layer:

addTiles(urlTemplate = "", attribution = credits_text)

However, ideally, I would like to have more control of this attribution text via a function like addAttribution or setAttribution. @tim-salabim do you know if a function like this exists somewhere?

@tim-salabim
Copy link

Nope, no idea

mtennekes added a commit that referenced this issue Feb 9, 2024
@mtennekes
Copy link
Member

Implemented, but I'd like your opinions about the defaults @olivroy and @Nowosad

Without tm_credits, the original attribution text appears (depends on the used tile layers):

tm_shape(world) + tm_polygons()

image

With tm_credits defined, the attribution text is replaced with the specified text:

tm_shape(world) + tm_polygons() + tm_credits("My attribution text")

image

Without arguments:

tm_shape(world) + tm_polygons() + tm_credits()

image

Two issues/questions:

  1. What if the user would like to append (instead of replace) the attribution text? So instead of "Leaflet | My attribution text", the user would like to have "Leaflet | Tiles @ Esri - Esri, DeLorme, NAVTEQ, My attribution text" ?
  2. Basemaps are also supported in plot mode. So if we keep the default attributions in view mode, to be consistent across modes, we also need a credits in plot mode, whenever tm_basemaps are added. Yes or no?

@olivroy
Copy link
Contributor Author

olivroy commented Feb 12, 2024

This is great, thanks for implementing! I like the defaults you implemented.

What if the user would like to append (instead of replace) the attribution text? So instead of "Leaflet | My attribution text", the user would like to have "Leaflet | Tiles @ Esri - Esri, DeLorme, NAVTEQ, My attribution text" ?

I don't have strong feelings, maybe wait for FR and keep it simple for now? Maybe with an append argument to tm_credits()?

Basemaps are also supported in plot mode. So if we keep the default attributions in view mode, to be consistent across modes, we also need a credits in plot mode, whenever tm_basemaps are added. Yes or no?

The original credits are not essential to the map imo, but I wouldn't know the legal / copyright implications. I'd rather not see them by default on static maps with basemaps, but no strong feelings

@olivroy olivroy changed the title In mode = "view", could tm_credit use leaflet::addTiles() In mode = "view", could tm_credits use leaflet::addTiles() Mar 28, 2024
@olivroy olivroy added the view View mode issues label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
view View mode issues
Projects
None yet
Development

No branches or pull requests

3 participants