@sindicum/libre-draw 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LibreDraw.d.ts +11 -1
- package/dist/core/ModeContext.d.ts +36 -0
- package/dist/core/ModeManager.d.ts +2 -4
- package/dist/index.d.ts +3 -2
- package/dist/input/MouseInput.d.ts +4 -2
- package/dist/input/TouchInput.d.ts +6 -0
- package/dist/libre-draw.cjs +1 -1
- package/dist/libre-draw.cjs.map +1 -1
- package/dist/libre-draw.js +950 -758
- package/dist/libre-draw.js.map +1 -1
- package/dist/modes/DrawMode.d.ts +7 -29
- package/dist/modes/IdleMode.d.ts +4 -0
- package/dist/modes/Mode.d.ts +9 -0
- package/dist/modes/PolygonDragger.d.ts +23 -0
- package/dist/modes/SelectMode.d.ts +15 -126
- package/dist/modes/SelectionManager.d.ts +19 -0
- package/dist/modes/VertexEditor.d.ts +28 -0
- package/dist/rendering/RenderManager.d.ts +11 -1
- package/dist/rendering/SourceManager.d.ts +4 -0
- package/dist/types/events.d.ts +3 -2
- package/dist/types/features.d.ts +3 -3
- package/dist/types/index.d.ts +3 -0
- package/dist/types/mode.d.ts +4 -0
- package/dist/types/options.d.ts +3 -0
- package/dist/types/style.d.ts +84 -0
- package/dist/utils/featureSnapshot.d.ts +21 -0
- package/dist/utils/geometry.d.ts +25 -0
- package/package.json +3 -5
package/dist/modes/DrawMode.d.ts
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
1
1
|
import type { Mode } from './Mode';
|
|
2
2
|
import type { NormalizedInputEvent } from '../types/input';
|
|
3
|
-
import type {
|
|
4
|
-
import type { LibreDrawEventMap } from '../types/events';
|
|
5
|
-
/**
|
|
6
|
-
* Callbacks that DrawMode needs from the host application.
|
|
7
|
-
*/
|
|
8
|
-
export interface DrawModeCallbacks {
|
|
9
|
-
/** Add a feature to the store and return it with its assigned ID. */
|
|
10
|
-
addFeatureToStore(feature: LibreDrawFeature): LibreDrawFeature;
|
|
11
|
-
/** Push an action to the history manager. */
|
|
12
|
-
pushToHistory(action: Action): void;
|
|
13
|
-
/** Emit an event through the event bus. */
|
|
14
|
-
emitEvent<K extends keyof LibreDrawEventMap>(type: K, payload: LibreDrawEventMap[K]): void;
|
|
15
|
-
/** Render a preview of the polygon being drawn. */
|
|
16
|
-
renderPreview(coordinates: Position[]): void;
|
|
17
|
-
/** Clear the drawing preview. */
|
|
18
|
-
clearPreview(): void;
|
|
19
|
-
/** Re-render all features. */
|
|
20
|
-
renderFeatures(): void;
|
|
21
|
-
/** Convert a geographic coordinate to a screen point. */
|
|
22
|
-
getScreenPoint(lngLat: {
|
|
23
|
-
lng: number;
|
|
24
|
-
lat: number;
|
|
25
|
-
}): {
|
|
26
|
-
x: number;
|
|
27
|
-
y: number;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
3
|
+
import type { ModeContext } from '../core/ModeContext';
|
|
30
4
|
/**
|
|
31
5
|
* Drawing mode for creating new polygons.
|
|
32
6
|
*
|
|
@@ -40,8 +14,12 @@ export interface DrawModeCallbacks {
|
|
|
40
14
|
export declare class DrawMode implements Mode {
|
|
41
15
|
private vertices;
|
|
42
16
|
private isActive;
|
|
43
|
-
private
|
|
44
|
-
constructor(
|
|
17
|
+
private context;
|
|
18
|
+
constructor(context: ModeContext);
|
|
19
|
+
mapInteractions(): {
|
|
20
|
+
dragPan: boolean;
|
|
21
|
+
doubleClickZoom: boolean;
|
|
22
|
+
};
|
|
45
23
|
activate(): void;
|
|
46
24
|
deactivate(): void;
|
|
47
25
|
onPointerDown(event: NormalizedInputEvent): void;
|
package/dist/modes/IdleMode.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ import type { NormalizedInputEvent } from '../types/input';
|
|
|
5
5
|
* All input handlers are no-ops.
|
|
6
6
|
*/
|
|
7
7
|
export declare class IdleMode implements Mode {
|
|
8
|
+
mapInteractions(): {
|
|
9
|
+
dragPan: boolean;
|
|
10
|
+
doubleClickZoom: boolean;
|
|
11
|
+
};
|
|
8
12
|
activate(): void;
|
|
9
13
|
deactivate(): void;
|
|
10
14
|
onPointerDown(_event: NormalizedInputEvent): void;
|
package/dist/modes/Mode.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { NormalizedInputEvent } from '../types/input';
|
|
2
|
+
/**
|
|
3
|
+
* Map interaction settings that a mode requires while active.
|
|
4
|
+
*/
|
|
5
|
+
export interface MapInteractionConfig {
|
|
6
|
+
dragPan: boolean;
|
|
7
|
+
doubleClickZoom: boolean;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* Interface that all drawing modes must implement.
|
|
4
11
|
*
|
|
@@ -7,6 +14,8 @@ import type { NormalizedInputEvent } from '../types/input';
|
|
|
7
14
|
* by the ModeManager during transitions.
|
|
8
15
|
*/
|
|
9
16
|
export interface Mode {
|
|
17
|
+
/** Map interaction settings required by this mode. */
|
|
18
|
+
mapInteractions(): MapInteractionConfig;
|
|
10
19
|
/** Called when the mode becomes active. */
|
|
11
20
|
activate(): void;
|
|
12
21
|
/** Called when the mode is deactivated. */
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ModeContext } from '../core/ModeContext';
|
|
2
|
+
import type { LibreDrawFeature } from '../types/features';
|
|
3
|
+
import type { NormalizedInputEvent } from '../types/input';
|
|
4
|
+
/**
|
|
5
|
+
* Handles whole-polygon drag interactions.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PolygonDragger {
|
|
8
|
+
private context;
|
|
9
|
+
private onFeatureMoved;
|
|
10
|
+
private dragging;
|
|
11
|
+
private dragStartFeature;
|
|
12
|
+
private dragStartLngLat;
|
|
13
|
+
constructor(context: ModeContext, onFeatureMoved: (feature: LibreDrawFeature) => void);
|
|
14
|
+
isDragging(): boolean;
|
|
15
|
+
getDragStartFeature(): LibreDrawFeature | null;
|
|
16
|
+
startDrag(feature: LibreDrawFeature, startLngLat: {
|
|
17
|
+
lng: number;
|
|
18
|
+
lat: number;
|
|
19
|
+
}): void;
|
|
20
|
+
handleDragMove(selectedId: string, event: NormalizedInputEvent): boolean;
|
|
21
|
+
endDrag(): void;
|
|
22
|
+
resetInteractionState(): void;
|
|
23
|
+
}
|
|
@@ -1,60 +1,20 @@
|
|
|
1
1
|
import type { Mode } from './Mode';
|
|
2
2
|
import type { NormalizedInputEvent } from '../types/input';
|
|
3
|
-
import type {
|
|
4
|
-
import type { LibreDrawEventMap } from '../types/events';
|
|
5
|
-
/**
|
|
6
|
-
* Callbacks that SelectMode needs from the host application.
|
|
7
|
-
*/
|
|
8
|
-
export interface SelectModeCallbacks {
|
|
9
|
-
/** Remove a feature from the store. */
|
|
10
|
-
removeFeatureFromStore(id: string): LibreDrawFeature | undefined;
|
|
11
|
-
/** Push an action to the history manager. */
|
|
12
|
-
pushToHistory(action: Action): void;
|
|
13
|
-
/** Emit an event through the event bus. */
|
|
14
|
-
emitEvent<K extends keyof LibreDrawEventMap>(type: K, payload: LibreDrawEventMap[K]): void;
|
|
15
|
-
/** Re-render all features. */
|
|
16
|
-
renderFeatures(): void;
|
|
17
|
-
/** Get a feature by ID. */
|
|
18
|
-
getFeatureById(id: string): LibreDrawFeature | undefined;
|
|
19
|
-
/** Get all features in the store. */
|
|
20
|
-
getAllFeatures(): LibreDrawFeature[];
|
|
21
|
-
/** Convert a geographic coordinate to a screen point. */
|
|
22
|
-
getScreenPoint(lngLat: {
|
|
23
|
-
lng: number;
|
|
24
|
-
lat: number;
|
|
25
|
-
}): {
|
|
26
|
-
x: number;
|
|
27
|
-
y: number;
|
|
28
|
-
};
|
|
29
|
-
/** Update a feature in the store. */
|
|
30
|
-
updateFeatureInStore(id: string, feature: LibreDrawFeature): void;
|
|
31
|
-
/** Render vertex and midpoint markers for editing. */
|
|
32
|
-
renderVertices(featureId: string, vertices: Position[], midpoints: Position[], highlightIndex?: number): void;
|
|
33
|
-
/** Clear vertex/midpoint markers. */
|
|
34
|
-
clearVertices(): void;
|
|
35
|
-
/** Enable or disable map drag panning. */
|
|
36
|
-
setDragPan(enabled: boolean): void;
|
|
37
|
-
}
|
|
3
|
+
import type { ModeContext } from '../core/ModeContext';
|
|
38
4
|
/**
|
|
39
5
|
* Selection and editing mode for existing polygons.
|
|
40
|
-
*
|
|
41
|
-
* Users click on a polygon to select it. Selected polygons display
|
|
42
|
-
* vertex handles that can be dragged to reshape the polygon. Midpoint
|
|
43
|
-
* handles appear between vertices and can be dragged to add new vertices.
|
|
44
|
-
* Double-clicking a vertex removes it (minimum 3 vertices maintained).
|
|
45
6
|
*/
|
|
46
7
|
export declare class SelectMode implements Mode {
|
|
47
|
-
private
|
|
8
|
+
private context;
|
|
9
|
+
private selection;
|
|
10
|
+
private vertexEditor;
|
|
11
|
+
private polygonDragger;
|
|
48
12
|
private isActive;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
private draggingPolygon;
|
|
55
|
-
private dragPolygonStartLngLat;
|
|
56
|
-
private highlightedVertexIndex;
|
|
57
|
-
constructor(callbacks: SelectModeCallbacks, onSelectionChange?: (selectedIds: string[]) => void);
|
|
13
|
+
constructor(context: ModeContext, onSelectionChange?: (selectedIds: string[]) => void);
|
|
14
|
+
mapInteractions(): {
|
|
15
|
+
dragPan: boolean;
|
|
16
|
+
doubleClickZoom: boolean;
|
|
17
|
+
};
|
|
58
18
|
activate(): void;
|
|
59
19
|
deactivate(): void;
|
|
60
20
|
/**
|
|
@@ -63,19 +23,11 @@ export declare class SelectMode implements Mode {
|
|
|
63
23
|
getSelectedIds(): string[];
|
|
64
24
|
/**
|
|
65
25
|
* Programmatically select a feature by ID.
|
|
66
|
-
*
|
|
67
|
-
* Replaces any existing selection. Renders vertex handles and
|
|
68
|
-
* emits a selectionchange event. Cancels any in-progress drag.
|
|
69
|
-
*
|
|
70
|
-
* @param id - The feature ID to select.
|
|
71
|
-
* @returns `true` if the feature was found and selected, `false` otherwise.
|
|
72
26
|
*/
|
|
73
27
|
selectFeature(id: string): boolean;
|
|
74
28
|
/**
|
|
75
29
|
* Programmatically clear the current selection.
|
|
76
|
-
*
|
|
77
|
-
* Removes vertex handles and emits a selectionchange event.
|
|
78
|
-
* No-op if nothing is selected or mode is not active.
|
|
30
|
+
* Public API keeps the active-mode guard.
|
|
79
31
|
*/
|
|
80
32
|
clearSelection(): void;
|
|
81
33
|
onPointerDown(event: NormalizedInputEvent): void;
|
|
@@ -85,74 +37,11 @@ export declare class SelectMode implements Mode {
|
|
|
85
37
|
onLongPress(event: NormalizedInputEvent): void;
|
|
86
38
|
onKeyDown(key: string, _event: KeyboardEvent): void;
|
|
87
39
|
/**
|
|
88
|
-
*
|
|
89
|
-
*/
|
|
90
|
-
private getThreshold;
|
|
91
|
-
/**
|
|
92
|
-
* Get the unique vertices (excluding closing point) of a polygon.
|
|
93
|
-
*/
|
|
94
|
-
private getVertices;
|
|
95
|
-
/**
|
|
96
|
-
* Find the nearest vertex within the hit threshold.
|
|
97
|
-
* @returns The vertex index, or -1 if none is close enough.
|
|
98
|
-
*/
|
|
99
|
-
private findNearestVertex;
|
|
100
|
-
/**
|
|
101
|
-
* Find the nearest point (vertex or midpoint) within the hit threshold.
|
|
102
|
-
* @returns The index, or -1 if none is close enough.
|
|
103
|
-
*/
|
|
104
|
-
private findNearestPoint;
|
|
105
|
-
/**
|
|
106
|
-
* Compute midpoints for each edge of the polygon.
|
|
107
|
-
*/
|
|
108
|
-
private computeMidpoints;
|
|
109
|
-
/**
|
|
110
|
-
* Start a vertex drag operation.
|
|
111
|
-
*/
|
|
112
|
-
private startDrag;
|
|
113
|
-
/**
|
|
114
|
-
* Start a polygon drag (whole-polygon move) operation.
|
|
115
|
-
*/
|
|
116
|
-
private startPolygonDrag;
|
|
117
|
-
/**
|
|
118
|
-
* End a drag operation and restore map interactions.
|
|
119
|
-
*/
|
|
120
|
-
private endDrag;
|
|
121
|
-
/**
|
|
122
|
-
* Create a new feature with a vertex moved to a new position.
|
|
123
|
-
*/
|
|
124
|
-
private moveVertex;
|
|
125
|
-
/**
|
|
126
|
-
* Create a new feature with all vertices translated by the given delta.
|
|
127
|
-
*/
|
|
128
|
-
private movePolygon;
|
|
129
|
-
/**
|
|
130
|
-
* Create a new feature with a vertex inserted at the given index.
|
|
131
|
-
*/
|
|
132
|
-
private insertVertex;
|
|
133
|
-
/**
|
|
134
|
-
* Create a new feature with a vertex removed at the given index.
|
|
135
|
-
*/
|
|
136
|
-
private removeVertex;
|
|
137
|
-
/**
|
|
138
|
-
* Refresh vertex/midpoint handles for the currently selected feature.
|
|
139
|
-
* Call this after external geometry changes (e.g. undo/redo).
|
|
40
|
+
* Refresh vertex/midpoint handles after external geometry changes.
|
|
140
41
|
*/
|
|
141
42
|
refreshVertexHandles(): void;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
*/
|
|
145
|
-
private showVertexHandles;
|
|
146
|
-
/**
|
|
147
|
-
* Get the first selected feature ID.
|
|
148
|
-
*/
|
|
149
|
-
private getFirstSelectedId;
|
|
150
|
-
/**
|
|
151
|
-
* Delete all currently selected features.
|
|
152
|
-
*/
|
|
43
|
+
private forceClearSelectionState;
|
|
44
|
+
private commitDragUpdate;
|
|
153
45
|
private deleteSelected;
|
|
154
|
-
|
|
155
|
-
* Notify the host about selection changes.
|
|
156
|
-
*/
|
|
157
|
-
private notifySelectionChange;
|
|
46
|
+
private hasGeometryChanged;
|
|
158
47
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ModeContext } from '../core/ModeContext';
|
|
2
|
+
/**
|
|
3
|
+
* Handles selected feature IDs and selection change notifications.
|
|
4
|
+
*/
|
|
5
|
+
export declare class SelectionManager {
|
|
6
|
+
private selectedIds;
|
|
7
|
+
private context;
|
|
8
|
+
private onSelectionChange?;
|
|
9
|
+
constructor(context: ModeContext, onSelectionChange?: (selectedIds: string[]) => void);
|
|
10
|
+
getSelectedIds(): string[];
|
|
11
|
+
getFirstSelectedId(): string | undefined;
|
|
12
|
+
hasSelection(): boolean;
|
|
13
|
+
has(id: string): boolean;
|
|
14
|
+
selectOnly(id: string): void;
|
|
15
|
+
remove(id: string): void;
|
|
16
|
+
clear(): void;
|
|
17
|
+
clearAndNotify(): boolean;
|
|
18
|
+
notify(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ModeContext } from '../core/ModeContext';
|
|
2
|
+
import type { LibreDrawFeature } from '../types/features';
|
|
3
|
+
import type { NormalizedInputEvent } from '../types/input';
|
|
4
|
+
/**
|
|
5
|
+
* Handles vertex/midpoint interactions for selected polygons.
|
|
6
|
+
*/
|
|
7
|
+
export declare class VertexEditor {
|
|
8
|
+
private context;
|
|
9
|
+
private dragging;
|
|
10
|
+
private dragVertexIndex;
|
|
11
|
+
private dragStartFeature;
|
|
12
|
+
private highlightedVertexIndex;
|
|
13
|
+
constructor(context: ModeContext);
|
|
14
|
+
isDragging(): boolean;
|
|
15
|
+
getDragStartFeature(): LibreDrawFeature | null;
|
|
16
|
+
resetInteractionState(): void;
|
|
17
|
+
clearHighlight(): void;
|
|
18
|
+
tryStartVertexDragOrInsert(feature: LibreDrawFeature, selectedId: string, event: NormalizedInputEvent): boolean;
|
|
19
|
+
handleDragMove(selectedId: string, event: NormalizedInputEvent): boolean;
|
|
20
|
+
updateHighlightIfNeeded(feature: LibreDrawFeature, event: NormalizedInputEvent): void;
|
|
21
|
+
deleteVertexAtPointer(selectedId: string, feature: LibreDrawFeature, event: NormalizedInputEvent): boolean;
|
|
22
|
+
renderHandles(feature: LibreDrawFeature): void;
|
|
23
|
+
endDrag(): void;
|
|
24
|
+
private startDrag;
|
|
25
|
+
private getThreshold;
|
|
26
|
+
private findNearestVertex;
|
|
27
|
+
private findNearestPoint;
|
|
28
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Map as MaplibreMap } from 'maplibre-gl';
|
|
2
2
|
import type { LibreDrawFeature, Position } from '../types/features';
|
|
3
|
+
import type { PartialStyleConfig } from '../types/style';
|
|
3
4
|
import { SourceManager } from './SourceManager';
|
|
4
5
|
/**
|
|
5
6
|
* Layer IDs used by LibreDraw for rendering.
|
|
@@ -31,7 +32,12 @@ export declare class RenderManager {
|
|
|
31
32
|
private pendingRender;
|
|
32
33
|
private pendingFeatures;
|
|
33
34
|
private initialized;
|
|
34
|
-
|
|
35
|
+
private style;
|
|
36
|
+
constructor(map: MaplibreMap, sourceManager: SourceManager, style?: PartialStyleConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Whether render layers and sources are ready on the current style.
|
|
39
|
+
*/
|
|
40
|
+
isReadyForCurrentStyle(): boolean;
|
|
35
41
|
/**
|
|
36
42
|
* Initialize rendering layers on the map.
|
|
37
43
|
* Should be called after the map style and sources are ready.
|
|
@@ -77,4 +83,8 @@ export declare class RenderManager {
|
|
|
77
83
|
* with selection state embedded in properties.
|
|
78
84
|
*/
|
|
79
85
|
private performRender;
|
|
86
|
+
/**
|
|
87
|
+
* Whether all draw layers exist on the current style.
|
|
88
|
+
*/
|
|
89
|
+
private hasAllLayers;
|
|
80
90
|
}
|
|
@@ -17,6 +17,10 @@ export declare class SourceManager {
|
|
|
17
17
|
private map;
|
|
18
18
|
private initialized;
|
|
19
19
|
constructor(map: MaplibreMap);
|
|
20
|
+
/**
|
|
21
|
+
* Whether all required GeoJSON sources exist on the current style.
|
|
22
|
+
*/
|
|
23
|
+
hasAllSources(): boolean;
|
|
20
24
|
/**
|
|
21
25
|
* Initialize the GeoJSON sources on the map.
|
|
22
26
|
* Should be called after the map style has loaded.
|
package/dist/types/events.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LibreDrawFeature } from './features';
|
|
2
|
+
import type { ModeName } from './mode';
|
|
2
3
|
/**
|
|
3
4
|
* Event payload for feature creation.
|
|
4
5
|
*/
|
|
@@ -28,8 +29,8 @@ export interface SelectionChangeEvent {
|
|
|
28
29
|
* Event payload for mode changes.
|
|
29
30
|
*/
|
|
30
31
|
export interface ModeChangeEvent {
|
|
31
|
-
mode:
|
|
32
|
-
previousMode:
|
|
32
|
+
mode: ModeName;
|
|
33
|
+
previousMode: ModeName;
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
35
36
|
* Map of all LibreDraw event types to their payloads.
|
package/dist/types/features.d.ts
CHANGED
|
@@ -57,8 +57,8 @@ export interface FeatureStoreInterface {
|
|
|
57
57
|
* Action that represents the creation of a new feature.
|
|
58
58
|
*/
|
|
59
59
|
export declare class CreateAction implements Action {
|
|
60
|
-
readonly feature: LibreDrawFeature;
|
|
61
60
|
readonly type: ActionType;
|
|
61
|
+
readonly feature: LibreDrawFeature;
|
|
62
62
|
constructor(feature: LibreDrawFeature);
|
|
63
63
|
apply(store: FeatureStoreInterface): void;
|
|
64
64
|
revert(store: FeatureStoreInterface): void;
|
|
@@ -67,10 +67,10 @@ export declare class CreateAction implements Action {
|
|
|
67
67
|
* Action that represents the update of an existing feature.
|
|
68
68
|
*/
|
|
69
69
|
export declare class UpdateAction implements Action {
|
|
70
|
+
readonly type: ActionType;
|
|
70
71
|
readonly id: string;
|
|
71
72
|
readonly oldFeature: LibreDrawFeature;
|
|
72
73
|
readonly newFeature: LibreDrawFeature;
|
|
73
|
-
readonly type: ActionType;
|
|
74
74
|
constructor(id: string, oldFeature: LibreDrawFeature, newFeature: LibreDrawFeature);
|
|
75
75
|
apply(store: FeatureStoreInterface): void;
|
|
76
76
|
revert(store: FeatureStoreInterface): void;
|
|
@@ -79,8 +79,8 @@ export declare class UpdateAction implements Action {
|
|
|
79
79
|
* Action that represents the deletion of a feature.
|
|
80
80
|
*/
|
|
81
81
|
export declare class DeleteAction implements Action {
|
|
82
|
-
readonly feature: LibreDrawFeature;
|
|
83
82
|
readonly type: ActionType;
|
|
83
|
+
readonly feature: LibreDrawFeature;
|
|
84
84
|
constructor(feature: LibreDrawFeature);
|
|
85
85
|
apply(store: FeatureStoreInterface): void;
|
|
86
86
|
revert(store: FeatureStoreInterface): void;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export type { Position, PolygonGeometry, FeatureProperties, LibreDrawFeature, FeatureCollection, ActionType, Action, FeatureStoreInterface, } from './features';
|
|
2
|
+
export type { ModeName } from './mode';
|
|
2
3
|
export { CreateAction, UpdateAction, DeleteAction, } from './features';
|
|
3
4
|
export type { CreateEvent, UpdateEvent, DeleteEvent, SelectionChangeEvent, ModeChangeEvent, LibreDrawEventMap, } from './events';
|
|
4
5
|
export type { ToolbarPosition, ToolbarControls, ToolbarOptions, LibreDrawOptions, } from './options';
|
|
6
|
+
export type { FillStyle, OutlineStyle, VertexStyle, PreviewStyle, EditVertexStyle, MidpointStyle, StyleConfig, PartialStyleConfig, } from './style';
|
|
7
|
+
export { DEFAULT_STYLE_CONFIG, mergeStyleConfig, } from './style';
|
|
5
8
|
export type { InputType, NormalizedInputEvent, } from './input';
|
package/dist/types/options.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PartialStyleConfig } from './style';
|
|
1
2
|
/**
|
|
2
3
|
* Position of the toolbar control on the map.
|
|
3
4
|
*/
|
|
@@ -27,4 +28,6 @@ export interface LibreDrawOptions {
|
|
|
27
28
|
toolbar?: boolean | ToolbarOptions;
|
|
28
29
|
/** Maximum number of undo/redo history entries. Defaults to 100. */
|
|
29
30
|
historyLimit?: number;
|
|
31
|
+
/** Partial style overrides for map layer rendering. */
|
|
32
|
+
style?: PartialStyleConfig;
|
|
30
33
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style for polygon fill rendering.
|
|
3
|
+
*/
|
|
4
|
+
export interface FillStyle {
|
|
5
|
+
color: string;
|
|
6
|
+
opacity: number;
|
|
7
|
+
selectedColor: string;
|
|
8
|
+
selectedOpacity: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Style for polygon outline rendering.
|
|
12
|
+
*/
|
|
13
|
+
export interface OutlineStyle {
|
|
14
|
+
color: string;
|
|
15
|
+
width: number;
|
|
16
|
+
selectedColor: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Style for feature vertex markers.
|
|
20
|
+
*/
|
|
21
|
+
export interface VertexStyle {
|
|
22
|
+
color: string;
|
|
23
|
+
strokeColor: string;
|
|
24
|
+
strokeWidth: number;
|
|
25
|
+
radius: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Style for draw preview line.
|
|
29
|
+
*/
|
|
30
|
+
export interface PreviewStyle {
|
|
31
|
+
color: string;
|
|
32
|
+
width: number;
|
|
33
|
+
dasharray: number[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Style for edit vertex handles.
|
|
37
|
+
*/
|
|
38
|
+
export interface EditVertexStyle {
|
|
39
|
+
color: string;
|
|
40
|
+
strokeColor: string;
|
|
41
|
+
strokeWidth: number;
|
|
42
|
+
radius: number;
|
|
43
|
+
highlightedColor: string;
|
|
44
|
+
highlightedStrokeColor: string;
|
|
45
|
+
highlightedRadius: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Style for midpoint handles.
|
|
49
|
+
*/
|
|
50
|
+
export interface MidpointStyle {
|
|
51
|
+
color: string;
|
|
52
|
+
opacity: number;
|
|
53
|
+
radius: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Full render style configuration.
|
|
57
|
+
*/
|
|
58
|
+
export interface StyleConfig {
|
|
59
|
+
fill: FillStyle;
|
|
60
|
+
outline: OutlineStyle;
|
|
61
|
+
vertex: VertexStyle;
|
|
62
|
+
preview: PreviewStyle;
|
|
63
|
+
editVertex: EditVertexStyle;
|
|
64
|
+
midpoint: MidpointStyle;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Partial style overrides accepted from user options.
|
|
68
|
+
*/
|
|
69
|
+
export interface PartialStyleConfig {
|
|
70
|
+
fill?: Partial<FillStyle>;
|
|
71
|
+
outline?: Partial<OutlineStyle>;
|
|
72
|
+
vertex?: Partial<VertexStyle>;
|
|
73
|
+
preview?: Partial<PreviewStyle>;
|
|
74
|
+
editVertex?: Partial<EditVertexStyle>;
|
|
75
|
+
midpoint?: Partial<MidpointStyle>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Built-in default style used when options.style is omitted.
|
|
79
|
+
*/
|
|
80
|
+
export declare const DEFAULT_STYLE_CONFIG: StyleConfig;
|
|
81
|
+
/**
|
|
82
|
+
* Merge user style overrides with defaults.
|
|
83
|
+
*/
|
|
84
|
+
export declare function mergeStyleConfig(overrides?: PartialStyleConfig): StyleConfig;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FeatureCollection, FeatureProperties, LibreDrawFeature, Position } from '../types/features';
|
|
2
|
+
/**
|
|
3
|
+
* Deep-clone JSON-like values to prevent shared mutable references.
|
|
4
|
+
*/
|
|
5
|
+
export declare function deepCloneValue<T>(value: T): T;
|
|
6
|
+
/**
|
|
7
|
+
* Clone coordinates deeply ([lng, lat][][]).
|
|
8
|
+
*/
|
|
9
|
+
export declare function cloneCoordinates(coordinates: Position[][]): Position[][];
|
|
10
|
+
/**
|
|
11
|
+
* Clone arbitrary feature properties deeply.
|
|
12
|
+
*/
|
|
13
|
+
export declare function cloneProperties(properties: FeatureProperties): FeatureProperties;
|
|
14
|
+
/**
|
|
15
|
+
* Create a deep snapshot of a feature.
|
|
16
|
+
*/
|
|
17
|
+
export declare function cloneFeature(feature: LibreDrawFeature): LibreDrawFeature;
|
|
18
|
+
/**
|
|
19
|
+
* Create a deep snapshot of a FeatureCollection.
|
|
20
|
+
*/
|
|
21
|
+
export declare function cloneFeatureCollection(collection: FeatureCollection): FeatureCollection;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LibreDrawFeature, Position } from '../types/features';
|
|
2
|
+
/**
|
|
3
|
+
* Get the unique vertices (excluding the closing point) of a polygon.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getVertices(feature: LibreDrawFeature): Position[];
|
|
6
|
+
/**
|
|
7
|
+
* Compute midpoints for each edge of a polygon.
|
|
8
|
+
*/
|
|
9
|
+
export declare function computeMidpoints(vertices: Position[]): Position[];
|
|
10
|
+
/**
|
|
11
|
+
* Create a new feature with a vertex moved to a new position.
|
|
12
|
+
*/
|
|
13
|
+
export declare function moveVertex(feature: LibreDrawFeature, vertexIndex: number, newPos: Position): LibreDrawFeature;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new feature with all vertices translated by the given delta.
|
|
16
|
+
*/
|
|
17
|
+
export declare function movePolygon(feature: LibreDrawFeature, dLng: number, dLat: number): LibreDrawFeature;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new feature with a vertex inserted at the given index.
|
|
20
|
+
*/
|
|
21
|
+
export declare function insertVertex(feature: LibreDrawFeature, insertIndex: number, pos: Position): LibreDrawFeature;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new feature with a vertex removed at the given index.
|
|
24
|
+
*/
|
|
25
|
+
export declare function removeVertex(feature: LibreDrawFeature, vertexIndex: number): LibreDrawFeature;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sindicum/libre-draw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "MapLibre GL JS polygon drawing and editing library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/libre-draw.cjs",
|
|
@@ -35,15 +35,13 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@turf/boolean-point-in-polygon": "^7.0.0",
|
|
38
|
-
"@turf/helpers": "^7.0.0"
|
|
39
|
-
"rbush": "^4.0.1"
|
|
38
|
+
"@turf/helpers": "^7.0.0"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
41
|
"@eslint/js": "^9.0.0",
|
|
43
|
-
"@types/rbush": "^4.0.0",
|
|
44
42
|
"eslint": "^9.0.0",
|
|
45
43
|
"eslint-config-prettier": "^10.0.0",
|
|
46
|
-
"happy-dom": "^
|
|
44
|
+
"happy-dom": "^20.7.0",
|
|
47
45
|
"maplibre-gl": "^4.0.0",
|
|
48
46
|
"prettier": "^3.0.0",
|
|
49
47
|
"typescript": "~5.7.0",
|