dwd / fun /map_helpers.R
alexdum's picture
fix: Center map directly on selected station by removing longitude offset.
eb8d6c0
#' Highlight Selected Station on Map (MapLibre version)
#'
#' @param proxy MapLibre proxy object
#' @param lng Longitude of the station
#' @param lat Latitude of the station
#' @param label_html HTML content for the label/tooltip
#' @param move_map Whether to fly to the station location
#'
highlight_selected_station <- function(proxy, lng, lat, label_html, move_map = TRUE) {
if (move_map) {
proxy %>% fly_to(center = c(lng, lat), zoom = 9)
}
# Create a single-point sf for the highlight marker
highlight_data <- data.frame(
id = "selected-highlight",
popup_content = label_html,
lng = lng,
lat = lat
)
highlight_sf <- sf::st_as_sf(highlight_data, coords = c("lng", "lat"), crs = 4326)
proxy %>%
clear_layer("selected-highlight") %>%
add_circle_layer(
id = "selected-highlight",
source = highlight_sf,
circle_color = "red",
circle_radius = 12,
circle_stroke_color = "red",
circle_stroke_width = 3,
circle_opacity = 0.4,
tooltip = "popup_content"
)
}