leaflet-anvil 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tim Tilch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # Leaflet Anvil 🛠️
2
+
3
+ Ein minimalistisches, leistungsstarkes Toolkit zum Zeichnen und Editieren von Geometrien in [Leaflet](https://leafletjs.com/). Fokus liegt
4
+ auf einer sauberen API, modernen TypeScript-Features und Unterstützung für komplexe geometrische Operationen wie Union und Subtract.
5
+
6
+ ## Features
7
+
8
+ - **Zeichen-Modi**: Marker, Polylines, Polygone, Rechtecke, Quadrate, Dreiecke, Kreise und Freehand-Drawing.
9
+ - **Editier-Tools**: Drag, Scale, Rotate und Vertex-Editing.
10
+ - **Geometrische Operationen**:
11
+ - `Union`: Verschmelzen von zwei Polygonen.
12
+ - `Subtract`: Abziehen eines Polygons von einem anderen.
13
+ - `Cut` & `Split`: Zerschneiden von Linien oder Flächen.
14
+ - **Smart Helpers**: Snapping (Einrasten) an vorhandenen Punkten und Magnetic-Modus.
15
+ - **Event-basiert**: Einfache Integration durch ein konsistentes Event-System.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install leaflet-anvil
21
+ ```
22
+
23
+ *Hinweis: Leaflet ist eine Peer-Dependency und muss ebenfalls installiert sein.*
24
+
25
+ ## Schnellstart
26
+
27
+ ```typescript
28
+ import L from 'leaflet';
29
+ import { Anvil } from 'leaflet-anvil';
30
+
31
+ const map = L.map('map').setView([51.505, -0.09], 13);
32
+ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
33
+
34
+ // Anvil initialisieren
35
+ const anvil = new Anvil(map, {
36
+ snapping: true,
37
+ snapDistance: 15
38
+ });
39
+
40
+ // Einen Modus aktivieren
41
+ anvil.enable('draw:polygon');
42
+
43
+ // Auf Events reagieren
44
+ map.on('anvil:created', (e) => {
45
+ console.log('Neuer Layer erstellt:', e.layer);
46
+ });
47
+ ```
48
+
49
+ ## Verfügbare Modi
50
+
51
+ Aktivierung über `anvil.enable(modeName)`:
52
+
53
+ | Modus | Beschreibung |
54
+ |:-----------------|:----------------------------------------|
55
+ | `draw:marker` | Setzt einen Marker |
56
+ | `draw:polyline` | Zeichnet eine Linie |
57
+ | `draw:polygon` | Zeichnet eine geschlossene Fläche |
58
+ | `draw:rectangle` | Zeichnet ein Rechteck |
59
+ | `draw:circle` | Zeichnet einen Kreis |
60
+ | `draw:freehand` | Freihandzeichnen (Klicken und Ziehen) |
61
+ | `edit` | Bearbeiten von Eckpunkten (Vertices) |
62
+ | `drag` | Verschieben von ganzen Layern |
63
+ | `rotate` | Rotieren von Geometrien |
64
+ | `scale` | Skalieren von Geometrien |
65
+ | `union` | Verschmelzen zweier Polygone |
66
+ | `subtract` | Abziehen des zweiten vom ersten Polygon |
67
+ | `delete` | Layer per Klick entfernen |
68
+
69
+ ## API Referenz
70
+
71
+ ### Anvil Options
72
+
73
+ | Option | Typ | Standard | Beschreibung |
74
+ |:--------------------------|:----------------|:---------|:------------------------------------|
75
+ | `snapping` | `boolean` | `false` | Aktiviert Snapping an Eckpunkten |
76
+ | `snapDistance` | `number` | `10` | Distanz in Pixeln für Snapping |
77
+ | `preventSelfIntersection` | `boolean` | `false` | Verhindert Selbstüberschneidungen |
78
+ | `pathOptions` | `L.PathOptions` | `{}` | Standard-Styles für neue Geometrien |
79
+
80
+ ### Events (`ANVIL_EVENTS`)
81
+
82
+ Alle Events werden auf der Leaflet-Map gefeuert:
83
+
84
+ - `anvil:created`: Wenn ein neuer Layer fertiggestellt wurde.
85
+ - `anvil:edited`: Wenn ein Layer verändert wurde (drag/rotate/edit/scale).
86
+ - `anvil:deleted`: Wenn ein Layer entfernt wurde.
87
+ - `anvil:modechange`: Wenn der aktive Modus wechselt.
88
+
89
+ ## Entwicklung
90
+
91
+ ```bash
92
+ # Abhängigkeiten installieren
93
+ npm install
94
+
95
+ # Entwicklungsserver (Vite)
96
+ npm run dev
97
+
98
+ # Tests ausführen
99
+ npm test
100
+
101
+ # Build erstellen
102
+ npm run build
103
+ ```
104
+
105
+ ## Lizenz
106
+
107
+ MIT
108
+
@@ -0,0 +1,50 @@
1
+ import * as L from 'leaflet';
2
+
3
+ interface Mode {
4
+ enable(): void;
5
+ disable(): void;
6
+ }
7
+ interface AnvilOptions {
8
+ layerGroup?: L.FeatureGroup;
9
+ snapping?: boolean;
10
+ snapDistance?: number;
11
+ magnetic?: boolean;
12
+ freehandTolerance?: number;
13
+ preventSelfIntersection?: boolean;
14
+ pathOptions?: L.PathOptions;
15
+ ghostPathOptions?: L.PathOptions;
16
+ vertexOptions?: L.MarkerOptions;
17
+ }
18
+ declare class Anvil {
19
+ private map;
20
+ private modeManager;
21
+ private store;
22
+ private options;
23
+ constructor(map: L.Map, options?: AnvilOptions);
24
+ enable(mode: 'draw:polygon' | 'draw:polyline' | 'draw:marker' | 'draw:rectangle' | 'draw:square' | 'draw:triangle' | 'draw:circle' | 'draw:freehand' | 'cut' | 'split' | 'union' | 'subtract' | 'drag' | 'scale' | 'rotate' | 'edit' | 'delete'): void;
25
+ disable(): void;
26
+ getLayerGroup(): L.FeatureGroup;
27
+ }
28
+
29
+ declare const ANVIL_EVENTS: {
30
+ readonly CREATED: "anvil:created";
31
+ readonly EDITED: "anvil:edited";
32
+ readonly DELETED: "anvil:deleted";
33
+ readonly SPLIT: "anvil:split";
34
+ readonly UNION: "anvil:union";
35
+ readonly SUBTRACT: "anvil:subtract";
36
+ readonly MODE_CHANGE: "anvil:modechange";
37
+ };
38
+
39
+ interface AnvilControlOptions extends L.ControlOptions {
40
+ position?: L.ControlPosition;
41
+ }
42
+ declare class AnvilControl extends L.Control {
43
+ private _btns;
44
+ private _anvil;
45
+ constructor(anvil: Anvil, options?: L.ControlOptions);
46
+ onAdd(map: L.Map): HTMLElement;
47
+ }
48
+ declare function anvilControl(anvil: Anvil, options?: AnvilControlOptions): AnvilControl;
49
+
50
+ export { ANVIL_EVENTS, Anvil, AnvilControl, type AnvilControlOptions, type AnvilOptions, type Mode, anvilControl };
@@ -0,0 +1,50 @@
1
+ import * as L from 'leaflet';
2
+
3
+ interface Mode {
4
+ enable(): void;
5
+ disable(): void;
6
+ }
7
+ interface AnvilOptions {
8
+ layerGroup?: L.FeatureGroup;
9
+ snapping?: boolean;
10
+ snapDistance?: number;
11
+ magnetic?: boolean;
12
+ freehandTolerance?: number;
13
+ preventSelfIntersection?: boolean;
14
+ pathOptions?: L.PathOptions;
15
+ ghostPathOptions?: L.PathOptions;
16
+ vertexOptions?: L.MarkerOptions;
17
+ }
18
+ declare class Anvil {
19
+ private map;
20
+ private modeManager;
21
+ private store;
22
+ private options;
23
+ constructor(map: L.Map, options?: AnvilOptions);
24
+ enable(mode: 'draw:polygon' | 'draw:polyline' | 'draw:marker' | 'draw:rectangle' | 'draw:square' | 'draw:triangle' | 'draw:circle' | 'draw:freehand' | 'cut' | 'split' | 'union' | 'subtract' | 'drag' | 'scale' | 'rotate' | 'edit' | 'delete'): void;
25
+ disable(): void;
26
+ getLayerGroup(): L.FeatureGroup;
27
+ }
28
+
29
+ declare const ANVIL_EVENTS: {
30
+ readonly CREATED: "anvil:created";
31
+ readonly EDITED: "anvil:edited";
32
+ readonly DELETED: "anvil:deleted";
33
+ readonly SPLIT: "anvil:split";
34
+ readonly UNION: "anvil:union";
35
+ readonly SUBTRACT: "anvil:subtract";
36
+ readonly MODE_CHANGE: "anvil:modechange";
37
+ };
38
+
39
+ interface AnvilControlOptions extends L.ControlOptions {
40
+ position?: L.ControlPosition;
41
+ }
42
+ declare class AnvilControl extends L.Control {
43
+ private _btns;
44
+ private _anvil;
45
+ constructor(anvil: Anvil, options?: L.ControlOptions);
46
+ onAdd(map: L.Map): HTMLElement;
47
+ }
48
+ declare function anvilControl(anvil: Anvil, options?: AnvilControlOptions): AnvilControl;
49
+
50
+ export { ANVIL_EVENTS, Anvil, AnvilControl, type AnvilControlOptions, type AnvilOptions, type Mode, anvilControl };