
How to use the interactive mapping family functions?
interactive_mapping.RmdIntroduction
This vignette demonstrates the use of the family of functions that
facilitates the production of interactive HTML maps of the so-ii
territory: set_provider(),
map_leaflet_commune(), add_visual_param() and
map_leaflet_multilayer(). This document will cover the
available options and demonstrate how to customize the resulting
plots.
The function set_provider()
This function helps to set the background map provider for interactive mapping applications. It allows you to select different base maps from a predefined list of options, primarily from the French Institut national de l’information géographique et forestière (IGN).
The set_provider() function retrieves the URL for the
map provider and its attribution information based on an alias, that it
takes as a parameter. The function returns either a list containing both
the provider URL address and the attribution information or just the
provider URL address depending on the value of the parameter
attribution. The output of the function can be used
directly in functions map_leaflet_commune() and
map_leaflet_multilayer().
Currently, the function supports the following provider aliases:
- ign_ortho: orthophotos
- ign_plan: plan IGN v2 (Cartographie multi-échelles sur le territoire national français)
- ign_parcellaire: cadastral plots(Cartographie parcellaire cadastral multi-échelles sur le territoire national français)
- ign_3d: 3D representation using shading derived from MNH LiDAR HD (estompage issu du MNH LiDAR HD)
- ign_building: BD TOPO® V3 - Buildings layer (BD TOPO® V3 - Bâtiments)
- ign_rpg: French land parcel identification system (RPG Dernière édition)
- ign_aoc_viti: IGN’s AOC wine region boundaries (délimitations parcellaires AOC viticoles (INAO))
The usage of this function is very straightforward:
First of all let us load the library so.ii in our R
session.
Default provider
If you call the function without specifying an alias, it will issue a warning and default to “ign_ortho”. This is useful for quickly getting a base map without needing to specify it each time.
set_provider()
#> Warning in set_provider(): Provider alias missing. Please see documentation.
#> Choosing 'ign_ortho' by default
#> $provider
#> [1] "https://data.geopf.fr/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&STYLE=normal&TILEMATRIXSET=PM&FORMAT=image/jpeg&LAYER=ORTHOIMAGERY.ORTHOPHOTOS&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}"
#>
#> $attribution
#> [1] "IGN-F/Geoportail"Provider with attribution
To set a specific provider and retrieve both the provider URL and its attribution information, simply pass the desired alias as the first argument.
set_provider("ign_ortho")
#> $provider
#> [1] "https://data.geopf.fr/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&STYLE=normal&TILEMATRIXSET=PM&FORMAT=image/jpeg&LAYER=ORTHOIMAGERY.ORTHOPHOTOS&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}"
#>
#> $attribution
#> [1] "IGN-F/Geoportail"Specifying a provider without attribution
If you only need the provider URL and don’t require the attribution
information, set the attribution argument to
FALSE.
set_provider("ign_plan", attribution = FALSE)
#> [1] "https://data.geopf.fr/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&STYLE=normal&TILEMATRIXSET=PM&FORMAT=image/png&LAYER=GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}"The function map_leaflet_commune()
This function creates an interactive Leaflet map displaying commune-level data with customizable styling and popups. This is particularly useful for visualizing geographic data related to the commune administrative level.
The map_leaflet_commune() function generates a Leaflet
map as follows: over a base map layer set using
set_provider(), it overlays the polygons in the
dataset sf object, and uses the content in the
popup column of the dataset to display information about
each polygon.
Let us create a simple example using the
so_ii_collectivity dataset to display a map with
commune-level information. First, load the necessary data and create a
popup variable containing the information you want to display in the
popups. In this example, we will display the commune name and
population.
dataset = so_ii_collectivity
dataset[["popup"]] = paste(
dataset[["commune_name"]],
sprintf("(%s hab)", formatC(so_ii_population[,"2019"], big.mark = " ", format = "d"))
)Now, call the map_leaflet_commune() function with the
prepared dataset to generate the interactive Leaflet map. Clicking on a
commune will reveal its corresponding popup with the name and
population.
map = map_leaflet_commune(dataset = dataset)
# Display map
mapYou can customize the base map by providing a different map_bg list,
which is generated using the set_provider() function. For
example, to use the “ign_plan” provider:
map_leaflet_commune(dataset = dataset, map_bg = set_provider("ign_plan"))If your dataset does not contain a popup column, the function will issue a warning and create an empty popup column, preventing errors.
# Example with a dataset missing the 'popup' column
dataset_no_popup = so_ii_collectivity
map = map_leaflet_commune(dataset = dataset_no_popup)
#> Warning in map_leaflet_commune(dataset = dataset_no_popup): 'popup' column is
#> missing. Using commune names as pooup content
# Display map
map