UNPKG

leaflet-polydraw

Version:

Advanced Leaflet plugin for freehand polygon drawing, with smart merging and powerful editing tools. Compatible with both Leaflet v1.x and v2.x.

92 lines 4.17 kB
import * as L from 'leaflet'; import type { EventManager } from './event-manager'; import type { LayerSnapshot, LayerInteraction, LayerPanelVisibility } from '../types/polydraw-interfaces'; export interface LayerState { id: string; label?: string; color: string; visible: boolean; interaction: LayerInteraction; panel: LayerPanelVisibility; metadata: Record<string, unknown>; featureGroups: L.FeatureGroup[]; } export interface LayerCreateOptions { label?: string; color?: string; visible?: boolean; interaction?: LayerInteraction; panel?: LayerPanelVisibility; metadata?: Record<string, unknown>; } export type SetActiveLayerResult = 'activated' | 'already-active' | 'not-found' | 'not-visible'; /** * Manages polygon layers and feature-group assignments. * Keeps a default layer and supports active-layer scoping for interactions. */ export declare class LayerManager { private readonly eventManager; private layers; private featureGroupToLayer; private activeLayerId; private defaultColor; constructor(eventManager: EventManager, defaultColor: string); getLayerCount(): number; getAllLayers(): LayerState[]; getPanelLayers(): LayerState[]; getPanelLayerCount(): number; getLayer(layerId: string): LayerState | undefined; getActiveLayerId(): string; getActiveLayer(): LayerState | undefined; getOrCreateLayer(layerId: string, colorOrOptions?: string | LayerCreateOptions): LayerState; setActiveLayer(layerId: string): boolean; setActiveLayerWithResult(layerId: string): SetActiveLayerResult; setLayerVisibility(layerId: string, visible: boolean): boolean; setLayerColor(layerId: string, color: string): boolean; setLayerLabel(layerId: string, label?: string): boolean; setLayerInteraction(layerId: string, interaction: LayerInteraction): boolean; setLayerPanelVisibility(layerId: string, panel: LayerPanelVisibility): boolean; setLayerMetadata(layerId: string, metadata?: Record<string, unknown>): boolean; isLayerEditable(layerId: string): boolean; isFeatureGroupEditable(featureGroup: L.FeatureGroup): boolean; /** * Reorder layers by moving layerId to the drop index of targetLayerId. * This mirrors list drag/drop behavior used in the layer panel. */ moveLayer(layerId: string, targetLayerId: string): boolean; assignFeatureGroupToLayer(featureGroup: L.FeatureGroup, layerId: string): boolean; removeFeatureGroupFromLayer(featureGroup: L.FeatureGroup): void; getLayerForFeatureGroup(featureGroup: L.FeatureGroup): string | undefined; getFeatureGroupsForLayer(layerId: string): L.FeatureGroup[]; isInActiveLayer(featureGroup: L.FeatureGroup): boolean; deleteLayer(layerId: string): L.FeatureGroup[]; /** * Moves a layer to a specific 0-based position in the full layer order. * The default layer always occupies index 0; the minimum valid target for * non-default layers is 1. The index is clamped to the valid range. */ moveLayerToIndex(layerId: string, index: number): boolean; /** * Sets the full layer order by providing an ordered list of layer IDs. * The default layer always stays first. Any layers not included in the * list are appended after the specified layers in their current relative order. * Returns false if any specified ID does not exist or equals 'default'. */ setLayerOrder(layerIds: string[]): boolean; clear(defaultColor?: string): void; captureLayerSnapshot(featureGroups: L.FeatureGroup[]): LayerSnapshot; restoreFromLayerSnapshot(snapshot: LayerSnapshot, featureGroups: L.FeatureGroup[]): void; private ensureDefaultLayer; private getFirstVisibleLayerId; private normalizeLayerId; private cloneLayerState; private normalizeInteraction; private normalizePanel; private cloneMetadata; /** * Normalize hex colors to "#rrggbb". * Accepts "f00", "#f00", "ff0000", "#ff0000". Returns fallback when invalid. */ static normalizeColor(input: string, fallback?: string): string; } //# sourceMappingURL=layer-manager.d.ts.map