GeoLeaf Core API - v3.19.0
    Preparing search index...

    Public + internal surface of the Labels singleton. Used to type the this receiver / self parameters in labels.ts and the Labels | null lite stub.

    interface LabelsApi {
        init(options?: Record<string, unknown>): void;
        initializeLayerLabels(layerId: string): void;
        enableLabels(
            layerId: string,
            labelConfig?: LabelUserConfig,
            showImmediately?: boolean,
        ): void | Promise<void>;
        disableLabels(layerId: string): void;
        _hideLabelsForLayer(layerId: string): void;
        toggleLabels(layerId: string): boolean;
        hasLabelConfig(layerId: string): boolean;
        areLabelsEnabled(layerId: string): boolean;
        refreshLabels(layerId: string): void;
        _createLabelsForLayer(layerId: string): Promise<void>;
        _getLayerData(layerId: string): LabelLayerData | null;
        _ensureZoomListener(): void;
        _handleZoomChange(detail: { zoom?: number }): void;
        _calculateMapScale(map: LabelsMapHandle | null): number;
        _isScaleInRange(
            currentScale: number,
            minScale: number | null | undefined,
            maxScale: number | null | undefined,
        ): boolean;
        destroy(): void;
    }
    Index
    • Lifecycle entry point of the module. It only logs.

      It subscribes to nothing: the zoomend and style.load listeners are attached later, once a layer's labels are prepared, and the loader drives labels by direct calls. The labels capability calls it when it mounts; an integrator has no need to.

      Parameters

      • Optionaloptions: Record<string, unknown>

        Ignored.

      Returns void

      GeoLeaf.Labels.init();
      
    • Rebuilds a layer's labels from its declared label configuration, if it has one.

      Called by the loader as a layer comes up, and again on a style change. A layer's declared configuration is the label object of its current style, else — the style carrying none, or its file being missing — the labels block of its definition. The layer's label state is purged first, so a layer that declares neither, or declares enabled: false, ends up with none — labels an inline LabelsApi.enableLabels call had set included. This is not the way to enable labels on such a layer: use enableLabels() with an inline config.

      Parameters

      • layerId: string

        Layer to initialise.

      Returns void

      GeoLeaf.Labels.initializeLayerLabels("poi_restaurants");
      
    • Prepares a layer's labels — from its declared configuration, else from an inline one — and shows them unless told otherwise.

      It returns a promise — await it. A labelConfig.styleFile rejects it: label style files are obsolete, the label object carries the look.

      Labels set up from an inline configuration are switched on and off by your own calls to this method and LabelsApi.disableLabels: LabelsApi.toggleLabels and the layer manager's labels button act only on a layer whose style or definition declares labels. Hiding the layer — the layer manager's visibility toggle, GeoJSON.hideLayer(), a theme — turns them off as disableLabels() does, and showing it again does not bring them back: call enableLabels() again.

      Parameters

      • layerId: string

        Layer to label.

      • OptionallabelConfig: LabelUserConfig

        On a layer that DECLARES no label configuration — neither its style's label object nor its definition's labels block — the whole configuration, which then requires enabled: true and labelId (the feature property displayed). On a layer that declares one, the declaration wins, and a declared enabled: false disables the labels whatever is passed here; only labelId (when the declaration names no field) and minZoom/maxZoom (together, when the current style sets no labelScale) are still read. See LabelUserConfig.

      • OptionalshowImmediately: boolean

        Show the labels once prepared; they render only while the layer is visible. Defaults to true. A declared visibleByDefault takes precedence over it, and a definition's labels block that omits it counts as visibleByDefault: false.

      Returns void | Promise<void>

      // A layer whose style or definition declares its labels: nothing else to pass
      await GeoLeaf.Labels.enableLabels("poi_restaurants");

      // A layer that declares none: the inline configuration, shown at once
      // (labels render only while the layer is visible)
      await GeoLeaf.Labels.enableLabels("poi_hotels", { enabled: true, labelId: "name" });

      // ...and turned off again. toggleLabels() would change nothing on this layer.
      GeoLeaf.Labels.disableLabels("poi_hotels");
    • Turns labels off for a layer and removes the rendered ones.

      The prepared configuration is kept. On a layer that declares its labels, LabelsApi.toggleLabels brings them back without re-supplying it; labels set up from an inline configuration come back only through another enableLabels() call.

      Parameters

      • layerId: string

        Layer whose labels are removed.

      Returns void

      GeoLeaf.Labels.disableLabels("poi_restaurants");
      
    • Flips a layer's labels and reports the state it settled on.

      Acts only on a layer whose declared configuration — its style's label object, else its definition's labels block — enables labels, and whose labels are prepared; for any other it returns false and changes nothing. Labels set up from an inline enableLabels() configuration are not among them: drive those with disableLabels() / enableLabels().

      Parameters

      • layerId: string

        Layer to toggle.

      Returns boolean

      true when labels are enabled after the call.

      const isNowEnabled = GeoLeaf.Labels.toggleLabels("poi_restaurants");
      
    • Whether a layer's labels are prepared — by the loader, or by an enableLabels() call.

      Distinct from LabelsApi.areLabelsEnabled: prepared labels can be off. The layer manager's labels button does not read it: it reads the layer's declared configuration.

      Parameters

      • layerId: string

        Layer to inspect.

      Returns boolean

      true when the module holds label state for the layer.

      if (GeoLeaf.Labels.hasLabelConfig("poi_restaurants")) {
      // config présente
      }
    • Whether a layer's labels are currently on.

      Parameters

      • layerId: string

        Layer to inspect.

      Returns boolean

      true when labels are enabled.

      if (GeoLeaf.Labels.areLabelsEnabled("poi_restaurants")) {
      console.log("Labels actifs");
      }
    • Rebuilds a layer's labels against its current data.

      Needed after the underlying features changed — enabling alone does not re-read them. It also re-reads the font the map's style serves: the capability calls it for every labelled layer when a basemap switch replaces the style.

      Parameters

      • layerId: string

        Layer to rebuild.

      Returns void

      GeoLeaf.Labels.refreshLabels("poi_restaurants");
      
    • Parameters

      • currentScale: number
      • minScale: number | null | undefined
      • maxScale: number | null | undefined

      Returns boolean