if (FALSE) {
library(mapgl)
m1 <- mapboxgl(style = mapbox_style("light"))
m2 <- mapboxgl(style = mapbox_style("dark"))
# Default swipe mode
compare(m1, m2)
# Synchronized side-by-side mode
compare(m1, m2, mode = "sync")
# Shiny example
library(shiny)
ui <- fluidPage(
maplibreCompareOutput("comparison")
)
server <- function(input, output, session) {
output$comparison <- renderMaplibreCompare({
compare(
maplibre(style = carto_style("positron")),
maplibre(style = carto_style("dark-matter")),
mode = "sync"
)
})
# Update the right map
observe({
right_proxy <- maplibre_compare_proxy("comparison", map_side = "after")
set_style(right_proxy, carto_style("voyager"))
})
}
}
Run the code above in your browser using DataLab