GeoLeaf Core API - v3.0.0
    Preparing search index...
    Legend: {
        init(mapInstance: unknown, options?: LegendInitOptions): boolean;
        _loadTaxonomy(): void;
        _initializeAllLayers(): void;
        loadLayerLegend(
            layerId: string,
            styleId: string,
            layerConfig: LayerConfigForLegend,
        ): void;
        setLayerVisibility(layerId: string, visible: boolean): void;
        _rebuildDisplay(): void;
        toggleAccordion(_layerId: string): void;
        getAllLayers(): Map<string, LayerInfo>;
        hideLegend(): void;
        removeLegend(): void;
        isLegendVisible(): boolean;
        showLoadingOverlay(): void;
        hideLoadingOverlay(): void;
        _reset(): void;
    } = LegendModule

    Type Declaration

    • init: function
      • Mounts the legend control on a map.

        Options are layered: the defaults from modules.legend in the profile, then anything passed here — explicit options always win. Without a core Config on the namespace (a standalone or embedded boot) the defaults are used directly.

        Parameters

        • mapInstance: unknown

          The MapLibre map; a falsy value logs an error and returns false.

        • Optionaloptions: LegendInitOptions

          Position, title and collapsed state, overriding the profile config.

        Returns boolean

        true when the control was mounted.

        import * as maplibregl from "maplibre-gl";
        const map = new maplibregl.Map({ container: "map", style: "..." });
        GeoLeaf.Legend.init(map);

        // Avec options
        GeoLeaf.Legend.init(map, {
        position: "bottomright",
        collapsed: false,
        title: "Légende des couches",
        });
    • _loadTaxonomy: function
    • _initializeAllLayers: function
    • loadLayerLegend: function
      • Loads and renders one layer's legend entries.

        Normally driven by the GeoJSON module as layers come up; calling it directly is the advanced path, for a legend that must be refreshed outside the usual load.

        Parameters

        • layerId: string

          Layer whose legend is being loaded.

        • styleId: string

          Style whose legend file to read, e.g. "default".

        • layerConfig: LayerConfigForLegend

          The layer's config, source of the legend file location.

        Returns void

        // Normalement appelée en interne par le module GeoJSON.
        // Pour usage manuel avancé :
        GeoLeaf.Legend.loadLayerLegend("parcs", "default", layerConfig);
    • setLayerVisibility: function
      • Shows or hides one layer's block within the legend.

        ⚠️ This is a legend-display concern only: it does not touch the map layer itself. Use the layer manager to change what is actually drawn.

        Parameters

        • layerId: string

          Layer whose legend block is toggled.

        • visible: boolean

          true to show the block.

        Returns void

        // Cacher la couche "parcs" dans la légende
        GeoLeaf.Legend.setLayerVisibility("parcs", false);

        // Afficher la couche "zones" dans la légende
        GeoLeaf.Legend.setLayerVisibility("zones", true);
    • _rebuildDisplay: function
    • toggleAccordion: function
    • getAllLayers: function
      • Every layer the legend currently tracks, keyed by layer id.

        Returns Map<string, LayerInfo>

        A Map — iterate with forEach((info, layerId) => …), not as an array.

        const layers = GeoLeaf.Legend.getAllLayers();
        layers.forEach((info, layerId) => {
        console.log(layerId, info.visible, info.label);
        });
    • hideLegend: function
    • removeLegend: function
    • isLegendVisible: function
      • Whether the legend control is currently displayed.

        Returns boolean

        false both when the legend is hidden and when it was never mounted.

        if (GeoLeaf.Legend.isLegendVisible()) {
        console.log("La légende est affichée");
        }
    • showLoadingOverlay: function
      • Covers the legend with a loading overlay while entries are being rebuilt.

        Always pair it with LegendModule.hideLoadingOverlay — nothing clears the overlay on its own, including a failed load.

        Returns void

        GeoLeaf.Legend.showLoadingOverlay();
        // ... chargement
        GeoLeaf.Legend.hideLoadingOverlay();
    • hideLoadingOverlay: function
    • _reset: function
      • Full teardown for module destroy / lifecycle recreate. Unlike the public removeLegend() (which only drops the control), this clears the three pending timers (debounced rebuild, sprite retry, and the overlay's auto-hide deadline via resetOverlay()), empties the layer map and releases the map / profile / taxonomy references so a subsequent init() starts from a clean slate.

        Returns void