import OlMap from 'ol/Map.js'; import OlLayerGroup from 'ol/layer/Group.js'; import OlLayerBase from 'ol/layer/Base.js'; import OlSourceSource from 'ol/source/Source.js'; import { olcUidKey } from '../uid.js'; import BaseObject, { ObjectEvent } from 'ol/Object.js'; import type { EventsKey } from 'ol/events.js'; import BaseEvent from 'ol/events/Event.js'; import type { CombinedOnSignature, EventTypes, OnSignature } from 'ol/Observable.js'; import type { Types } from 'ol/ObjectEventType.js'; /** * Options to create a layer group. */ export interface LayerGroupOptions { /** * Position of the layer group in the map layer array. This position is * fixed. */ position?: number; /** Unique ID for the layer group. */ groupUid?: string; } export declare const LayerPropertyChangedEventType = "olcLayerPropertyChanged"; export declare const LayerAffectedEventType = "olcLayerAffected"; /** * An event to provide changed-like-event, without touching the original layer. * With source layer uid and free reason why/by/for it's fired. * Example: fire/listen to silently set layer opacity (as reason) without touching the real * layer and having to listen to every layer individually. */ export declare class LayerAffectedEvent extends BaseEvent { static readonly type = "olcLayerAffected"; readonly [olcUidKey]: string; readonly reason: string; constructor(layerUid: string, reason: string); } /** * An event to listen on layer property changes in this LayerGroup without the need of having * the layer itself. */ export declare class LayerPropertyChangedEvent extends BaseEvent { static readonly type = "olcLayerPropertyChanged"; readonly [olcUidKey]: string; readonly propertyKey: string; constructor(layerUid: string, propertyKey: string); } export type LayerGroupOnSignature = OnSignature & // Default Ol OnSignature & OnSignature & OnSignature & CombinedOnSignature; /** * Parent (abstract) class for a layer group. Helps to manipulate one layer group. * The child class must start by setting the layerGroup. * It extends ol/Object to be able to listen to events and dispatch them. */ export declare class LayerGroup extends BaseObject { protected readonly map: OlMap; protected layerGroup: OlLayerGroup; on: LayerGroupOnSignature; once: LayerGroupOnSignature; un: LayerGroupOnSignature; constructor(map: OlMap); /** * @returns the layer group of this instance. */ getLayerGroup(): OlLayerGroup; /** * Remove all layers from the map and clear the layer group. */ clearAll(): void; /** * Add a single layer at the end of the layer group. * @param layer Ol layer. * @param layerUid id of the layer. */ addLayer(layer: OlLayerBase, layerUid: string): void; /** * Retrieve a layer currently in the layer group. * @returns The matching layer or null. */ findLayer(layerUid: string): OlLayerBase | null; /** * Retrieve all layers currently in the layer group that start with a specific UID. * @returns An array of matching layers. */ findLayersStartsWith(layerUidPrefix: string): OlLayerBase[]; /** * @returns The attribution of all visible layers. */ getAttributions(): string[]; /** * Refresh the source of every layer with a source in the layer group. */ refreshSource(): void; /** * @returns Every source from layers having sources in the layer group. */ getAllSources(): OlSourceSource[]; /** * Set a property of a layer and fires a "LayerPropertyChanged" event if the value has changed. */ setLayerProperty(layerUid: string, propertyKey: string, value: unknown): void; /** * Fires an "affected" layer event. */ dispatchLayerAffected(layerUid: string, reason: string): void; /** * Fires a "LayerPropertyChanged" and call a "changed" event on the matching OL layer. */ dispatchLayerPropertyChanged(layerUid: string, propertyKey: string): void; /** * Provides checks on a layer to know if the layer can be added to the map * and set an id for it. * @returns true if the layer is valid and can be added. False otherwise. * @protected */ protected setupAddLayer(layer: OlLayerBase, layerUid: string): boolean; /** * Add a layer group to a specified position in the array of a map's * layers. * @protected */ protected addLayerGroup(layerGroupUid: string, position: number): void; /** * Retrieve a layer group based on its unique id. */ protected findLayerGroup(layerUid: string): OlLayerGroup | null; /** * @param layer The layer to extract the attributions from. * @returns An array of attributions. * @private */ private getAttributionFromLayer; }