Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 63 additions & 51 deletions leaflet-geoman.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,17 @@ declare module 'leaflet' {
on(type: 'pm:globalcancel', fn: PM.GlobalCancelEventHandler): this;
once(type: 'pm:globalcancel', fn: PM.GlobalCancelEventHandler): this;
off(type: 'pm:globalcancel', fn?: PM.GlobalCancelEventHandler): this;

/******************************************
*
* TODO: ERROR EVENTS ON MAP ONLY
*
********************************************/

/** Fired when an error is thrown. */
on(type: 'pm:error', fn: PM.ErrorEventHandler): this;
once(type: 'pm:error', fn: PM.ErrorEventHandler): this;
off(type: 'pm:error', fn?: PM.ErrorEventHandler): this;
}

namespace PM {
Expand Down Expand Up @@ -1073,7 +1084,7 @@ declare module 'leaflet' {
/** Creates a copy of a draw Control. Returns the drawInstance and the control. */
copyDrawControl(
copyInstance: string,
options?: CustomControlOptions
options: CustomControlOptions
): {
drawInstance: Draw;
control: L.Control;
Expand Down Expand Up @@ -1113,33 +1124,33 @@ declare module 'leaflet' {

interface Button {
/** Actions */
actions: (ACTION_NAMES | Action)[];
actions?: (ACTION_NAMES | Action)[];

/** Function fired after clicking the control. */
afterClick: () => void;
afterClick?: () => void;

/** CSS class with the Icon. */
className: string;
className?: string;

/** If true, other buttons will be disabled on click (default: true) */
disableOtherButtons: boolean;
disableOtherButtons?: boolean;

/** Control can be toggled. */
doToggle: boolean;
doToggle?: boolean;

/** Extending Class f. ex. Line, Polygon, ... L.PM.Draw.EXTENDINGCLASS */
jsClass: string;
jsClass?: string;

/** Function fired when clicking the control. */
onClick: () => void;
onClick?: () => void;

position: L.ControlPosition;
position?: L.ControlPosition;

/** Text showing when you hover the control. */
title: string;
title?: string;

/** Toggle state true -> enabled, false -> disabled (default: false) */
toggleStatus: boolean;
toggleStatus?: boolean;

/** Block of the control. 'options' is ⭐ only. */
tool?: 'draw' | 'edit' | 'custom' | 'options';
Expand Down Expand Up @@ -1255,8 +1266,11 @@ declare module 'leaflet' {

/** Customize the style of the drawn layer. Only for L.Path layers. Shapes can be excluded with a ignoreShapes array or merged with the current style with merge: true in optionsModifier. */
setPathOptions(
options: L.PathOptions,
optionsModifier?: { ignoreShapes?: SUPPORTED_SHAPES[]; merge?: boolean }
options: L.PathOptions | L.CircleMarkerOptions,
optionsModifier?: {
ignoreShapes?: SUPPORTED_SHAPES[],
merge?: boolean
}
): void;

/** Returns all Geoman layers on the map as array. Pass true to get a L.FeatureGroup. */
Expand Down Expand Up @@ -1609,15 +1623,15 @@ declare module 'leaflet' {
/** Returns the active shape. */
getActiveShape(): SUPPORTED_SHAPES;

[key: SUPPORTED_SHAPES]: DrawShape;
[key: string]: DrawShape | ((...args: any[]) => any);
}

interface DrawShape {
/** Applies the styles (templineStyle, hintlineStyle, pathOptions, markerStyle) to the drawing layer. map.pm.Draw.Line.setStyle(options). */
setStyle(options: L.PathOptions): void;
setStyle(options: L.PathOptions | L.CircleMarkerOptions): void;

/** Set path options */
setPathOptions(options: L.PathOptions): void;
setPathOptions(options: L.PathOptions | L.CircleMarkerOptions): void;

/** Set options */
setOptions(options: DrawModeOptions): void;
Expand Down Expand Up @@ -1729,7 +1743,7 @@ declare module 'leaflet' {
| 'contextmenu';

/** A function for validation if a vertex (of a Line / Polygon) is allowed to add. It passes a object with `[layer, marker, event}`. For example to check if the layer has a certain property or if the `Ctrl` key is pressed. (default:undefined). */
addVertexValidation?: undefined | VertexValidationHandler;
addVertexValidation?: VertexValidationHandler;

/** Leaflet layer event to remove a vertex from a Line or Polygon, like dblclick. (default:contextmenu). */
removeVertexOn?:
Expand All @@ -1741,10 +1755,10 @@ declare module 'leaflet' {
| 'contextmenu';

/** A function for validation if a vertex (of a Line / Polygon) is allowed to remove. It passes a object with `[layer, marker, event}`. For example to check if the layer has a certain property or if the `Ctrl` key is pressed. */
removeVertexValidation?: undefined | VertexValidationHandler;
removeVertexValidation?: VertexValidationHandler;

/** A function for validation if a vertex / helper-marker is allowed to move / drag. It passes a object with `[layer, marker, event}`. For example to check if the layer has a certain property or if the `Ctrl` key is pressed. */
moveVertexValidation?: undefined | VertexValidationHandler;
moveVertexValidation?: VertexValidationHandler;

/** Shows only n markers closest to the cursor. Use -1 for no limit (default:-1). */
limitMarkersToCount?: number;
Expand All @@ -1768,46 +1782,46 @@ declare module 'leaflet' {
snapGuidesAngles?: number[];

/** Styles the border helpline. ⭐ */
scaleBorderStyle: L.PathOptions;
scaleBorderStyle?: L.PathOptions;

/** Scale origin is the center, else it is the opposite corner. If false Alt-Key can be used. (default:true). ⭐ */
centerScaling: boolean;
centerScaling?: boolean;

/** Width and height are scaled with the same ratio. If false Shift-Key can be used. (default:true). ⭐ */
uniformScaling: boolean;
uniformScaling?: boolean;

/** Layer can be prevented from auto tracing. (default:true). ⭐ */
allowAutoTracing: boolean;
allowAutoTracing?: boolean;

/** Add Vertices while clicking on the line of Polyline or Polygon. (default:true). ⭐ */
addVertexOnClick: boolean;
addVertexOnClick?: boolean;

/** Layer can be prevented from pinning. (default:true). ⭐ */
allowPinning: boolean;
allowPinning?: boolean;

/** Styles the Snap Guides. ⭐ */
snapGuidesStyle: L.PathOptions;
snapGuidesStyle?: L.PathOptions;

/** Enables the Snap guides. (default:false). ⭐ */
showSnapGuides: boolean;
showSnapGuides?: boolean;

/** Layer can be prevented from used in Union Mode. (default:true). ⭐ */
allowUnion: boolean;
allowUnion?: boolean;

/** Layer can be prevented from used in Difference Mode. (default:true). ⭐ */
allowDifference: boolean;
allowDifference?: boolean;

/** Selecting via Lasso can be disabled for the layer. (default:true). ⭐ */
lassoSelectable: boolean;
lassoSelectable?: boolean;

/** While editing the layer needs to be contained in one of the layers in the Array. ⭐ */
requireContainment: (L.Polygon | L.Circle | L.ImageOverlay)[];
requireContainment?: (L.Polygon | L.Circle | L.ImageOverlay)[];

/** While editing the layer can't intersect with the layers in the Array. ⭐ */
preventIntersection: L.Layer[];
preventIntersection?: L.Layer[];

/** Layer can be prevented from scaling. (default:true). ⭐ */
allowScale: boolean;
allowScale?: boolean;
}

interface TextOptions {
Expand Down Expand Up @@ -1838,13 +1852,13 @@ declare module 'leaflet' {
allowSelfIntersection?: boolean;

/** Leaflet path options for the lines between drawn vertices/markers. (default:{color:'red'}). */
templineStyle?: L.CircleMarkerOptions;
templineStyle?: L.PathOptions | L.CircleMarkerOptions;

/** Leaflet path options for the helper line between last drawn vertex and the cursor. (default:{color:'red',dashArray:[5,5]}). */
hintlineStyle?: L.PathOptions;
hintlineStyle?: L.PathOptions | L.CircleMarkerOptions;

/** Leaflet path options for the drawn layer (Only for L.Path layers). (default:null). */
pathOptions?: L.PathOptions;
pathOptions?: L.PathOptions | L.CircleMarkerOptions;

/** Leaflet marker options (only for drawing markers). (default:{draggable:true}). */
markerStyle?: L.MarkerOptions;
Expand Down Expand Up @@ -1904,19 +1918,19 @@ declare module 'leaflet' {
textOptions?: TextOptions;

/** Leaflet path options for the freehand polygon while drawing. To the resulting layer will be the pathOptions applied (default:null) ⭐ */
freehandOptions: L.PathOptions;
freehandOptions?: L.PathOptions;

/** Leaflet path options for the lasso polygon while drawing. The option `fill` will be always true. (default:null) ⭐ */
lassoDrawOptions: L.PathOptions;
lassoDrawOptions?: L.PathOptions;

/** Style / Geojson ooptions for custom shape. ⭐ */
customShapeGeoJSONOptions?: L.GeoJSONOptions;

/** While drawing one of the layers in the Array need to contain the new layer. ⭐ */
requireContainment: (L.Polygon | L.Circle | L.ImageOverlay)[];
requireContainment?: (L.Polygon | L.Circle | L.ImageOverlay)[];

/** While drawing the new layer can't intersect with one of the layers in the Array. ⭐ */
preventIntersection: L.Layer[];
preventIntersection?: L.Layer[];

/** Closes the Polygon while drawing. ⭐ */
closedPolygonEdge?: boolean;
Expand Down Expand Up @@ -1945,6 +1959,8 @@ declare module 'leaflet' {
snapVertex?: boolean;
}

type CancelActionModes = 'editMode' | 'dragMode' | 'removalMode' | 'rotateMode' | 'scaleMode' | 'lineSimplificationMode';

/**
* PM toolbar options.
*/
Expand Down Expand Up @@ -2055,20 +2071,11 @@ declare module 'leaflet' {
lineSimplificationMode?: boolean;

/** Hide the cancel button for edit modes (default: []) ⭐ */
hideCancelActionOf:
| null
| (
| 'editMode'
| 'dragMode'
| 'removalMode'
| 'rotateMode'
| 'scaleMode'
| 'lineSimplificationMode'
)[];
hideCancelActionOf?: CancelActionModes[];

/** Adds custom button (default:true) */
// The type of custom buttons are always boolean but TS needs the other types defined too.
[key: string]: L.ControlPosition | BlockPositions | boolean | undefined;
[key: string]: L.ControlPosition | BlockPositions | boolean | undefined | CancelActionModes[];
}

/** the position of each block. */
Expand Down Expand Up @@ -2704,5 +2711,10 @@ declare module 'leaflet' {
* CANCEL MODE MAP EVENT HANDLERS
*/
export type GlobalCancelEventHandler = (e: { map: L.Map }) => void;

/**
* ERROR MAP EVENT HANDLERS
*/
export type ErrorEventHandler = (e: { message: string, source: string, payload: any }) => void;
}
}