Skip to contents

This function generates an interactive Leaflet map displaying commune-level data, with customizable styling and popups. It uses spatial data from an sf object to render polygons representing communes on the map.

The function adds a base map layer using the provided map_bg information and then overlays polygons representing the communes. Communes are styled with a light fill color and a transparent background. When a commune is clicked, its corresponding popup content is displayed. A background polygon representing the overall limit is also added for context.

Usage

map_leaflet_commune(
  dataset = so.ii::so_ii_collectivity,
  map_bg = set_provider("ign_ortho")
)

Arguments

dataset

sf object, data to be plotted. Default to so_ii_collectivity. See details

map_bg

named list, containing the background map provider URL and the attribution text, as issued from the function set_provider()

Value

A Leaflet map object (invisibly). The map is displayed in the viewer or within an R Markdown or quarto document.

Details

dataset should contain valid html content in popup variable added to the tributary table of the sf object. If this column does not exist, the function issues a warning and generate and empty popup column

Examples


if (FALSE) { # \dontrun{
# example 1
dataset = so.ii::so_ii_collectivity
dataset[["popup"]] = paste(
 dataset[["commune_name"]],
 sprintf("(%s hab)", formatC(so_ii_population[,"2019"], big.mark = " ", format = "d"))
)
map_leaflet_commune(dataset)

# example 2:  issues warning and creates empty popup
map_leaflet_commune()
} # }