map_territorial_units.RdCreates an interactive web map for any Italian territorial unit type (comuni, province, regioni, ripartizioni) using Leaflet. This function automatically detects the type of territorial data and applies appropriate defaults, or allows manual specification of display parameters.
map_territorial_units(
territorial_sf,
name_col = NULL,
id_col = NULL,
color_by = NULL,
palette = "Set3",
popup_fields = NULL,
tile_provider = "OpenStreetMap",
add_legend = TRUE,
verbose = FALSE
)An sf object with territorial unit boundaries and attributes. Supports comuni, province, regioni, or ripartizioni data.
Character string. Column name to use for labels. If NULL (default), the function auto-detects based on territorial type (COMUNE, DEN_REG, DEN_UTS, DEN_RIP).
Character string. Column name containing IDs. If NULL (default), auto-detects based on territorial type (PRO_COM, COD_REG, COD_UTS, COD_RIP).
Character string. Attribute name to use for coloring polygons. Set to NULL for uniform color. If NULL, no coloring is applied.
Character string. Color palette name from RColorBrewer.
Defaults to "Set3". See RColorBrewer::display.brewer.all() for options.
Character vector. Fields to display in popup when clicking a territorial unit. If NULL (default), appropriate fields are auto-selected based on territorial type.
Character string. Base map tile provider. Options: "OpenStreetMap" (default), "CartoDB.Positron", "Esri.WorldImagery".
Logical. Add a legend for colored regions. Default TRUE. Only applicable when color_by is not NULL.
Logical. If TRUE, prints messages about auto-detection decisions. Default FALSE.
A leaflet map object that can be displayed interactively or embedded in Shiny applications.
if (FALSE) { # \dontrun{
# Map comuni (municipalities)
comuni <- readRDS("data/comuni_map.rds")
map_territorial_units(comuni, color_by = "COD_REG")
# Map regioni (regions)
regioni <- sf::st_read("regioni.geojson")
map_territorial_units(regioni, color_by = "COD_REG")
# Map province (provinces) with custom popup
province <- sf::st_read("province.geojson")
map_territorial_units(
province,
popup_fields = c("DEN_UTS", "DEN_REG"),
verbose = TRUE
)
# Map ripartizioni (macro-regions) with uniform color
ripartizioni <- sf::st_read("ripartizioni.geojson")
map_territorial_units(ripartizioni, color_by = NULL)
# Manual specification of columns
map_territorial_units(
territorial_sf,
name_col = "custom_name",
id_col = "custom_id",
color_by = "custom_category"
)
} # }