leaflet-anvil 0.1.0 → 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/README.md +71 -61
- package/dist/index.d.mts +29 -3
- package/dist/index.d.ts +29 -3
- package/dist/index.js +260 -123
- package/dist/index.mjs +259 -123
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35,11 +35,35 @@ __export(index_exports, {
|
|
|
35
35
|
ANVIL_EVENTS: () => ANVIL_EVENTS,
|
|
36
36
|
Anvil: () => Anvil,
|
|
37
37
|
AnvilControl: () => AnvilControl,
|
|
38
|
+
AnvilMode: () => AnvilMode,
|
|
38
39
|
anvilControl: () => anvilControl
|
|
39
40
|
});
|
|
40
41
|
module.exports = __toCommonJS(index_exports);
|
|
41
42
|
var L22 = __toESM(require("leaflet"));
|
|
42
43
|
|
|
44
|
+
// src/types.ts
|
|
45
|
+
var AnvilMode = /* @__PURE__ */ ((AnvilMode2) => {
|
|
46
|
+
AnvilMode2["Polygon"] = "polygon";
|
|
47
|
+
AnvilMode2["Polyline"] = "polyline";
|
|
48
|
+
AnvilMode2["Marker"] = "marker";
|
|
49
|
+
AnvilMode2["Rectangle"] = "rectangle";
|
|
50
|
+
AnvilMode2["Square"] = "square";
|
|
51
|
+
AnvilMode2["Triangle"] = "triangle";
|
|
52
|
+
AnvilMode2["Circle"] = "circle";
|
|
53
|
+
AnvilMode2["Freehand"] = "freehand";
|
|
54
|
+
AnvilMode2["Cut"] = "cut";
|
|
55
|
+
AnvilMode2["Split"] = "split";
|
|
56
|
+
AnvilMode2["Drag"] = "drag";
|
|
57
|
+
AnvilMode2["Scale"] = "scale";
|
|
58
|
+
AnvilMode2["Rotate"] = "rotate";
|
|
59
|
+
AnvilMode2["Union"] = "union";
|
|
60
|
+
AnvilMode2["Subtract"] = "subtract";
|
|
61
|
+
AnvilMode2["Edit"] = "edit";
|
|
62
|
+
AnvilMode2["Delete"] = "delete";
|
|
63
|
+
AnvilMode2["Off"] = "off";
|
|
64
|
+
return AnvilMode2;
|
|
65
|
+
})(AnvilMode || {});
|
|
66
|
+
|
|
43
67
|
// src/events.ts
|
|
44
68
|
var ANVIL_EVENTS = {
|
|
45
69
|
CREATED: "anvil:created",
|
|
@@ -89,6 +113,7 @@ var L3 = __toESM(require("leaflet"));
|
|
|
89
113
|
var L = __toESM(require("leaflet"));
|
|
90
114
|
function getSnapLatLng(map, latlng, store, options, additionalPoints = [], skipLayer) {
|
|
91
115
|
if (!options.snapping) return latlng;
|
|
116
|
+
const verifiedAdditionalPoints = Array.isArray(additionalPoints) ? additionalPoints : [];
|
|
92
117
|
const snapDistance = options.snapDistance || 10;
|
|
93
118
|
const basePoint = map.latLngToContainerPoint(latlng);
|
|
94
119
|
let closestPoint = null;
|
|
@@ -125,7 +150,7 @@ function getSnapLatLng(map, latlng, store, options, additionalPoints = [], skipL
|
|
|
125
150
|
}
|
|
126
151
|
});
|
|
127
152
|
});
|
|
128
|
-
|
|
153
|
+
verifiedAdditionalPoints.forEach((p) => {
|
|
129
154
|
const containerPoint = map.latLngToContainerPoint(p);
|
|
130
155
|
const dist = basePoint.distanceTo(containerPoint);
|
|
131
156
|
if (dist < minDistance) {
|
|
@@ -397,7 +422,7 @@ var DrawMarkerMode = class {
|
|
|
397
422
|
}
|
|
398
423
|
onClick(e) {
|
|
399
424
|
const latlng = this.store ? getSnapLatLng(this.map, e.latlng, this.store, this.options) : e.latlng;
|
|
400
|
-
const marker4 = L5.marker(latlng).addTo(this.map);
|
|
425
|
+
const marker4 = L5.marker(latlng, this.options.vertexOptions).addTo(this.map);
|
|
401
426
|
this.map.fire(ANVIL_EVENTS.CREATED, { layer: marker4 });
|
|
402
427
|
}
|
|
403
428
|
};
|
|
@@ -1064,27 +1089,41 @@ var DragMode = class {
|
|
|
1064
1089
|
this.map = map;
|
|
1065
1090
|
this.store = store;
|
|
1066
1091
|
this.options = options;
|
|
1092
|
+
__publicField(this, "isEnabled", false);
|
|
1067
1093
|
__publicField(this, "draggingLayer", null);
|
|
1068
1094
|
__publicField(this, "startLatLng", null);
|
|
1069
1095
|
__publicField(this, "initialLatLngs", null);
|
|
1096
|
+
this.store.getGroup().on("layeradd", (e) => {
|
|
1097
|
+
if (this.isEnabled) {
|
|
1098
|
+
this.addLayerListener(e.layer);
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1070
1101
|
}
|
|
1071
1102
|
enable() {
|
|
1103
|
+
this.isEnabled = true;
|
|
1072
1104
|
this.store.getGroup().eachLayer((layer) => {
|
|
1073
|
-
|
|
1074
|
-
layer.on("mousedown", this.onMouseDown, this);
|
|
1075
|
-
layer.getElement()?.style.setProperty("cursor", "move");
|
|
1076
|
-
}
|
|
1105
|
+
this.addLayerListener(layer);
|
|
1077
1106
|
});
|
|
1078
1107
|
}
|
|
1079
1108
|
disable() {
|
|
1109
|
+
this.isEnabled = false;
|
|
1080
1110
|
this.store.getGroup().eachLayer((layer) => {
|
|
1081
|
-
|
|
1082
|
-
layer.off("mousedown", this.onMouseDown, this);
|
|
1083
|
-
layer.getElement()?.style.setProperty("cursor", "");
|
|
1084
|
-
}
|
|
1111
|
+
this.removeLayerListener(layer);
|
|
1085
1112
|
});
|
|
1086
1113
|
this.stopDragging();
|
|
1087
1114
|
}
|
|
1115
|
+
addLayerListener(layer) {
|
|
1116
|
+
if (layer instanceof L13.Path || layer instanceof L13.Marker) {
|
|
1117
|
+
layer.on("mousedown", this.onMouseDown, this);
|
|
1118
|
+
layer.getElement()?.style.setProperty("cursor", "move");
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
removeLayerListener(layer) {
|
|
1122
|
+
if (layer instanceof L13.Path || layer instanceof L13.Marker) {
|
|
1123
|
+
layer.off("mousedown", this.onMouseDown, this);
|
|
1124
|
+
layer.getElement()?.style.setProperty("cursor", "");
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1088
1127
|
onMouseDown(e) {
|
|
1089
1128
|
L13.DomEvent.stopPropagation(e);
|
|
1090
1129
|
const layer = e.target;
|
|
@@ -1869,23 +1908,37 @@ var DeleteMode = class {
|
|
|
1869
1908
|
constructor(map, store) {
|
|
1870
1909
|
this.map = map;
|
|
1871
1910
|
this.store = store;
|
|
1911
|
+
__publicField(this, "isEnabled", false);
|
|
1912
|
+
this.store.getGroup().on("layeradd", (e) => {
|
|
1913
|
+
if (this.isEnabled) {
|
|
1914
|
+
this.addLayerListener(e.layer);
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1872
1917
|
}
|
|
1873
1918
|
enable() {
|
|
1919
|
+
this.isEnabled = true;
|
|
1874
1920
|
this.store.getGroup().eachLayer((layer) => {
|
|
1875
|
-
|
|
1876
|
-
if (layer instanceof L19.Path || layer instanceof L19.Marker) {
|
|
1877
|
-
layer.getElement()?.style.setProperty("cursor", "pointer");
|
|
1878
|
-
}
|
|
1921
|
+
this.addLayerListener(layer);
|
|
1879
1922
|
});
|
|
1880
1923
|
}
|
|
1881
1924
|
disable() {
|
|
1925
|
+
this.isEnabled = false;
|
|
1882
1926
|
this.store.getGroup().eachLayer((layer) => {
|
|
1883
|
-
|
|
1884
|
-
if (layer instanceof L19.Path || layer instanceof L19.Marker) {
|
|
1885
|
-
layer.getElement()?.style.setProperty("cursor", "");
|
|
1886
|
-
}
|
|
1927
|
+
this.removeLayerListener(layer);
|
|
1887
1928
|
});
|
|
1888
1929
|
}
|
|
1930
|
+
addLayerListener(layer) {
|
|
1931
|
+
layer.on("click", this.onClick, this);
|
|
1932
|
+
if (layer instanceof L19.Path || layer instanceof L19.Marker) {
|
|
1933
|
+
layer.getElement()?.style.setProperty("cursor", "pointer");
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
removeLayerListener(layer) {
|
|
1937
|
+
layer.off("click", this.onClick, this);
|
|
1938
|
+
if (layer instanceof L19.Path || layer instanceof L19.Marker) {
|
|
1939
|
+
layer.getElement()?.style.setProperty("cursor", "");
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1889
1942
|
onClick(e) {
|
|
1890
1943
|
L19.DomEvent.stopPropagation(e);
|
|
1891
1944
|
const layer = e.target;
|
|
@@ -1914,50 +1967,8 @@ var LayerStore = class {
|
|
|
1914
1967
|
getGroup() {
|
|
1915
1968
|
return this.group;
|
|
1916
1969
|
}
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
// src/anvil.ts
|
|
1920
|
-
var Anvil = class {
|
|
1921
|
-
constructor(map, options) {
|
|
1922
|
-
this.map = map;
|
|
1923
|
-
__publicField(this, "modeManager");
|
|
1924
|
-
__publicField(this, "store");
|
|
1925
|
-
__publicField(this, "options");
|
|
1926
|
-
this.options = { snapping: false, snapDistance: 10, preventSelfIntersection: false, ...options };
|
|
1927
|
-
this.store = new LayerStore(map, this.options.layerGroup);
|
|
1928
|
-
this.modeManager = new ModeManager(map);
|
|
1929
|
-
this.modeManager.addMode("draw:polygon", new DrawPolygonMode(this.map, this.options, this.store));
|
|
1930
|
-
this.modeManager.addMode("draw:polyline", new DrawPolylineMode(this.map, this.options, this.store));
|
|
1931
|
-
this.modeManager.addMode("draw:marker", new DrawMarkerMode(this.map, this.options, this.store));
|
|
1932
|
-
this.modeManager.addMode("draw:rectangle", new DrawRectangleMode(this.map, this.options, this.store));
|
|
1933
|
-
this.modeManager.addMode("draw:square", new DrawSquareMode(this.map, this.options, this.store));
|
|
1934
|
-
this.modeManager.addMode("draw:triangle", new DrawTriangleMode(this.map, this.options, this.store));
|
|
1935
|
-
this.modeManager.addMode("draw:circle", new DrawCircleMode(this.map, this.options, this.store));
|
|
1936
|
-
this.modeManager.addMode("draw:freehand", new FreehandMode(this.map, this.store, this.options));
|
|
1937
|
-
this.modeManager.addMode("cut", new CutMode(map, this.store, this.options));
|
|
1938
|
-
this.modeManager.addMode("split", new SplitMode(map, this.store, this.options));
|
|
1939
|
-
this.modeManager.addMode("union", new UnionMode(map, this.store, this.options));
|
|
1940
|
-
this.modeManager.addMode("subtract", new SubtractMode(map, this.store, this.options));
|
|
1941
|
-
this.modeManager.addMode("drag", new DragMode(map, this.store, this.options));
|
|
1942
|
-
this.modeManager.addMode("scale", new ScaleMode(map, this.store, this.options));
|
|
1943
|
-
this.modeManager.addMode("rotate", new RotateMode(map, this.store, this.options));
|
|
1944
|
-
this.modeManager.addMode("edit", new EditMode(this.map, this.store, this.options));
|
|
1945
|
-
this.modeManager.addMode("delete", new DeleteMode(map, this.store));
|
|
1946
|
-
this.map.on(ANVIL_EVENTS.CREATED, (e) => {
|
|
1947
|
-
this.store.addLayer(e.layer);
|
|
1948
|
-
});
|
|
1949
|
-
this.map.on(ANVIL_EVENTS.DELETED, (e) => {
|
|
1950
|
-
this.store.removeLayer(e.layer);
|
|
1951
|
-
});
|
|
1952
|
-
}
|
|
1953
|
-
enable(mode) {
|
|
1954
|
-
this.modeManager.enable(mode);
|
|
1955
|
-
}
|
|
1956
|
-
disable() {
|
|
1957
|
-
this.modeManager.disable();
|
|
1958
|
-
}
|
|
1959
|
-
getLayerGroup() {
|
|
1960
|
-
return this.store.getGroup();
|
|
1970
|
+
getLayers() {
|
|
1971
|
+
return this.group.getLayers();
|
|
1961
1972
|
}
|
|
1962
1973
|
};
|
|
1963
1974
|
|
|
@@ -1966,101 +1977,133 @@ var L21 = __toESM(require("leaflet"));
|
|
|
1966
1977
|
var SVG_ATTRS = 'xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"';
|
|
1967
1978
|
var ICONS = {
|
|
1968
1979
|
// Marker: Map-Pin mit Punkt in der Mitte
|
|
1969
|
-
"
|
|
1980
|
+
["marker" /* Marker */]: `<svg ${SVG_ATTRS}><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z"/><circle cx="12" cy="10" r="3"/></svg>`,
|
|
1970
1981
|
// Polyline: Kurvige Route mit Endpunkten
|
|
1971
|
-
"
|
|
1982
|
+
["polyline" /* Polyline */]: `<svg ${SVG_ATTRS}><path d="M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15"/><circle cx="18" cy="5" r="3"/><circle cx="6" cy="19" r="3"/></svg>`,
|
|
1972
1983
|
// Polygon: Klassische unregelmäßige 5-Eck-Form
|
|
1973
|
-
"
|
|
1984
|
+
["polygon" /* Polygon */]: `<svg ${SVG_ATTRS}><path d="m12 2 10 7-3 12H5l-3-12Z"/></svg>`,
|
|
1974
1985
|
// Rectangle: Horizontales Rechteck
|
|
1975
|
-
"
|
|
1986
|
+
["rectangle" /* Rectangle */]: `<svg ${SVG_ATTRS}><rect width="20" height="12" x="2" y="6" rx="2"/></svg>`,
|
|
1976
1987
|
// Square: Quadratisches Rechteck (1:1)
|
|
1977
|
-
"
|
|
1988
|
+
["square" /* Square */]: `<svg ${SVG_ATTRS}><rect width="18" height="18" x="3" y="3" rx="2"/></svg>`,
|
|
1978
1989
|
// Triangle: Gleichschenkliges Dreieck
|
|
1979
|
-
"
|
|
1990
|
+
["triangle" /* Triangle */]: `<svg ${SVG_ATTRS}><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/></svg>`,
|
|
1980
1991
|
// Circle: Klassischer Kreis
|
|
1981
|
-
"
|
|
1992
|
+
["circle" /* Circle */]: `<svg ${SVG_ATTRS}><circle cx="12" cy="12" r="10"/></svg>`,
|
|
1982
1993
|
// Freehand: Geschwungene Signatur-Linie
|
|
1983
|
-
"
|
|
1994
|
+
["freehand" /* Freehand */]: `<svg ${SVG_ATTRS}><path d="m3 16 2 2 16-16"/><path d="M7 21h14"/><path d="M3 11c0 2 2 2 2 2z"/></svg>`,
|
|
1984
1995
|
// Cut: Offene Schere
|
|
1985
|
-
"cut": `<svg ${SVG_ATTRS}><circle cx="6" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M20 4 8.12 15.88"/><path d="M14.47 14.48 20 20"/><path d="M8.12 8.12 12 12"/></svg>`,
|
|
1996
|
+
["cut" /* Cut */]: `<svg ${SVG_ATTRS}><circle cx="6" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M20 4 8.12 15.88"/><path d="M14.47 14.48 20 20"/><path d="M8.12 8.12 12 12"/></svg>`,
|
|
1986
1997
|
// Split: Linie, die eine Form teilt
|
|
1987
|
-
"split": `<svg ${SVG_ATTRS}><path d="M3 12h18"/><path d="M8 3v18"/><path d="M16 3v18"/><rect width="18" height="18" x="3" y="3" rx="2" stroke-dasharray="4 4" opacity="0.5"/></svg>`,
|
|
1998
|
+
["split" /* Split */]: `<svg ${SVG_ATTRS}><path d="M3 12h18"/><path d="M8 3v18"/><path d="M16 3v18"/><rect width="18" height="18" x="3" y="3" rx="2" stroke-dasharray="4 4" opacity="0.5"/></svg>`,
|
|
1988
1999
|
// Union: Zwei verschmolzene Rechtecke
|
|
1989
|
-
"union": `<svg ${SVG_ATTRS}><path d="M8 4H4v4"/><path d="M4 12v4a2 2 0 0 0 2 2h4"/><path d="M14 18h4v-4"/><path d="M20 10V6a2 2 0 0 0-2-2h-4"/><path d="M14 10h-4v4" stroke-dasharray="2 2"/></svg>`,
|
|
2000
|
+
["union" /* Union */]: `<svg ${SVG_ATTRS}><path d="M8 4H4v4"/><path d="M4 12v4a2 2 0 0 0 2 2h4"/><path d="M14 18h4v-4"/><path d="M20 10V6a2 2 0 0 0-2-2h-4"/><path d="M14 10h-4v4" stroke-dasharray="2 2"/></svg>`,
|
|
1990
2001
|
// Subtract: Hauptform mit "ausgeschnittenem" Bereich (Minus-Metapher)
|
|
1991
|
-
"subtract": `<svg ${SVG_ATTRS}><path d="M4 4h16v16H4z"/><path d="M10 10h10v10H10z" stroke-dasharray="2 2" opacity="0.7"/><path d="M15 6h-6"/></svg>`,
|
|
2002
|
+
["subtract" /* Subtract */]: `<svg ${SVG_ATTRS}><path d="M4 4h16v16H4z"/><path d="M10 10h10v10H10z" stroke-dasharray="2 2" opacity="0.7"/><path d="M15 6h-6"/></svg>`,
|
|
1992
2003
|
// Drag: Vier-Wege-Pfeil (Move-Metapher)
|
|
1993
|
-
"drag": `<svg ${SVG_ATTRS}><path d="m5 9-3 3 3 3"/><path d="m9 5 3-3 3 3"/><path d="m15 19 3 3 3-3"/><path d="m19 9 3 3-3 3"/><path d="M2 12h20"/><path d="M12 2v20"/></svg>`,
|
|
2004
|
+
["drag" /* Drag */]: `<svg ${SVG_ATTRS}><path d="m5 9-3 3 3 3"/><path d="m9 5 3-3 3 3"/><path d="m15 19 3 3 3-3"/><path d="m19 9 3 3-3 3"/><path d="M2 12h20"/><path d="M12 2v20"/></svg>`,
|
|
1994
2005
|
// Scale: Diagonal-Pfeile (Maximize-Metapher)
|
|
1995
|
-
"scale": `<svg ${SVG_ATTRS}><path d="M15 3h6v6"/><path d="M9 21H3v-6"/><path d="M21 3 14 10"/><path d="M3 21l7-7"/></svg>`,
|
|
2006
|
+
["scale" /* Scale */]: `<svg ${SVG_ATTRS}><path d="M15 3h6v6"/><path d="M9 21H3v-6"/><path d="M21 3 14 10"/><path d="M3 21l7-7"/></svg>`,
|
|
1996
2007
|
// Rotate: Kreispfeil mit Ziel-Icon
|
|
1997
|
-
"rotate": `<svg ${SVG_ATTRS}><path d="M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/></svg>`,
|
|
2008
|
+
["rotate" /* Rotate */]: `<svg ${SVG_ATTRS}><path d="M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/></svg>`,
|
|
1998
2009
|
// Edit: Stift, der über einen Pfad zeichnet
|
|
1999
|
-
"edit": `<svg ${SVG_ATTRS}><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>`,
|
|
2010
|
+
["edit" /* Edit */]: `<svg ${SVG_ATTRS}><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>`,
|
|
2000
2011
|
// Delete: Mülleimer mit Deckel und Schlitzen
|
|
2001
|
-
"delete": `<svg ${SVG_ATTRS}><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg>`,
|
|
2012
|
+
["delete" /* Delete */]: `<svg ${SVG_ATTRS}><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg>`,
|
|
2002
2013
|
// Off: Durchgestrichener Kreis (Power-Off/Disable Metapher)
|
|
2003
|
-
"off": `<svg ${SVG_ATTRS}><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>`
|
|
2014
|
+
["off" /* Off */]: `<svg ${SVG_ATTRS}><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>`
|
|
2004
2015
|
};
|
|
2005
2016
|
var AnvilControl = class extends L21.Control {
|
|
2006
2017
|
constructor(anvil, options) {
|
|
2007
2018
|
super(L21.Util.extend({ position: "topleft" }, options));
|
|
2008
2019
|
__publicField(this, "_btns", {});
|
|
2009
2020
|
__publicField(this, "_anvil");
|
|
2021
|
+
__publicField(this, "_options");
|
|
2010
2022
|
this._anvil = anvil;
|
|
2023
|
+
this._options = { ...options };
|
|
2011
2024
|
}
|
|
2012
2025
|
onAdd(map) {
|
|
2013
2026
|
console.log("AnvilControl: triggering onAdd");
|
|
2014
|
-
const container = L21.DomUtil.create("div", "
|
|
2015
|
-
container.style.backgroundColor = "white";
|
|
2027
|
+
const container = L21.DomUtil.create("div", "anvil-toolbar-container");
|
|
2016
2028
|
container.style.display = "flex";
|
|
2017
2029
|
container.style.flexDirection = "column";
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
{ id: "
|
|
2021
|
-
{ id: "
|
|
2022
|
-
{ id: "
|
|
2023
|
-
{ id: "
|
|
2024
|
-
{ id: "
|
|
2025
|
-
{ id: "
|
|
2026
|
-
{ id: "
|
|
2027
|
-
{ id: "
|
|
2028
|
-
{ id: "
|
|
2029
|
-
{ id: "
|
|
2030
|
-
{ id: "
|
|
2031
|
-
{ id: "
|
|
2032
|
-
{ id: "
|
|
2033
|
-
{ id: "
|
|
2034
|
-
{ id: "
|
|
2035
|
-
{ id: "
|
|
2036
|
-
{ id: "
|
|
2030
|
+
container.style.gap = "10px";
|
|
2031
|
+
const allModeConfigs = [
|
|
2032
|
+
{ id: "marker" /* Marker */, title: "Marker" },
|
|
2033
|
+
{ id: "polyline" /* Polyline */, title: "Line" },
|
|
2034
|
+
{ id: "polygon" /* Polygon */, title: "Polygon" },
|
|
2035
|
+
{ id: "rectangle" /* Rectangle */, title: "Rectangle" },
|
|
2036
|
+
{ id: "square" /* Square */, title: "Square" },
|
|
2037
|
+
{ id: "triangle" /* Triangle */, title: "Triangle" },
|
|
2038
|
+
{ id: "circle" /* Circle */, title: "Circle" },
|
|
2039
|
+
{ id: "freehand" /* Freehand */, title: "Freehand" },
|
|
2040
|
+
{ id: "cut" /* Cut */, title: "Cut" },
|
|
2041
|
+
{ id: "split" /* Split */, title: "Split" },
|
|
2042
|
+
{ id: "union" /* Union */, title: "Union" },
|
|
2043
|
+
{ id: "subtract" /* Subtract */, title: "Subtract" },
|
|
2044
|
+
{ id: "drag" /* Drag */, title: "Drag" },
|
|
2045
|
+
{ id: "scale" /* Scale */, title: "Scale" },
|
|
2046
|
+
{ id: "rotate" /* Rotate */, title: "Rotate" },
|
|
2047
|
+
{ id: "edit" /* Edit */, title: "Edit" },
|
|
2048
|
+
{ id: "delete" /* Delete */, title: "Delete" }
|
|
2037
2049
|
];
|
|
2038
|
-
modes.
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2050
|
+
const modesInput = this._options.modes || allModeConfigs.map((m) => m.id);
|
|
2051
|
+
const blocks = Array.isArray(modesInput[0]) ? modesInput : [modesInput];
|
|
2052
|
+
blocks.forEach((block, index) => {
|
|
2053
|
+
const group = L21.DomUtil.create("div", "leaflet-bar anvil-toolbar-group", container);
|
|
2054
|
+
group.style.display = "flex";
|
|
2055
|
+
group.style.flexDirection = "column";
|
|
2056
|
+
group.style.backgroundColor = "white";
|
|
2057
|
+
block.forEach((modeId) => {
|
|
2058
|
+
const config = allModeConfigs.find((c) => c.id === modeId);
|
|
2059
|
+
if (!config && modeId !== "off" /* Off */) return;
|
|
2060
|
+
const id = modeId;
|
|
2061
|
+
const title = config ? config.title : "Turn Off";
|
|
2062
|
+
const btn = L21.DomUtil.create("a", "anvil-control-btn", group);
|
|
2063
|
+
btn.innerHTML = ICONS[id] || title;
|
|
2064
|
+
btn.href = "#";
|
|
2065
|
+
btn.title = title;
|
|
2066
|
+
btn.style.display = "flex";
|
|
2067
|
+
btn.style.alignItems = "center";
|
|
2068
|
+
btn.style.justifyContent = "center";
|
|
2069
|
+
btn.style.width = "30px";
|
|
2070
|
+
btn.style.height = "30px";
|
|
2071
|
+
btn.style.color = "#333";
|
|
2072
|
+
btn.style.cursor = "pointer";
|
|
2073
|
+
L21.DomEvent.disableClickPropagation(btn);
|
|
2074
|
+
L21.DomEvent.on(btn, "click", (e) => {
|
|
2075
|
+
L21.DomEvent.preventDefault(e);
|
|
2076
|
+
if (id === "off" /* Off */) {
|
|
2077
|
+
this._anvil.disable();
|
|
2078
|
+
} else {
|
|
2079
|
+
this._anvil.enable(id);
|
|
2080
|
+
}
|
|
2081
|
+
});
|
|
2082
|
+
this._btns[id] = btn;
|
|
2058
2083
|
});
|
|
2059
|
-
this._btns[
|
|
2084
|
+
if (index === blocks.length - 1 && !this._btns["off" /* Off */]) {
|
|
2085
|
+
const offBtn = L21.DomUtil.create("a", "anvil-control-btn", group);
|
|
2086
|
+
offBtn.innerHTML = ICONS["off" /* Off */];
|
|
2087
|
+
offBtn.href = "#";
|
|
2088
|
+
offBtn.title = "Turn Off";
|
|
2089
|
+
offBtn.style.display = "flex";
|
|
2090
|
+
offBtn.style.alignItems = "center";
|
|
2091
|
+
offBtn.style.justifyContent = "center";
|
|
2092
|
+
offBtn.style.width = "30px";
|
|
2093
|
+
offBtn.style.height = "30px";
|
|
2094
|
+
offBtn.style.color = "#333";
|
|
2095
|
+
offBtn.style.cursor = "pointer";
|
|
2096
|
+
L21.DomEvent.disableClickPropagation(offBtn);
|
|
2097
|
+
L21.DomEvent.on(offBtn, "click", (e) => {
|
|
2098
|
+
L21.DomEvent.preventDefault(e);
|
|
2099
|
+
this._anvil.disable();
|
|
2100
|
+
});
|
|
2101
|
+
this._btns["off" /* Off */] = offBtn;
|
|
2102
|
+
}
|
|
2060
2103
|
});
|
|
2061
2104
|
const updateFn = (m) => {
|
|
2062
2105
|
for (const id in this._btns) {
|
|
2063
|
-
const active = id === m || id === "off" && !m;
|
|
2106
|
+
const active = id === m || id === "off" /* Off */ && !m;
|
|
2064
2107
|
this._btns[id].style.backgroundColor = active ? "#eee" : "#fff";
|
|
2065
2108
|
}
|
|
2066
2109
|
};
|
|
@@ -2073,6 +2116,99 @@ function anvilControl(anvil, options) {
|
|
|
2073
2116
|
return new AnvilControl(anvil, options);
|
|
2074
2117
|
}
|
|
2075
2118
|
|
|
2119
|
+
// src/anvil.ts
|
|
2120
|
+
var Anvil = class {
|
|
2121
|
+
constructor(map, options) {
|
|
2122
|
+
this.map = map;
|
|
2123
|
+
__publicField(this, "modeManager");
|
|
2124
|
+
__publicField(this, "store");
|
|
2125
|
+
__publicField(this, "options");
|
|
2126
|
+
__publicField(this, "control");
|
|
2127
|
+
this.options = {
|
|
2128
|
+
snapping: false,
|
|
2129
|
+
snapDistance: 10,
|
|
2130
|
+
preventSelfIntersection: false,
|
|
2131
|
+
controlPosition: "topleft",
|
|
2132
|
+
...options
|
|
2133
|
+
};
|
|
2134
|
+
this.store = new LayerStore(map, this.options.layerGroup);
|
|
2135
|
+
this.modeManager = new ModeManager(map);
|
|
2136
|
+
const modesFromOptions = this.options.modes || Object.values(AnvilMode);
|
|
2137
|
+
const flattenedModes = modesFromOptions.flat();
|
|
2138
|
+
if (flattenedModes.includes("polygon" /* Polygon */)) {
|
|
2139
|
+
this.modeManager.addMode("polygon" /* Polygon */, new DrawPolygonMode(this.map, this.options, this.store));
|
|
2140
|
+
}
|
|
2141
|
+
if (flattenedModes.includes("polyline" /* Polyline */)) {
|
|
2142
|
+
this.modeManager.addMode("polyline" /* Polyline */, new DrawPolylineMode(this.map, this.options, this.store));
|
|
2143
|
+
}
|
|
2144
|
+
if (flattenedModes.includes("marker" /* Marker */)) {
|
|
2145
|
+
this.modeManager.addMode("marker" /* Marker */, new DrawMarkerMode(this.map, this.options, this.store));
|
|
2146
|
+
}
|
|
2147
|
+
if (flattenedModes.includes("rectangle" /* Rectangle */)) {
|
|
2148
|
+
this.modeManager.addMode("rectangle" /* Rectangle */, new DrawRectangleMode(this.map, this.options, this.store));
|
|
2149
|
+
}
|
|
2150
|
+
if (flattenedModes.includes("square" /* Square */)) {
|
|
2151
|
+
this.modeManager.addMode("square" /* Square */, new DrawSquareMode(this.map, this.options, this.store));
|
|
2152
|
+
}
|
|
2153
|
+
if (flattenedModes.includes("triangle" /* Triangle */)) {
|
|
2154
|
+
this.modeManager.addMode("triangle" /* Triangle */, new DrawTriangleMode(this.map, this.options, this.store));
|
|
2155
|
+
}
|
|
2156
|
+
if (flattenedModes.includes("circle" /* Circle */)) {
|
|
2157
|
+
this.modeManager.addMode("circle" /* Circle */, new DrawCircleMode(this.map, this.options, this.store));
|
|
2158
|
+
}
|
|
2159
|
+
if (flattenedModes.includes("freehand" /* Freehand */)) {
|
|
2160
|
+
this.modeManager.addMode("freehand" /* Freehand */, new FreehandMode(this.map, this.store, this.options));
|
|
2161
|
+
}
|
|
2162
|
+
if (flattenedModes.includes("cut" /* Cut */)) {
|
|
2163
|
+
this.modeManager.addMode("cut" /* Cut */, new CutMode(map, this.store, this.options));
|
|
2164
|
+
}
|
|
2165
|
+
if (flattenedModes.includes("split" /* Split */)) {
|
|
2166
|
+
this.modeManager.addMode("split" /* Split */, new SplitMode(map, this.store, this.options));
|
|
2167
|
+
}
|
|
2168
|
+
if (flattenedModes.includes("union" /* Union */)) {
|
|
2169
|
+
this.modeManager.addMode("union" /* Union */, new UnionMode(map, this.store, this.options));
|
|
2170
|
+
}
|
|
2171
|
+
if (flattenedModes.includes("subtract" /* Subtract */)) {
|
|
2172
|
+
this.modeManager.addMode("subtract" /* Subtract */, new SubtractMode(map, this.store, this.options));
|
|
2173
|
+
}
|
|
2174
|
+
if (flattenedModes.includes("drag" /* Drag */)) {
|
|
2175
|
+
this.modeManager.addMode("drag" /* Drag */, new DragMode(map, this.store, this.options));
|
|
2176
|
+
}
|
|
2177
|
+
if (flattenedModes.includes("scale" /* Scale */)) {
|
|
2178
|
+
this.modeManager.addMode("scale" /* Scale */, new ScaleMode(map, this.store, this.options));
|
|
2179
|
+
}
|
|
2180
|
+
if (flattenedModes.includes("rotate" /* Rotate */)) {
|
|
2181
|
+
this.modeManager.addMode("rotate" /* Rotate */, new RotateMode(map, this.store, this.options));
|
|
2182
|
+
}
|
|
2183
|
+
if (flattenedModes.includes("edit" /* Edit */)) {
|
|
2184
|
+
this.modeManager.addMode("edit" /* Edit */, new EditMode(this.map, this.store, this.options));
|
|
2185
|
+
}
|
|
2186
|
+
if (flattenedModes.includes("delete" /* Delete */)) {
|
|
2187
|
+
this.modeManager.addMode("delete" /* Delete */, new DeleteMode(map, this.store));
|
|
2188
|
+
}
|
|
2189
|
+
this.map.on(ANVIL_EVENTS.CREATED, (e) => {
|
|
2190
|
+
this.store.addLayer(e.layer);
|
|
2191
|
+
});
|
|
2192
|
+
this.map.on(ANVIL_EVENTS.DELETED, (e) => {
|
|
2193
|
+
this.store.removeLayer(e.layer);
|
|
2194
|
+
});
|
|
2195
|
+
this.control = anvilControl(this, {
|
|
2196
|
+
position: this.options.controlPosition,
|
|
2197
|
+
modes: modesFromOptions
|
|
2198
|
+
});
|
|
2199
|
+
this.control?.addTo(this.map);
|
|
2200
|
+
}
|
|
2201
|
+
enable(mode) {
|
|
2202
|
+
this.modeManager.enable(mode);
|
|
2203
|
+
}
|
|
2204
|
+
disable() {
|
|
2205
|
+
this.modeManager.disable();
|
|
2206
|
+
}
|
|
2207
|
+
getLayerGroup() {
|
|
2208
|
+
return this.store.getGroup();
|
|
2209
|
+
}
|
|
2210
|
+
};
|
|
2211
|
+
|
|
2076
2212
|
// src/index.ts
|
|
2077
2213
|
var leaflet = L22;
|
|
2078
2214
|
leaflet.Anvil = Anvil;
|
|
@@ -2086,5 +2222,6 @@ if (leaflet.Control) {
|
|
|
2086
2222
|
ANVIL_EVENTS,
|
|
2087
2223
|
Anvil,
|
|
2088
2224
|
AnvilControl,
|
|
2225
|
+
AnvilMode,
|
|
2089
2226
|
anvilControl
|
|
2090
2227
|
});
|