rr-leaflet

How to add a custom map to addMiniMap?


I would like to use a different map in addMiniMap() than the main leaflet window. How can I do that? For example, I want to display CartoDB.Positron in the main window and Esri.NatGeoWorldMap in the addMiniMap window.

leaflet() |>
  addProviderTiles(providers$CartoDB.Positron) %>%
  setView(lng = 13.4, lat = 52.52, zoom = 14) %>%
  addMiniMap(width = 150, height = 180, "topleft") %>%
  addProviderTiles(providers$Esri.NatGeoWorldMap)

I tried the natGeoWorldMap inside addMiniMap function with no success.


Solution

  • addMiniMap() takes the tiles parameter which allows you to specify a URL for map tiles or use one of the pre-defined map tile providers, so just adjust your code to the following:

    leaflet() |>
      addProviderTiles("CartoDB.Positron") %>%
      setView(lng = 13.4, lat = 52.52, zoom = 14) %>%
      addMiniMap(width = 150, height = 180, position = "topleft", tiles = "Esri.NatGeoWorldMap")
    

    enter image description here