get_queried_features: Get queried features from a map as an sf object

View source: R/query_rendered_features.R

get_queried_featuresR Documentation

Get queried features from a map as an sf object

Description

This function retrieves the results of a feature query triggered by query_rendered_features(). It returns the features as a deduplicated sf object. Note that only features that were visible in the viewport at the time of the query will be included.

Usage

get_queried_features(map)

Arguments

map

A map object (mapboxgl, maplibre) or proxy object (mapboxgl_proxy, maplibre_proxy, mapboxgl_compare_proxy, maplibre_compare_proxy)

Value

An sf object containing the queried features, or an empty sf object if no features were found

Examples

## Not run: 
# In a Shiny server function:
observeEvent(input$query_button, {
    proxy <- maplibre_proxy("map")
    query_rendered_features(proxy, layer_id = "counties")
    features <- get_queried_features(proxy)
    print(nrow(features))
})

## End(Not run)

mapgl documentation built on Aug. 18, 2025, 5:35 p.m.