这是indexloc提供的服务,不要输入任何密码
Skip to content

tm_basemap: group + group.control="radio" does not switch basemap in tmap v4.1 #1151

@YONGHUNI

Description

@YONGHUNI

Hi, I'm struggling to create the map using the tm_basemap function in 'view' mode.

Am I overlooking something, or could this potentially be a bug?

Description

When I add multiple basemaps via tm_basemap(..., group=…) and then use group.control="radio" (or group.single=TRUE), the UI toggles, but the underlying tile layers never get removed. Toggling between “Satellite” and “Street Map” does not switch the visible basemap.

Expected behavior

Clicking on a different basemap radio button should turn off the previous tile layer and display only the newly selected one.

Actual behavior

The radio buttons appear, but selecting a new basemap does not remove the old one. The map always shows the last-added tiles.

Reproducible example

library(tmap)
# view mode
tmap_mode("view")

# minimal map
tm_shape(World) +
  tm_polygons(
    "pop_est",
    fill.legend = tm_legend(title = "Population")
  ) +
  tm_basemap("OpenStreetMap",     group = "Street Map") +
  tm_basemap("Esri.WorldImagery", group = "Satellite") +
  tm_view(
    # basemap groups as radios, overlays as checkboxes
    group.control = list(
      base    = "radio",
      overlay = "checkbox"
    ),
    # force only one group visible at a time
    group.single = TRUE
  )

Session info

> sessionInfo()
R version 4.5.0 (2025-04-11 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26100)

Matrix products: default
  LAPACK version 3.12.1

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: Europe/Berlin
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tmap_4.1

loaded via a namespace (and not attached):
 [1] s2_1.1.9                class_7.3-23            lwgeom_0.2-14           KernSmooth_2.23-26      lattice_0.22-6          digest_0.6.37          
 [7] magrittr_2.0.3          grid_4.5.0              RColorBrewer_1.1-3      fastmap_1.2.0           jsonlite_2.0.0          e1071_1.7-16           
[13] leafsync_0.1.0          DBI_1.2.3               crosstalk_1.2.1         viridisLite_0.4.2       cols4all_0.8            XML_3.99-0.18          
[19] jquerylib_0.1.4         codetools_0.2-20        abind_1.4-8             cli_3.6.5               rlang_1.1.6             units_0.8-7            
[25] tmaptools_3.2           base64enc_0.1-3         leaflegend_1.2.1        tools_4.5.0             raster_3.6-32           parallel_4.5.0         
[31] maptiles_0.10.0         colorspace_2.1-1        spacesXYZ_1.6-0         logger_0.4.0            R6_2.6.1                png_0.1-8              
[37] proxy_0.4-27            classInt_0.4-11         leaflet_2.2.2           leaflet.providers_2.0.0 htmlwidgets_1.6.4       terra_1.8-54           
[43] data.table_1.17.6       glue_1.8.0              Rcpp_1.0.14             sf_1.0-21               rstudioapi_0.17.1       dichromat_2.0-0.1      
[49] htmltools_0.5.8.1       leafem_0.2.4            wk_0.9.4                compiler_4.5.0          sp_2.2-0                stars_0.6-8   

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions