GeoLeaf Core API - v3.0.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

    Methods

    • Brings the labels capability up and attaches its zoom listener.

      Parameters

      • Optionaloptions: Record<string, unknown>

        Capability options, merged over modules.labels from the profile.

      Returns void

      GeoLeaf.Labels.init();
      // ou avec options
      GeoLeaf.Labels.init({ defaultEnabled: false });
    • Applies a layer's declared label configuration, if it has one.

      Called by the loader as each layer comes up. A layer without a label block is left alone — this is not the way to enable labels on a layer that declares none, use LabelsApi.enableLabels with an inline config for that.

      Parameters

      • layerId: string

        Layer to initialise.

      Returns void

      GeoLeaf.Labels.initializeLayerLabels("poi_restaurants");
      
    • Turns labels on for a layer, optionally with an inline configuration.

      ⚠️ The return type is Promise<void> | void, not always a promise: the call only becomes asynchronous when it has a styleFile to fetch. await it anyway — that is the only form that is correct in both cases.

      Parameters

      • layerId: string

        Layer to label.

      • OptionallabelConfig: LabelUserConfig

        Inline configuration; omitted, the layer's declared label block is used. property names the feature field to display, and template supersedes it with a function over the whole properties object.

      • OptionalshowImmediately: boolean

        Render at once instead of waiting for the next zoom evaluation. Defaults to false.

      Returns void | Promise<void>

      // Activation simple
      await GeoLeaf.Labels.enableLabels("poi_restaurants");

      // Avec config inline
      await GeoLeaf.Labels.enableLabels("poi_restaurants", {
      property: "name",
      minZoom: 14,
      });

      // Affichage immédiat
      await GeoLeaf.Labels.enableLabels("poi_hotels", { property: "name" }, true);
    • Turns labels off for a layer and removes the rendered ones.

      The configuration is kept, so LabelsApi.toggleLabels can bring them back without re-supplying it.

      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.

      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 carries a label configuration at all.

      Distinct from LabelsApi.areLabelsEnabled: a layer can be configured and currently off. This is the test that decides whether a label button is worth rendering.

      Parameters

      • layerId: string

        Layer to inspect.

      Returns boolean

      true when a configuration exists.

      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.

      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