SymbolixAU / mapdeck

R interface to Deck.gl and Mapbox
https://symbolixau.github.io/mapdeck/articles/mapdeck.html
362 stars 40 forks source link

Titles #113

Closed SymbolixAU closed 5 years ago

SymbolixAU commented 5 years ago

Overlay text on the map. Would work like

mapdeck() %>%
  add_title(
    text = "My map title"
    , position = "TOP_MIDDLE"
    )

And controllable by CSS.


TODO

SymbolixAU commented 5 years ago

example of updating titles


library(shiny)
library(shinydashboard)
library(mapdeck)
library(sf)

ui <- dashboardPage(
    dashboardHeader()
    , dashboardSidebar(
        actionButton(
            inputId = "shuffle"
            , label = "shuffle"
        )
    )
    , dashboardBody(
        mapdeck::mapdeckOutput(
            outputId = "map"
            , height = "600px"
        )
    )
)

server <- function(input, output) {

    df <- roads[1:500, ]
    df$colour <- "#FFFFFF"

    output$map <- mapdeck::renderMapdeck({
        mapdeck( location = c(145, -37.85), zoom = 10, style = mapdeck_style("dark")) %>%
            add_path(
                data = df
                , update_view = FALSE
                , stroke_colour = "colour"
            )
    })

    observeEvent({input$shuffle},{

        df$colour <- "#FFFFFF"
        n <- sample(1:nrow(df), size = 1)
        r <- sample(1:nrow(df), size = n)
        df[r, "colour"] <- "#00FF00"

        mapdeck_update(
            map_id = "map"
        ) %>%
            add_path(
                data = df
                , stroke_colour = "colour"
                , stroke_width = 20
                , update_view = FALSE
            ) %>%
            add_title(
                title = paste0(n, " roads are coloured")
                , layer_id = "colouered"
            ) %>%
            add_title(
                title = paste0(nrow(df) - n, " roads are not coloured")
                , layer_id = "notcoloured"
            )

    })

}
shinyApp(ui, server)