leaflet-anvil 0.2.2 → 0.3.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/README.md CHANGED
@@ -9,12 +9,12 @@ TypeScript features, and support for complex geometric operations like Union and
9
9
  ## Features
10
10
 
11
11
  - **Drawing Modes**: Marker, Polylines, Polygons, Rectangles, Squares, Triangles, Circles, and Freehand Drawing.
12
- - **Editing Tools**: Drag, Scale, Rotate, and Vertex editing.
12
+ - **Editing Tools**: Drag, Scale, Rotate, vertex editing, and full-layer topology editing.
13
13
  - **Geometric Operations**:
14
14
  - `Union`: Merge two polygons into one.
15
15
  - `Subtract`: Subtract one polygon from another.
16
16
  - `Cut` & `Split`: Cut lines or split areas.
17
- - **Smart Helpers**: Snapping to existing points and Magnetic mode.
17
+ - **Smart Helpers**: Snapping to existing points, topology-aware splitting, and linked vertices across touching layers while editing.
18
18
  - **Event-driven**: Easy integration through a consistent event system.
19
19
 
20
20
  ## Installation
@@ -38,7 +38,6 @@ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
38
38
  const anvil = new Anvil(map, {
39
39
  snapping: true,
40
40
  snapDistance: 15,
41
- magnetic: true,
42
41
  preventSelfIntersection: true,
43
42
  controlPosition: 'topleft',
44
43
  modes: [
@@ -70,7 +69,8 @@ Activation via `anvil.enable(AnvilMode.Name)` or through the UI toolbar:
70
69
  | | `Square` | Creates a square with a fixed aspect ratio. |
71
70
  | | `Triangle` | Creates a triangle. |
72
71
  | | `Circle` | Creates a circle with radius determination. |
73
- | **Transform** | `Edit` | Edit individual vertices. |
72
+ | **Transform** | `Edit` | Edit selected geometries vertex-by-vertex. |
73
+ | | `Topology` | Edit the whole layer group with linked vertices across touching layers. |
74
74
  | | `Drag` | Move entire geometries on the map. |
75
75
  | | `Scale` | Proportional resizing (scaling). |
76
76
  | | `Rotate` | Rotate geometries around their center. |
@@ -86,7 +86,6 @@ Activation via `anvil.enable(AnvilMode.Name)` or through the UI toolbar:
86
86
  |:--------------------------|:----------|:------------|:---------------------------------------------------------------------------------------------------------------------|
87
87
  | `snapping` | `boolean` | `false` | **Snapping:** If `true`, new points automatically snap to existing vertices of other geometries. |
88
88
  | `snapDistance` | `number` | `10` | **Snap Distance:** Determines the distance in pixels at which a point "jumps" to the nearest existing vertex. |
89
- | `magnetic` | `boolean` | `false` | **Magnetism:** Enhances snapping behavior. Points are actively attracted once they enter the radius. |
90
89
  | `preventSelfIntersection` | `boolean` | `false` | **Validation:** Prevents edges from self-intersecting in polygons and lines. Blocks invalid segments during drawing. |
91
90
  | `pathOptions` | `object` | `Leaflet` | Global fallback styles for path-based layers such as polygons, lines, rectangles and circles. |
92
91
  | `ghostPathOptions` | `object` | `Inherited` | Global fallback styles for temporary preview geometry while drawing. |
@@ -94,6 +93,7 @@ Activation via `anvil.enable(AnvilMode.Name)` or through the UI toolbar:
94
93
  | `modeStyles` | `object` | `{}` | Per-mode style overrides for drawing, handles and active selection/highlight states. |
95
94
  | `controlPosition` | `string` | `'topleft'` | Determines the position of the toolbar on the map (e.g., `'topright'`). |
96
95
  | `modes` | `Array` | `All` | Defines which buttons appear in the toolbar. Supports nested arrays for button groups (blocks). |
96
+ | `modeTooltips` | `object \\| function` | `Defaults` | Overrides toolbar button tooltips. Missing values keep the built-in defaults. Use a function if translations can change after initialization. |
97
97
 
98
98
  ### Mode-Specific Styles
99
99
 
@@ -106,7 +106,7 @@ Supported per-mode keys:
106
106
  - `ghostPathOptions`: Temporary preview style while drawing.
107
107
  - `vertexOptions`: Marker options for marker-based modes.
108
108
  - `handleOptions`: Options for helper handles such as polygon close handles or edit handles.
109
- - `selectionPathOptions`: Highlight style for selected/active geometry in modes like `Edit`, `Drag`, `Scale`, `Rotate`, `Union` and `Subtract`.
109
+ - `selectionPathOptions`: Highlight style for selected/active geometry in modes like `Edit`, `Topology`, `Drag`, `Scale`, `Rotate`, `Union` and `Subtract`.
110
110
 
111
111
  ```typescript
112
112
  const anvil = new Anvil(map, {
@@ -147,6 +147,17 @@ const anvil = new Anvil(map, {
147
147
  radius: 6,
148
148
  },
149
149
  },
150
+ [AnvilMode.Topology]: {
151
+ selectionPathOptions: {
152
+ color: '#0891b2',
153
+ weight: 3,
154
+ },
155
+ handleOptions: {
156
+ color: '#0891b2',
157
+ fillColor: '#ecfeff',
158
+ radius: 5,
159
+ },
160
+ },
150
161
  [AnvilMode.Rotate]: {
151
162
  selectionPathOptions: {
152
163
  color: '#8b5cf6',
@@ -168,7 +179,31 @@ const anvil = new Anvil(map, {
168
179
  ```
169
180
 
170
181
  If you want to style the active highlight of interaction modes, use `selectionPathOptions`.
171
- 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`.
182
+ That is what controls the temporary emphasis color when a geometry is selected in modes such as `Edit` or while actively transforming it in `Topology`, `Drag`, `Scale`, `Rotate`, `Union` or `Subtract`.
183
+
184
+ ### Custom Toolbar Tooltips
185
+
186
+ For simple overrides, pass a static map:
187
+
188
+ ```typescript
189
+ const anvil = new Anvil(map, {
190
+ modeTooltips: {
191
+ [AnvilMode.Edit]: 'Edit geometry',
192
+ [AnvilMode.Delete]: 'Remove geometry',
193
+ [AnvilMode.Off]: 'Disable tools',
194
+ },
195
+ });
196
+ ```
197
+
198
+ If your app language can change after `Anvil` has been created, pass a resolver instead.
199
+ 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.
200
+ The second argument is the built-in default tooltip, so you can preserve defaults without duplicating them.
201
+
202
+ ```typescript
203
+ const anvil = new Anvil(map, {
204
+ modeTooltips: (mode, fallback) => i18n.t(`mapTools.${mode}`, fallback),
205
+ });
206
+ ```
172
207
 
173
208
  ### Events (`ANVIL_EVENTS`)
174
209
 
package/dist/index.d.mts CHANGED
@@ -17,6 +17,7 @@ declare enum AnvilMode {
17
17
  Union = "union",
18
18
  Subtract = "subtract",
19
19
  Edit = "edit",
20
+ Topology = "topology",
20
21
  Delete = "delete",
21
22
  Off = "off"
22
23
  }
@@ -25,11 +26,12 @@ interface Mode {
25
26
  enable(): void;
26
27
  disable(): void;
27
28
  }
29
+ type AnvilModeTooltips = Partial<Record<AnvilMode, string>>;
30
+ type AnvilModeTooltipResolver = (mode: AnvilMode, defaultTooltip: string) => string | null | undefined;
28
31
  interface AnvilOptions {
29
32
  layerGroup?: L.FeatureGroup;
30
33
  snapping?: boolean;
31
34
  snapDistance?: number;
32
- magnetic?: boolean;
33
35
  freehandTolerance?: number;
34
36
  preventSelfIntersection?: boolean;
35
37
  pathOptions?: L.PathOptions;
@@ -38,6 +40,7 @@ interface AnvilOptions {
38
40
  modeStyles?: AnvilModeStyles;
39
41
  controlPosition?: L.ControlPosition;
40
42
  modes?: (AnvilMode | AnvilMode[])[];
43
+ modeTooltips?: AnvilModeTooltips | AnvilModeTooltipResolver;
41
44
  }
42
45
  interface AnvilModeStyleOptions {
43
46
  pathOptions?: L.PathOptions;
@@ -72,6 +75,7 @@ declare const ANVIL_EVENTS: {
72
75
  interface AnvilControlOptions extends L.ControlOptions {
73
76
  position?: L.ControlPosition;
74
77
  modes?: (AnvilMode | AnvilMode[])[];
78
+ modeTooltips?: AnvilModeTooltips | AnvilModeTooltipResolver;
75
79
  }
76
80
  declare class AnvilControl extends L.Control {
77
81
  private _btns;
@@ -82,4 +86,4 @@ declare class AnvilControl extends L.Control {
82
86
  }
83
87
  declare function anvilControl(anvil: Anvil, options?: AnvilControlOptions): AnvilControl;
84
88
 
85
- export { ANVIL_EVENTS, Anvil, AnvilControl, type AnvilControlOptions, AnvilMode, type AnvilModeStyleOptions, type AnvilModeStyles, 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
@@ -17,6 +17,7 @@ declare enum AnvilMode {
17
17
  Union = "union",
18
18
  Subtract = "subtract",
19
19
  Edit = "edit",
20
+ Topology = "topology",
20
21
  Delete = "delete",
21
22
  Off = "off"
22
23
  }
@@ -25,11 +26,12 @@ interface Mode {
25
26
  enable(): void;
26
27
  disable(): void;
27
28
  }
29
+ type AnvilModeTooltips = Partial<Record<AnvilMode, string>>;
30
+ type AnvilModeTooltipResolver = (mode: AnvilMode, defaultTooltip: string) => string | null | undefined;
28
31
  interface AnvilOptions {
29
32
  layerGroup?: L.FeatureGroup;
30
33
  snapping?: boolean;
31
34
  snapDistance?: number;
32
- magnetic?: boolean;
33
35
  freehandTolerance?: number;
34
36
  preventSelfIntersection?: boolean;
35
37
  pathOptions?: L.PathOptions;
@@ -38,6 +40,7 @@ interface AnvilOptions {
38
40
  modeStyles?: AnvilModeStyles;
39
41
  controlPosition?: L.ControlPosition;
40
42
  modes?: (AnvilMode | AnvilMode[])[];
43
+ modeTooltips?: AnvilModeTooltips | AnvilModeTooltipResolver;
41
44
  }
42
45
  interface AnvilModeStyleOptions {
43
46
  pathOptions?: L.PathOptions;
@@ -72,6 +75,7 @@ declare const ANVIL_EVENTS: {
72
75
  interface AnvilControlOptions extends L.ControlOptions {
73
76
  position?: L.ControlPosition;
74
77
  modes?: (AnvilMode | AnvilMode[])[];
78
+ modeTooltips?: AnvilModeTooltips | AnvilModeTooltipResolver;
75
79
  }
76
80
  declare class AnvilControl extends L.Control {
77
81
  private _btns;
@@ -82,4 +86,4 @@ declare class AnvilControl extends L.Control {
82
86
  }
83
87
  declare function anvilControl(anvil: Anvil, options?: AnvilControlOptions): AnvilControl;
84
88
 
85
- export { ANVIL_EVENTS, Anvil, AnvilControl, type AnvilControlOptions, AnvilMode, type AnvilModeStyleOptions, type AnvilModeStyles, 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 };