leaflet.indoor registers its dependencies on both
ordinary widgets and leafletProxy() calls. The application
below exposes user floor changes and updates the map from the
server.
ui <- fluidPage(
actionButton("floor_two", "Show floor 2"),
verbatimTextOutput("selected_floor"),
leafletOutput("map", height = 500)
)
server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet(
indoor_demo,
options = leafletOptions(crs = leafletCRS("L.CRS.Simple"))
) |>
addIndoor(
label = ~name,
popup = ~description,
layerId = ~feature_id,
style = list(fillColor = ~fill),
crs = "simple"
) |>
addIndoorControl(position = "bottomright")
})
observeEvent(input$floor_two, {
leafletProxy("map", session) |>
setIndoorLevel("2")
})
output$selected_floor <- renderPrint(input$map_indoor_level)
}
app <- shinyApp(ui, server)
invisible(app)Run the installed example with:
shiny::runApp(system.file("examples/shiny", package = "leaflet.indoor"))Input values
User selection produces input$MAPID_indoor_level
with:
-
level: the selected floor as text; -
dataset_id: the indoor data set; -
control_id: the control used.
Feature clicks produce input$MAPID_indoor_feature_click
with id, dataset_id, level,
lat, and lng. Programmatic floor changes do
not emit the user-selection event, which prevents reactive feedback
loops.
When comments are supplied to addIndoor(),
comment-icon clicks produce
input$MAPID_indoor_comment_click with id,
dataset_id, level, lat,
lng, and comment_count. Comment icons belong
to the same floor groups as the rooms and are replaced or cleared with
their indoor data set.
Replacing and clearing data
addIndoor() can be called on a proxy with explicit
data. Reusing a dataset_id replaces its layer
groups and refreshes linked controls. clearIndoor() removes
its features but retains the controls in their empty state.
removeIndoorControl() removes only the named control.