Skip to contents

Creates two observers for handling Leaflet map interactions in a linked component system. The first observer handles direct marker clicks on the map, while the second observer responds to selection changes from other linked components.

Usage

setup_leaflet_observers(
  component_id,
  session,
  components,
  shared_state,
  on_selection_change,
  registry = NULL
)

Arguments

component_id

Character string. The unique identifier for the Leaflet component.

session

Shiny session object for the current user session.

components

List containing component configuration data including data reactives and shared ID columns.

shared_state

Reactive values object containing selected_id and selection_source for coordinating selections across components.

on_selection_change

Function to call when selection changes (currently unused).

registry

Optional registry object with set_selection method for managing selections. If NULL, falls back to direct shared_state updates.

Value

List containing two observer objects:

observer1

Handles marker click events on the map

observer2

Responds to selection changes from other components

Details

The marker click observer:

  • Extracts clicked marker ID from the click event

  • Retrieves corresponding data row from the component's data

  • Clears existing popups and applies click behavior (custom or default)

  • Updates selection state through registry or direct shared_state modification

The selection response observer:

  • Only responds to selections from other components (not self-selections)

  • Updates the map visualization to reflect the new selection

Examples

if (FALSE) { # \dontrun{
observers <- setup_leaflet_observers(
  component_id = "map1",
  session = session,
  components = components_list,
  shared_state = shared_values,
  on_selection_change = NULL,
  registry = selection_registry
)
} # }