leaflet-polydraw
Version:
Advanced polygon drawing and editing plugin for Leaflet with drag-and-drop, smart merging, and comprehensive editing tools
240 lines • 8.08 kB
TypeScript
import * as L from 'leaflet';
import { DrawMode } from './enums';
import './styles/polydraw.css';
import type { PolydrawConfig } from './types/polydraw-interfaces';
declare class Polydraw extends L.Control {
private map;
private tracer;
private turfHelper;
private subContainer?;
private config;
private mapStateService;
private eventManager;
private polygonInformation;
private modeManager;
private polygonDrawManager;
private polygonMutationManager;
private arrayOfFeatureGroups;
private drawMode;
private drawModeListeners;
private _boundKeyDownHandler;
private _boundKeyUpHandler;
private isModifierKeyHeld;
private _boundTouchMove;
private _boundTouchEnd;
private _boundTouchStart;
constructor(options?: L.ControlOptions & {
config?: PolydrawConfig;
configPath?: string;
});
/**
* Method called when the control is added to the map.
* It initializes the control, creates the UI, and sets up event listeners.
* @param _map - The map instance.
* @returns The control's container element.
*/
onAdd(_map: L.Map): HTMLElement;
/**
* Method called when the control is removed from the map.
* It handles the cleanup of layers, events, and handlers.
* @param _map - The map instance, unused but required by the L.Control interface.
*/
onRemove(_map: L.Map): void;
/**
* Adds the control to the given map.
* @param map - The map instance.
* @returns The current instance of the control.
*/
addTo(map: L.Map): this;
/**
* Returns the array of feature groups currently managed by the control.
* @returns An array of L.FeatureGroup objects.
*/
getFeatureGroups(): L.FeatureGroup[];
/**
* Adds a predefined polygon to the map.
* @param geographicBorders - An array of LatLng arrays representing the polygon's coordinates.
* @param options - Optional parameters, including visual optimization level.
*/
addPredefinedPolygon(geographicBorders: L.LatLng[][][], options?: {
visualOptimizationLevel?: number;
}): Promise<void>;
/**
* Sets the current drawing mode.
* @param mode - The drawing mode to set.
*/
setDrawMode(mode: DrawMode): void;
/**
* Returns the current drawing mode.
* @returns The current DrawMode.
*/
getDrawMode(): DrawMode;
/**
* Registers an event listener for a given event type.
* @param event - The event type to listen for.
* @param callback - The callback function to execute when the event is triggered.
*/
on(event: any, callback: any): void;
/**
* Unregisters an event listener for a given event type.
* @param event - The event type to stop listening for.
* @param callback - The callback function to remove.
*/
off(event: any, callback: any): void;
/**
* Removes all feature groups from the map and clears the internal storage.
*/
removeAllFeatureGroups(): void;
/**
* Initializes the user interface, creates DOM elements, sets up buttons, and injects styles.
* @param container - The main control container element.
*/
private initializeUI;
/**
* Attaches listeners to polygonMutationManager and eventManager.
*/
private setupEventListeners;
/**
* Initializes and adds the tracer polyline to the map.
*/
private createTracer;
/**
* Sets up PolygonDrawManager and PolygonMutationManager with the map.
*/
private initializeManagers;
/**
* Loads an external configuration file and merges it with the default and inline configs.
* @param configPath - The path to the external configuration file.
* @param inlineConfig - An optional inline configuration object.
*/
private loadExternalConfig;
/**
* Initializes the core components of the Polydraw control.
*/
/**
* Updates the state of the drawing mode.
* @param mode - The new drawing mode.
*/
private _updateDrawModeState;
/**
* Updates the UI after a change in the drawing mode.
* @param mode - The new drawing mode.
*/
private _updateUIAfterDrawModeChange;
/**
* Updates map interactions based on the current drawing mode.
*/
private _handleActivateToggle;
private _handleDrawClick;
private _handleSubtractClick;
private _handleEraseClick;
private _handlePointToPointClick;
private _updateMapInteractions;
private initializeComponents;
/**
* Emits an event to notify listeners that the drawing mode has changed.
*/
private emitDrawModeChanged;
/**
* Update the draggable state of all existing markers when draw mode changes
*/
private updateMarkerDraggableState;
/**
* Stops the current drawing operation and resets the tracer.
*/
private stopDraw;
/**
* Enables or disables Leaflet's default map interactions.
* @param enableDragging - Whether to enable map dragging.
* @param enableDoubleClickZoom - Whether to enable double-click zoom.
* @param enableScrollWheelZoom - Whether to enable scroll wheel zoom.
*/
private setLeafletMapEvents;
/**
* Resets the tracer polyline by clearing its LatLngs.
*/
private resetTracker;
/**
* Attaches or detaches the mouse move and mouse up event listeners for drawing.
* @param onoff - A boolean indicating whether to attach or detach the events.
*/
private drawStartedEvents;
/**
* Attaches or detaches the main drawing event listeners.
* @param onoff - A boolean indicating whether to attach or detach the events.
*/
private events;
/**
* Handles the mouse down event to start a drawing operation.
* @param event - The mouse or touch event.
*/
private mouseDown;
/**
* Handles the mouse move event to draw the tracer polyline.
* @param event - The mouse or touch event.
*/
private mouseMove;
/**
* Handles the mouse up event to complete a drawing operation.
* @param event - The mouse or touch event.
*/
private mouseUpLeave;
/**
* Handles the completion of a freehand drawing operation.
* @param geoPos - The GeoJSON feature representing the drawn polygon.
*/
private handleFreehandDrawCompletion;
/**
* Starts a drawing operation by attaching the necessary event listeners.
*/
private startDraw;
/**
* Sets up the keyboard event handlers for the document.
*/
private setupKeyboardHandlers;
/**
* Removes the keyboard event handlers from the document.
*/
private removeKeyboardHandlers;
/**
* Handles the key down event for keyboard shortcuts.
* @param e - The keyboard event.
*/
private handleKeyDown;
/**
* Handles the key up event for keyboard shortcuts.
* @param e - The keyboard event.
*/
private handleKeyUp;
/**
* Update all markers to show/hide edge deletion visual feedback
*/
private updateAllMarkersForEdgeDeletion;
/**
* Update individual marker for edge deletion visual feedback
*/
private updateMarkerForEdgeDeletion;
/**
* Handle marker hover when modifier key is held - event handler version
*/
private onMarkerHoverForEdgeDeletionEvent;
/**
* Handle marker leave when modifier key is held - event handler version
*/
private onMarkerLeaveForEdgeDeletionEvent;
/**
* Handles the double-click event for point-to-point drawing.
* @param e - The mouse event.
*/
private handleDoubleClick;
/**
* Detect if modifier key is pressed (Ctrl on Windows/Linux, Cmd on Mac)
*/
private isModifierKeyPressed;
/**
* Updates the visual indicator on the activate button to show if there are active polygons.
*/
private updateActivateButtonIndicator;
}
export default Polydraw;
//# sourceMappingURL=polydraw.d.ts.map