Skip to content

Commit d5250ca

Browse files
committed
Added an advanced example of using layer control w/ minimap.
1 parent 727dd47 commit d5250ca

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

inst/examples/minimap.R

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library(leaflet)
22

3-
l <- leaflet() %>% setView(0,0,1)
3+
l <- leaflet() %>% setView(0,0,3)
44

55
#' Default Minimap
66
l %>% addTiles() %>% addMiniMap()
@@ -11,3 +11,26 @@ l %>% addProviderTiles(providers$Esri.WorldStreetMap) %>%
1111
addMiniMap(
1212
tiles = providers$Esri.WorldStreetMap,
1313
toggleDisplay = T)
14+
15+
#' <br/>
16+
#' Slightly advanced use case
17+
#' Change minimap basemap to match main map's basemap
18+
#' This approach will work for basemaps added via addProviderTiles
19+
#' But not for one's added with addTiles using a URL schema.
20+
m <- l
21+
esri <- providers %>%
22+
purrr::keep(~ grepl('^Esri',.))
23+
24+
esri %>%
25+
purrr::walk(function(x) m <<- m %>% addProviderTiles(x,group=x))
26+
27+
m %>%
28+
addLayersControl(
29+
baseGroups = names(esri),
30+
options = layersControlOptions(collapsed = FALSE)
31+
) %>%
32+
addMiniMap(
33+
tiles = esri[[1]],
34+
toggleDisplay = T) %>%
35+
htmlwidgets::onRender("function(el, x) { var myMap = this; this.on('baselayerchange', function (e) { myMap.minimap.changeLayer(L.tileLayer.provider(e.name)); }) }")
36+

0 commit comments

Comments
 (0)