syncWith: Synchronize multiple maps

Description Usage Arguments Value Examples

View source: R/sync_with.R

Description

This function can be used when multiple leaflet maps are displayed on the same view (for instance in a shiny application or a Rmarkdown document) and one wants to synchronize their center, zoom and time.

syncWith() can also be used with basic leaflet maps to synchronize only their zoom and center.

Usage

1
syncWith(map, groupname)

Arguments

map

A leaflet map object created with leaflet.

groupname

Character string. All maps that use the same group name will be synchronized.

Value

The modified leaflet map object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
if (require(manipulateWidget) & require(leaflet)) {

  # Synchronize zoom and center of basic maps.
  basicMap1 <- leaflet() %>% addTiles() %>% syncWith("basicmaps")
  basicMap2 <- leaflet() %>% addTiles() %>% syncWith("basicmaps")
  combineWidgets(basicMap1, basicMap2)

  # Synchronize time step of two maps that represent the evolution of some
  # variable.
  map1 <- leaflet() %>% addTiles() %>%
    addMinicharts(0, 40, chartdata = 1:10, time = 1:10) %>%
    syncWith("maps")
  map2 <- leaflet() %>% addTiles() %>%
    addMinicharts(0, 40, chartdata = 10:1, time = 1:10) %>%
    syncWith("maps")
  combineWidgets(map1, map2)

}

leaflet.minicharts documentation built on May 11, 2021, 5:07 p.m.