### Install Carte Facile and MapLibre GL JS via npm Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/premiers-pas/installation.md Installs the Carte Facile and MapLibre GL JS libraries using npm. Requires Node.js and a project setup with npm. This is the recommended method for professional projects. ```bash npm install carte-facile maplibre-gl ``` -------------------------------- ### Callout Component Example Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/aller-plus-loin/api-adresse.md Example of using a Jinja2 component for a callout box, linking to external API documentation. ```Nunjucks { title: "Documentation officielle", description: "Le site national des adresses présente plus de détails sur les paramètres et points de terminaison de l'API Adresse.", link: { url: "https://adresse.data.gouv.fr/api-doc/adresse", title: "Consulter la documentation" } } ``` -------------------------------- ### Carte Facile Installation (NPM) Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/index.md Instructions for installing the Carte Facile library via npm, enabling its use in JavaScript projects. This is the recommended method for most web applications. ```bash npm install carte-facile ``` -------------------------------- ### Install Carte Facile and MapLibre GL JS via CDN Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/premiers-pas/installation.md Includes Carte Facile and MapLibre GL JS libraries directly in an HTML page using CDN links. This method is suitable for simple projects or quick tests and does not require Node.js. ```html ``` -------------------------------- ### Nunjucks Alert Rendering Examples Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/alerte.md Provides various examples of rendering the alert component with different types ('info', 'warning', 'success', 'error') and content structures in Nunjucks. The 'type' parameter defaults to 'info' if omitted. ```njk {% from "components/component.njk" import component with context %} {{ component("alert", { type: "warning", title: "Titre d'avertissement", description: "
Le contenu de l'alerte
" }) }} ``` ```njk {% from "components/component.njk" import component with context %} {{ component("alert", { type: "success", description: "Contenu de l'alerte seule" }) }} ``` ```njk {% from "components/component.njk" import component with context %} {{ component("alert", { type: "error", title: "Titre d'une erreur simple" }) }} ``` -------------------------------- ### Unstyled JavaScript Snippet Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/en/blog/posts/thirdpost.md Presents the same JavaScript code as the styled example, but without any syntax highlighting. It includes a simple function and console log statement. ```javascript // this is a command function myCommand() { let counter = 0; counter++; } // Test with a line break above this line. console.log('Test'); ``` -------------------------------- ### JavaScript Command Example with Diff Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/en/blog/posts/firstpost.md Demonstrates a simple JavaScript function with lines added and removed, often used to show code changes or differences. This snippet illustrates basic function definition and variable manipulation. ```diff-js // this is a command function myCommand() { + let counter = 0; - let counter = 1; counter++; } // Test with a line break above this line. console.log('Test'); ``` -------------------------------- ### Carte Facile Installation (CDN) Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/index.md Instructions for including Carte Facile in web projects using a Content Delivery Network (CDN) link. This method is suitable for simpler projects or quick prototyping. ```html ``` -------------------------------- ### Nunjucks Callout Component with Link Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/mise-en-avant.md Illustrates how to use the 'callout' component in a Nunjucks template. This example includes a title, HTML-formatted description, and an optional button link with a URL and label. ```njk {% raw %} {% from "components/component.njk" import component with context %} {{ component("callout", { title: "Titre mise en avant", description: "Contenu HTML", link: { url: "/", title: "Label bouton MD" } }) }} {% endraw %} ``` -------------------------------- ### Ajouter une carte simple (MapLibre CDN) Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/index.md An example demonstrating how to add a basic map to a web page using Carte Facile and MapLibre GL JS via CDN links. This snippet shows the essential HTML structure and JavaScript initialization. ```htmlLe contenu de l'alerte
" }) }} ``` -------------------------------- ### Eleventy Pagination for Tags Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/pagination.md Configures level 2 pagination for blog posts, grouping them by tags. This snippet uses Eleventy's `paginateCollectionTags` function within a `before` callback to process collections and prepare paginated data for each tag. It requires the `collections.posts` data and filters by language. ```javascript --- js { pagination: { data: "collections.posts", size: 1, alias: "tag", before: function(paginationData, fullData) { return this.paginateCollectionTags(this.filterCollectionLang(paginationData, fullData.lang), 6); } } } --- ``` -------------------------------- ### Markdown Callout Component Usage Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/mise-en-avant.md Demonstrates the integration of the 'callout' component within a Markdown file. This method allows for basic text content and a title to be displayed as a highlighted section. ```md :::callout Titre mise en avant Contenu **Mardown** ::: ``` -------------------------------- ### Intégrer un système d'onglets avec Nunjucks Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/onglet.md Ce snippet montre comment utiliser le composant Nunjucks `tabs` pour intégrer un système d'onglets dans une page. Il prend un objet de configuration avec un `ariaLabel` et une liste d' `items`, où chaque item définit un onglet avec son `id`, `label` et `content`. Ce composant est utile pour organiser le contenu de manière interactive. ```njk {% raw %} {% from "components/tab.njk" import tabs %} {{ tabs({ ariaLabel: "Titre du système d'onglets", items: [ { id: "tab1", label: "Label", content: "Contenu 1
" }, { id: "tab2", label: "Label", content: "Contenu 2
" } ] }) }} {% endraw %} ``` -------------------------------- ### Utilisation du composant Tuile en Nunjucks Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/tuile.md Démontre comment inclure un composant 'tuile' dans un template Nunjucks. Il accepte un objet de configuration avec des propriétés telles que url, title, description et pictogram. L'utilisation de `externalUrl` nécessite que `url` soit défini sur `false`. ```njk {% from "components/component.njk" import component with context %} {{ component("tile", { url: "/", title: "Intitulé de la tuile", description: "Lorem [...] elit ut.", pictogram: "buildings/city-hall.svg" }) }} ``` -------------------------------- ### Accordion Syntax Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/md-cheatsheet.md Demonstrates the Markdown syntax for creating accordions, including group and individual accordion elements with rich markdown content. ```markdown ????accordionsgroup ??? Intitulé accordéon Contenu **markdown** _riche_ ??? ???? ``` -------------------------------- ### Géocodage d'adresse unitaire avec Geopy (Python) Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/aller-plus-loin/api-adresse.md Utilisation de la bibliothèque Geopy en Python pour le géocodage d'adresses. La classe `BANFrance` de Geopy est spécifiquement conçue pour interagir avec la Base d'Adresses Nationale française. ```python from geopy.geocoders import BANFrance def geocode_with_geopy_ban(address): """Géocode une adresse en utilisant la classe BANFrance de Geopy.""" geolocator = BANFrance() try: location = geolocator.geocode(address) if location: return { "address": location.address, "latitude": location.latitude, "longitude": location.longitude, "raw": location.raw } else: return None except Exception as e: print(f"Erreur lors du géocodage avec Geopy : {e}") return None # Exemple d'utilisation : if __name__ == "__main__": address_to_geocode = "20 Avenue de Ségur, Paris" result = geocode_with_geopy_ban(address_to_geocode) if result: print(f"Adresse trouvée: {result['address']}") print(f"Coordonnées: Latitude {result['latitude']}, Longitude {result['longitude']}") # print(f"Données brutes: {result['raw']}") # Pour voir toutes les informations retournées else: print(f"Impossible de géocoder l'adresse : {address_to_geocode}") ``` -------------------------------- ### Géocodage d'adresse unitaire avec Python Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/aller-plus-loin/api-adresse.md Ce snippet Python montre comment effectuer des appels unitaires pour géocoder des adresses en utilisant le script `geocode-addok-unit-call.py`. Il est conçu pour interagir avec un service de géocodage comme Addok. ```python import requests import json # URL du service de géocodage (exemple avec Addok) GEOCODING_URL = "https://api-adresse.data.gouv.fr/1.0/reverse/" def geocode_address_unit(address): """Effectue un appel unitaire de géocodage pour une adresse donnée.""" params = { "q": address, "limit": 1 } try: response = requests.get(GEOCODING_URL, params=params) response.raise_for_status() # Lève une exception pour les codes d'erreur HTTP data = response.json() if data and data.get('features'): feature = data['features'][0] properties = feature.get('properties', {}) geometry = feature.get('geometry', {}) return { "address": properties.get('label'), "latitude": geometry.get('coordinates')[1] if geometry.get('coordinates') else None, "longitude": geometry.get('coordinates')[0] if geometry.get('coordinates') else None, "city": properties.get('city'), "postcode": properties.get('postcode') } else: return None except requests.exceptions.RequestException as e: print(f"Erreur lors de la requête : {e}") return None except json.JSONDecodeError: print("Erreur lors du décodage de la réponse JSON.") return None # Exemple d'utilisation : if __name__ == "__main__": address_to_geocode = "10 Rue de Rivoli, Paris" result = geocode_address_unit(address_to_geocode) if result: print(f"Adresse: {result['address']}") print(f"Ville: {result['city']}, Code Postal: {result['postcode']}") print(f"Coordonnées: Latitude {result['latitude']}, Longitude {result['longitude']}") else: print(f"Impossible de géocoder l'adresse : {address_to_geocode}") ``` -------------------------------- ### List Available Overlays in Console Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/premiers-pas/ajouter-des-surcouches.md Provides methods to inspect all available map overlays. It logs the `Overlay` object to the browser's console, allowing developers to see all possible overlay names and their corresponding values. This is useful for autocompletion or programmatic access. ```typescript import { Overlay } from 'carte-facile'; console.log(Overlay); ``` ```typescript console.log(CarteFacile.Overlay); ``` -------------------------------- ### Quote Syntax Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/md-cheatsheet.md Illustrates the Markdown syntax for creating blockquotes, typically used for citations or emphasized text. ```markdown :::quote « Lorem [...] elit ut. » ::: ``` -------------------------------- ### Alert Syntax Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/md-cheatsheet.md Shows the Markdown syntax for displaying alerts with different types like 'info', including rich markdown content within the alert. ```markdown :::info Test d'alerte Contenu ** Mardown** ::: ``` -------------------------------- ### Add Banner Image to Blog Post Layout Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/blog-post.md This snippet demonstrates how to add a banner image to a blog post layout. It requires defining the `image.path` and `image.alt` properties within the YAML frontmatter of the post file. The `image.path` should be a relative path to the image file from the page's location. ```markdown --- image: path: ./possum.png alt: A possum --- ``` -------------------------------- ### Géocodage massif avec addok-geocode-stream (Node.js) Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/aller-plus-loin/api-adresse.md Utilisation de la solution en ligne de commande `addok-geocode-stream` pour le géocodage massif via Node.js. Ce script traite les adresses à partir d'un flux d'entrée et génère un flux de sortie avec les résultats géocodés. ```bash # Installer le package si ce n'est pas déjà fait : npm install -g addok-geocode-stream # Exemple d'utilisation avec un fichier CSV en entrée : # Supposons que votre fichier CSV s'appelle 'adresses.csv' et contient une colonne 'adresse'. # Le script lira le fichier, géocoderra chaque adresse et écrira le résultat dans la sortie standard. cat adresses.csv | addok-geocode-stream --input-format csv --input-columns adresse --output-format csv > resultats_geocodes.csv # Pour spécifier une URL de service Addok différente (si vous n'utilisez pas le service par défaut) : # cat adresses.csv | addok-geocode-stream --endpoint http://votre-addok-instance.com/1.0/search --input-format csv --input-columns adresse --output-format csv > resultats_geocodes.csv ``` -------------------------------- ### Markdown Alert Usage Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/alerte.md Demonstrates how to render an alert component directly within a Markdown file using the ':::' directive. This allows for simple integration of informational messages. ```md :::info Test d'alerte Contenu **Mardown** ::: ``` -------------------------------- ### Ajouter une carte de téléchargement Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/telechargement.md Présente un téléchargement de fichier sous forme de carte. Inclut un titre, une description optionnelle, l'URL du fichier et des détails supplémentaires. ```njk {% raw %}{% from "components/component.njk" import component with context %} {{ component("download", { type: "card", title: "Nom du fichier", description: "Description du fichier", href: "/data/dossier/fichier.ext", detail: "Format ou extension - 850Ko" })}{% endraw %} ``` -------------------------------- ### Ajouter un lien de téléchargement Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/telechargement.md Intègre un lien simple pour télécharger un fichier. Nécessite le nom du fichier et son URL. Peut inclure des détails comme le format et la taille. ```njk {% raw %}{% from "components/component.njk" import component with context %} {{ component("download", { title: "Nom du fichier", href: "/data/dossier/fichier.ext", detail: "Format ou extension - 850Ko" }) }}{% endraw %} ``` -------------------------------- ### Show Breadcrumbs in Blog Post Layout Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/blog-post.md This snippet shows how to enable the display of breadcrumbs for a blog post layout. By setting the `showBreadcrumb` variable to `true` in the YAML frontmatter, the navigation trail will be automatically rendered. ```markdown --- showBreadcrumb: true --- ``` -------------------------------- ### Intégration Fil d'Ariane (Nunjucks) Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/fil-d-ariane.md Exemple d'utilisation du composant 'breadcrumb' dans un fichier Nunjucks (.njk). Il montre comment passer les segments du fil d'Ariane, incluant l'URL et le titre de chaque segment. ```njk {% from "components/component.njk" import component with context %} {{ component("breadcrumb", { segments: [{ url: "/blog/", title: "Blog" }] }) }} ``` -------------------------------- ### Ajouter une tuile de téléchargement Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/blog/posts/telechargement.md Affiche un téléchargement de fichier comme une tuile interactive. Permet d'ajouter un pictogramme pour une meilleure identification visuelle, en plus des informations de base. ```njk {% raw %}{% from "components/component.njk" import component with context %} {{ component("download", { type: "tile", title: "Nom du fichier", href: "/data/dossier/fichier.ext", detail: "Format ou extension - 850Ko", pictogram: "buildings/city-hall.svg" })}{% endraw %} ``` -------------------------------- ### Add Overlays to Map with Carte Facile Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/premiers-pas/ajouter-des-surcouches.md Demonstrates how to add single or multiple map overlays using the `addOverlay` function from the 'carte-facile' library. The function automatically styles overlays based on the selected base map. It takes the map object and an overlay or an array of overlays as input. ```typescript import { addOverlay, Overlay } from 'carte-facile'; // Ajouter une seule surcouche addOverlay(map, Overlay.administrativeBoundaries); // Ou ajouter plusieurs surcouches en même temps addOverlay(map, [Overlay.administrativeBoundaries, Overlay.cadastre]); ``` ```typescript CarteFacile.addOverlay(map, ['levelCurves', 'administrativeBoundaries']); ``` -------------------------------- ### API Découpage Administratif - Recherche et Récupération de Données Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/aller-plus-loin/api-decoupage-administratif.md Permet d'interroger l'API Découpage Administratif pour obtenir des informations sur les communes, départements et régions françaises. Les appels peuvent être filtrés par code postal, code INSEE, nom, coordonnées géographiques, ou liés à un département ou une région spécifique. Des liens directs vers des fichiers JSON globaux pour les départements et régions sont également disponibles. ```APIDOC API Découpage Administratif Base URL: https://geo.api.gouv.fr/ Fonctionnalités : 1. **Recherche de Communes** * Par code postal : `GET /communes?codePostal={codePostal}` Exemple : `https://geo.api.gouv.fr/communes?codePostal=78000` * Par code INSEE : `GET /communes?code={code}` Exemple : `https://geo.api.gouv.fr/communes?code=44109` * Par nom (avec boost par population et limite) : `GET /communes?nom={nom}&boost={boost}&limit={limit}` Exemple : `https://geo.api.gouv.fr/communes?nom=Nantes&boost=population&limit=5` * Par coordonnées (latitude, longitude) : `GET /communes?lat={lat}&lon={lon}` Exemple : `https://geo.api.gouv.fr/communes?lat=47.0482944&lon=-1.1501568` * Filtrer par département (pour éviter homonymie) : `GET /communes?nom={nom}&codeDepartement={codeDepartement}` Exemple : `https://geo.api.gouv.fr/communes?nom=Saint-Aubin&codeDepartement=21` * Obtenir toutes les communes d'un département : `GET /departements/{codeDepartement}/communes` Exemple : `https://geo.api.gouv.fr/departements/44/communes` * Obtenir toutes les communes d'une région : `GET /communes?codeRegion={codeRegion}` Exemple : `https://geo.api.gouv.fr/communes?codeRegion=84` * Note : L'option `fields` permet de ne retourner que les champs nécessaires. 2. **Recherche de Régions et Départements** * Obtenir une région par son nom : `GET /regions?nom={nom}` Exemple : `https://geo.api.gouv.fr/regions?nom=Auvergne` * Obtenir un département par son nom : `GET /departements?nom={nom}` Exemple : `https://geo.api.gouv.fr/departements?nom=Ain` 3. **Données globales (sans géométrie)** * Fichier JSON des départements : `https://unpkg.com/@etalab/decoupage-administratif@4.1.0/data/departements.json` * Fichier JSON des régions : `https://unpkg.com/@etalab/decoupage-administratif@4.1.0/data/regions.json` Paramètres courants : - `codePostal`: Code postal de la commune. - `code`: Code INSEE de la commune. - `nom`: Nom de la commune, département ou région. - `boost`: Critère de tri pour la recherche par nom (ex: 'population'). - `limit`: Nombre maximum de résultats. - `lat`: Latitude pour la recherche par coordonnées. - `lon`: Longitude pour la recherche par coordonnées. - `codeDepartement`: Code du département pour filtrer les communes. - `codeRegion`: Code de la région pour filtrer les communes. - `fields`: Permet de spécifier les champs à retourner. ``` -------------------------------- ### Display Available Layer Groups Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/premiers-pas/masquer-des-couches.md Shows how to log all available layer group names to the browser console using the `LayerGroup` enum from the `carte-facile` library. This helps in discovering and using the correct group names. ```typescript import { LayerGroup } from 'carte-facile'; console.log(LayerGroup); ``` -------------------------------- ### Autocomplétion d'adresse avec Leaflet Geocoder BAN (JavaScript) Source: https://github.com/fab-geocommuns/carte-facile-site/blob/main/content/fr/documentation/aller-plus-loin/api-adresse.md Exemples d'intégration du plugin Leaflet Geocoder BAN pour l'autocomplétion d'adresses françaises. Les démos montrent l'ajout d'une barre de recherche et d'un contrôle de recherche sur une carte Leaflet. ```HTML