leaflet-anvil 0.2.1 → 0.2.3
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/README.md +107 -0
- package/dist/index.d.mts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +507 -248
- package/dist/index.mjs +527 -248
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
A minimalist, powerful toolkit for drawing and editing geometries in [Leaflet](https://leafletjs.com/). Focused on a clean API, modern
|
|
4
4
|
TypeScript features, and support for complex geometric operations like Union and Subtract.
|
|
5
5
|
|
|
6
|
+
> Leaflet Anvil is currently a work in progress. Feedback, ideas, and bug reports are very welcome.
|
|
7
|
+
> The API and overall behavior are planned to be considered stable starting with `v1.0.0`.
|
|
8
|
+
|
|
6
9
|
## Features
|
|
7
10
|
|
|
8
11
|
- **Drawing Modes**: Marker, Polylines, Polygons, Rectangles, Squares, Triangles, Circles, and Freehand Drawing.
|
|
@@ -85,8 +88,112 @@ Activation via `anvil.enable(AnvilMode.Name)` or through the UI toolbar:
|
|
|
85
88
|
| `snapDistance` | `number` | `10` | **Snap Distance:** Determines the distance in pixels at which a point "jumps" to the nearest existing vertex. |
|
|
86
89
|
| `magnetic` | `boolean` | `false` | **Magnetism:** Enhances snapping behavior. Points are actively attracted once they enter the radius. |
|
|
87
90
|
| `preventSelfIntersection` | `boolean` | `false` | **Validation:** Prevents edges from self-intersecting in polygons and lines. Blocks invalid segments during drawing. |
|
|
91
|
+
| `pathOptions` | `object` | `Leaflet` | Global fallback styles for path-based layers such as polygons, lines, rectangles and circles. |
|
|
92
|
+
| `ghostPathOptions` | `object` | `Inherited` | Global fallback styles for temporary preview geometry while drawing. |
|
|
93
|
+
| `vertexOptions` | `object` | `Leaflet` | Global fallback marker options for marker-based drawing. |
|
|
94
|
+
| `modeStyles` | `object` | `{}` | Per-mode style overrides for drawing, handles and active selection/highlight states. |
|
|
88
95
|
| `controlPosition` | `string` | `'topleft'` | Determines the position of the toolbar on the map (e.g., `'topright'`). |
|
|
89
96
|
| `modes` | `Array` | `All` | Defines which buttons appear in the toolbar. Supports nested arrays for button groups (blocks). |
|
|
97
|
+
| `modeTooltips` | `object \\| function` | `Defaults` | Overrides toolbar button tooltips. Missing values keep the built-in defaults. Use a function if translations can change after initialization. |
|
|
98
|
+
|
|
99
|
+
### Mode-Specific Styles
|
|
100
|
+
|
|
101
|
+
Global `pathOptions`, `ghostPathOptions` and `vertexOptions` still work as shared defaults.
|
|
102
|
+
With `modeStyles`, you can override them per mode.
|
|
103
|
+
|
|
104
|
+
Supported per-mode keys:
|
|
105
|
+
|
|
106
|
+
- `pathOptions`: Final style of created path layers for that mode.
|
|
107
|
+
- `ghostPathOptions`: Temporary preview style while drawing.
|
|
108
|
+
- `vertexOptions`: Marker options for marker-based modes.
|
|
109
|
+
- `handleOptions`: Options for helper handles such as polygon close handles or edit handles.
|
|
110
|
+
- `selectionPathOptions`: Highlight style for selected/active geometry in modes like `Edit`, `Drag`, `Scale`, `Rotate`, `Union` and `Subtract`.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const anvil = new Anvil(map, {
|
|
114
|
+
pathOptions: {
|
|
115
|
+
color: '#334155',
|
|
116
|
+
weight: 3,
|
|
117
|
+
},
|
|
118
|
+
ghostPathOptions: {
|
|
119
|
+
dashArray: '6 4',
|
|
120
|
+
opacity: 0.7,
|
|
121
|
+
},
|
|
122
|
+
modeStyles: {
|
|
123
|
+
[AnvilMode.Polyline]: {
|
|
124
|
+
pathOptions: {
|
|
125
|
+
color: '#0f766e',
|
|
126
|
+
weight: 5,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
[AnvilMode.Polygon]: {
|
|
130
|
+
pathOptions: {
|
|
131
|
+
color: '#ea580c',
|
|
132
|
+
fillColor: '#fdba74',
|
|
133
|
+
fillOpacity: 0.35,
|
|
134
|
+
},
|
|
135
|
+
handleOptions: {
|
|
136
|
+
radius: 6,
|
|
137
|
+
color: '#ea580c',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
[AnvilMode.Edit]: {
|
|
141
|
+
selectionPathOptions: {
|
|
142
|
+
color: '#db2777',
|
|
143
|
+
weight: 4,
|
|
144
|
+
},
|
|
145
|
+
handleOptions: {
|
|
146
|
+
color: '#db2777',
|
|
147
|
+
fillColor: '#fff7fb',
|
|
148
|
+
radius: 6,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
[AnvilMode.Rotate]: {
|
|
152
|
+
selectionPathOptions: {
|
|
153
|
+
color: '#8b5cf6',
|
|
154
|
+
weight: 5,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
[AnvilMode.Marker]: {
|
|
158
|
+
vertexOptions: {
|
|
159
|
+
icon: L.divIcon({
|
|
160
|
+
className: 'custom-marker',
|
|
161
|
+
html: '<div class="marker-dot"></div>',
|
|
162
|
+
iconSize: [16, 16],
|
|
163
|
+
iconAnchor: [8, 8],
|
|
164
|
+
}),
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
If you want to style the active highlight of interaction modes, use `selectionPathOptions`.
|
|
172
|
+
That is what controls the temporary emphasis color when a geometry is selected in modes such as `Edit` or while actively transforming it in `Drag`, `Scale`, `Rotate`, `Union` or `Subtract`.
|
|
173
|
+
|
|
174
|
+
### Custom Toolbar Tooltips
|
|
175
|
+
|
|
176
|
+
For simple overrides, pass a static map:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
const anvil = new Anvil(map, {
|
|
180
|
+
modeTooltips: {
|
|
181
|
+
[AnvilMode.Edit]: 'Edit geometry',
|
|
182
|
+
[AnvilMode.Delete]: 'Remove geometry',
|
|
183
|
+
[AnvilMode.Off]: 'Disable tools',
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
If your app language can change after `Anvil` has been created, pass a resolver instead.
|
|
189
|
+
The toolbar re-reads the tooltip when a button is focused or hovered, so the next interaction uses the current language without recreating the control.
|
|
190
|
+
The second argument is the built-in default tooltip, so you can preserve defaults without duplicating them.
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
const anvil = new Anvil(map, {
|
|
194
|
+
modeTooltips: (mode, fallback) => i18n.t(`mapTools.${mode}`, fallback),
|
|
195
|
+
});
|
|
196
|
+
```
|
|
90
197
|
|
|
91
198
|
### Events (`ANVIL_EVENTS`)
|
|
92
199
|
|
package/dist/index.d.mts
CHANGED
|
@@ -25,6 +25,8 @@ interface Mode {
|
|
|
25
25
|
enable(): void;
|
|
26
26
|
disable(): void;
|
|
27
27
|
}
|
|
28
|
+
type AnvilModeTooltips = Partial<Record<AnvilMode, string>>;
|
|
29
|
+
type AnvilModeTooltipResolver = (mode: AnvilMode, defaultTooltip: string) => string | null | undefined;
|
|
28
30
|
interface AnvilOptions {
|
|
29
31
|
layerGroup?: L.FeatureGroup;
|
|
30
32
|
snapping?: boolean;
|
|
@@ -35,9 +37,19 @@ interface AnvilOptions {
|
|
|
35
37
|
pathOptions?: L.PathOptions;
|
|
36
38
|
ghostPathOptions?: L.PathOptions;
|
|
37
39
|
vertexOptions?: L.MarkerOptions;
|
|
40
|
+
modeStyles?: AnvilModeStyles;
|
|
38
41
|
controlPosition?: L.ControlPosition;
|
|
39
42
|
modes?: (AnvilMode | AnvilMode[])[];
|
|
43
|
+
modeTooltips?: AnvilModeTooltips | AnvilModeTooltipResolver;
|
|
40
44
|
}
|
|
45
|
+
interface AnvilModeStyleOptions {
|
|
46
|
+
pathOptions?: L.PathOptions;
|
|
47
|
+
ghostPathOptions?: L.PathOptions;
|
|
48
|
+
vertexOptions?: L.MarkerOptions;
|
|
49
|
+
handleOptions?: L.CircleMarkerOptions;
|
|
50
|
+
selectionPathOptions?: L.PathOptions;
|
|
51
|
+
}
|
|
52
|
+
type AnvilModeStyles = Partial<Record<AnvilMode, AnvilModeStyleOptions>>;
|
|
41
53
|
declare class Anvil {
|
|
42
54
|
private map;
|
|
43
55
|
private modeManager;
|
|
@@ -63,6 +75,7 @@ declare const ANVIL_EVENTS: {
|
|
|
63
75
|
interface AnvilControlOptions extends L.ControlOptions {
|
|
64
76
|
position?: L.ControlPosition;
|
|
65
77
|
modes?: (AnvilMode | AnvilMode[])[];
|
|
78
|
+
modeTooltips?: AnvilModeTooltips | AnvilModeTooltipResolver;
|
|
66
79
|
}
|
|
67
80
|
declare class AnvilControl extends L.Control {
|
|
68
81
|
private _btns;
|
|
@@ -73,4 +86,4 @@ declare class AnvilControl extends L.Control {
|
|
|
73
86
|
}
|
|
74
87
|
declare function anvilControl(anvil: Anvil, options?: AnvilControlOptions): AnvilControl;
|
|
75
88
|
|
|
76
|
-
export { ANVIL_EVENTS, Anvil, AnvilControl, type AnvilControlOptions, AnvilMode, type AnvilOptions, type Mode, anvilControl };
|
|
89
|
+
export { ANVIL_EVENTS, Anvil, AnvilControl, type AnvilControlOptions, AnvilMode, type AnvilModeStyleOptions, type AnvilModeStyles, type AnvilModeTooltipResolver, type AnvilModeTooltips, type AnvilOptions, type Mode, anvilControl };
|
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ interface Mode {
|
|
|
25
25
|
enable(): void;
|
|
26
26
|
disable(): void;
|
|
27
27
|
}
|
|
28
|
+
type AnvilModeTooltips = Partial<Record<AnvilMode, string>>;
|
|
29
|
+
type AnvilModeTooltipResolver = (mode: AnvilMode, defaultTooltip: string) => string | null | undefined;
|
|
28
30
|
interface AnvilOptions {
|
|
29
31
|
layerGroup?: L.FeatureGroup;
|
|
30
32
|
snapping?: boolean;
|
|
@@ -35,9 +37,19 @@ interface AnvilOptions {
|
|
|
35
37
|
pathOptions?: L.PathOptions;
|
|
36
38
|
ghostPathOptions?: L.PathOptions;
|
|
37
39
|
vertexOptions?: L.MarkerOptions;
|
|
40
|
+
modeStyles?: AnvilModeStyles;
|
|
38
41
|
controlPosition?: L.ControlPosition;
|
|
39
42
|
modes?: (AnvilMode | AnvilMode[])[];
|
|
43
|
+
modeTooltips?: AnvilModeTooltips | AnvilModeTooltipResolver;
|
|
40
44
|
}
|
|
45
|
+
interface AnvilModeStyleOptions {
|
|
46
|
+
pathOptions?: L.PathOptions;
|
|
47
|
+
ghostPathOptions?: L.PathOptions;
|
|
48
|
+
vertexOptions?: L.MarkerOptions;
|
|
49
|
+
handleOptions?: L.CircleMarkerOptions;
|
|
50
|
+
selectionPathOptions?: L.PathOptions;
|
|
51
|
+
}
|
|
52
|
+
type AnvilModeStyles = Partial<Record<AnvilMode, AnvilModeStyleOptions>>;
|
|
41
53
|
declare class Anvil {
|
|
42
54
|
private map;
|
|
43
55
|
private modeManager;
|
|
@@ -63,6 +75,7 @@ declare const ANVIL_EVENTS: {
|
|
|
63
75
|
interface AnvilControlOptions extends L.ControlOptions {
|
|
64
76
|
position?: L.ControlPosition;
|
|
65
77
|
modes?: (AnvilMode | AnvilMode[])[];
|
|
78
|
+
modeTooltips?: AnvilModeTooltips | AnvilModeTooltipResolver;
|
|
66
79
|
}
|
|
67
80
|
declare class AnvilControl extends L.Control {
|
|
68
81
|
private _btns;
|
|
@@ -73,4 +86,4 @@ declare class AnvilControl extends L.Control {
|
|
|
73
86
|
}
|
|
74
87
|
declare function anvilControl(anvil: Anvil, options?: AnvilControlOptions): AnvilControl;
|
|
75
88
|
|
|
76
|
-
export { ANVIL_EVENTS, Anvil, AnvilControl, type AnvilControlOptions, AnvilMode, type AnvilOptions, type Mode, anvilControl };
|
|
89
|
+
export { ANVIL_EVENTS, Anvil, AnvilControl, type AnvilControlOptions, AnvilMode, type AnvilModeStyleOptions, type AnvilModeStyles, type AnvilModeTooltipResolver, type AnvilModeTooltips, type AnvilOptions, type Mode, anvilControl };
|