@element-editor/adapter-maplibre 0.0.0-stage → 0.2.1
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/AGENTS.md +119 -0
- package/LICENSE +21 -0
- package/README.md +82 -2
- package/basemaps/sprite.json +1 -0
- package/basemaps/sprite.png +0 -0
- package/basemaps/sprite@2x.json +1 -0
- package/basemaps/sprite@2x.png +0 -0
- package/basemaps/thumbs/dark.webp +0 -0
- package/basemaps/thumbs/light.webp +0 -0
- package/basemaps/thumbs/osm.webp +0 -0
- package/basemaps/thumbs/streets.webp +0 -0
- package/basemaps/thumbs/terrain.webp +0 -0
- package/dist/adapter-maplibre.css +1 -0
- package/dist/basemapIds-2GdXIJS1.cjs +1 -0
- package/dist/basemapIds-CVTxeXkr.js +11 -0
- package/dist/basemaps.cjs +1 -0
- package/dist/basemaps.d.cts +2 -0
- package/dist/basemaps.d.ts +2 -0
- package/dist/basemaps.es.js +10 -0
- package/dist/catalog-Cnqi23GZ.cjs +1 -0
- package/dist/catalog-gI-xABuu.js +10 -0
- package/dist/dark-C5d5FijX.cjs +1 -0
- package/dist/dark-CcJT_yHE.js +13 -0
- package/dist/index.cjs +26 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.es.js +3792 -0
- package/dist/light-Cf5tUOoP.js +13 -0
- package/dist/light-DCtd1z4V.cjs +1 -0
- package/dist/src/BasemapControl.d.cts +47 -0
- package/dist/src/BasemapControl.d.ts +47 -0
- package/dist/src/ElementEditorControls.d.cts +113 -0
- package/dist/src/ElementEditorControls.d.ts +113 -0
- package/dist/src/basemapIds.d.cts +10 -0
- package/dist/src/basemapIds.d.ts +10 -0
- package/dist/src/basemaps/catalog.d.cts +7 -0
- package/dist/src/basemaps/catalog.d.ts +7 -0
- package/dist/src/basemaps/index.d.cts +3 -0
- package/dist/src/basemaps/index.d.ts +3 -0
- package/dist/src/basemaps/style.d.cts +61 -0
- package/dist/src/basemaps/style.d.ts +61 -0
- package/dist/src/components/BoundaryLayer.d.cts +11 -0
- package/dist/src/components/BoundaryLayer.d.ts +11 -0
- package/dist/src/components/BoxSelectHandler.d.cts +13 -0
- package/dist/src/components/BoxSelectHandler.d.ts +13 -0
- package/dist/src/components/DrawingLayer.d.cts +8 -0
- package/dist/src/components/DrawingLayer.d.ts +8 -0
- package/dist/src/components/DrawingPreviewLayer.d.cts +8 -0
- package/dist/src/components/DrawingPreviewLayer.d.ts +8 -0
- package/dist/src/components/FeatureInteractionLayer.d.cts +8 -0
- package/dist/src/components/FeatureInteractionLayer.d.ts +8 -0
- package/dist/src/components/FeatureLayer.d.cts +15 -0
- package/dist/src/components/FeatureLayer.d.ts +15 -0
- package/dist/src/components/GeometryProcessingPreview.d.cts +8 -0
- package/dist/src/components/GeometryProcessingPreview.d.ts +8 -0
- package/dist/src/components/MeasurePreviewLayer.d.cts +9 -0
- package/dist/src/components/MeasurePreviewLayer.d.ts +9 -0
- package/dist/src/components/MeasurementTooltip.d.cts +6 -0
- package/dist/src/components/MeasurementTooltip.d.ts +6 -0
- package/dist/src/components/OsmTraceHandler.d.cts +8 -0
- package/dist/src/components/OsmTraceHandler.d.ts +8 -0
- package/dist/src/components/PreciseCoordsOverlay.d.cts +10 -0
- package/dist/src/components/PreciseCoordsOverlay.d.ts +10 -0
- package/dist/src/components/SnapController.d.cts +9 -0
- package/dist/src/components/SnapController.d.ts +9 -0
- package/dist/src/components/TextEditOverlay.d.cts +9 -0
- package/dist/src/components/TextEditOverlay.d.ts +9 -0
- package/dist/src/components/TransformControls.d.cts +8 -0
- package/dist/src/components/TransformControls.d.ts +8 -0
- package/dist/src/components/VertexEditor.d.cts +15 -0
- package/dist/src/components/VertexEditor.d.ts +15 -0
- package/dist/src/contexts/FeatureStyleContext.d.cts +9 -0
- package/dist/src/contexts/FeatureStyleContext.d.ts +9 -0
- package/dist/src/contexts/MapControllerContext.d.cts +2 -0
- package/dist/src/contexts/MapControllerContext.d.ts +2 -0
- package/dist/src/contexts/StyleEpochContext.d.cts +7 -0
- package/dist/src/contexts/StyleEpochContext.d.ts +7 -0
- package/dist/src/elementLayers.d.cts +17 -0
- package/dist/src/elementLayers.d.ts +17 -0
- package/dist/src/hooks/lastPointer.d.cts +18 -0
- package/dist/src/hooks/lastPointer.d.ts +18 -0
- package/dist/src/hooks/useCursorWhileMode.d.cts +20 -0
- package/dist/src/hooks/useCursorWhileMode.d.ts +20 -0
- package/dist/src/hooks/useModifierDragCursor.d.cts +8 -0
- package/dist/src/hooks/useModifierDragCursor.d.ts +8 -0
- package/dist/src/index.d.cts +30 -0
- package/dist/src/index.d.ts +30 -0
- package/dist/src/store/StoreContext.d.cts +1 -0
- package/dist/src/store/StoreContext.d.ts +1 -0
- package/dist/src/utils/accentPaint.d.cts +13 -0
- package/dist/src/utils/accentPaint.d.ts +13 -0
- package/dist/src/utils/boxSelect.d.cts +4 -0
- package/dist/src/utils/boxSelect.d.ts +4 -0
- package/dist/src/utils/darkStyle.d.cts +8 -0
- package/dist/src/utils/darkStyle.d.ts +8 -0
- package/dist/src/utils/featureTooltip.d.cts +16 -0
- package/dist/src/utils/featureTooltip.d.ts +16 -0
- package/dist/src/utils/findPartAtPoint.d.cts +2 -0
- package/dist/src/utils/findPartAtPoint.d.ts +2 -0
- package/dist/src/utils/freehandCommitFlag.d.cts +2 -0
- package/dist/src/utils/freehandCommitFlag.d.ts +2 -0
- package/dist/src/utils/freshFeature.d.cts +3 -0
- package/dist/src/utils/freshFeature.d.ts +3 -0
- package/dist/src/utils/geojson.d.cts +10 -0
- package/dist/src/utils/geojson.d.ts +10 -0
- package/dist/src/utils/liveFeatureSource.d.cts +6 -0
- package/dist/src/utils/liveFeatureSource.d.ts +6 -0
- package/dist/src/utils/measureClickFlag.d.cts +2 -0
- package/dist/src/utils/measureClickFlag.d.ts +2 -0
- package/dist/src/utils/modifierDragFlag.d.cts +2 -0
- package/dist/src/utils/modifierDragFlag.d.ts +2 -0
- package/dist/src/utils/rafThrottle.d.cts +11 -0
- package/dist/src/utils/rafThrottle.d.ts +11 -0
- package/dist/src/utils/snapping.d.cts +25 -0
- package/dist/src/utils/snapping.d.ts +25 -0
- package/dist/src/utils/toolCursor.d.cts +3 -0
- package/dist/src/utils/toolCursor.d.ts +3 -0
- package/dist/streets-Bakdn2nG.cjs +1 -0
- package/dist/streets-D0l2l7xn.js +13 -0
- package/dist/style-Db7kunP9.cjs +1 -0
- package/dist/style-Di9c4u-c.js +75 -0
- package/dist/terrain-CUJe0pn4.cjs +1 -0
- package/dist/terrain-CZOhjFPd.js +13 -0
- package/package.json +128 -3
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,3792 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as X, jsxs as fe, Fragment as lt } from "react/jsx-runtime";
|
|
3
|
+
import { useContext as pt, createContext as Nt, useEffect as K, useState as le, useRef as $, useCallback as ve, useMemo as Bt, memo as ao, useLayoutEffect as uo, forwardRef as In, useImperativeHandle as fo } from "react";
|
|
4
|
+
import { canProcessShape as _t, warnOnce as Rn, DEFAULT_FEATURE_COLOR_ON_DARK as go, createClickRepeatGuard as yo, routingError as po, CLICK_TOOL_MODES as ho, CLICK_SLOP_PX as mo, makeCircleCoords as vo, makeRectCoords as xo, isMultiGeometry as ht, getPartCount as wo, getPartGeometry as At, placeBox as Fn, commitTopoMove as on, vertexEditPatch as So, commitTopoInsert as wt, commitTopoDelete as rn, rdp as bo, withXY as Ve, setPartGeometry as Lo, insertedPosition as sn, transformUpdates as Eo, getMercatorLatCorrectionRatio as Te, unproject as Ot, project as me, offsetGeometry as $t, applyVisualTransform as Po, toRadians as Ke, mapPositions as _n, vertexEditNotice as Co, fitPadding as jt, addPickedFeature as Mo, OSM_PICK_OVERLAY_COLORS as at, unionPieces as ko, tileCandidateResult as Io, OSM_PICK_MIN_ZOOM as Ro, overpassRadiusForZoom as Fo, tileCandidates as _o, normalizeFitBoundsTarget as Ao, visibleCenterOffset as cn, loadErrorCode as ln } from "@element-editor/core/internal";
|
|
5
|
+
import { useAccentPalette as To, useDataStore as he, useUIStore as W, useElementEditorConfig as ke, useGeoStore as Le, useEmit as Ue, useIsEventForEditor as zt, featureLabel as Do, ContextMenu as Ko, VertexSelectionBar as No, FeatureMapContextMenu as Bo, useAccentStyle as Oo, useTheme as An, runGeometryWorkerOperation as $o, MapControllerProvider as jo, EventProvider as zo, useAdapterControls as Ho, useKeyboardShortcuts as Vo, useApplyAccentToRoot as Xo, useReportThemeFromRoot as Yo, preloadEditorPanelsWhenIdle as Go, useSetMapController as Wo, BasemapPicker as Uo } from "@element-editor/ui";
|
|
6
|
+
import { ActiveDrawingToolbar as fi, EditingToolbar as gi, ElementEditorUIProvider as yi, FloatingToolbar as pi, GeoStoreProvider as hi, MapControllerProvider as mi, StoreContext as vi, useDataStore as xi, useGeoStore as wi, useKeyboardShortcuts as Si, useMapController as bi, useSetMapController as Li, useUIStore as Ei } from "@element-editor/ui";
|
|
7
|
+
import { useOptionalEmit as Tn, useRouting as Zo, applyRootTokens as qo, useContextMenu as Jo } from "@element-editor/ui/internal";
|
|
8
|
+
import { readAccentPalette as Dn, DEFAULT_FEATURE_COLOR as Kn, fetchRoute as an, getGeometryBBox as Nn, formatLength as mt, formatArea as Ht, fetchOverpassFeatures as Qo, overpassErrorMessage as er, OverpassError as tr, readStorage as nr, writeStorage as or, ElementEditorError as Tt } from "@element-editor/core";
|
|
9
|
+
import { ElementEditorError as Ci } from "@element-editor/core";
|
|
10
|
+
import * as De from "maplibre-gl";
|
|
11
|
+
import { Crosshair as rr, Trash as sr } from "@phosphor-icons/react";
|
|
12
|
+
import { createPortal as Ze } from "react-dom";
|
|
13
|
+
import { transformRotate as ir } from "@turf/transform-rotate";
|
|
14
|
+
import { featureCollection as cr, lineString as We, polygon as ut } from "@turf/helpers";
|
|
15
|
+
import { bbox as Bn } from "@turf/bbox";
|
|
16
|
+
import lr from "@turf/boolean-intersects";
|
|
17
|
+
import { length as _e } from "@turf/length";
|
|
18
|
+
import { area as dt } from "@turf/area";
|
|
19
|
+
import { g as ar, r as ur } from "./basemapIds-CVTxeXkr.js";
|
|
20
|
+
import { distance as Pe } from "@turf/distance";
|
|
21
|
+
function Ie() {
|
|
22
|
+
return { type: "FeatureCollection", features: [] };
|
|
23
|
+
}
|
|
24
|
+
const dr = "elm-features", On = /* @__PURE__ */ new WeakMap();
|
|
25
|
+
function fr(e, t, n) {
|
|
26
|
+
On.set(e, { features: t, uniqueIds: n });
|
|
27
|
+
}
|
|
28
|
+
function Vt(e, t) {
|
|
29
|
+
const n = e.getSource(dr), o = On.get(e);
|
|
30
|
+
if (!(!n || !o || t.size === 0))
|
|
31
|
+
try {
|
|
32
|
+
if (o.uniqueIds) {
|
|
33
|
+
const i = [];
|
|
34
|
+
let l = !0;
|
|
35
|
+
for (const [u, c] of t)
|
|
36
|
+
if (c.type === "GeometryCollection") {
|
|
37
|
+
if (c.geometries.length !== 1) {
|
|
38
|
+
l = !1;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
i.push({ id: u, newGeometry: c.geometries[0] });
|
|
42
|
+
} else
|
|
43
|
+
i.push({ id: u, newGeometry: c });
|
|
44
|
+
if (l) {
|
|
45
|
+
n.updateData({ update: i });
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const r = /* @__PURE__ */ new Map(), s = o.features.map((i) => {
|
|
50
|
+
var c;
|
|
51
|
+
const l = (c = i.properties) == null ? void 0 : c.id, u = t.get(l);
|
|
52
|
+
if (!u) return i;
|
|
53
|
+
if (u.type === "GeometryCollection") {
|
|
54
|
+
const v = r.get(l) ?? 0;
|
|
55
|
+
r.set(l, v + 1);
|
|
56
|
+
const d = u.geometries[v];
|
|
57
|
+
return d ? { ...i, geometry: d } : i;
|
|
58
|
+
}
|
|
59
|
+
return { ...i, geometry: u };
|
|
60
|
+
});
|
|
61
|
+
n.setData({ type: "FeatureCollection", features: s });
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const $n = Nt(void 0);
|
|
66
|
+
function gr({
|
|
67
|
+
getFeatureStyle: e,
|
|
68
|
+
children: t
|
|
69
|
+
}) {
|
|
70
|
+
return /* @__PURE__ */ X($n.Provider, { value: e, children: t });
|
|
71
|
+
}
|
|
72
|
+
function yr() {
|
|
73
|
+
return pt($n);
|
|
74
|
+
}
|
|
75
|
+
function pr(e) {
|
|
76
|
+
let t, n, o;
|
|
77
|
+
const r = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
|
|
78
|
+
if (r) {
|
|
79
|
+
const i = r[1].length === 3 ? r[1].replace(/./g, (l) => l + l) : r[1];
|
|
80
|
+
t = parseInt(i.slice(0, 2), 16), n = parseInt(i.slice(2, 4), 16), o = parseInt(i.slice(4, 6), 16);
|
|
81
|
+
} else {
|
|
82
|
+
const i = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec(e.trim());
|
|
83
|
+
if (!i) return null;
|
|
84
|
+
t = +i[1], n = +i[2], o = +i[3];
|
|
85
|
+
}
|
|
86
|
+
const s = (i) => {
|
|
87
|
+
const l = i / 255;
|
|
88
|
+
return l <= 0.03928 ? l / 12.92 : ((l + 0.055) / 1.055) ** 2.4;
|
|
89
|
+
};
|
|
90
|
+
return 0.2126 * s(t) + 0.7152 * s(n) + 0.0722 * s(o);
|
|
91
|
+
}
|
|
92
|
+
function un(e) {
|
|
93
|
+
var t, n, o;
|
|
94
|
+
try {
|
|
95
|
+
const r = (n = (t = e.getStyle()) == null ? void 0 : t.layers) == null ? void 0 : n.find((l) => l.type === "background"), s = (o = r == null ? void 0 : r.paint) == null ? void 0 : o["background-color"];
|
|
96
|
+
if (typeof s != "string") return !1;
|
|
97
|
+
const i = pr(s);
|
|
98
|
+
return i !== null && i < 0.18;
|
|
99
|
+
} catch {
|
|
100
|
+
return !1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const jn = Nt(0), vt = () => pt(jn);
|
|
104
|
+
function Ne(e, t, n = Dn(e.getContainer())) {
|
|
105
|
+
for (const [o, r, s] of t)
|
|
106
|
+
e.getLayer(o) && e.setPaintProperty(o, r, s(n));
|
|
107
|
+
}
|
|
108
|
+
function qe(e, t) {
|
|
109
|
+
const n = To(e.getContainer());
|
|
110
|
+
return K(() => {
|
|
111
|
+
Ne(e, t, n);
|
|
112
|
+
}, [e, t, n]), n;
|
|
113
|
+
}
|
|
114
|
+
const ge = "elm-features", Xt = "elm-features-line-hit", hr = 16, ft = ["boolean", ["feature-state", "hovered"], !1], mr = ["boolean", ["feature-state", "fresh"], !1], St = (e, t, n) => [
|
|
115
|
+
"case",
|
|
116
|
+
["boolean", ["feature-state", "selected"], !1],
|
|
117
|
+
e,
|
|
118
|
+
["coalesce", ...t, ["case", ft, n.hover, n.color]]
|
|
119
|
+
], dn = [["get", "_fillColor"], ["get", "_color"]], vr = { color: Kn, hover: "#64748b", casing: "rgba(255, 255, 255, 0.7)" }, xr = { color: go, hover: "#cbd5e1", casing: "rgba(15, 23, 42, 0.5)" }, zn = (e) => [
|
|
120
|
+
["elm-features-fill", "fill-color", (t) => St(t[500], dn, e)],
|
|
121
|
+
["elm-features-line-casing", "line-color", () => e.casing],
|
|
122
|
+
["elm-features-line", "line-color", (t) => St(t[500], [["get", "_color"]], e)],
|
|
123
|
+
// A fresh point: one accent step darker instead of a snap ring on it.
|
|
124
|
+
["elm-features-point", "circle-color", (t) => ["case", mr, t[600], St(t[500], dn, e)]]
|
|
125
|
+
], Hn = zn(vr), wr = zn(xr), Yt = ["in", ["geometry-type"], ["literal", ["LineString", "MultiLineString"]]], fn = ["coalesce", ["get", "_weight"], ["case", Yt, 3.5, 1.8]], gn = [
|
|
126
|
+
"case",
|
|
127
|
+
["boolean", ["feature-state", "selected"], !1],
|
|
128
|
+
["case", Yt, 4, 2.5],
|
|
129
|
+
ft,
|
|
130
|
+
["+", fn, 0.7],
|
|
131
|
+
fn
|
|
132
|
+
], Sr = 1.5;
|
|
133
|
+
function br(e) {
|
|
134
|
+
e.getSource(ge) || (e.addSource(ge, {
|
|
135
|
+
type: "geojson",
|
|
136
|
+
data: Ie(),
|
|
137
|
+
promoteId: "id"
|
|
138
|
+
// use each feature's `id` property as the MapLibre feature ID
|
|
139
|
+
}), e.addLayer({
|
|
140
|
+
id: "elm-features-fill",
|
|
141
|
+
type: "fill",
|
|
142
|
+
source: ge,
|
|
143
|
+
filter: ["in", ["geometry-type"], ["literal", ["Polygon", "MultiPolygon"]]],
|
|
144
|
+
paint: {
|
|
145
|
+
"fill-opacity": [
|
|
146
|
+
"case",
|
|
147
|
+
["boolean", ["feature-state", "selected"], !1],
|
|
148
|
+
0.28,
|
|
149
|
+
ft,
|
|
150
|
+
["max", ["coalesce", ["get", "_fillOpacity"], 0.13], 0.22],
|
|
151
|
+
["coalesce", ["get", "_fillOpacity"], 0.13]
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
}), e.addLayer({
|
|
155
|
+
id: "elm-features-line-casing",
|
|
156
|
+
type: "line",
|
|
157
|
+
source: ge,
|
|
158
|
+
filter: Yt,
|
|
159
|
+
paint: {
|
|
160
|
+
"line-width": ["+", gn, 2 * Sr],
|
|
161
|
+
"line-opacity": ["coalesce", ["get", "_opacity"], 1]
|
|
162
|
+
}
|
|
163
|
+
}), e.addLayer({
|
|
164
|
+
id: "elm-features-line",
|
|
165
|
+
type: "line",
|
|
166
|
+
source: ge,
|
|
167
|
+
filter: [
|
|
168
|
+
"in",
|
|
169
|
+
["geometry-type"],
|
|
170
|
+
["literal", ["LineString", "MultiLineString", "Polygon", "MultiPolygon"]]
|
|
171
|
+
],
|
|
172
|
+
paint: {
|
|
173
|
+
"line-width": gn,
|
|
174
|
+
"line-opacity": ["coalesce", ["get", "_opacity"], 1]
|
|
175
|
+
}
|
|
176
|
+
}), e.addLayer({
|
|
177
|
+
id: Xt,
|
|
178
|
+
type: "line",
|
|
179
|
+
source: ge,
|
|
180
|
+
filter: ["in", ["geometry-type"], ["literal", ["LineString", "MultiLineString"]]],
|
|
181
|
+
paint: { "line-width": hr, "line-color": "#000", "line-opacity": 0 }
|
|
182
|
+
}), e.addLayer({
|
|
183
|
+
id: "elm-features-point",
|
|
184
|
+
type: "circle",
|
|
185
|
+
source: ge,
|
|
186
|
+
filter: [
|
|
187
|
+
"all",
|
|
188
|
+
["in", ["geometry-type"], ["literal", ["Point", "MultiPoint"]]],
|
|
189
|
+
["!=", ["get", "_isText"], "true"]
|
|
190
|
+
],
|
|
191
|
+
paint: {
|
|
192
|
+
"circle-radius": [
|
|
193
|
+
"case",
|
|
194
|
+
["boolean", ["feature-state", "selected"], !1],
|
|
195
|
+
10,
|
|
196
|
+
ft,
|
|
197
|
+
9,
|
|
198
|
+
8
|
|
199
|
+
],
|
|
200
|
+
"circle-opacity": ["coalesce", ["get", "_fillOpacity"], 1],
|
|
201
|
+
"circle-stroke-width": 2,
|
|
202
|
+
"circle-stroke-color": "#ffffff"
|
|
203
|
+
}
|
|
204
|
+
}), e.getGlyphs() ? e.addLayer({
|
|
205
|
+
id: "elm-features-text",
|
|
206
|
+
type: "symbol",
|
|
207
|
+
source: ge,
|
|
208
|
+
filter: ["==", ["get", "_isText"], "true"],
|
|
209
|
+
layout: {
|
|
210
|
+
"text-field": ["get", "name"],
|
|
211
|
+
// OpenFreeMap's glyph server only has Noto Sans (Open Sans 404s), see basemaps/index.ts.
|
|
212
|
+
"text-font": ["Noto Sans Regular"],
|
|
213
|
+
"text-size": 14,
|
|
214
|
+
"text-allow-overlap": !0
|
|
215
|
+
},
|
|
216
|
+
paint: {
|
|
217
|
+
"text-color": "#ffffff",
|
|
218
|
+
"text-halo-color": Kn,
|
|
219
|
+
"text-halo-width": 2
|
|
220
|
+
}
|
|
221
|
+
}) : Rn("maplibre-no-glyphs", 'The map style has no `glyphs`, so Element can\'t show text features. Use a style with glyphs that serve "Noto Sans Regular".'), Ne(e, Hn));
|
|
222
|
+
}
|
|
223
|
+
function Lr(e) {
|
|
224
|
+
for (const t of ["elm-features-text", "elm-features-point", Xt, "elm-features-line", "elm-features-line-casing", "elm-features-fill"])
|
|
225
|
+
e.getLayer(t) && e.removeLayer(t);
|
|
226
|
+
e.getSource(ge) && e.removeSource(ge);
|
|
227
|
+
}
|
|
228
|
+
const Be = ["elm-features-fill", "elm-features-line", Xt, "elm-features-point"];
|
|
229
|
+
function Er({ map: e }) {
|
|
230
|
+
const t = he((_) => _.features), n = he((_) => _.groups), o = he((_) => _.selectedIds), r = W((_) => _.editingMode), s = W((_) => _.geometryPreview !== null), i = W((_) => _.bufferCreateNew), l = yr(), u = ke().featureColor, c = vt(), [v, d] = le(() => un(e));
|
|
231
|
+
K(() => {
|
|
232
|
+
const _ = () => d(un(e));
|
|
233
|
+
return _(), e.on("styledata", _), () => {
|
|
234
|
+
e.off("styledata", _);
|
|
235
|
+
};
|
|
236
|
+
}, [e, c]);
|
|
237
|
+
const g = v ? wr : Hn, w = qe(e, g);
|
|
238
|
+
K(() => {
|
|
239
|
+
Ne(e, g, w);
|
|
240
|
+
}, [c]);
|
|
241
|
+
const C = Tn(), T = $(!1);
|
|
242
|
+
K(() => {
|
|
243
|
+
T.current || e.getGlyphs() || (T.current = !0, C == null || C({
|
|
244
|
+
type: "error",
|
|
245
|
+
code: "unsupported",
|
|
246
|
+
source: "basemap",
|
|
247
|
+
quiet: !0,
|
|
248
|
+
message: 'The map style has no glyphs, so text features are not shown. Use a style whose glyphs serve "Noto Sans Regular".'
|
|
249
|
+
}));
|
|
250
|
+
}, [e, c, C]);
|
|
251
|
+
const k = s && (r === "simplify-shape" || r === "smooth-shape" || r === "buffer-shape" && !i) ? o : null;
|
|
252
|
+
K(() => {
|
|
253
|
+
const _ = e.getSource(ge);
|
|
254
|
+
if (!_) return;
|
|
255
|
+
const D = new Set(n.filter((M) => M.hidden).map((M) => M.id)), q = k ? new Set(k) : null, p = t.filter((M) => !(M.hidden || M.groupId && D.has(M.groupId) || q != null && q.has(M.id) && _t(M.geometry.type))), f = [];
|
|
256
|
+
let b = !0;
|
|
257
|
+
for (const M of p) {
|
|
258
|
+
const { _validation: A, ...E } = M, a = l == null ? void 0 : l(M), x = {}, y = (a == null ? void 0 : a.color) ?? u;
|
|
259
|
+
if (y !== void 0 && (x._color = y), a && (a.fillColor !== void 0 && (x._fillColor = a.fillColor), a.opacity !== void 0 && (x._opacity = a.opacity), a.fillOpacity !== void 0 && (x._fillOpacity = a.fillOpacity), a.weight !== void 0 && (x._weight = a.weight)), M.geometry.type === "GeometryCollection") {
|
|
260
|
+
M.geometry.geometries.length > 1 && (b = !1);
|
|
261
|
+
for (const m of M.geometry.geometries)
|
|
262
|
+
f.push({
|
|
263
|
+
...E,
|
|
264
|
+
geometry: m,
|
|
265
|
+
properties: { ...E.properties, ...x, id: M.id }
|
|
266
|
+
});
|
|
267
|
+
} else
|
|
268
|
+
f.push({
|
|
269
|
+
...E,
|
|
270
|
+
properties: { ...E.properties, ...x, id: M.id }
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
_.setData({ type: "FeatureCollection", features: f }), fr(e, f, b);
|
|
274
|
+
}, [t, n, e, k, l, u, c]);
|
|
275
|
+
const N = $(/* @__PURE__ */ new Set()), P = $(c);
|
|
276
|
+
return K(() => {
|
|
277
|
+
if (!e.getSource(ge)) return;
|
|
278
|
+
P.current !== c && (P.current = c, N.current = /* @__PURE__ */ new Set());
|
|
279
|
+
const _ = N.current, D = new Set(o);
|
|
280
|
+
for (const q of _)
|
|
281
|
+
D.has(q) || e.setFeatureState({ source: ge, id: q }, { selected: !1 });
|
|
282
|
+
for (const q of D)
|
|
283
|
+
_.has(q) || e.setFeatureState({ source: ge, id: q }, { selected: !0 });
|
|
284
|
+
N.current = D;
|
|
285
|
+
}, [o, e, c]), null;
|
|
286
|
+
}
|
|
287
|
+
function bt(e, t, n) {
|
|
288
|
+
e.getSource(ge) && (n && e.setFeatureState({ source: ge, id: n }, { hovered: !1 }), t && e.setFeatureState({ source: ge, id: t }, { hovered: !0 }));
|
|
289
|
+
}
|
|
290
|
+
function Vn(e, t, n, o, r = 15, s = /* @__PURE__ */ new Set()) {
|
|
291
|
+
const i = n.project([e, t]), l = i.x, u = i.y;
|
|
292
|
+
let c = 1 / 0, v = null, d = null, g = 1 / 0, w = 0, C = 0, T = !1, F = null;
|
|
293
|
+
const k = r + 1;
|
|
294
|
+
let N = 1 / 0, P = -1 / 0, _ = 1 / 0, D = -1 / 0;
|
|
295
|
+
for (const [b, M] of [[l - k, u - k], [l + k, u - k], [l - k, u + k], [l + k, u + k]]) {
|
|
296
|
+
const A = n.unproject([b, M]);
|
|
297
|
+
A.lng < N && (N = A.lng), A.lng > P && (P = A.lng), A.lat < _ && (_ = A.lat), A.lat > D && (D = A.lat);
|
|
298
|
+
}
|
|
299
|
+
let q = "";
|
|
300
|
+
function p(b, M = !0) {
|
|
301
|
+
if (!b || b.length === 0) return;
|
|
302
|
+
let A = -1, E = 0, a = 0;
|
|
303
|
+
for (let x = 0; x < b.length; x++) {
|
|
304
|
+
const y = b[x];
|
|
305
|
+
if (!(y[0] < N || y[0] > P || y[1] < _ || y[1] > D)) {
|
|
306
|
+
if (A !== x) {
|
|
307
|
+
const R = n.project(y);
|
|
308
|
+
E = R.x, a = R.y, A = x;
|
|
309
|
+
}
|
|
310
|
+
const m = Math.hypot(l - E, u - a);
|
|
311
|
+
m < c && (c = m, v = y, d = q);
|
|
312
|
+
}
|
|
313
|
+
if (M && x < b.length - 1) {
|
|
314
|
+
const m = b[x + 1];
|
|
315
|
+
if (y[0] < N && m[0] < N || y[0] > P && m[0] > P || y[1] < _ && m[1] < _ || y[1] > D && m[1] > D) continue;
|
|
316
|
+
if (A !== x) {
|
|
317
|
+
const I = n.project(y);
|
|
318
|
+
E = I.x, a = I.y;
|
|
319
|
+
}
|
|
320
|
+
const R = E, S = a, L = n.project(m);
|
|
321
|
+
A = x + 1, E = L.x, a = L.y;
|
|
322
|
+
const B = (R - L.x) ** 2 + (S - L.y) ** 2;
|
|
323
|
+
let V = R, j = S;
|
|
324
|
+
if (B !== 0) {
|
|
325
|
+
let I = ((l - R) * (L.x - R) + (u - S) * (L.y - S)) / B;
|
|
326
|
+
I = Math.max(0, Math.min(1, I)), V = R + I * (L.x - R), j = S + I * (L.y - S);
|
|
327
|
+
}
|
|
328
|
+
const h = Math.hypot(l - V, u - j);
|
|
329
|
+
h < g && (g = h, w = V, C = j, T = !0, F = q);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function f(b) {
|
|
334
|
+
switch (b.type) {
|
|
335
|
+
case "Point":
|
|
336
|
+
p([b.coordinates]);
|
|
337
|
+
break;
|
|
338
|
+
case "MultiPoint":
|
|
339
|
+
p(b.coordinates, !1);
|
|
340
|
+
break;
|
|
341
|
+
case "LineString":
|
|
342
|
+
p(b.coordinates);
|
|
343
|
+
break;
|
|
344
|
+
case "Polygon":
|
|
345
|
+
case "MultiLineString":
|
|
346
|
+
for (const M of b.coordinates) p(M);
|
|
347
|
+
break;
|
|
348
|
+
case "MultiPolygon":
|
|
349
|
+
for (const M of b.coordinates)
|
|
350
|
+
for (const A of M) p(A);
|
|
351
|
+
break;
|
|
352
|
+
case "GeometryCollection":
|
|
353
|
+
for (const M of b.geometries) f(M);
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
for (const b of o)
|
|
358
|
+
if (!s.has(b.id)) {
|
|
359
|
+
if (b.bbox) {
|
|
360
|
+
const [M, A, E, a] = b.bbox;
|
|
361
|
+
if (E < N || M > P || a < _ || A > D) continue;
|
|
362
|
+
}
|
|
363
|
+
q = b.id, f(b.geometry);
|
|
364
|
+
}
|
|
365
|
+
if (c <= r && v)
|
|
366
|
+
return {
|
|
367
|
+
lnglat: v,
|
|
368
|
+
isVertex: !0,
|
|
369
|
+
featureId: d ?? void 0
|
|
370
|
+
};
|
|
371
|
+
if (g <= r && T) {
|
|
372
|
+
const b = n.unproject([w, C]);
|
|
373
|
+
return {
|
|
374
|
+
lnglat: [b.lng, b.lat],
|
|
375
|
+
isVertex: !1,
|
|
376
|
+
featureId: F ?? void 0
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
function Dt(e, t, n, o = 15) {
|
|
382
|
+
const r = e.project(t), s = e.project(n), i = s.x - r.x, l = s.y - r.y, u = Math.hypot(i, l);
|
|
383
|
+
if (u < 1) return n;
|
|
384
|
+
const c = Math.atan2(l, i), v = o * Math.PI / 180, d = Math.round(c / v) * v, g = r.x + u * Math.cos(d), w = r.y + u * Math.sin(d), C = e.unproject([g, w]);
|
|
385
|
+
return [C.lng, C.lat];
|
|
386
|
+
}
|
|
387
|
+
let Kt = !1;
|
|
388
|
+
function Pr() {
|
|
389
|
+
Kt = !0, Promise.resolve().then(() => {
|
|
390
|
+
Kt = !1;
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function Cr() {
|
|
394
|
+
return Kt;
|
|
395
|
+
}
|
|
396
|
+
let Xn = 0;
|
|
397
|
+
function Mr() {
|
|
398
|
+
Xn = Date.now();
|
|
399
|
+
}
|
|
400
|
+
function kr() {
|
|
401
|
+
return Date.now() - Xn < 200;
|
|
402
|
+
}
|
|
403
|
+
let Yn = 0;
|
|
404
|
+
function Lt() {
|
|
405
|
+
Yn = Date.now();
|
|
406
|
+
}
|
|
407
|
+
function Gn() {
|
|
408
|
+
return Date.now() - Yn < 200;
|
|
409
|
+
}
|
|
410
|
+
const Ge = (e) => e !== "none" ? "crosshair" : "", Ir = 3, yn = 5;
|
|
411
|
+
function Rr({ map: e, routingApiKey: t }) {
|
|
412
|
+
const { uiStore: n, dataStore: o } = Le(), r = Zo(t), s = ke().network.fetch, i = $(null);
|
|
413
|
+
i.current = r === !1 ? null : { ...r, fetch: s };
|
|
414
|
+
const l = Ue(), u = zt(), c = W((p) => p.editingMode), v = W((p) => p.cancelDrawing), d = W((p) => p.routeWaypoints), g = $(d);
|
|
415
|
+
K(() => {
|
|
416
|
+
g.current = d;
|
|
417
|
+
}, [d]);
|
|
418
|
+
const w = $(null), C = $(null), T = $(null), F = $(!1), k = $(!1), N = $(!1), P = $(null), _ = $(yo()).current, D = $(!1), q = ve(
|
|
419
|
+
async (p) => {
|
|
420
|
+
if (!(p.length < 2)) {
|
|
421
|
+
n.getState().setRoutePreview(null, !0);
|
|
422
|
+
try {
|
|
423
|
+
if (!i.current) throw new Error("routing is off");
|
|
424
|
+
const f = await an(p, i.current);
|
|
425
|
+
g.current.length >= 2 && n.getState().setRoutePreview(f, !1);
|
|
426
|
+
} catch (f) {
|
|
427
|
+
const b = po(f);
|
|
428
|
+
l({ type: "error", code: b.code, source: "routing", message: b.message, error: b }), n.getState().setRoutePreview(p, !1);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
[n, l]
|
|
433
|
+
);
|
|
434
|
+
return K(() => {
|
|
435
|
+
const p = e.getCanvas();
|
|
436
|
+
function f() {
|
|
437
|
+
D.current || (D.current = !0, e.dragPan.enable(), p.style.cursor = "grab");
|
|
438
|
+
}
|
|
439
|
+
function b() {
|
|
440
|
+
if (!D.current) return;
|
|
441
|
+
D.current = !1;
|
|
442
|
+
const y = n.getState().editingMode;
|
|
443
|
+
p.style.cursor = Ge(y), (y === "draw-rect" || y === "draw-circle" || y === "draw-freehand") && e.dragPan.disable();
|
|
444
|
+
}
|
|
445
|
+
const M = (y) => {
|
|
446
|
+
if (y.key === "Shift" && (k.current = !0), !!u(y)) {
|
|
447
|
+
if (y.code === "Space") {
|
|
448
|
+
const m = y.target;
|
|
449
|
+
if (m && (m.tagName === "INPUT" || m.tagName === "TEXTAREA" || m.isContentEditable)) return;
|
|
450
|
+
y.preventDefault(), n.getState().editingMode !== "none" && f();
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (y.key === "Escape") {
|
|
454
|
+
const { selectedMeasurementId: m, setSelectedMeasurementId: R } = n.getState();
|
|
455
|
+
if (m) {
|
|
456
|
+
R(null);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
v();
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if (y.key === "Enter") {
|
|
463
|
+
const m = n.getState();
|
|
464
|
+
if (m.editingMode === "measure") {
|
|
465
|
+
m.completeMeasure();
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
if (y.key === "Backspace" || y.key === "Delete") {
|
|
470
|
+
const m = n.getState();
|
|
471
|
+
if (m.selectedMeasurementId) {
|
|
472
|
+
m.removeMeasurement(m.selectedMeasurementId);
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
const R = m.editingMode;
|
|
476
|
+
if (R === "measure") {
|
|
477
|
+
m.removeLastMeasurePoint();
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
if (R === "draw-line" || R === "slice-shape") {
|
|
481
|
+
m.removeLastLineVertex();
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
if (R === "draw-polygon" || R === "cut-hole") {
|
|
485
|
+
m.removeLastPolygonVertex();
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
if (R === "draw-route") {
|
|
489
|
+
m.removeLastRouteWaypoint();
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}, A = (y) => {
|
|
495
|
+
if (y.code === "Space") {
|
|
496
|
+
b();
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
y.key === "Shift" && (k.current = !1);
|
|
500
|
+
}, E = () => b(), a = () => {
|
|
501
|
+
p.style.cursor = "grabbing";
|
|
502
|
+
}, x = () => {
|
|
503
|
+
p.style.cursor = D.current ? "grab" : Ge(n.getState().editingMode);
|
|
504
|
+
};
|
|
505
|
+
return window.addEventListener("keydown", M), window.addEventListener("keyup", A), window.addEventListener("blur", E), e.on("dragstart", a), e.on("dragend", x), () => {
|
|
506
|
+
window.removeEventListener("keydown", M), window.removeEventListener("keyup", A), window.removeEventListener("blur", E), e.off("dragstart", a), e.off("dragend", x);
|
|
507
|
+
};
|
|
508
|
+
}, [v, n, e, u]), K(() => {
|
|
509
|
+
e.getCanvas().style.cursor = Ge(c);
|
|
510
|
+
}, [c, e]), K(() => {
|
|
511
|
+
c === "draw-freehand" ? e.dragPan.disable() : (e.dragPan.enable(), F.current = !1);
|
|
512
|
+
}, [c, e]), K(() => (c !== "none" ? e.doubleClickZoom.disable() : e.doubleClickZoom.enable(), () => {
|
|
513
|
+
e.doubleClickZoom.enable();
|
|
514
|
+
}), [c, e]), K(() => {
|
|
515
|
+
var A;
|
|
516
|
+
if (!ho.includes(c)) return;
|
|
517
|
+
const p = e, f = (A = p.handlers ?? p._handlerManager) == null ? void 0 : A._handlersById, b = [f == null ? void 0 : f.mapEvent, f == null ? void 0 : f.mousePan].filter((E) => typeof (E == null ? void 0 : E._clickTolerance) == "number"), M = b.map((E) => E._clickTolerance);
|
|
518
|
+
for (const E of b) E._clickTolerance = mo;
|
|
519
|
+
return () => b.forEach((E, a) => {
|
|
520
|
+
E._clickTolerance = M[a];
|
|
521
|
+
});
|
|
522
|
+
}, [c, e]), K(() => (c !== "none" ? e.boxZoom.disable() : e.boxZoom.enable(), () => {
|
|
523
|
+
e.boxZoom.enable();
|
|
524
|
+
}), [c, e]), K(() => () => {
|
|
525
|
+
C.current && clearTimeout(C.current), T.current && T.current.abort();
|
|
526
|
+
}, []), K(() => {
|
|
527
|
+
const p = (a) => a.metaKey || a.ctrlKey || a.altKey, f = (a) => {
|
|
528
|
+
if (!p(a.originalEvent) && !D.current) {
|
|
529
|
+
if (c === "draw-freehand") {
|
|
530
|
+
F.current = !0, n.getState().clearFreehandPoints(), n.getState().addFreehandPoint([a.lngLat.lng, a.lngLat.lat]);
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
if (c === "draw-rect") {
|
|
534
|
+
e.dragPan.disable(), o.getState().selectedIds.length > 0 && o.setState({ selectedIds: [] });
|
|
535
|
+
const x = n.getState().snappedCoord ?? [a.lngLat.lng, a.lngLat.lat];
|
|
536
|
+
n.getState().setRectCorner(x), N.current = !0, P.current = { x: a.point.x, y: a.point.y };
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
if (c === "draw-circle") {
|
|
540
|
+
e.dragPan.disable(), o.getState().selectedIds.length > 0 && o.setState({ selectedIds: [] });
|
|
541
|
+
const x = n.getState().snappedCoord ?? [a.lngLat.lng, a.lngLat.lat];
|
|
542
|
+
n.getState().setCircleCenter(x), N.current = !0, P.current = { x: a.point.x, y: a.point.y };
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}, b = (a) => {
|
|
547
|
+
if (c === "draw-freehand" && F.current) {
|
|
548
|
+
F.current = !1;
|
|
549
|
+
const R = e.getZoom(), S = 156543.03392 * Math.cos(a.lngLat.lat * Math.PI / 180) / Math.pow(2, R), L = Ir * S / 111320;
|
|
550
|
+
n.getState().commitFreehand(L), Lt();
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
if (!N.current) return;
|
|
554
|
+
N.current = !1, e.dragPan.enable();
|
|
555
|
+
const x = P.current, y = x ? Math.hypot(a.point.x - x.x, a.point.y - x.y) : 0;
|
|
556
|
+
P.current = null;
|
|
557
|
+
const m = n.getState();
|
|
558
|
+
if (c === "draw-rect") {
|
|
559
|
+
const R = m.rectCorner;
|
|
560
|
+
if (!R) return;
|
|
561
|
+
if (y < yn) {
|
|
562
|
+
n.setState({ rectCorner: null });
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
const S = m.snappedCoord ?? [a.lngLat.lng, a.lngLat.lat], L = k.current || a.originalEvent.shiftKey;
|
|
566
|
+
m.commitRect(R, S, {}, L), Lt();
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
if (c === "draw-circle") {
|
|
570
|
+
const R = m.circleCenter;
|
|
571
|
+
if (!R) return;
|
|
572
|
+
let S;
|
|
573
|
+
if (y < yn) {
|
|
574
|
+
const V = e.unproject([a.point.x + 25, a.point.y]);
|
|
575
|
+
S = [V.lng, V.lat];
|
|
576
|
+
} else
|
|
577
|
+
S = m.snappedCoord ?? [a.lngLat.lng, a.lngLat.lat];
|
|
578
|
+
const L = S[0] - R[0], B = S[1] - R[1];
|
|
579
|
+
Math.hypot(L, B) >= 1e-6 && (m.commitCircle(R, S, {}), Lt());
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
}, M = (a) => {
|
|
583
|
+
const x = n.getState();
|
|
584
|
+
if (c === "draw-freehand" && F.current) {
|
|
585
|
+
x.addFreehandPoint([a.lngLat.lng, a.lngLat.lat]);
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
if (c === "draw-route" && g.current.length > 0) {
|
|
589
|
+
const y = [a.lngLat.lng, a.lngLat.lat];
|
|
590
|
+
x.setRouteCursorPos(y), x.setRouteCursorPreview(null), C.current && clearTimeout(C.current), T.current && T.current.abort();
|
|
591
|
+
const m = g.current[g.current.length - 1];
|
|
592
|
+
C.current = setTimeout(async () => {
|
|
593
|
+
const R = new AbortController();
|
|
594
|
+
T.current = R;
|
|
595
|
+
try {
|
|
596
|
+
if (!i.current) return;
|
|
597
|
+
const S = await an([m, y], { ...i.current, signal: R.signal });
|
|
598
|
+
R.signal.aborted || n.getState().setRouteCursorPreview(S);
|
|
599
|
+
} catch {
|
|
600
|
+
}
|
|
601
|
+
}, 400);
|
|
602
|
+
}
|
|
603
|
+
if ((c === "draw-polygon" || c === "cut-hole") && x.polygonInProgress.length >= 3) {
|
|
604
|
+
const y = x.polygonInProgress[0], m = e.project(y), R = Math.hypot(a.point.x - m.x, a.point.y - m.y);
|
|
605
|
+
e.getCanvas().style.cursor = R <= 48 ? "pointer" : "crosshair";
|
|
606
|
+
}
|
|
607
|
+
}, A = (a) => {
|
|
608
|
+
const x = _.click(a.originalEvent);
|
|
609
|
+
if (p(a.originalEvent) || kr() || D.current || Gn()) return;
|
|
610
|
+
const y = n.getState();
|
|
611
|
+
if (c === "measure") {
|
|
612
|
+
if (x || Cr()) return;
|
|
613
|
+
y.selectedMeasurementId && y.setSelectedMeasurementId(null);
|
|
614
|
+
const S = y.snappedCoord ?? [a.lngLat.lng, a.lngLat.lat];
|
|
615
|
+
y.addMeasurePoint(S);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
["place-point", "draw-line", "draw-polygon", "draw-route", "draw-circle", "draw-rect"].includes(c) && o.getState().selectedIds.length > 0 && o.setState({ selectedIds: [] });
|
|
619
|
+
const R = y.snappedCoord ?? [a.lngLat.lng, a.lngLat.lat];
|
|
620
|
+
if (c === "place-point") {
|
|
621
|
+
if (x) return;
|
|
622
|
+
y.commitPoint(R);
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (c === "draw-line" || c === "draw-polygon" || c === "draw-route" || c === "cut-hole" || c === "slice-shape") {
|
|
626
|
+
let S = R;
|
|
627
|
+
if (k.current || a.originalEvent.shiftKey) {
|
|
628
|
+
const L = c === "draw-line" || c === "slice-shape" ? y.lineInProgress : y.polygonInProgress;
|
|
629
|
+
L.length >= 1 && (S = Dt(e, L[L.length - 1], S));
|
|
630
|
+
}
|
|
631
|
+
if ((c === "draw-polygon" || c === "cut-hole") && y.polygonInProgress.length >= 2) {
|
|
632
|
+
const L = y.polygonInProgress[0], B = e.project(L);
|
|
633
|
+
if (Math.hypot(a.point.x - B.x, a.point.y - B.y) <= 48) {
|
|
634
|
+
c === "draw-polygon" ? y.commitPolygon({}) : y.commitCutHole();
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (x) return;
|
|
639
|
+
if (c === "draw-line" || c === "slice-shape") y.addLineVertex(S);
|
|
640
|
+
else if (c === "draw-polygon" || c === "cut-hole") y.addPolygonVertex(S);
|
|
641
|
+
else if (c === "draw-route") {
|
|
642
|
+
w.current = { waypoints: [...g.current], preview: y.routePreview }, C.current && (clearTimeout(C.current), C.current = null), T.current && (T.current.abort(), T.current = null), y.setRouteCursorPos(null), y.setRouteCursorPreview(null), y.addRouteWaypoint(S);
|
|
643
|
+
const L = [...g.current, S];
|
|
644
|
+
q(L);
|
|
645
|
+
}
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
}, E = () => {
|
|
649
|
+
if (!_.isDouble()) return;
|
|
650
|
+
const a = n.getState();
|
|
651
|
+
if (c === "measure") {
|
|
652
|
+
a.completeMeasure();
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
c === "draw-line" ? a.commitLine({}) : c === "draw-polygon" ? a.commitPolygon({}) : c === "cut-hole" ? a.commitCutHole() : c === "slice-shape" ? a.commitSliceShape() : c === "draw-route" && (w.current && (n.setState({
|
|
656
|
+
routeWaypoints: w.current.waypoints,
|
|
657
|
+
routePreview: w.current.preview,
|
|
658
|
+
routeLoading: !1
|
|
659
|
+
}), w.current = null), a.commitRoute());
|
|
660
|
+
};
|
|
661
|
+
return e.on("mousedown", f), e.on("mouseup", b), e.on("mousemove", M), e.on("click", A), e.on("dblclick", E), () => {
|
|
662
|
+
e.off("mousedown", f), e.off("mouseup", b), e.off("mousemove", M), e.off("click", A), e.off("dblclick", E);
|
|
663
|
+
};
|
|
664
|
+
}, [c, e, q, n, o]), null;
|
|
665
|
+
}
|
|
666
|
+
function pn(e) {
|
|
667
|
+
var t, n;
|
|
668
|
+
return `${e.editingMode}|${e.lineInProgress.length}|${e.polygonInProgress.length}|${e.circleCenter}|${e.rectCorner}|${e.routeWaypoints.length}|${((t = e.routePreview) == null ? void 0 : t.length) ?? 0}|${((n = e.routeCursorPreview) == null ? void 0 : n.length) ?? 0}|${e.freehandPoints.length}`;
|
|
669
|
+
}
|
|
670
|
+
const Se = "elm-preview", Wn = [
|
|
671
|
+
["elm-preview-fill", "fill-color", (e) => e[500]],
|
|
672
|
+
["elm-preview-line", "line-color", (e) => e[500]],
|
|
673
|
+
["elm-preview-vertex", "circle-color", (e) => e[500]]
|
|
674
|
+
];
|
|
675
|
+
function Fr(e) {
|
|
676
|
+
e.getSource(Se) || (e.addSource(Se, { type: "geojson", data: Ie() }), e.addLayer({
|
|
677
|
+
id: "elm-preview-fill",
|
|
678
|
+
type: "fill",
|
|
679
|
+
source: Se,
|
|
680
|
+
filter: ["==", ["geometry-type"], "Polygon"],
|
|
681
|
+
paint: { "fill-opacity": 0.13 }
|
|
682
|
+
}), e.addLayer({
|
|
683
|
+
id: "elm-preview-line",
|
|
684
|
+
type: "line",
|
|
685
|
+
source: Se,
|
|
686
|
+
filter: ["in", ["geometry-type"], ["literal", ["LineString", "Polygon"]]],
|
|
687
|
+
paint: { "line-width": 2, "line-dasharray": [4, 3] }
|
|
688
|
+
}), e.addLayer({
|
|
689
|
+
id: "elm-preview-vertex",
|
|
690
|
+
type: "circle",
|
|
691
|
+
source: Se,
|
|
692
|
+
filter: ["all", ["==", ["geometry-type"], "Point"], ["!=", ["get", "_isFirst"], !0]],
|
|
693
|
+
paint: {
|
|
694
|
+
"circle-radius": 5,
|
|
695
|
+
"circle-stroke-width": 2,
|
|
696
|
+
"circle-stroke-color": "#ffffff"
|
|
697
|
+
}
|
|
698
|
+
}), e.addLayer({
|
|
699
|
+
id: "elm-preview-first-vertex",
|
|
700
|
+
type: "circle",
|
|
701
|
+
source: Se,
|
|
702
|
+
filter: ["==", ["get", "_isFirst"], !0],
|
|
703
|
+
paint: {
|
|
704
|
+
"circle-radius": 7,
|
|
705
|
+
"circle-color": "#22c55e",
|
|
706
|
+
"circle-stroke-width": 2,
|
|
707
|
+
"circle-stroke-color": "#ffffff"
|
|
708
|
+
}
|
|
709
|
+
}), Ne(e, Wn));
|
|
710
|
+
}
|
|
711
|
+
function _r(e) {
|
|
712
|
+
for (const t of ["elm-preview-first-vertex", "elm-preview-vertex", "elm-preview-line", "elm-preview-fill"])
|
|
713
|
+
e.getLayer(t) && e.removeLayer(t);
|
|
714
|
+
e.getSource(Se) && e.removeSource(Se);
|
|
715
|
+
}
|
|
716
|
+
function Fe(e, t) {
|
|
717
|
+
const n = e.getSource(Se);
|
|
718
|
+
n && n.setData({ type: "FeatureCollection", features: t });
|
|
719
|
+
}
|
|
720
|
+
function Ar({ map: e }) {
|
|
721
|
+
qe(e, Wn);
|
|
722
|
+
const { uiStore: t, dataStore: n } = Le(), o = W((c) => c.editingMode), r = he((c) => c.geometryMode), s = $(r);
|
|
723
|
+
K(() => {
|
|
724
|
+
s.current = r;
|
|
725
|
+
}, [r]);
|
|
726
|
+
const i = $(null), l = $(!1);
|
|
727
|
+
K(() => {
|
|
728
|
+
const c = (g) => {
|
|
729
|
+
i.current = [g.lngLat.lng, g.lngLat.lat], u();
|
|
730
|
+
}, v = (g) => {
|
|
731
|
+
g.key === "Shift" && (l.current = !0);
|
|
732
|
+
}, d = (g) => {
|
|
733
|
+
g.key === "Shift" && (l.current = !1);
|
|
734
|
+
};
|
|
735
|
+
return e.on("mousemove", c), window.addEventListener("keydown", v), window.addEventListener("keyup", d), () => {
|
|
736
|
+
e.off("mousemove", c), window.removeEventListener("keydown", v), window.removeEventListener("keyup", d);
|
|
737
|
+
};
|
|
738
|
+
}, [e]), K(() => {
|
|
739
|
+
let c = pn(t.getState());
|
|
740
|
+
return t.subscribe((d) => {
|
|
741
|
+
const g = pn(d);
|
|
742
|
+
g !== c && (c = g, u());
|
|
743
|
+
});
|
|
744
|
+
}, [t]), K(() => {
|
|
745
|
+
i.current = null, o === "none" && Fe(e, []);
|
|
746
|
+
}, [o, e]);
|
|
747
|
+
function u() {
|
|
748
|
+
const c = t.getState(), v = i.current, d = [];
|
|
749
|
+
if (c.editingMode === "draw-line" || c.editingMode === "slice-shape") {
|
|
750
|
+
const g = c.lineInProgress;
|
|
751
|
+
if (g.length === 0) return Fe(e, []);
|
|
752
|
+
let w = v ?? g[g.length - 1];
|
|
753
|
+
l.current && g.length >= 1 && (w = Dt(e, g[g.length - 1], w));
|
|
754
|
+
const C = [...g, w];
|
|
755
|
+
d.push({ type: "Feature", properties: {}, geometry: { type: "LineString", coordinates: C } }), g.forEach((T, F) => {
|
|
756
|
+
d.push({ type: "Feature", properties: { _isFirst: F === 0 }, geometry: { type: "Point", coordinates: T } });
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
if (c.editingMode === "draw-polygon" || c.editingMode === "cut-hole") {
|
|
760
|
+
const g = c.polygonInProgress;
|
|
761
|
+
if (g.length === 0) return Fe(e, []);
|
|
762
|
+
let w = v ?? g[g.length - 1];
|
|
763
|
+
l.current && g.length >= 1 && (w = Dt(e, g[g.length - 1], w));
|
|
764
|
+
const C = [...g, w, g[0]];
|
|
765
|
+
g.length >= 2 ? d.push({ type: "Feature", properties: {}, geometry: { type: "Polygon", coordinates: [C] } }) : d.push({ type: "Feature", properties: {}, geometry: { type: "LineString", coordinates: C } }), g.forEach((T, F) => {
|
|
766
|
+
d.push({ type: "Feature", properties: { _isFirst: F === 0 }, geometry: { type: "Point", coordinates: T } });
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
if (c.editingMode === "draw-circle") {
|
|
770
|
+
const g = c.circleCenter;
|
|
771
|
+
if (!g) return Fe(e, []);
|
|
772
|
+
const w = v ?? g, C = vo(g, w, s.current, 64);
|
|
773
|
+
d.push({ type: "Feature", properties: {}, geometry: { type: "Polygon", coordinates: [C] } }), d.push({ type: "Feature", properties: { _isFirst: !0 }, geometry: { type: "Point", coordinates: g } }), d.push({ type: "Feature", properties: {}, geometry: { type: "Point", coordinates: w } });
|
|
774
|
+
}
|
|
775
|
+
if (c.editingMode === "draw-rect") {
|
|
776
|
+
const g = c.rectCorner;
|
|
777
|
+
if (!g) return Fe(e, []);
|
|
778
|
+
const C = xo(g, v ?? g, s.current, l.current);
|
|
779
|
+
d.push({ type: "Feature", properties: {}, geometry: { type: "Polygon", coordinates: [C] } });
|
|
780
|
+
}
|
|
781
|
+
if (c.editingMode === "draw-route") {
|
|
782
|
+
const g = c.routeWaypoints;
|
|
783
|
+
if (g.length === 0) return Fe(e, []);
|
|
784
|
+
const w = c.routePreview ?? g;
|
|
785
|
+
w.length >= 2 && d.push({ type: "Feature", properties: {}, geometry: { type: "LineString", coordinates: w } });
|
|
786
|
+
const C = c.routeCursorPreview ?? (v ? [g[g.length - 1], v] : null);
|
|
787
|
+
C && C.length >= 2 && d.push({ type: "Feature", properties: {}, geometry: { type: "LineString", coordinates: C } }), g.forEach((T, F) => {
|
|
788
|
+
d.push({ type: "Feature", properties: { _isFirst: F === 0 }, geometry: { type: "Point", coordinates: T } });
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
if (c.editingMode === "draw-freehand") {
|
|
792
|
+
const g = c.freehandPoints;
|
|
793
|
+
g.length >= 2 && d.push({ type: "Feature", properties: {}, geometry: { type: "LineString", coordinates: g } });
|
|
794
|
+
}
|
|
795
|
+
Fe(e, d);
|
|
796
|
+
}
|
|
797
|
+
return null;
|
|
798
|
+
}
|
|
799
|
+
function hn(e, t) {
|
|
800
|
+
const [n, o] = e;
|
|
801
|
+
let r = !1;
|
|
802
|
+
for (let s = 0, i = t.length - 1; s < t.length; i = s++) {
|
|
803
|
+
const [l, u] = t[s], [c, v] = t[i];
|
|
804
|
+
u > o != v > o && n < (c - l) * (o - u) / (v - u + 1e-20) + l && (r = !r);
|
|
805
|
+
}
|
|
806
|
+
return r;
|
|
807
|
+
}
|
|
808
|
+
function mn(e, t) {
|
|
809
|
+
if (t.length === 0 || !hn(e, t[0])) return !1;
|
|
810
|
+
for (let n = 1; n < t.length; n++)
|
|
811
|
+
if (hn(e, t[n])) return !1;
|
|
812
|
+
return !0;
|
|
813
|
+
}
|
|
814
|
+
function Tr(e, t, n) {
|
|
815
|
+
const o = n[0] - t[0], r = n[1] - t[1];
|
|
816
|
+
if (o === 0 && r === 0) {
|
|
817
|
+
const v = e[0] - t[0], d = e[1] - t[1];
|
|
818
|
+
return v * v + d * d;
|
|
819
|
+
}
|
|
820
|
+
const s = Math.max(0, Math.min(1, ((e[0] - t[0]) * o + (e[1] - t[1]) * r) / (o * o + r * r))), i = t[0] + s * o, l = t[1] + s * r, u = e[0] - i, c = e[1] - l;
|
|
821
|
+
return u * u + c * c;
|
|
822
|
+
}
|
|
823
|
+
function tt(e, t) {
|
|
824
|
+
let n = 1 / 0;
|
|
825
|
+
for (let o = 0; o < t.length - 1; o++) {
|
|
826
|
+
const r = Tr(e, t[o], t[o + 1]);
|
|
827
|
+
r < n && (n = r);
|
|
828
|
+
}
|
|
829
|
+
return n;
|
|
830
|
+
}
|
|
831
|
+
function Dr(e, t) {
|
|
832
|
+
if (!ht(e)) return null;
|
|
833
|
+
const n = wo(e);
|
|
834
|
+
if (n === 0) return null;
|
|
835
|
+
if (e.type === "MultiPolygon") {
|
|
836
|
+
for (let s = 0; s < n; s++)
|
|
837
|
+
if (mn(t, e.coordinates[s]))
|
|
838
|
+
return s;
|
|
839
|
+
let o = 0, r = 1 / 0;
|
|
840
|
+
for (let s = 0; s < n; s++) {
|
|
841
|
+
const i = tt(t, e.coordinates[s][0]);
|
|
842
|
+
i < r && (r = i, o = s);
|
|
843
|
+
}
|
|
844
|
+
return o;
|
|
845
|
+
}
|
|
846
|
+
if (e.type === "MultiLineString") {
|
|
847
|
+
let o = 0, r = 1 / 0;
|
|
848
|
+
const s = e.coordinates;
|
|
849
|
+
for (let i = 0; i < n; i++) {
|
|
850
|
+
const l = tt(t, s[i]);
|
|
851
|
+
l < r && (r = l, o = i);
|
|
852
|
+
}
|
|
853
|
+
return o;
|
|
854
|
+
}
|
|
855
|
+
if (e.type === "MultiPoint") {
|
|
856
|
+
let o = 0, r = 1 / 0;
|
|
857
|
+
const s = e.coordinates;
|
|
858
|
+
for (let i = 0; i < n; i++) {
|
|
859
|
+
const l = t[0] - s[i][0], u = t[1] - s[i][1], c = l * l + u * u;
|
|
860
|
+
c < r && (r = c, o = i);
|
|
861
|
+
}
|
|
862
|
+
return o;
|
|
863
|
+
}
|
|
864
|
+
if (e.type === "GeometryCollection") {
|
|
865
|
+
for (let s = 0; s < n; s++) {
|
|
866
|
+
const i = At(e, s);
|
|
867
|
+
if (i.type === "Polygon" && mn(t, i.coordinates))
|
|
868
|
+
return s;
|
|
869
|
+
}
|
|
870
|
+
let o = 0, r = 1 / 0;
|
|
871
|
+
for (let s = 0; s < n; s++) {
|
|
872
|
+
const i = At(e, s);
|
|
873
|
+
let l = 1 / 0;
|
|
874
|
+
if (i.type === "Point") {
|
|
875
|
+
const u = t[0] - i.coordinates[0], c = t[1] - i.coordinates[1];
|
|
876
|
+
l = u * u + c * c;
|
|
877
|
+
} else i.type === "LineString" ? l = tt(t, i.coordinates) : i.type === "Polygon" && (l = tt(t, i.coordinates[0]));
|
|
878
|
+
l < r && (r = l, o = s);
|
|
879
|
+
}
|
|
880
|
+
return o;
|
|
881
|
+
}
|
|
882
|
+
return null;
|
|
883
|
+
}
|
|
884
|
+
function Un({ map: e, coords: t, onSave: n, onClose: o }) {
|
|
885
|
+
const r = Ue(), [s, i] = le(t[0].toFixed(6)), [l, u] = le(t[1].toFixed(6)), [c, v] = le(() => {
|
|
886
|
+
const w = e.project(t);
|
|
887
|
+
return { x: w.x, y: w.y };
|
|
888
|
+
}), d = $(null);
|
|
889
|
+
K(() => {
|
|
890
|
+
const w = () => {
|
|
891
|
+
const C = e.project(t);
|
|
892
|
+
v({ x: C.x, y: C.y });
|
|
893
|
+
};
|
|
894
|
+
return e.on("move", w), e.on("zoom", w), e.on("resize", w), () => {
|
|
895
|
+
e.off("move", w), e.off("zoom", w), e.off("resize", w);
|
|
896
|
+
};
|
|
897
|
+
}, [e, t]), K(() => {
|
|
898
|
+
var w, C;
|
|
899
|
+
(w = d.current) == null || w.focus(), (C = d.current) == null || C.select();
|
|
900
|
+
}, []);
|
|
901
|
+
function g() {
|
|
902
|
+
const w = parseFloat(s), C = parseFloat(l);
|
|
903
|
+
if (isNaN(w) || isNaN(C)) {
|
|
904
|
+
r({ type: "warning", message: "Invalid coordinates" });
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
n([w, C]), r({ type: "success", message: "Coordinate updated" }), o();
|
|
908
|
+
}
|
|
909
|
+
return Ze(
|
|
910
|
+
/* @__PURE__ */ X(
|
|
911
|
+
"div",
|
|
912
|
+
{
|
|
913
|
+
"data-elm-theme": !0,
|
|
914
|
+
style: {
|
|
915
|
+
position: "absolute",
|
|
916
|
+
left: c.x,
|
|
917
|
+
top: c.y - 16,
|
|
918
|
+
transform: "translate(-50%, -100%)",
|
|
919
|
+
zIndex: 500,
|
|
920
|
+
pointerEvents: "auto"
|
|
921
|
+
},
|
|
922
|
+
onMouseDown: (w) => w.stopPropagation(),
|
|
923
|
+
onDoubleClick: (w) => w.stopPropagation(),
|
|
924
|
+
onContextMenu: (w) => w.stopPropagation(),
|
|
925
|
+
children: /* @__PURE__ */ fe(
|
|
926
|
+
"div",
|
|
927
|
+
{
|
|
928
|
+
className: "flex flex-col gap-2 min-w-[160px] bg-(--elm-surface,var(--color-white))/95 backdrop-blur-md border border-(--elm-border-strong,var(--color-slate-300)) rounded-elm-control shadow-elm-control p-2 text-(--elm-text,var(--color-slate-800))",
|
|
929
|
+
onKeyDown: (w) => {
|
|
930
|
+
w.key === "Enter" ? g() : w.key === "Escape" && o();
|
|
931
|
+
},
|
|
932
|
+
children: [
|
|
933
|
+
/* @__PURE__ */ X("p", { className: "text-xs font-semibold m-0 leading-none", children: "Precise coordinates" }),
|
|
934
|
+
/* @__PURE__ */ fe("label", { className: "flex items-center gap-2 text-xs text-(--elm-text-muted,var(--color-slate-500))", children: [
|
|
935
|
+
"Lat:",
|
|
936
|
+
/* @__PURE__ */ X(
|
|
937
|
+
"input",
|
|
938
|
+
{
|
|
939
|
+
ref: d,
|
|
940
|
+
type: "text",
|
|
941
|
+
inputMode: "decimal",
|
|
942
|
+
value: l,
|
|
943
|
+
onChange: (w) => u(w.target.value),
|
|
944
|
+
className: "flex-1 w-full min-w-0 border border-(--elm-border,var(--color-slate-200)) rounded-elm-chip px-1.5 py-0.5 text-xs outline-none focus:border-primary-400"
|
|
945
|
+
}
|
|
946
|
+
)
|
|
947
|
+
] }),
|
|
948
|
+
/* @__PURE__ */ fe("label", { className: "flex items-center gap-2 text-xs text-(--elm-text-muted,var(--color-slate-500))", children: [
|
|
949
|
+
"Lng:",
|
|
950
|
+
/* @__PURE__ */ X(
|
|
951
|
+
"input",
|
|
952
|
+
{
|
|
953
|
+
type: "text",
|
|
954
|
+
inputMode: "decimal",
|
|
955
|
+
value: s,
|
|
956
|
+
onChange: (w) => i(w.target.value),
|
|
957
|
+
className: "flex-1 w-full min-w-0 border border-(--elm-border,var(--color-slate-200)) rounded-elm-chip px-1.5 py-0.5 text-xs outline-none focus:border-primary-400"
|
|
958
|
+
}
|
|
959
|
+
)
|
|
960
|
+
] }),
|
|
961
|
+
/* @__PURE__ */ fe("div", { className: "flex items-center justify-end gap-1 mt-1", children: [
|
|
962
|
+
/* @__PURE__ */ X(
|
|
963
|
+
"button",
|
|
964
|
+
{
|
|
965
|
+
type: "button",
|
|
966
|
+
onClick: o,
|
|
967
|
+
className: "px-2 py-1 text-xs text-(--elm-text-muted,var(--color-slate-500)) hover:bg-(--elm-surface-hover,var(--color-slate-100)) rounded-elm-chip transition-colors",
|
|
968
|
+
children: "Cancel"
|
|
969
|
+
}
|
|
970
|
+
),
|
|
971
|
+
/* @__PURE__ */ X(
|
|
972
|
+
"button",
|
|
973
|
+
{
|
|
974
|
+
type: "button",
|
|
975
|
+
onClick: g,
|
|
976
|
+
className: "px-2 py-1 text-xs text-white bg-primary-500 hover:bg-primary-600 rounded-elm-chip transition-colors font-medium",
|
|
977
|
+
children: "Save"
|
|
978
|
+
}
|
|
979
|
+
)
|
|
980
|
+
] })
|
|
981
|
+
]
|
|
982
|
+
}
|
|
983
|
+
)
|
|
984
|
+
}
|
|
985
|
+
),
|
|
986
|
+
e.getCanvasContainer()
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
const Et = "elm-features";
|
|
990
|
+
let Xe = null;
|
|
991
|
+
const Gt = () => Xe;
|
|
992
|
+
function Pt(e, t) {
|
|
993
|
+
Xe !== t && (e.getSource(Et) && (Xe && e.setFeatureState({ source: Et, id: Xe }, { fresh: !1 }), t && e.setFeatureState({ source: Et, id: t }, { fresh: !0 })), Xe = t);
|
|
994
|
+
}
|
|
995
|
+
let ae = null, Wt = !1, Ut = null, Zt = 0, qt = 0;
|
|
996
|
+
function Jt(e) {
|
|
997
|
+
return e.ctrlKey || e.metaKey || e.altKey;
|
|
998
|
+
}
|
|
999
|
+
function Zn(e) {
|
|
1000
|
+
Jt(e) && ae && (ae.style.display = "none");
|
|
1001
|
+
}
|
|
1002
|
+
function qn(e) {
|
|
1003
|
+
Jt(e) || Wt || Ut && ae && ae.textContent && (ae.style.display = "", gt(Zt, qt));
|
|
1004
|
+
}
|
|
1005
|
+
function Jn(e) {
|
|
1006
|
+
if (!ae) return;
|
|
1007
|
+
gt(e.clientX, e.clientY);
|
|
1008
|
+
const t = e.target;
|
|
1009
|
+
!!(t != null && t.closest(".maplibregl-canvas-container, .maplibregl-canvas")) || (ae.style.display = "none");
|
|
1010
|
+
}
|
|
1011
|
+
function gt(e, t) {
|
|
1012
|
+
if (Zt = e, qt = t, !ae || ae.style.display === "none") return;
|
|
1013
|
+
const { left: n, top: o } = Fn(e, t, ae.offsetWidth, ae.offsetHeight, { x: "center", y: "before", gapY: 12 });
|
|
1014
|
+
ae.style.left = n + "px", ae.style.top = o + "px";
|
|
1015
|
+
}
|
|
1016
|
+
function Kr() {
|
|
1017
|
+
return ae || (ae = document.createElement("div"), ae.className = "elm-feature-tooltip", ae.style.cssText = "position:fixed;pointer-events:none;z-index:10000;display:none", document.body.appendChild(ae), window.addEventListener("keydown", Zn), window.addEventListener("keyup", qn), document.addEventListener("mousemove", Jn, { passive: !0 })), ae;
|
|
1018
|
+
}
|
|
1019
|
+
function Nr(e, t, n) {
|
|
1020
|
+
var i, l;
|
|
1021
|
+
if (Wt) return;
|
|
1022
|
+
const o = t.getState();
|
|
1023
|
+
if (!o.showFeatureNameOnHover || o.vertexEditActive || Gt() === e.id) {
|
|
1024
|
+
ct();
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
const r = Do(e);
|
|
1028
|
+
if (!r) return;
|
|
1029
|
+
const s = Kr();
|
|
1030
|
+
s.textContent = r, qo(s, (l = (i = n == null ? void 0 : n.target) == null ? void 0 : i.closest) == null ? void 0 : l.call(i, "[data-elm-theme]")), Ut = e.id, n && gt(n.clientX, n.clientY), n && Jt(n) ? s.style.display = "none" : (s.style.display = "", gt(Zt, qt));
|
|
1031
|
+
}
|
|
1032
|
+
function ct() {
|
|
1033
|
+
Ut = null, ae && (ae.remove(), ae = null, window.removeEventListener("keydown", Zn), window.removeEventListener("keyup", qn), document.removeEventListener("mousemove", Jn));
|
|
1034
|
+
}
|
|
1035
|
+
function Ce(e) {
|
|
1036
|
+
Wt = e, e && ae && (ae.style.display = "none");
|
|
1037
|
+
}
|
|
1038
|
+
function ze(e) {
|
|
1039
|
+
let t = 0, n = null;
|
|
1040
|
+
const o = () => {
|
|
1041
|
+
t = 0;
|
|
1042
|
+
const r = n;
|
|
1043
|
+
n = null, r && e(...r);
|
|
1044
|
+
};
|
|
1045
|
+
return {
|
|
1046
|
+
schedule(...r) {
|
|
1047
|
+
n = r, t || (t = requestAnimationFrame(o));
|
|
1048
|
+
},
|
|
1049
|
+
flush() {
|
|
1050
|
+
t && cancelAnimationFrame(t), o();
|
|
1051
|
+
},
|
|
1052
|
+
cancel() {
|
|
1053
|
+
t && cancelAnimationFrame(t), t = 0, n = null;
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
function Oe(e, t) {
|
|
1058
|
+
return ht(e) ? t == null ? null : At(e, t) : e;
|
|
1059
|
+
}
|
|
1060
|
+
function nt(e, t, n) {
|
|
1061
|
+
return ht(e) && t != null ? Lo(e, t, n) : n;
|
|
1062
|
+
}
|
|
1063
|
+
function ot(e) {
|
|
1064
|
+
return e.type === "Point" ? [[e.coordinates]] : e.type === "MultiPoint" ? [e.coordinates] : e.type === "LineString" ? [e.coordinates] : e.type === "Polygon" ? e.coordinates : [];
|
|
1065
|
+
}
|
|
1066
|
+
function Ct(e, t) {
|
|
1067
|
+
e.style.background = t ? "var(--color-primary-500)" : "#ffffff", e.style.borderColor = t ? "var(--color-primary-700)" : "var(--color-primary-500)", e.dataset.elmSelected = t ? "1" : "0";
|
|
1068
|
+
}
|
|
1069
|
+
let vn = !1;
|
|
1070
|
+
function Br() {
|
|
1071
|
+
if (vn) return;
|
|
1072
|
+
const e = document.createElement("style");
|
|
1073
|
+
e.textContent = ".elm-midpoint-marker{pointer-events:auto!important}", document.head.appendChild(e), vn = !0;
|
|
1074
|
+
}
|
|
1075
|
+
function xn(e, t = !1) {
|
|
1076
|
+
if (t) {
|
|
1077
|
+
const o = document.createElement("div");
|
|
1078
|
+
o.classList.add("elm-midpoint-marker"), o.style.cssText = "width:24px;height:24px;display:flex;align-items:center;justify-content:center;cursor:pointer;background:rgba(0,0,0,0.001)";
|
|
1079
|
+
const r = document.createElement("div");
|
|
1080
|
+
return r.style.cssText = [
|
|
1081
|
+
"width:12px",
|
|
1082
|
+
"height:12px",
|
|
1083
|
+
"background:#ffffff",
|
|
1084
|
+
"border:2px solid var(--color-primary-500)",
|
|
1085
|
+
"box-shadow:0 1px 3px rgba(0,0,0,0.35)",
|
|
1086
|
+
"transform:rotate(45deg)",
|
|
1087
|
+
"border-radius:3px",
|
|
1088
|
+
"transition:all 0.1s"
|
|
1089
|
+
].join(";"), o.appendChild(r), o.addEventListener("mouseenter", () => {
|
|
1090
|
+
r.style.background = "var(--color-primary-100)";
|
|
1091
|
+
}), o.addEventListener("mouseleave", () => {
|
|
1092
|
+
r.style.background = "#ffffff";
|
|
1093
|
+
}), o;
|
|
1094
|
+
}
|
|
1095
|
+
const n = document.createElement("div");
|
|
1096
|
+
return n.classList.add("elm-vertex"), n.style.cssText = [
|
|
1097
|
+
"width:12px",
|
|
1098
|
+
"height:12px",
|
|
1099
|
+
`background:${e ? "var(--color-primary-500)" : "#ffffff"}`,
|
|
1100
|
+
`border:2px solid ${e ? "var(--color-primary-700)" : "var(--color-primary-500)"}`,
|
|
1101
|
+
"border-radius:3px",
|
|
1102
|
+
"cursor:pointer",
|
|
1103
|
+
"box-shadow:0 1px 3px rgba(0,0,0,0.35)",
|
|
1104
|
+
"transition:background 0.15s"
|
|
1105
|
+
].join(";"), n.dataset.elmSelected = e ? "1" : "0", n.addEventListener("mouseenter", () => {
|
|
1106
|
+
n.style.background = "var(--color-primary-100)";
|
|
1107
|
+
}), n.addEventListener("mouseleave", () => {
|
|
1108
|
+
n.style.background = n.dataset.elmSelected === "1" ? "var(--color-primary-500)" : "#ffffff";
|
|
1109
|
+
}), n;
|
|
1110
|
+
}
|
|
1111
|
+
const rt = 500, wn = 15;
|
|
1112
|
+
function Sn(e, t, n) {
|
|
1113
|
+
const o = t.map((d, g) => g);
|
|
1114
|
+
if (t.length <= rt) return { indices: o, capped: !1 };
|
|
1115
|
+
const r = e.getBounds(), s = o.filter((d) => r.contains(t[d]));
|
|
1116
|
+
if (s.length <= rt) return { indices: s, capped: !0 };
|
|
1117
|
+
const i = [0];
|
|
1118
|
+
let l = e.project(t[s[0]]);
|
|
1119
|
+
for (let d = 1; d < s.length; d++) {
|
|
1120
|
+
const g = e.project(t[s[d]]);
|
|
1121
|
+
i.push(i[d - 1] + Math.hypot(g.x - l.x, g.y - l.y)), l = g;
|
|
1122
|
+
}
|
|
1123
|
+
const u = i[i.length - 1], c = /* @__PURE__ */ new Set();
|
|
1124
|
+
let v = 0;
|
|
1125
|
+
for (let d = 0; d < rt; d++) {
|
|
1126
|
+
const g = u === 0 ? d : d * u / rt;
|
|
1127
|
+
for (; v < i.length - 1 && i[v + 1] < g; ) v++;
|
|
1128
|
+
c.add(s[v]);
|
|
1129
|
+
}
|
|
1130
|
+
for (const d of s) n(d) && c.add(d);
|
|
1131
|
+
return { indices: [...c].sort((d, g) => d - g), capped: !0 };
|
|
1132
|
+
}
|
|
1133
|
+
function Or(e, t) {
|
|
1134
|
+
const n = (e[0] + t[0]) / 2, o = (i) => Math.log(Math.tan(Math.PI / 4 + i * Math.PI / 180 / 2)), s = ((i) => (2 * Math.atan(Math.exp(i)) - Math.PI / 2) * 180 / Math.PI)((o(e[1]) + o(t[1])) / 2);
|
|
1135
|
+
return [n, s];
|
|
1136
|
+
}
|
|
1137
|
+
function $r({ map: e, feature: t, initialSelectedIndices: n }) {
|
|
1138
|
+
var j;
|
|
1139
|
+
const { dataStore: o, uiStore: r } = Le(), s = Ue(), i = zt(), l = he((h) => h.selectedIds), u = W((h) => h.selectedPartIndex), c = $([]), [v, d] = le(() => n && n.length > 0 ? new Set(n.map((h) => `0:${h}`)) : /* @__PURE__ */ new Set()), g = $(v);
|
|
1140
|
+
K(() => {
|
|
1141
|
+
g.current = v;
|
|
1142
|
+
}, [v]);
|
|
1143
|
+
const w = $(/* @__PURE__ */ new Map()), [C, T] = le(null), F = ve(() => T(null), []), [k, N] = le(null);
|
|
1144
|
+
K(() => {
|
|
1145
|
+
d(/* @__PURE__ */ new Set()), T(null), N(null);
|
|
1146
|
+
}, [t.id, u]);
|
|
1147
|
+
const P = $(n);
|
|
1148
|
+
K(() => {
|
|
1149
|
+
n !== P.current && (P.current = n, !(!n || n.length === 0) && d((h) => {
|
|
1150
|
+
const I = new Set(h);
|
|
1151
|
+
for (const O of n) I.add(`0:${O}`);
|
|
1152
|
+
for (const O of n) {
|
|
1153
|
+
const z = w.current.get(`0:${O}`);
|
|
1154
|
+
z && Ct(z, !0);
|
|
1155
|
+
}
|
|
1156
|
+
return I;
|
|
1157
|
+
}));
|
|
1158
|
+
}, [n]);
|
|
1159
|
+
function _(h) {
|
|
1160
|
+
Vt(e, /* @__PURE__ */ new Map([[t.id, h]]));
|
|
1161
|
+
}
|
|
1162
|
+
function D(h) {
|
|
1163
|
+
const I = nt(t.geometry, u, h);
|
|
1164
|
+
o.getState().updateFeature(t.id, So(t, I));
|
|
1165
|
+
}
|
|
1166
|
+
const q = $(!1);
|
|
1167
|
+
K(() => {
|
|
1168
|
+
const h = (I) => {
|
|
1169
|
+
q.current = I.metaKey || I.ctrlKey;
|
|
1170
|
+
};
|
|
1171
|
+
return window.addEventListener("keydown", h), window.addEventListener("keyup", h), () => {
|
|
1172
|
+
window.removeEventListener("keydown", h), window.removeEventListener("keyup", h);
|
|
1173
|
+
};
|
|
1174
|
+
}, []);
|
|
1175
|
+
function p() {
|
|
1176
|
+
Br(), c.current.forEach((z) => z.remove()), c.current = [], w.current = /* @__PURE__ */ new Map(), f.current = [], b.current = null, M.current = !1;
|
|
1177
|
+
const h = Oe(t.geometry, u);
|
|
1178
|
+
if (!h) return;
|
|
1179
|
+
const I = ot(h), O = g.current;
|
|
1180
|
+
E.current = !1, I.forEach((z, G) => {
|
|
1181
|
+
const H = h.type === "Polygon" ? z.slice(0, -1) : z, te = Sn(e, H, (Z) => O.has(`${G}:${Z}`));
|
|
1182
|
+
te.capped && (E.current = !0);
|
|
1183
|
+
for (const Z of te.indices) {
|
|
1184
|
+
const ne = H[Z], se = `${G}:${Z}`, ie = xn(O.has(se));
|
|
1185
|
+
w.current.set(se, ie);
|
|
1186
|
+
const re = new De.Marker({ element: ie, draggable: !0 }).setLngLat(ne).addTo(e);
|
|
1187
|
+
let J = !1;
|
|
1188
|
+
ie.addEventListener("click", (Y) => {
|
|
1189
|
+
if (Y.stopPropagation(), Y.preventDefault(), J) {
|
|
1190
|
+
J = !1;
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
Y.shiftKey ? d((ee) => {
|
|
1194
|
+
const oe = new Set(ee);
|
|
1195
|
+
oe.has(se) ? oe.delete(se) : oe.add(se);
|
|
1196
|
+
const Q = w.current.get(se);
|
|
1197
|
+
return Q && Ct(Q, oe.has(se)), oe;
|
|
1198
|
+
}) : (d(/* @__PURE__ */ new Set([se])), w.current.forEach((ee, oe) => Ct(ee, oe === se)));
|
|
1199
|
+
}), re.on("dragstart", () => {
|
|
1200
|
+
J = !0, M.current = !0, o.getState().takeSnapshot(), document.querySelectorAll(".elm-midpoint-marker").forEach((Y) => {
|
|
1201
|
+
Y.style.display = "none";
|
|
1202
|
+
}), Ce(!0);
|
|
1203
|
+
});
|
|
1204
|
+
const ce = [ne[0], ne[1]], U = ze(() => {
|
|
1205
|
+
const Y = re.getLngLat(), ee = [Y.lng, Y.lat], oe = Mt(h, G, Z, ee);
|
|
1206
|
+
_(nt(t.geometry, u, oe));
|
|
1207
|
+
});
|
|
1208
|
+
re.on("drag", () => U.schedule()), re.on("dragend", () => {
|
|
1209
|
+
U.cancel();
|
|
1210
|
+
const Y = re.getLngLat(), ee = [Y.lng, Y.lat], oe = Mt(h, G, Z, ee);
|
|
1211
|
+
if (D(oe), r.getState().topoEditEnabled && !q.current) {
|
|
1212
|
+
const Q = o.getState();
|
|
1213
|
+
Q.updateFeatures(on(
|
|
1214
|
+
Q.features,
|
|
1215
|
+
t.id,
|
|
1216
|
+
ce,
|
|
1217
|
+
ee
|
|
1218
|
+
));
|
|
1219
|
+
}
|
|
1220
|
+
Ce(!1), M.current = !1, setTimeout(() => {
|
|
1221
|
+
J = !1;
|
|
1222
|
+
}, 50);
|
|
1223
|
+
}), ie.addEventListener("contextmenu", (Y) => {
|
|
1224
|
+
Y.preventDefault(), Y.stopPropagation(), T({ ringIdx: G, vertIdx: Z, x: Y.clientX, y: Y.clientY });
|
|
1225
|
+
}), c.current.push(re);
|
|
1226
|
+
}
|
|
1227
|
+
if (H.length >= 2) {
|
|
1228
|
+
const Z = h.type === "Polygon" ? H.length : H.length - 1, ne = [];
|
|
1229
|
+
for (let ie = 0; ie < Z; ie++) ne.push(Or(H[ie], H[(ie + 1) % H.length]));
|
|
1230
|
+
const se = Sn(e, ne, () => !1);
|
|
1231
|
+
se.capped && (E.current = !0);
|
|
1232
|
+
for (const ie of se.indices) {
|
|
1233
|
+
const re = H[ie], J = H[(ie + 1) % H.length], ce = ne[ie], U = xn(!1, !0);
|
|
1234
|
+
U.style.display = "none", f.current.push({ el: U, a: re, b: J });
|
|
1235
|
+
const Y = new De.Marker({ element: U, draggable: !0 }).setLngLat(ce).addTo(e);
|
|
1236
|
+
let ee = !1;
|
|
1237
|
+
Y.on("dragstart", () => {
|
|
1238
|
+
ee = !0, M.current = !0, o.getState().takeSnapshot(), Ce(!0);
|
|
1239
|
+
});
|
|
1240
|
+
const oe = ze(() => {
|
|
1241
|
+
const Q = Y.getLngLat(), de = [Q.lng, Q.lat], ue = He(h, G, ie + 1, de);
|
|
1242
|
+
_(nt(t.geometry, u, ue));
|
|
1243
|
+
});
|
|
1244
|
+
Y.on("drag", () => oe.schedule()), Y.on("dragend", () => {
|
|
1245
|
+
oe.cancel();
|
|
1246
|
+
const Q = Y.getLngLat(), de = [Q.lng, Q.lat], ue = He(h, G, ie + 1, de);
|
|
1247
|
+
if (D(ue), r.getState().topoEditEnabled) {
|
|
1248
|
+
const Re = o.getState();
|
|
1249
|
+
Re.updateFeatures(wt(
|
|
1250
|
+
Re.features,
|
|
1251
|
+
t.id,
|
|
1252
|
+
re,
|
|
1253
|
+
J,
|
|
1254
|
+
de
|
|
1255
|
+
));
|
|
1256
|
+
}
|
|
1257
|
+
setTimeout(() => {
|
|
1258
|
+
ee = !1;
|
|
1259
|
+
}, 50), Ce(!1), M.current = !1;
|
|
1260
|
+
}), U.addEventListener("click", (Q) => {
|
|
1261
|
+
if (Q.stopPropagation(), ee) {
|
|
1262
|
+
ee = !1;
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
o.getState().takeSnapshot();
|
|
1266
|
+
const de = He(h, G, ie + 1, ce);
|
|
1267
|
+
if (D(de), r.getState().topoEditEnabled) {
|
|
1268
|
+
const ue = o.getState();
|
|
1269
|
+
ue.updateFeatures(wt(
|
|
1270
|
+
ue.features,
|
|
1271
|
+
t.id,
|
|
1272
|
+
re,
|
|
1273
|
+
J,
|
|
1274
|
+
ce
|
|
1275
|
+
));
|
|
1276
|
+
}
|
|
1277
|
+
}), c.current.push(Y);
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
const f = $([]), b = $(null), M = $(!1);
|
|
1283
|
+
K(() => {
|
|
1284
|
+
const h = (z) => {
|
|
1285
|
+
if (z === b.current) return;
|
|
1286
|
+
const G = f.current;
|
|
1287
|
+
b.current !== null && G[b.current] && (G[b.current].el.style.display = "none"), z !== null && (G[z].el.style.display = "flex"), b.current = z;
|
|
1288
|
+
}, I = (z) => {
|
|
1289
|
+
if (M.current) return;
|
|
1290
|
+
const { x: G, y: H } = z.point;
|
|
1291
|
+
let te = -1, Z = 1 / 0;
|
|
1292
|
+
f.current.forEach(({ a: se, b: ie }, re) => {
|
|
1293
|
+
const J = e.project(se), ce = e.project(ie), U = ce.x - J.x, Y = ce.y - J.y, ee = U * U + Y * Y, oe = ee ? Math.max(0, Math.min(1, ((G - J.x) * U + (H - J.y) * Y) / ee)) : 0, Q = (J.x + oe * U - G) ** 2 + (J.y + oe * Y - H) ** 2;
|
|
1294
|
+
Q < Z && (Z = Q, te = re);
|
|
1295
|
+
});
|
|
1296
|
+
const ne = b.current === null ? 22 : 36;
|
|
1297
|
+
h(te >= 0 && Z <= ne * ne ? te : null);
|
|
1298
|
+
}, O = (z) => {
|
|
1299
|
+
const G = z.originalEvent.relatedTarget;
|
|
1300
|
+
!M.current && !(G instanceof Node && e.getContainer().contains(G)) && h(null);
|
|
1301
|
+
};
|
|
1302
|
+
return e.on("mousemove", I), e.on("mouseout", O), () => {
|
|
1303
|
+
e.off("mousemove", I), e.off("mouseout", O);
|
|
1304
|
+
};
|
|
1305
|
+
}, [e]);
|
|
1306
|
+
const A = $(() => {
|
|
1307
|
+
});
|
|
1308
|
+
A.current = (h) => {
|
|
1309
|
+
var ee, oe;
|
|
1310
|
+
const I = h.originalEvent;
|
|
1311
|
+
if (M.current || I.button !== 0 || I.shiftKey || (oe = (ee = I.target) == null ? void 0 : ee.closest) != null && oe.call(ee, ".maplibregl-marker")) return;
|
|
1312
|
+
const O = Oe(t.geometry, u);
|
|
1313
|
+
if (!O || O.type !== "Polygon" && O.type !== "LineString") return;
|
|
1314
|
+
const z = O.type === "Polygon";
|
|
1315
|
+
let G = null, H = wn * wn;
|
|
1316
|
+
if (ot(O).forEach((Q, de) => {
|
|
1317
|
+
const ue = z ? Q.slice(0, -1) : Q, Re = z ? ue.length : ue.length - 1;
|
|
1318
|
+
if (ue.length < 2) return;
|
|
1319
|
+
let xe = e.project(ue[0]);
|
|
1320
|
+
for (let Ee = 0; Ee < Re; Ee++) {
|
|
1321
|
+
const Je = ue[(Ee + 1) % ue.length], xt = e.project(Je), Qe = xt.x - xe.x, et = xt.y - xe.y, en = Qe * Qe + et * et, tn = en ? Math.max(0, Math.min(1, ((h.point.x - xe.x) * Qe + (h.point.y - xe.y) * et) / en)) : 0, nn = (xe.x + tn * Qe - h.point.x) ** 2 + (xe.y + tn * et - h.point.y) ** 2;
|
|
1322
|
+
nn < H && (H = nn, G = { ringIdx: de, seg: Ee, a: ue[Ee], b: Je }), xe = xt;
|
|
1323
|
+
}
|
|
1324
|
+
}), !G) return;
|
|
1325
|
+
const { ringIdx: te, seg: Z, a: ne, b: se } = G;
|
|
1326
|
+
h.preventDefault();
|
|
1327
|
+
const ie = h.point;
|
|
1328
|
+
let re = [h.lngLat.lng, h.lngLat.lat], J = !1;
|
|
1329
|
+
const ce = ze(() => {
|
|
1330
|
+
_(nt(t.geometry, u, He(O, te, Z + 1, re)));
|
|
1331
|
+
}), U = (Q) => {
|
|
1332
|
+
if (!J) {
|
|
1333
|
+
if (Math.hypot(Q.point.x - ie.x, Q.point.y - ie.y) < 3) return;
|
|
1334
|
+
J = !0, M.current = !0, o.getState().takeSnapshot(), document.querySelectorAll(".elm-midpoint-marker").forEach((ue) => {
|
|
1335
|
+
ue.style.display = "none";
|
|
1336
|
+
}), b.current = null, Ce(!0);
|
|
1337
|
+
}
|
|
1338
|
+
re = [Q.lngLat.lng, Q.lngLat.lat];
|
|
1339
|
+
const de = Q.originalEvent.metaKey || Q.originalEvent.ctrlKey;
|
|
1340
|
+
if (r.getState().snapEnabled && !de) {
|
|
1341
|
+
const ue = Vn(re[0], re[1], e, o.getState().features, 15, /* @__PURE__ */ new Set([t.id]));
|
|
1342
|
+
ue && (re = ue.lnglat);
|
|
1343
|
+
}
|
|
1344
|
+
ce.schedule();
|
|
1345
|
+
}, Y = () => {
|
|
1346
|
+
if (e.off("mousemove", U), window.removeEventListener("mouseup", Y), ce.cancel(), !!J) {
|
|
1347
|
+
if (D(He(O, te, Z + 1, re)), z && r.getState().topoEditEnabled) {
|
|
1348
|
+
const Q = o.getState();
|
|
1349
|
+
Q.updateFeatures(wt(Q.features, t.id, ne, se, re));
|
|
1350
|
+
}
|
|
1351
|
+
Ce(!1), M.current = !1;
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
e.on("mousemove", U), window.addEventListener("mouseup", Y);
|
|
1355
|
+
}, K(() => {
|
|
1356
|
+
const h = (I) => A.current(I);
|
|
1357
|
+
return e.on("mousedown", h), () => {
|
|
1358
|
+
e.off("mousedown", h);
|
|
1359
|
+
};
|
|
1360
|
+
}, [e]);
|
|
1361
|
+
const E = $(!1), a = $(p);
|
|
1362
|
+
a.current = p, K(() => {
|
|
1363
|
+
const h = () => {
|
|
1364
|
+
E.current && a.current();
|
|
1365
|
+
};
|
|
1366
|
+
return e.on("moveend", h), () => {
|
|
1367
|
+
e.off("moveend", h);
|
|
1368
|
+
};
|
|
1369
|
+
}, [e]), K(() => (p(), () => {
|
|
1370
|
+
c.current.forEach((h) => h.remove()), c.current = [], w.current = /* @__PURE__ */ new Map();
|
|
1371
|
+
}), [t, e, l, u]);
|
|
1372
|
+
function x(h, I) {
|
|
1373
|
+
const O = Oe(t.geometry, u);
|
|
1374
|
+
if (!O) return;
|
|
1375
|
+
const z = jr(O, h, I);
|
|
1376
|
+
if (!z) {
|
|
1377
|
+
s({ type: "warning", message: `Cannot delete: ${O.type === "Polygon" ? "an area needs at least 3" : O.type === "LineString" ? "a line needs at least 2" : "at least 1"} points` });
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
const G = ot(O)[h][I];
|
|
1381
|
+
if (o.getState().takeSnapshot(), D(z), d(/* @__PURE__ */ new Set()), O.type === "Polygon" && r.getState().topoEditEnabled) {
|
|
1382
|
+
const H = o.getState();
|
|
1383
|
+
H.updateFeatures(rn(H.features, t.id, [G]));
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
function y() {
|
|
1387
|
+
const h = g.current;
|
|
1388
|
+
if (h.size === 0) return;
|
|
1389
|
+
const I = Oe(t.geometry, u);
|
|
1390
|
+
if (!I) return;
|
|
1391
|
+
const O = /* @__PURE__ */ new Map();
|
|
1392
|
+
for (const z of h) {
|
|
1393
|
+
const [G, H] = z.split(":"), te = Number(G), Z = Number(H), ne = O.get(te) ?? [];
|
|
1394
|
+
ne.push(Z), O.set(te, ne);
|
|
1395
|
+
}
|
|
1396
|
+
if (I.type === "LineString") {
|
|
1397
|
+
const z = I.coordinates, G = new Set(O.get(0) ?? []), H = z.filter((te, Z) => !G.has(Z));
|
|
1398
|
+
if (H.length < 2) {
|
|
1399
|
+
s({ type: "warning", message: "Cannot delete: a line needs at least 2 points" });
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
o.getState().takeSnapshot(), D({ type: "LineString", coordinates: H }), d(/* @__PURE__ */ new Set());
|
|
1403
|
+
return;
|
|
1404
|
+
}
|
|
1405
|
+
if (I.type === "MultiPoint") {
|
|
1406
|
+
const z = I.coordinates, G = new Set(O.get(0) ?? []), H = z.filter((te, Z) => !G.has(Z));
|
|
1407
|
+
if (H.length < 1) {
|
|
1408
|
+
s({ type: "warning", message: "Cannot delete: at least 1 point required" });
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1411
|
+
o.getState().takeSnapshot(), D({ type: "MultiPoint", coordinates: H }), d(/* @__PURE__ */ new Set());
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
if (I.type === "Polygon") {
|
|
1415
|
+
const z = I.coordinates, G = [];
|
|
1416
|
+
for (let H = 0; H < z.length; H++) {
|
|
1417
|
+
const te = z[H], Z = te.slice(0, -1), ne = new Set(O.get(H) ?? []);
|
|
1418
|
+
if (ne.size === 0) {
|
|
1419
|
+
G.push(te);
|
|
1420
|
+
continue;
|
|
1421
|
+
}
|
|
1422
|
+
const se = Z.filter((ie, re) => !ne.has(re));
|
|
1423
|
+
if (se.length < 3) {
|
|
1424
|
+
s({ type: "warning", message: "Cannot delete: an area needs at least 3 points" });
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
G.push([...se, se[0]]);
|
|
1428
|
+
}
|
|
1429
|
+
if (o.getState().takeSnapshot(), D({ type: "Polygon", coordinates: G }), d(/* @__PURE__ */ new Set()), r.getState().topoEditEnabled) {
|
|
1430
|
+
const H = [...O].flatMap(([Z, ne]) => ne.map((se) => z[Z][se])), te = o.getState();
|
|
1431
|
+
te.updateFeatures(rn(te.features, t.id, H));
|
|
1432
|
+
}
|
|
1433
|
+
return;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
function m() {
|
|
1437
|
+
if (g.current.size < 3) {
|
|
1438
|
+
s({ type: "warning", message: "Select at least 3 points to simplify" });
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
const h = Oe(t.geometry, u);
|
|
1442
|
+
if (!h || h.type !== "LineString" && h.type !== "Polygon") return;
|
|
1443
|
+
const I = /* @__PURE__ */ new Map();
|
|
1444
|
+
for (const U of g.current) {
|
|
1445
|
+
const [Y, ee] = U.split(":"), oe = Number(Y), Q = Number(ee), de = I.get(oe) ?? [];
|
|
1446
|
+
de.push(Q), I.set(oe, de);
|
|
1447
|
+
}
|
|
1448
|
+
if (I.size !== 1) {
|
|
1449
|
+
s({ type: "warning", message: "Selection must stay within one ring/line to simplify" });
|
|
1450
|
+
return;
|
|
1451
|
+
}
|
|
1452
|
+
const [O, z] = Array.from(I.entries())[0], G = z.sort((U, Y) => U - Y), H = G[0], te = G[G.length - 1], Z = h.type === "Polygon", ne = Z ? h.coordinates[O].slice(0, -1) : h.coordinates, se = ne.slice(H, te + 1), ie = bo(se, 1e-5), re = se.length - ie.length;
|
|
1453
|
+
if (re === 0) {
|
|
1454
|
+
s({ type: "warning", message: "Nothing to remove: no selected point sits on a straight line" });
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
const J = [...ne.slice(0, H), ...ie, ...ne.slice(te + 1)], ce = Z ? 3 : 2;
|
|
1458
|
+
if (J.length < ce) {
|
|
1459
|
+
s({ type: "warning", message: `Cannot simplify: ${Z ? "an area needs at least 3" : "a line needs at least 2"} points` });
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1462
|
+
if (o.getState().takeSnapshot(), Z) {
|
|
1463
|
+
const U = h.coordinates.map(
|
|
1464
|
+
(Y, ee) => ee === O ? [...J, J[0]] : Y
|
|
1465
|
+
);
|
|
1466
|
+
D({ type: "Polygon", coordinates: U });
|
|
1467
|
+
} else
|
|
1468
|
+
D({ type: "LineString", coordinates: J });
|
|
1469
|
+
d(/* @__PURE__ */ new Set()), s({ type: "success", message: `Removed ${re} extra point${re !== 1 ? "s" : ""}` });
|
|
1470
|
+
}
|
|
1471
|
+
K(() => {
|
|
1472
|
+
if (v.size === 0) return;
|
|
1473
|
+
function h(I) {
|
|
1474
|
+
if (I.key !== "Delete" && I.key !== "Backspace") return;
|
|
1475
|
+
const O = I.target;
|
|
1476
|
+
O && (O.tagName === "INPUT" || O.tagName === "TEXTAREA" || O.isContentEditable) || i(I) && (I.preventDefault(), I.stopPropagation(), y());
|
|
1477
|
+
}
|
|
1478
|
+
return window.addEventListener("keydown", h, { capture: !0 }), () => window.removeEventListener("keydown", h, { capture: !0 });
|
|
1479
|
+
}, [v]);
|
|
1480
|
+
const R = v.size > 0, S = C && (() => {
|
|
1481
|
+
const h = `${C.ringIdx}:${C.vertIdx}`, I = v.has(h) && v.size > 1;
|
|
1482
|
+
return /* @__PURE__ */ X(
|
|
1483
|
+
Ko,
|
|
1484
|
+
{
|
|
1485
|
+
x: C.x,
|
|
1486
|
+
y: C.y,
|
|
1487
|
+
onClose: F,
|
|
1488
|
+
items: [
|
|
1489
|
+
{ label: "Edit coordinates…", icon: /* @__PURE__ */ X(rr, { size: 16 }), onClick: () => N({ ringIdx: C.ringIdx, vertIdx: C.vertIdx }) },
|
|
1490
|
+
{ separator: !0 },
|
|
1491
|
+
{
|
|
1492
|
+
label: I ? `Delete ${v.size} points` : "Delete point",
|
|
1493
|
+
icon: /* @__PURE__ */ X(sr, { size: 16 }),
|
|
1494
|
+
onClick: () => I ? y() : x(C.ringIdx, C.vertIdx)
|
|
1495
|
+
}
|
|
1496
|
+
]
|
|
1497
|
+
}
|
|
1498
|
+
);
|
|
1499
|
+
})(), L = k && Oe(t.geometry, u), B = L && k ? (j = ot(L)[k.ringIdx]) == null ? void 0 : j[k.vertIdx] : void 0, V = k && L && B && /* @__PURE__ */ X(
|
|
1500
|
+
Un,
|
|
1501
|
+
{
|
|
1502
|
+
map: e,
|
|
1503
|
+
coords: B,
|
|
1504
|
+
onSave: (h) => {
|
|
1505
|
+
if (o.getState().takeSnapshot(), D(Mt(L, k.ringIdx, k.vertIdx, h)), L.type === "Polygon" && r.getState().topoEditEnabled) {
|
|
1506
|
+
const I = o.getState();
|
|
1507
|
+
I.updateFeatures(on(I.features, t.id, B, h));
|
|
1508
|
+
}
|
|
1509
|
+
},
|
|
1510
|
+
onClose: () => N(null)
|
|
1511
|
+
},
|
|
1512
|
+
`${k.ringIdx}:${k.vertIdx}`
|
|
1513
|
+
);
|
|
1514
|
+
return /* @__PURE__ */ fe(lt, { children: [
|
|
1515
|
+
S,
|
|
1516
|
+
V,
|
|
1517
|
+
R && /* @__PURE__ */ X(
|
|
1518
|
+
No,
|
|
1519
|
+
{
|
|
1520
|
+
mapContainer: e.getContainer(),
|
|
1521
|
+
count: v.size,
|
|
1522
|
+
onSimplify: m,
|
|
1523
|
+
onDelete: y
|
|
1524
|
+
}
|
|
1525
|
+
)
|
|
1526
|
+
] });
|
|
1527
|
+
}
|
|
1528
|
+
function Mt(e, t, n, o) {
|
|
1529
|
+
if (e.type === "Point") return { type: "Point", coordinates: Ve(e.coordinates, o) };
|
|
1530
|
+
if (e.type === "MultiPoint") {
|
|
1531
|
+
const r = [...e.coordinates];
|
|
1532
|
+
return r[n] = Ve(r[n], o), { type: "MultiPoint", coordinates: r };
|
|
1533
|
+
}
|
|
1534
|
+
if (e.type === "LineString") {
|
|
1535
|
+
const r = [...e.coordinates];
|
|
1536
|
+
return r[n] = Ve(r[n], o), { type: "LineString", coordinates: r };
|
|
1537
|
+
}
|
|
1538
|
+
return e.type === "Polygon" ? { type: "Polygon", coordinates: e.coordinates.map((s, i) => {
|
|
1539
|
+
if (i !== t) return s;
|
|
1540
|
+
const l = [...s];
|
|
1541
|
+
return l[n] = Ve(l[n], o), n === 0 && (l[l.length - 1] = l[0]), l;
|
|
1542
|
+
}) } : e;
|
|
1543
|
+
}
|
|
1544
|
+
function jr(e, t, n) {
|
|
1545
|
+
if (e.type === "LineString") {
|
|
1546
|
+
const o = e.coordinates.filter((r, s) => s !== n);
|
|
1547
|
+
return o.length < 2 ? null : { type: "LineString", coordinates: o };
|
|
1548
|
+
}
|
|
1549
|
+
if (e.type === "Polygon") {
|
|
1550
|
+
const r = e.coordinates[t].slice(0, -1);
|
|
1551
|
+
if (r.length <= 3) return null;
|
|
1552
|
+
const s = r.filter((l, u) => u !== n);
|
|
1553
|
+
return { type: "Polygon", coordinates: e.coordinates.map(
|
|
1554
|
+
(l, u) => u === t ? [...s, s[0]] : l
|
|
1555
|
+
) };
|
|
1556
|
+
}
|
|
1557
|
+
if (e.type === "MultiPoint") {
|
|
1558
|
+
const o = e.coordinates.filter((r, s) => s !== n);
|
|
1559
|
+
return o.length < 1 ? null : { type: "MultiPoint", coordinates: o };
|
|
1560
|
+
}
|
|
1561
|
+
return null;
|
|
1562
|
+
}
|
|
1563
|
+
function He(e, t, n, o) {
|
|
1564
|
+
if (e.type === "LineString") {
|
|
1565
|
+
const r = [...e.coordinates];
|
|
1566
|
+
return r.splice(n, 0, sn(r[n - 1], r[n], o)), { type: "LineString", coordinates: r };
|
|
1567
|
+
}
|
|
1568
|
+
if (e.type === "Polygon") {
|
|
1569
|
+
const s = e.coordinates[t].slice(0, -1);
|
|
1570
|
+
return s.splice(n, 0, sn(s[n - 1], s[n % s.length], o)), { type: "Polygon", coordinates: e.coordinates.map(
|
|
1571
|
+
(l, u) => u === t ? [...s, s[0]] : l
|
|
1572
|
+
) };
|
|
1573
|
+
}
|
|
1574
|
+
return e;
|
|
1575
|
+
}
|
|
1576
|
+
function zr(e, t, n) {
|
|
1577
|
+
if (!n) return [t[0] - e[0], t[1] - e[1]];
|
|
1578
|
+
const o = me(e), r = me(t);
|
|
1579
|
+
return [r[0] - o[0], r[1] - o[1]];
|
|
1580
|
+
}
|
|
1581
|
+
function st(e, t, n) {
|
|
1582
|
+
return $t({ type: "MultiPoint", coordinates: e }, t, n).coordinates;
|
|
1583
|
+
}
|
|
1584
|
+
function Hr(e, t, n) {
|
|
1585
|
+
let o = !1;
|
|
1586
|
+
for (let r = 0, s = t.length - 1; r < t.length; s = r++) {
|
|
1587
|
+
const i = t[r], l = t[s];
|
|
1588
|
+
i.y > e.y != l.y > e.y && e.x < (l.x - i.x) * (e.y - i.y) / (l.y - i.y) + i.x && (o = !o);
|
|
1589
|
+
const u = l.x - i.x, c = l.y - i.y, v = u * u + c * c, d = v ? Math.max(0, Math.min(1, ((e.x - i.x) * u + (e.y - i.y) * c) / v)) : 0;
|
|
1590
|
+
if (Math.hypot(i.x + d * u - e.x, i.y + d * c - e.y) <= n) return !0;
|
|
1591
|
+
}
|
|
1592
|
+
return o;
|
|
1593
|
+
}
|
|
1594
|
+
const Vr = 3, Xr = 8;
|
|
1595
|
+
function it(e) {
|
|
1596
|
+
const t = cr(e), [n, o, r, s] = Bn(t), i = (n + r) / 2, l = Zr(o, s);
|
|
1597
|
+
return {
|
|
1598
|
+
corners: [
|
|
1599
|
+
[n, s],
|
|
1600
|
+
[r, s],
|
|
1601
|
+
[r, o],
|
|
1602
|
+
[n, o]
|
|
1603
|
+
],
|
|
1604
|
+
edges: [
|
|
1605
|
+
[i, s],
|
|
1606
|
+
[r, l],
|
|
1607
|
+
[i, o],
|
|
1608
|
+
[n, l]
|
|
1609
|
+
],
|
|
1610
|
+
// The box centre (rotation pivot, Alt-scale anchor), not the vertex mean.
|
|
1611
|
+
center: [i, l],
|
|
1612
|
+
rotateHandle: [i, s]
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
function kt(e, t, n) {
|
|
1616
|
+
const [o, r] = t, s = Ke(n), i = Math.cos(s), l = Math.sin(s), u = Te(r);
|
|
1617
|
+
return e.map(([c, v]) => {
|
|
1618
|
+
const d = (c - o) * u, g = v - r;
|
|
1619
|
+
return [
|
|
1620
|
+
o + (d * i - g * l) / u,
|
|
1621
|
+
r + (d * l + g * i)
|
|
1622
|
+
];
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
function Yr(e, t, n, o, r) {
|
|
1626
|
+
const [s, i] = t, l = Ke(r), u = Math.cos(l), c = Math.sin(l), v = Te(i);
|
|
1627
|
+
return e.map(([d, g]) => {
|
|
1628
|
+
const w = (d - s) * v, C = g - i, T = w * u + C * c, F = -w * c + C * u, k = T * n, N = F * o, P = k * u - N * c, _ = k * c + N * u;
|
|
1629
|
+
return [s + P / v, i + _];
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
function Gr(e, t, n, o) {
|
|
1633
|
+
const r = me(t), s = Ke(o), i = Math.cos(s), l = Math.sin(s);
|
|
1634
|
+
function u(c) {
|
|
1635
|
+
const v = me(c), d = v[0] - r[0], g = v[1] - r[1], w = d * i + g * l, C = -d * l + g * i, T = w * n, F = C * n, k = T * i - F * l, N = T * l + F * i;
|
|
1636
|
+
return Ot([r[0] + k, r[1] + N]);
|
|
1637
|
+
}
|
|
1638
|
+
return { ...e, geometry: _n(e.geometry, u) };
|
|
1639
|
+
}
|
|
1640
|
+
function Wr(e, t, n, o) {
|
|
1641
|
+
const r = me(t), s = Ke(o), i = Math.cos(s), l = Math.sin(s);
|
|
1642
|
+
return e.map((u) => {
|
|
1643
|
+
const c = me(u), v = c[0] - r[0], d = c[1] - r[1], g = v * i + d * l, w = -v * l + d * i, C = g * n, T = w * n, F = C * i - T * l, k = C * l + T * i;
|
|
1644
|
+
return Ot([r[0] + F, r[1] + k]);
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
function Ur(e, t, n, o, r) {
|
|
1648
|
+
const [s, i] = t, l = Ke(r), u = Math.cos(l), c = Math.sin(l), v = Te(i);
|
|
1649
|
+
function d(g) {
|
|
1650
|
+
const w = (g[0] - s) * v, C = g[1] - i, T = w * u + C * c, F = -w * c + C * u, k = T * n, N = F * o, P = k * u - N * c, _ = k * c + N * u;
|
|
1651
|
+
return [s + P / v, i + _];
|
|
1652
|
+
}
|
|
1653
|
+
return { ...e, geometry: _n(e.geometry, d) };
|
|
1654
|
+
}
|
|
1655
|
+
function Zr(e, t) {
|
|
1656
|
+
return Ot([0, (me([0, e])[1] + me([0, t])[1]) / 2])[1];
|
|
1657
|
+
}
|
|
1658
|
+
function qr(e, t, n, o) {
|
|
1659
|
+
const r = o ? e.initialBbox.center : e.origin, s = Math.cos(Ke(e.rotationAngle)), i = Math.sin(Ke(e.rotationAngle));
|
|
1660
|
+
let l;
|
|
1661
|
+
if (n) {
|
|
1662
|
+
const F = me(r);
|
|
1663
|
+
l = (k) => {
|
|
1664
|
+
const N = me(k), P = N[0] - F[0], _ = N[1] - F[1];
|
|
1665
|
+
return [P * s + _ * i, -P * i + _ * s];
|
|
1666
|
+
};
|
|
1667
|
+
} else {
|
|
1668
|
+
const F = Te(r[1]);
|
|
1669
|
+
l = (k) => {
|
|
1670
|
+
const N = (k[0] - r[0]) * F, P = k[1] - r[1];
|
|
1671
|
+
return [N * s + P * i, -N * i + P * s];
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
const [u, c] = l(e.startLngLat), [v, d] = l(t), g = e.edgeIndex === 0 || e.edgeIndex === 2, w = e.edgeIndex === 1 || e.edgeIndex === 3, C = (F) => Math.abs(F) < 0.01 ? F < 0 ? -0.01 : 0.01 : F, T = (F, k) => Math.abs(k) > 1e-9 ? F / k : 1;
|
|
1675
|
+
if (n) {
|
|
1676
|
+
let F;
|
|
1677
|
+
if (g) F = T(d, c);
|
|
1678
|
+
else if (w) F = T(v, u);
|
|
1679
|
+
else {
|
|
1680
|
+
const k = u * u + c * c;
|
|
1681
|
+
F = k > 1e-18 ? (v * u + d * c) / k : 1;
|
|
1682
|
+
}
|
|
1683
|
+
return { origin: r, uniform: !0, factor: C(F) };
|
|
1684
|
+
}
|
|
1685
|
+
return {
|
|
1686
|
+
origin: r,
|
|
1687
|
+
uniform: !1,
|
|
1688
|
+
scaleX: w || !g ? C(T(v, u)) : 1,
|
|
1689
|
+
scaleY: g || !w ? C(T(d, c)) : 1
|
|
1690
|
+
};
|
|
1691
|
+
}
|
|
1692
|
+
function Jr(e, t, n, o) {
|
|
1693
|
+
const r = n.uniform ? (s) => Wr(s, n.origin, n.factor, o) : (s) => Yr(s, n.origin, n.scaleX, n.scaleY, o);
|
|
1694
|
+
return {
|
|
1695
|
+
features: e.map((s) => n.uniform ? Gr(s, n.origin, n.factor, o) : Ur(s, n.origin, n.scaleX, n.scaleY, o)),
|
|
1696
|
+
box: {
|
|
1697
|
+
corners: r(t.corners),
|
|
1698
|
+
edges: r(t.edges),
|
|
1699
|
+
center: r([t.center])[0],
|
|
1700
|
+
rotateHandle: r([t.rotateHandle])[0]
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1704
|
+
function Qr(e) {
|
|
1705
|
+
return e === "nw" || e === "se" ? "nwse-resize" : e === "ne" || e === "sw" ? "nesw-resize" : e === "n" || e === "s" ? "ns-resize" : e === "e" || e === "w" ? "ew-resize" : "grab";
|
|
1706
|
+
}
|
|
1707
|
+
function It(e) {
|
|
1708
|
+
const t = document.createElement("div");
|
|
1709
|
+
if (e === "rotate") {
|
|
1710
|
+
t.style.cssText = [
|
|
1711
|
+
"position:relative",
|
|
1712
|
+
"display:flex",
|
|
1713
|
+
"align-items:center",
|
|
1714
|
+
"justify-content:center",
|
|
1715
|
+
"width:16px",
|
|
1716
|
+
"height:32px",
|
|
1717
|
+
"cursor:grab"
|
|
1718
|
+
].join(";");
|
|
1719
|
+
const n = document.createElement("div");
|
|
1720
|
+
n.style.cssText = "position:absolute;bottom:0;left:50%;transform:translateX(-50%);width:2px;height:24px;background:var(--color-primary-600);", t.appendChild(n);
|
|
1721
|
+
const o = document.createElement("div");
|
|
1722
|
+
o.style.cssText = [
|
|
1723
|
+
"position:absolute",
|
|
1724
|
+
"top:0",
|
|
1725
|
+
"left:50%",
|
|
1726
|
+
"transform:translateX(-50%)",
|
|
1727
|
+
"width:16px",
|
|
1728
|
+
"height:16px",
|
|
1729
|
+
"background:#ffffff",
|
|
1730
|
+
"border:2px solid var(--color-primary-600)",
|
|
1731
|
+
"border-radius:50%",
|
|
1732
|
+
"box-shadow:0 1px 3px rgba(0,0,0,0.35)",
|
|
1733
|
+
"display:flex",
|
|
1734
|
+
"align-items:center",
|
|
1735
|
+
"justify-content:center"
|
|
1736
|
+
].join(";");
|
|
1737
|
+
const r = document.createElement("div");
|
|
1738
|
+
return r.style.cssText = "width:6px;height:6px;background:var(--color-primary-600);border-radius:50%;", o.appendChild(r), t.appendChild(o), t;
|
|
1739
|
+
}
|
|
1740
|
+
return t.style.cssText = [
|
|
1741
|
+
"width:12px",
|
|
1742
|
+
"height:12px",
|
|
1743
|
+
"background:#ffffff",
|
|
1744
|
+
"border:2px solid var(--color-primary-600)",
|
|
1745
|
+
"border-radius:3px",
|
|
1746
|
+
`cursor:${Qr(e)}`,
|
|
1747
|
+
"box-shadow:0 1px 3px rgba(0,0,0,0.35)"
|
|
1748
|
+
].join(";"), t;
|
|
1749
|
+
}
|
|
1750
|
+
function es({ map: e, features: t }) {
|
|
1751
|
+
const { dataStore: n, uiStore: o } = Le(), r = he((p) => p.selectedIds), s = W((p) => p.transformActive), i = W((p) => p.setTransformDragging), l = $(t);
|
|
1752
|
+
l.current = t;
|
|
1753
|
+
const [u, c] = le(null), v = $(null);
|
|
1754
|
+
v.current = u;
|
|
1755
|
+
const d = $(0), g = r.join(",");
|
|
1756
|
+
K(() => {
|
|
1757
|
+
c(null), d.current = 0;
|
|
1758
|
+
}, [g]);
|
|
1759
|
+
const w = $(null), C = $(null), T = $([]);
|
|
1760
|
+
function F() {
|
|
1761
|
+
T.current.forEach((p) => p.remove()), T.current = [];
|
|
1762
|
+
}
|
|
1763
|
+
function k(p) {
|
|
1764
|
+
const f = /* @__PURE__ */ new Map();
|
|
1765
|
+
for (const b of p) f.set(String(b.id ?? ""), b.geometry);
|
|
1766
|
+
Vt(e, f);
|
|
1767
|
+
}
|
|
1768
|
+
function N(p) {
|
|
1769
|
+
const f = T.current;
|
|
1770
|
+
if (f.length === 9) {
|
|
1771
|
+
for (let b = 0; b < 4; b++) f[b].setLngLat(p.corners[b]);
|
|
1772
|
+
for (let b = 0; b < 4; b++) f[4 + b].setLngLat(p.edges[b]);
|
|
1773
|
+
f[8].setLngLat(p.rotateHandle);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
const P = $(null);
|
|
1777
|
+
K(() => {
|
|
1778
|
+
if (!s || t.length === 0) return;
|
|
1779
|
+
F();
|
|
1780
|
+
const p = v.current ?? it(t), f = ["nw", "ne", "se", "sw"], b = ["n", "e", "s", "w"], M = [];
|
|
1781
|
+
p.corners.forEach((A, E) => {
|
|
1782
|
+
const a = It(f[E]), x = new De.Marker({ element: a, draggable: !1 }).setLngLat(A).addTo(e);
|
|
1783
|
+
a.addEventListener("mousedown", (y) => D(y, E, !1)), M.push(x);
|
|
1784
|
+
}), p.edges.forEach((A, E) => {
|
|
1785
|
+
const a = It(b[E]), x = new De.Marker({ element: a, draggable: !1 }).setLngLat(A).addTo(e);
|
|
1786
|
+
a.addEventListener("mousedown", (y) => D(y, E, !0)), M.push(x);
|
|
1787
|
+
});
|
|
1788
|
+
{
|
|
1789
|
+
const A = It("rotate"), E = new De.Marker({ element: A, anchor: "bottom", draggable: !1 }).setLngLat(p.rotateHandle).addTo(e);
|
|
1790
|
+
A.addEventListener("mousedown", (a) => q(a)), M.push(E);
|
|
1791
|
+
}
|
|
1792
|
+
return T.current = M, () => {
|
|
1793
|
+
F();
|
|
1794
|
+
};
|
|
1795
|
+
}, [s, g, u, e]), K(() => {
|
|
1796
|
+
function p(S) {
|
|
1797
|
+
const L = e.getCanvasContainer().getBoundingClientRect(), B = e.unproject([S.clientX - L.left, S.clientY - L.top]);
|
|
1798
|
+
return [B.lng, B.lat];
|
|
1799
|
+
}
|
|
1800
|
+
const f = ze(E);
|
|
1801
|
+
let b = null;
|
|
1802
|
+
function M(S) {
|
|
1803
|
+
P.current && (S.preventDefault(), b = { clientX: S.clientX, clientY: S.clientY }, f.schedule(S));
|
|
1804
|
+
}
|
|
1805
|
+
function A(S) {
|
|
1806
|
+
var L;
|
|
1807
|
+
S.key !== "Shift" && S.key !== "Alt" || ((L = P.current) == null ? void 0 : L.type) !== "scale" || !b || (S.preventDefault(), f.schedule({ ...b, shiftKey: S.shiftKey, altKey: S.altKey }));
|
|
1808
|
+
}
|
|
1809
|
+
function E(S) {
|
|
1810
|
+
const L = P.current;
|
|
1811
|
+
if (!L) return;
|
|
1812
|
+
const [B, V] = p(S), j = n.getState().geometryMode;
|
|
1813
|
+
if (L.type === "move") {
|
|
1814
|
+
if (!L.moving) {
|
|
1815
|
+
const H = e.getCanvasContainer().getBoundingClientRect();
|
|
1816
|
+
if (Math.hypot(S.clientX - H.left - L.startPoint.x, S.clientY - H.top - L.startPoint.y) < Vr) return;
|
|
1817
|
+
L.moving = !0, i(!0);
|
|
1818
|
+
}
|
|
1819
|
+
const h = j === "visual", I = zr(L.startLngLat, [B, V], h), O = L.initialFeatures.map((H) => ({ ...H, geometry: $t(H.geometry, I, h) })), z = L.initialBbox, G = {
|
|
1820
|
+
corners: st(z.corners, I, h),
|
|
1821
|
+
edges: st(z.edges, I, h),
|
|
1822
|
+
center: st([z.center], I, h)[0],
|
|
1823
|
+
rotateHandle: st([z.rotateHandle], I, h)[0]
|
|
1824
|
+
};
|
|
1825
|
+
w.current = O, C.current = G, k(O), N(G);
|
|
1826
|
+
} else if (L.type === "rotate") {
|
|
1827
|
+
const h = L.center, I = Te(h[1]), O = V - h[1], z = j === "visual" ? (B - h[0]) * I : B - h[0], H = (Math.atan2(O, z) - L.initialAngle) * (180 / Math.PI), te = L.initialFeatures.map(
|
|
1828
|
+
(ne) => j === "visual" ? Po(ne, h, 1, 1, H) : ir(ne, H, { pivot: h })
|
|
1829
|
+
), Z = {
|
|
1830
|
+
corners: kt(L.initialBbox.corners, h, H),
|
|
1831
|
+
edges: kt(L.initialBbox.edges, h, H),
|
|
1832
|
+
center: h,
|
|
1833
|
+
rotateHandle: kt([L.initialBbox.rotateHandle], h, H)[0]
|
|
1834
|
+
};
|
|
1835
|
+
w.current = te, C.current = Z, k(te), N(Z);
|
|
1836
|
+
} else if (L.type === "scale") {
|
|
1837
|
+
const h = L.rotationAngle, I = qr({
|
|
1838
|
+
initialBbox: L.initialBbox,
|
|
1839
|
+
origin: L.origin,
|
|
1840
|
+
startLngLat: L.startLngLat,
|
|
1841
|
+
edgeIndex: L.edgeIndex,
|
|
1842
|
+
rotationAngle: h
|
|
1843
|
+
}, [B, V], S.shiftKey, S.altKey), O = Jr(L.initialFeatures, L.initialBbox, I, h);
|
|
1844
|
+
w.current = O.features, C.current = O.box, k(O.features), N(O.box);
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
function a() {
|
|
1848
|
+
f.flush();
|
|
1849
|
+
const S = P.current;
|
|
1850
|
+
if (!S) return;
|
|
1851
|
+
const L = w.current, B = C.current, V = S.type === "rotate";
|
|
1852
|
+
if (P.current = null, b = null, w.current = null, C.current = null, e.dragPan.enable(), i(!1), S.type === "move" && L) {
|
|
1853
|
+
const j = e.getContainer(), h = (I) => I.stopPropagation();
|
|
1854
|
+
j.addEventListener("click", h, !0), setTimeout(() => j.removeEventListener("click", h, !0), 0);
|
|
1855
|
+
}
|
|
1856
|
+
if (L && (n.getState().takeSnapshot(), n.getState().updateFeatures(Eo(
|
|
1857
|
+
n.getState().features,
|
|
1858
|
+
L.flatMap((j) => j.id == null || j.id === "" ? [] : [{ id: String(j.id), geometry: j.geometry }]),
|
|
1859
|
+
o.getState().topoEditEnabled
|
|
1860
|
+
))), B) {
|
|
1861
|
+
if (V) {
|
|
1862
|
+
const j = B.center, h = B.edges[1], I = Te(j[1]), O = (h[0] - j[0]) * I, z = h[1] - j[1];
|
|
1863
|
+
d.current = Math.atan2(z, O) * (180 / Math.PI);
|
|
1864
|
+
}
|
|
1865
|
+
c(B);
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
function x(S, L, B) {
|
|
1869
|
+
S.preventDefault(), S.stopPropagation(), e.dragPan.disable();
|
|
1870
|
+
const V = v.current ?? it(l.current), [j, h] = p(S), I = B ? V.edges[(L + 2) % 4] : V.corners[(L + 2) % 4];
|
|
1871
|
+
P.current = {
|
|
1872
|
+
type: "scale",
|
|
1873
|
+
initialFeatures: structuredClone(l.current),
|
|
1874
|
+
initialBbox: V,
|
|
1875
|
+
rotationAngle: d.current,
|
|
1876
|
+
origin: I,
|
|
1877
|
+
startLngLat: [j, h],
|
|
1878
|
+
edgeIndex: B ? L : void 0
|
|
1879
|
+
}, i(!0);
|
|
1880
|
+
}
|
|
1881
|
+
function y(S) {
|
|
1882
|
+
S.preventDefault(), S.stopPropagation(), e.dragPan.disable();
|
|
1883
|
+
const L = v.current ?? it(l.current), B = L.center, [V, j] = p(S), h = n.getState().geometryMode, I = Te(B[1]), O = j - B[1], z = h === "visual" ? (V - B[0]) * I : V - B[0];
|
|
1884
|
+
P.current = {
|
|
1885
|
+
type: "rotate",
|
|
1886
|
+
initialFeatures: structuredClone(l.current),
|
|
1887
|
+
initialBbox: L,
|
|
1888
|
+
rotationAngle: d.current,
|
|
1889
|
+
center: B,
|
|
1890
|
+
initialAngle: Math.atan2(O, z)
|
|
1891
|
+
}, i(!0);
|
|
1892
|
+
}
|
|
1893
|
+
function m(S) {
|
|
1894
|
+
if (P.current || S.button !== 0 || S.shiftKey || S.altKey || S.ctrlKey || S.metaKey || S.target !== e.getCanvas()) return;
|
|
1895
|
+
const L = o.getState();
|
|
1896
|
+
if (!L.transformActive || L.readonly || L.editingMode !== "none" || L.vertexEditActive) return;
|
|
1897
|
+
const B = l.current;
|
|
1898
|
+
if (B.length === 0) return;
|
|
1899
|
+
const V = v.current ?? it(B), j = e.getCanvasContainer().getBoundingClientRect(), h = { x: S.clientX - j.left, y: S.clientY - j.top };
|
|
1900
|
+
Hr(h, V.corners.map((I) => e.project(I)), Xr) && (S.preventDefault(), S.stopPropagation(), e.dragPan.disable(), P.current = {
|
|
1901
|
+
type: "move",
|
|
1902
|
+
initialFeatures: structuredClone(B),
|
|
1903
|
+
initialBbox: V,
|
|
1904
|
+
rotationAngle: d.current,
|
|
1905
|
+
startLngLat: p(S),
|
|
1906
|
+
startPoint: h,
|
|
1907
|
+
moving: !1
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
const R = e.getContainer();
|
|
1911
|
+
return R.addEventListener("mousedown", m, !0), _.current.handleScaleStart = x, _.current.handleRotateStart = y, document.addEventListener("mousemove", M), document.addEventListener("mouseup", a), document.addEventListener("keydown", A), document.addEventListener("keyup", A), () => {
|
|
1912
|
+
f.cancel(), R.removeEventListener("mousedown", m, !0), document.removeEventListener("mousemove", M), document.removeEventListener("mouseup", a), document.removeEventListener("keydown", A), document.removeEventListener("keyup", A);
|
|
1913
|
+
};
|
|
1914
|
+
}, [e, n, o, i]);
|
|
1915
|
+
const _ = $({
|
|
1916
|
+
handleScaleStart: () => {
|
|
1917
|
+
},
|
|
1918
|
+
handleRotateStart: () => {
|
|
1919
|
+
}
|
|
1920
|
+
});
|
|
1921
|
+
function D(p, f, b) {
|
|
1922
|
+
_.current.handleScaleStart(p, f, b);
|
|
1923
|
+
}
|
|
1924
|
+
function q(p) {
|
|
1925
|
+
_.current.handleRotateStart(p);
|
|
1926
|
+
}
|
|
1927
|
+
return null;
|
|
1928
|
+
}
|
|
1929
|
+
function ts({ map: e, feature: t, onDone: n }) {
|
|
1930
|
+
const o = he((d) => d.updateFeature), [r, s] = le(
|
|
1931
|
+
t.properties.name ?? ""
|
|
1932
|
+
), [i, l] = le(() => {
|
|
1933
|
+
const d = t.geometry.coordinates, g = e.project(d);
|
|
1934
|
+
return { x: g.x, y: g.y };
|
|
1935
|
+
}), u = $(null);
|
|
1936
|
+
K(() => {
|
|
1937
|
+
const d = t.geometry.coordinates, g = () => {
|
|
1938
|
+
const w = e.project(d);
|
|
1939
|
+
l({ x: w.x, y: w.y });
|
|
1940
|
+
};
|
|
1941
|
+
return e.on("move", g), e.on("zoom", g), e.on("resize", g), () => {
|
|
1942
|
+
e.off("move", g), e.off("zoom", g), e.off("resize", g);
|
|
1943
|
+
};
|
|
1944
|
+
}, [e, t.geometry]), K(() => {
|
|
1945
|
+
const d = setTimeout(() => {
|
|
1946
|
+
var g, w;
|
|
1947
|
+
(g = u.current) == null || g.focus(), (w = u.current) == null || w.select();
|
|
1948
|
+
}, 0);
|
|
1949
|
+
return () => clearTimeout(d);
|
|
1950
|
+
}, []);
|
|
1951
|
+
function c() {
|
|
1952
|
+
const d = r;
|
|
1953
|
+
d !== (t.properties.name ?? "") && o(t.id, {
|
|
1954
|
+
properties: { ...t.properties, name: d }
|
|
1955
|
+
}), n();
|
|
1956
|
+
}
|
|
1957
|
+
const v = e.getCanvasContainer();
|
|
1958
|
+
return Ze(
|
|
1959
|
+
/* @__PURE__ */ X(
|
|
1960
|
+
"div",
|
|
1961
|
+
{
|
|
1962
|
+
"data-elm-theme": !0,
|
|
1963
|
+
style: {
|
|
1964
|
+
position: "absolute",
|
|
1965
|
+
left: i.x,
|
|
1966
|
+
top: i.y,
|
|
1967
|
+
transform: "translate(-50%, -50%)",
|
|
1968
|
+
zIndex: 500,
|
|
1969
|
+
pointerEvents: "auto"
|
|
1970
|
+
},
|
|
1971
|
+
onMouseDown: (d) => d.stopPropagation(),
|
|
1972
|
+
onDoubleClick: (d) => d.stopPropagation(),
|
|
1973
|
+
onContextMenu: (d) => d.stopPropagation(),
|
|
1974
|
+
children: /* @__PURE__ */ fe("div", { className: "grid items-center justify-items-center bg-white/95 backdrop-blur-md border border-slate-800 text-slate-800 rounded px-3 py-1.5 text-sm font-medium shadow-lg", children: [
|
|
1975
|
+
/* @__PURE__ */ X(
|
|
1976
|
+
"div",
|
|
1977
|
+
{
|
|
1978
|
+
className: "invisible whitespace-pre pointer-events-none col-start-1 row-start-1 min-w-[12px] px-[2px] leading-tight",
|
|
1979
|
+
"aria-hidden": !0,
|
|
1980
|
+
children: r + " "
|
|
1981
|
+
}
|
|
1982
|
+
),
|
|
1983
|
+
/* @__PURE__ */ X(
|
|
1984
|
+
"textarea",
|
|
1985
|
+
{
|
|
1986
|
+
ref: u,
|
|
1987
|
+
value: r,
|
|
1988
|
+
onChange: (d) => s(d.target.value),
|
|
1989
|
+
onKeyDown: (d) => {
|
|
1990
|
+
d.key === "Enter" && !d.shiftKey ? (d.preventDefault(), c()) : d.key === "Escape" && (d.preventDefault(), n());
|
|
1991
|
+
},
|
|
1992
|
+
onBlur: c,
|
|
1993
|
+
className: "col-start-1 row-start-1 bg-transparent outline-none resize-none overflow-hidden whitespace-pre text-center leading-tight min-w-0 min-h-0 px-[2px] w-full h-full m-0 border-none",
|
|
1994
|
+
rows: 1
|
|
1995
|
+
}
|
|
1996
|
+
)
|
|
1997
|
+
] })
|
|
1998
|
+
}
|
|
1999
|
+
),
|
|
2000
|
+
v
|
|
2001
|
+
);
|
|
2002
|
+
}
|
|
2003
|
+
function ns([e, t, n, o], r, s, i, l) {
|
|
2004
|
+
return e >= r && n <= i && t >= s && o <= l;
|
|
2005
|
+
}
|
|
2006
|
+
function os(e, t) {
|
|
2007
|
+
if (e === t) return !0;
|
|
2008
|
+
if (e.length !== t.length) return !1;
|
|
2009
|
+
const n = new Set(e);
|
|
2010
|
+
return t.every((o) => n.has(o));
|
|
2011
|
+
}
|
|
2012
|
+
function rs({ map: e, onVertexBoxSelect: t }) {
|
|
2013
|
+
const { dataStore: n } = Le(), o = W((d) => d.editingMode), r = W((d) => d.vertexEditActive), s = W((d) => d.transformActive), i = W((d) => d.readonly), l = $(o), u = $(r), c = $(s), v = $(i);
|
|
2014
|
+
return l.current = o, u.current = r, c.current = s, v.current = i, K(() => {
|
|
2015
|
+
const d = e.getCanvas(), g = e.getContainer(), w = (C) => {
|
|
2016
|
+
if (!C.shiftKey || v.current || c.current) return;
|
|
2017
|
+
const T = u.current;
|
|
2018
|
+
if (!T && l.current !== "none") return;
|
|
2019
|
+
C.preventDefault(), e.dragPan.disable(), e.boxZoom.disable();
|
|
2020
|
+
const F = C.clientX, k = C.clientY, N = g.getBoundingClientRect(), P = [...n.getState().selectedIds], _ = document.createElement("div");
|
|
2021
|
+
_.style.cssText = [
|
|
2022
|
+
"position:absolute",
|
|
2023
|
+
"pointer-events:none",
|
|
2024
|
+
"border:2px solid var(--color-primary-500)",
|
|
2025
|
+
"background:color-mix(in srgb, var(--color-primary-500) 8%, transparent)",
|
|
2026
|
+
"z-index:9999",
|
|
2027
|
+
"border-radius:2px"
|
|
2028
|
+
].join(";"), g.appendChild(_);
|
|
2029
|
+
let D = !1, q = 0;
|
|
2030
|
+
function p(a) {
|
|
2031
|
+
const x = Math.min(F, a.clientX) - N.left, y = Math.min(k, a.clientY) - N.top, m = Math.max(F, a.clientX) - N.left, R = Math.max(k, a.clientY) - N.top, S = e.unproject([x, y]), L = e.unproject([m, R]);
|
|
2032
|
+
return {
|
|
2033
|
+
boxW: S.lng,
|
|
2034
|
+
boxE: L.lng,
|
|
2035
|
+
boxN: S.lat,
|
|
2036
|
+
boxS: L.lat,
|
|
2037
|
+
overlayX: x,
|
|
2038
|
+
overlayY: y,
|
|
2039
|
+
overlayW: m - x,
|
|
2040
|
+
overlayH: R - y
|
|
2041
|
+
};
|
|
2042
|
+
}
|
|
2043
|
+
function f(a) {
|
|
2044
|
+
const { boxW: x, boxE: y, boxN: m, boxS: R } = p(a), S = n.getState(), L = new Set(S.groups.filter((h) => h.hidden).map((h) => h.id)), B = S.features.filter(
|
|
2045
|
+
(h) => !h.hidden && (!h.groupId || !L.has(h.groupId))
|
|
2046
|
+
), V = {
|
|
2047
|
+
type: "Feature",
|
|
2048
|
+
properties: {},
|
|
2049
|
+
geometry: {
|
|
2050
|
+
type: "Polygon",
|
|
2051
|
+
coordinates: [[
|
|
2052
|
+
[x, R],
|
|
2053
|
+
[y, R],
|
|
2054
|
+
[y, m],
|
|
2055
|
+
[x, m],
|
|
2056
|
+
[x, R]
|
|
2057
|
+
]]
|
|
2058
|
+
}
|
|
2059
|
+
}, j = [];
|
|
2060
|
+
for (const h of B) {
|
|
2061
|
+
if (h.geometry.type === "Point") {
|
|
2062
|
+
const [te, Z] = h.geometry.coordinates;
|
|
2063
|
+
te >= x && te <= y && Z >= R && Z <= m && j.push(h.id);
|
|
2064
|
+
continue;
|
|
2065
|
+
}
|
|
2066
|
+
const I = h.bbox ?? Nn(h.geometry), [O, z, G, H] = I;
|
|
2067
|
+
if (G >= x && O <= y && H >= R && z <= m) {
|
|
2068
|
+
if (ns(I, x, R, y, m)) {
|
|
2069
|
+
j.push(h.id);
|
|
2070
|
+
continue;
|
|
2071
|
+
}
|
|
2072
|
+
try {
|
|
2073
|
+
lr(V, h) && j.push(h.id);
|
|
2074
|
+
} catch {
|
|
2075
|
+
j.push(h.id);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
return j;
|
|
2080
|
+
}
|
|
2081
|
+
function b(a) {
|
|
2082
|
+
const x = new Set(P);
|
|
2083
|
+
a.forEach((R) => x.add(R));
|
|
2084
|
+
const y = Array.from(x), m = n.getState();
|
|
2085
|
+
os(m.selectedIds, y) && m.selectedGroupId === null || m.setSelection(y);
|
|
2086
|
+
}
|
|
2087
|
+
function M(a) {
|
|
2088
|
+
const x = n.getState().selectedIds[0];
|
|
2089
|
+
if (!x) return null;
|
|
2090
|
+
const y = n.getState().features.find((j) => j.id === x);
|
|
2091
|
+
if (!y) return null;
|
|
2092
|
+
let m;
|
|
2093
|
+
if (y.geometry.type === "LineString")
|
|
2094
|
+
m = y.geometry.coordinates;
|
|
2095
|
+
else if (y.geometry.type === "Polygon")
|
|
2096
|
+
m = y.geometry.coordinates[0].slice(0, -1);
|
|
2097
|
+
else
|
|
2098
|
+
return null;
|
|
2099
|
+
const { boxW: R, boxE: S, boxN: L, boxS: B } = p(a), V = [];
|
|
2100
|
+
for (let j = 0; j < m.length; j++) {
|
|
2101
|
+
const [h, I] = m[j];
|
|
2102
|
+
h >= R && h <= S && I >= B && I <= L && V.push(j);
|
|
2103
|
+
}
|
|
2104
|
+
return { id: x, indices: V };
|
|
2105
|
+
}
|
|
2106
|
+
const A = (a) => {
|
|
2107
|
+
const x = Math.abs(a.clientX - F), y = Math.abs(a.clientY - k);
|
|
2108
|
+
if (!D && x < 5 && y < 5) return;
|
|
2109
|
+
D = !0;
|
|
2110
|
+
const { overlayX: m, overlayY: R, overlayW: S, overlayH: L } = p(a);
|
|
2111
|
+
_.style.left = `${m}px`, _.style.top = `${R}px`, _.style.width = `${S}px`, _.style.height = `${L}px`, !T && Date.now() - q > 30 && (b(f(a)), q = Date.now());
|
|
2112
|
+
}, E = (a) => {
|
|
2113
|
+
if (_.remove(), e.dragPan.enable(), e.boxZoom.enable(), window.removeEventListener("mousemove", A), window.removeEventListener("mouseup", E), !D) return;
|
|
2114
|
+
if (T) {
|
|
2115
|
+
const y = M(a);
|
|
2116
|
+
y && y.indices.length > 0 && t && t(y.id, y.indices);
|
|
2117
|
+
return;
|
|
2118
|
+
}
|
|
2119
|
+
const x = f(a);
|
|
2120
|
+
if (b(x), x.length === 0 && P.length === 1 && t) {
|
|
2121
|
+
const y = n.getState().features.find((m) => m.id === P[0]);
|
|
2122
|
+
if (y && (y.geometry.type === "LineString" || y.geometry.type === "Polygon")) {
|
|
2123
|
+
const m = M(a);
|
|
2124
|
+
m && m.indices.length > 0 && t(m.id, m.indices);
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
};
|
|
2128
|
+
window.addEventListener("mousemove", A), window.addEventListener("mouseup", E);
|
|
2129
|
+
};
|
|
2130
|
+
return d.addEventListener("mousedown", w), () => d.removeEventListener("mousedown", w);
|
|
2131
|
+
}, [e, n, t]), null;
|
|
2132
|
+
}
|
|
2133
|
+
function ss(e) {
|
|
2134
|
+
return e && "style" in e ? e : null;
|
|
2135
|
+
}
|
|
2136
|
+
function is(e) {
|
|
2137
|
+
const t = $(null), n = $(!1), o = $({ value: "", priority: "" });
|
|
2138
|
+
function r(l, u, c = "important") {
|
|
2139
|
+
l.style.setProperty("cursor", u, c);
|
|
2140
|
+
}
|
|
2141
|
+
K(() => {
|
|
2142
|
+
if (e) return;
|
|
2143
|
+
function l(u) {
|
|
2144
|
+
if (!n.current) return;
|
|
2145
|
+
const c = t.current;
|
|
2146
|
+
if (!c) return;
|
|
2147
|
+
const v = u.ctrlKey || u.metaKey, d = u.altKey;
|
|
2148
|
+
v || d ? r(c, d ? "copy" : "move") : r(c, o.current.value, o.current.priority);
|
|
2149
|
+
}
|
|
2150
|
+
return window.addEventListener("keydown", l), window.addEventListener("keyup", l), () => {
|
|
2151
|
+
window.removeEventListener("keydown", l), window.removeEventListener("keyup", l);
|
|
2152
|
+
};
|
|
2153
|
+
}, [e]);
|
|
2154
|
+
const s = ve((l, u, c) => {
|
|
2155
|
+
const v = ss(l), d = v !== null && v === t.current && n.current;
|
|
2156
|
+
t.current = v, n.current = !0, c !== void 0 ? o.current = { value: c, priority: "" } : d || (o.current = {
|
|
2157
|
+
value: (v == null ? void 0 : v.style.getPropertyValue("cursor")) ?? "",
|
|
2158
|
+
priority: (v == null ? void 0 : v.style.getPropertyPriority("cursor")) ?? ""
|
|
2159
|
+
});
|
|
2160
|
+
const g = u;
|
|
2161
|
+
v && g && (g.ctrlKey || g.metaKey || g.altKey) ? r(v, g.altKey ? "copy" : "move") : v && c !== void 0 && r(v, c, "");
|
|
2162
|
+
}, []), i = ve((l) => {
|
|
2163
|
+
n.current = !1, t.current && (l !== void 0 ? r(t.current, l, "") : r(t.current, o.current.value, o.current.priority), t.current = null), o.current = { value: "", priority: "" };
|
|
2164
|
+
}, []);
|
|
2165
|
+
return Bt(() => ({ enter: s, leave: i }), [s, i]);
|
|
2166
|
+
}
|
|
2167
|
+
let Ye = { x: -1, y: -1, ctrlKey: !1, metaKey: !1, altKey: !1 };
|
|
2168
|
+
if (typeof window < "u") {
|
|
2169
|
+
window.addEventListener("mousemove", (n) => {
|
|
2170
|
+
Ye = { x: n.clientX, y: n.clientY, ctrlKey: n.ctrlKey, metaKey: n.metaKey, altKey: n.altKey };
|
|
2171
|
+
}, { capture: !0, passive: !0 });
|
|
2172
|
+
const e = (n) => {
|
|
2173
|
+
Ye = { x: n.clientX, y: n.clientY, ctrlKey: n.ctrlKey, metaKey: n.metaKey, altKey: n.altKey };
|
|
2174
|
+
};
|
|
2175
|
+
window.addEventListener("pointerdown", e, { capture: !0, passive: !0 }), window.addEventListener("mousedown", e, { capture: !0, passive: !0 });
|
|
2176
|
+
const t = (n) => {
|
|
2177
|
+
Ye = { ...Ye, ctrlKey: n.ctrlKey, metaKey: n.metaKey, altKey: n.altKey };
|
|
2178
|
+
};
|
|
2179
|
+
window.addEventListener("keydown", t, { capture: !0 }), window.addEventListener("keyup", t, { capture: !0 });
|
|
2180
|
+
}
|
|
2181
|
+
function cs() {
|
|
2182
|
+
return Ye;
|
|
2183
|
+
}
|
|
2184
|
+
function $e(e, t, n) {
|
|
2185
|
+
if (!n.every((o) => e.getLayer(o))) return [];
|
|
2186
|
+
try {
|
|
2187
|
+
return e.queryRenderedFeatures(t, { layers: n });
|
|
2188
|
+
} catch {
|
|
2189
|
+
return [];
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
function ls(e) {
|
|
2193
|
+
const t = "elm-drag-ghost";
|
|
2194
|
+
e.getSource(t) || (e.addSource(t, { type: "geojson", data: { type: "FeatureCollection", features: [] } }), e.addLayer({
|
|
2195
|
+
id: "elm-drag-ghost-fill",
|
|
2196
|
+
type: "fill",
|
|
2197
|
+
source: t,
|
|
2198
|
+
filter: ["in", ["geometry-type"], ["literal", ["Polygon", "MultiPolygon"]]],
|
|
2199
|
+
paint: { "fill-opacity": 0.18 }
|
|
2200
|
+
}), e.addLayer({
|
|
2201
|
+
id: "elm-drag-ghost-line",
|
|
2202
|
+
type: "line",
|
|
2203
|
+
source: t,
|
|
2204
|
+
filter: [
|
|
2205
|
+
"in",
|
|
2206
|
+
["geometry-type"],
|
|
2207
|
+
["literal", ["LineString", "MultiLineString", "Polygon", "MultiPolygon"]]
|
|
2208
|
+
],
|
|
2209
|
+
paint: { "line-opacity": 0.6, "line-width": 2, "line-dasharray": [3, 3] }
|
|
2210
|
+
}), e.addLayer({
|
|
2211
|
+
id: "elm-drag-ghost-point",
|
|
2212
|
+
type: "circle",
|
|
2213
|
+
source: t,
|
|
2214
|
+
filter: ["in", ["geometry-type"], ["literal", ["Point", "MultiPoint"]]],
|
|
2215
|
+
paint: {
|
|
2216
|
+
"circle-radius": 7,
|
|
2217
|
+
"circle-opacity": 0.6,
|
|
2218
|
+
"circle-stroke-color": "#ffffff",
|
|
2219
|
+
"circle-stroke-width": 2
|
|
2220
|
+
}
|
|
2221
|
+
}), Ne(e, Qn));
|
|
2222
|
+
}
|
|
2223
|
+
function as(e) {
|
|
2224
|
+
for (const t of ["elm-drag-ghost-point", "elm-drag-ghost-line", "elm-drag-ghost-fill"])
|
|
2225
|
+
e.getLayer(t) && e.removeLayer(t);
|
|
2226
|
+
e.getSource("elm-drag-ghost") && e.removeSource("elm-drag-ghost");
|
|
2227
|
+
}
|
|
2228
|
+
const Qn = [
|
|
2229
|
+
["elm-drag-ghost-fill", "fill-color", (e) => e[500]],
|
|
2230
|
+
["elm-drag-ghost-line", "line-color", (e) => e[500]],
|
|
2231
|
+
["elm-drag-ghost-point", "circle-color", (e) => e[500]]
|
|
2232
|
+
];
|
|
2233
|
+
function us({ map: e }) {
|
|
2234
|
+
qe(e, Qn);
|
|
2235
|
+
const { dataStore: t, uiStore: n } = Le(), o = Ue(), r = he((a) => a.features), s = he((a) => a.selectedIds), i = W((a) => a.vertexEditActive), l = W((a) => a.transformActive), u = W((a) => a.editingMode), c = W((a) => a.readonly);
|
|
2236
|
+
K(() => {
|
|
2237
|
+
ct();
|
|
2238
|
+
}, [r.length, i]), K(() => {
|
|
2239
|
+
if (!i) return;
|
|
2240
|
+
const a = t.getState(), x = a.selectedIds.length === 1 ? a.features.find((m) => m.id === a.selectedIds[0]) : void 0, y = Co(x);
|
|
2241
|
+
y && o({ type: "warning", message: y });
|
|
2242
|
+
}, [i, t, o]);
|
|
2243
|
+
const v = $(!1);
|
|
2244
|
+
K(() => {
|
|
2245
|
+
if (!l || v.current) return;
|
|
2246
|
+
const a = t.getState(), x = a.selectedIds.length === 1 ? a.features.find((y) => y.id === a.selectedIds[0]) : void 0;
|
|
2247
|
+
(x == null ? void 0 : x._drawType) === "route" && (o({ type: "warning", message: "Transforming may break road alignment." }), v.current = !0);
|
|
2248
|
+
}, [l, s, t, o]);
|
|
2249
|
+
const d = $(null), g = $(null), [w, C] = le(null), [T, F] = le(null), [k, N] = le(null);
|
|
2250
|
+
K(() => {
|
|
2251
|
+
!i && k && N(null);
|
|
2252
|
+
}, [i, k]);
|
|
2253
|
+
const P = is(c), _ = Jo();
|
|
2254
|
+
K(() => {
|
|
2255
|
+
if (c) return;
|
|
2256
|
+
const a = e.getCanvasContainer(), x = (y) => {
|
|
2257
|
+
var I, O;
|
|
2258
|
+
y.preventDefault();
|
|
2259
|
+
const m = a.getBoundingClientRect(), R = [y.clientX - m.left, y.clientY - m.top], S = $e(e, R, Be);
|
|
2260
|
+
if (S.length === 0) return;
|
|
2261
|
+
const L = String(S[0].id ?? ((I = S[0].properties) == null ? void 0 : I.id) ?? "");
|
|
2262
|
+
if (!L) return;
|
|
2263
|
+
const B = t.getState(), V = B.features.find((z) => z.id === L);
|
|
2264
|
+
if (!V) return;
|
|
2265
|
+
const j = B.selectedIds;
|
|
2266
|
+
j.length >= 2 && j.includes(L) || B.selectFeature(L);
|
|
2267
|
+
const h = V.geometry.type === "Point" && ((O = V.properties) == null ? void 0 : O._isText) !== "true";
|
|
2268
|
+
_.open(y.clientX, y.clientY, {
|
|
2269
|
+
feature: V,
|
|
2270
|
+
requestPreciseCoords: h ? () => F(L) : void 0
|
|
2271
|
+
});
|
|
2272
|
+
};
|
|
2273
|
+
return a.addEventListener("contextmenu", x), () => {
|
|
2274
|
+
a.removeEventListener("contextmenu", x);
|
|
2275
|
+
};
|
|
2276
|
+
}, [c, t, e, _]), K(() => {
|
|
2277
|
+
const a = u !== "none", x = (R = !0) => {
|
|
2278
|
+
bt(e, null, d.current), d.current = null, R && Pt(e, null), ct(), P.leave(a ? void 0 : "");
|
|
2279
|
+
}, y = (R) => {
|
|
2280
|
+
var V, j;
|
|
2281
|
+
if (e.dragPan.isActive() || (V = g.current) != null && V.dragging) return;
|
|
2282
|
+
const S = $e(e, R.point, Be), L = S.length > 0 ? String(S[0].id ?? ((j = S[0].properties) == null ? void 0 : j.id)) : null;
|
|
2283
|
+
if (L === d.current) return;
|
|
2284
|
+
if (!L) {
|
|
2285
|
+
x();
|
|
2286
|
+
return;
|
|
2287
|
+
}
|
|
2288
|
+
Gt() !== L && Pt(e, null), a || bt(e, L, d.current), d.current = L;
|
|
2289
|
+
const B = t.getState().features.find((h) => h.id === L);
|
|
2290
|
+
B ? Nr(B, n, R.originalEvent) : ct(), P.enter(e.getCanvas(), R.originalEvent, a ? void 0 : "pointer");
|
|
2291
|
+
};
|
|
2292
|
+
e.on("mousemove", y);
|
|
2293
|
+
const m = () => x();
|
|
2294
|
+
return e.on("mouseout", m), () => {
|
|
2295
|
+
e.off("mousemove", y), e.off("mouseout", m);
|
|
2296
|
+
try {
|
|
2297
|
+
x(!1);
|
|
2298
|
+
} catch {
|
|
2299
|
+
}
|
|
2300
|
+
};
|
|
2301
|
+
}, [u, e, t, n, P]);
|
|
2302
|
+
const D = $(r);
|
|
2303
|
+
K(() => {
|
|
2304
|
+
const a = D.current;
|
|
2305
|
+
if (D.current = r, r.length <= a.length) return;
|
|
2306
|
+
const y = e.getCanvas().getBoundingClientRect(), m = cs();
|
|
2307
|
+
if (m.x < y.left || m.x > y.right || m.y < y.top || m.y > y.bottom) return;
|
|
2308
|
+
const R = new Set(a.map((h) => h.id)), S = new Set(r.filter((h) => !R.has(h.id)).map((h) => h.id)), L = [m.x - y.left, m.y - y.top], B = () => {
|
|
2309
|
+
var h;
|
|
2310
|
+
try {
|
|
2311
|
+
const I = e.unproject(L), O = $e(e, e.project(I), Be)[0], z = O ? String(O.id ?? ((h = O.properties) == null ? void 0 : h.id)) : null;
|
|
2312
|
+
z && S.has(z) && Pt(e, z), e.fire("mousemove", {
|
|
2313
|
+
// A real Point: a plain { x, y } makes every listener's
|
|
2314
|
+
// queryRenderedFeatures(e.point) hit the whole viewport, so the
|
|
2315
|
+
// hover tooltip named whichever feature was on top (not under the cursor).
|
|
2316
|
+
// `map.project` returns the map's own Point class (a `new Point` from the
|
|
2317
|
+
// peer copy fails maplibre's instanceof check when the host bundles its own
|
|
2318
|
+
// maplibre, e.g. MapTiler SDK) and avoids a named import from CJS maplibre-gl.
|
|
2319
|
+
point: e.project(I),
|
|
2320
|
+
lngLat: I,
|
|
2321
|
+
originalEvent: new MouseEvent("mousemove", {
|
|
2322
|
+
clientX: m.x,
|
|
2323
|
+
clientY: m.y,
|
|
2324
|
+
ctrlKey: m.ctrlKey,
|
|
2325
|
+
metaKey: m.metaKey,
|
|
2326
|
+
altKey: m.altKey
|
|
2327
|
+
})
|
|
2328
|
+
});
|
|
2329
|
+
} catch {
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
let V = !1;
|
|
2333
|
+
const j = () => {
|
|
2334
|
+
V || B();
|
|
2335
|
+
};
|
|
2336
|
+
return e.once("idle", j), () => {
|
|
2337
|
+
V = !0, e.off("idle", j);
|
|
2338
|
+
};
|
|
2339
|
+
}, [r.length, e]), K(() => {
|
|
2340
|
+
if (c || u !== "none") return;
|
|
2341
|
+
const a = (x) => {
|
|
2342
|
+
var L;
|
|
2343
|
+
if (Gn()) return;
|
|
2344
|
+
const y = $e(e, x.point, Be), m = t.getState();
|
|
2345
|
+
if (y.length === 0) {
|
|
2346
|
+
i ? n.getState().setVertexEditActive(!1) : m.clearSelection();
|
|
2347
|
+
return;
|
|
2348
|
+
}
|
|
2349
|
+
const R = y[0], S = String(R.id ?? ((L = R.properties) == null ? void 0 : L.id) ?? "");
|
|
2350
|
+
if (S)
|
|
2351
|
+
if (x.originalEvent.shiftKey) {
|
|
2352
|
+
const B = m.selectedIds;
|
|
2353
|
+
B.includes(S) ? m.setSelection(B.filter((V) => V !== S)) : m.setSelection([...B, S]);
|
|
2354
|
+
} else
|
|
2355
|
+
m.selectedIds.length === 1 && m.selectedIds[0] === S || m.selectFeature(S);
|
|
2356
|
+
};
|
|
2357
|
+
return e.on("click", a), () => {
|
|
2358
|
+
e.off("click", a);
|
|
2359
|
+
};
|
|
2360
|
+
}, [c, u, i, t, n, e]), K(() => {
|
|
2361
|
+
if (c || u !== "none") return;
|
|
2362
|
+
const a = (x) => {
|
|
2363
|
+
var S, L;
|
|
2364
|
+
const y = $e(e, x.point, Be);
|
|
2365
|
+
if (y.length === 0) return;
|
|
2366
|
+
x.preventDefault();
|
|
2367
|
+
const m = String(y[0].id ?? ((S = y[0].properties) == null ? void 0 : S.id) ?? "");
|
|
2368
|
+
if (!m) return;
|
|
2369
|
+
const R = t.getState().features.find((B) => B.id === m);
|
|
2370
|
+
if (R) {
|
|
2371
|
+
if (((L = R.properties) == null ? void 0 : L._isText) === "true") {
|
|
2372
|
+
t.getState().selectFeature(m), C(m);
|
|
2373
|
+
return;
|
|
2374
|
+
}
|
|
2375
|
+
if (t.getState().selectFeature(m), ht(R.geometry)) {
|
|
2376
|
+
const B = Dr(R.geometry, [x.lngLat.lng, x.lngLat.lat]);
|
|
2377
|
+
n.getState().setSelectedPartIndex(B);
|
|
2378
|
+
} else
|
|
2379
|
+
n.getState().setSelectedPartIndex(null);
|
|
2380
|
+
n.getState().setVertexEditActive(!0);
|
|
2381
|
+
}
|
|
2382
|
+
};
|
|
2383
|
+
return e.on("dblclick", a), () => {
|
|
2384
|
+
e.off("dblclick", a);
|
|
2385
|
+
};
|
|
2386
|
+
}, [c, u, t, n, e]), K(() => {
|
|
2387
|
+
if (c || i) return;
|
|
2388
|
+
const x = u !== "none", y = (m) => {
|
|
2389
|
+
var re;
|
|
2390
|
+
if (m.originalEvent.shiftKey) return;
|
|
2391
|
+
const R = m.originalEvent.altKey, S = m.originalEvent.ctrlKey || m.originalEvent.metaKey;
|
|
2392
|
+
if (x && !R && !S) return;
|
|
2393
|
+
const L = $e(e, m.point, Be);
|
|
2394
|
+
if (L.length === 0) return;
|
|
2395
|
+
const B = String(L[0].id ?? ((re = L[0].properties) == null ? void 0 : re.id) ?? "");
|
|
2396
|
+
if (!B) return;
|
|
2397
|
+
const V = t.getState();
|
|
2398
|
+
if (V.selectedIds.includes(B) && V.selectedIds.length >= 2 && !R && !S) return;
|
|
2399
|
+
V.selectedIds.includes(B) || V.selectFeature(B);
|
|
2400
|
+
const h = t.getState().selectedIds, I = h.includes(B) ? h : [B], O = new Map(
|
|
2401
|
+
I.flatMap((J) => {
|
|
2402
|
+
const ce = V.features.find((U) => U.id === J);
|
|
2403
|
+
return ce ? [[J, ce.geometry]] : [];
|
|
2404
|
+
})
|
|
2405
|
+
), z = R, G = V.geometryMode, H = [m.lngLat.lng, m.lngLat.lat], te = G === "visual" ? me(H) : H;
|
|
2406
|
+
e.dragPan.disable(), g.current = {
|
|
2407
|
+
featureIds: I,
|
|
2408
|
+
startLngLat: H,
|
|
2409
|
+
startProjected: te,
|
|
2410
|
+
geometryMode: G,
|
|
2411
|
+
startCoords: O,
|
|
2412
|
+
dragging: !1,
|
|
2413
|
+
duplicate: z
|
|
2414
|
+
};
|
|
2415
|
+
const Z = /* @__PURE__ */ new Map(), ne = ze((J, ce) => {
|
|
2416
|
+
const U = g.current;
|
|
2417
|
+
if (!U) return;
|
|
2418
|
+
const Y = J - U.startLngLat[0], ee = ce - U.startLngLat[1];
|
|
2419
|
+
let oe;
|
|
2420
|
+
if (U.geometryMode === "visual") {
|
|
2421
|
+
const Q = [U.startLngLat[0] + Y, U.startLngLat[1] + ee], de = me(Q);
|
|
2422
|
+
oe = [de[0] - U.startProjected[0], de[1] - U.startProjected[1]];
|
|
2423
|
+
} else
|
|
2424
|
+
oe = [Y, ee];
|
|
2425
|
+
for (const Q of U.featureIds) {
|
|
2426
|
+
const de = U.startCoords.get(Q);
|
|
2427
|
+
de && Z.set(Q, $t(de, oe, U.geometryMode === "visual"));
|
|
2428
|
+
}
|
|
2429
|
+
if (U.duplicate) {
|
|
2430
|
+
const Q = e.getSource("elm-drag-ghost");
|
|
2431
|
+
if (Q) {
|
|
2432
|
+
const de = t.getState(), ue = [];
|
|
2433
|
+
for (const Re of U.featureIds) {
|
|
2434
|
+
const xe = de.features.find((Je) => Je.id === Re), Ee = Z.get(Re);
|
|
2435
|
+
xe && Ee && ue.push({
|
|
2436
|
+
type: "Feature",
|
|
2437
|
+
properties: {},
|
|
2438
|
+
geometry: Ee
|
|
2439
|
+
});
|
|
2440
|
+
}
|
|
2441
|
+
try {
|
|
2442
|
+
Q.setData({ type: "FeatureCollection", features: ue });
|
|
2443
|
+
} catch {
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
} else
|
|
2447
|
+
Vt(e, Z);
|
|
2448
|
+
}), se = (J) => {
|
|
2449
|
+
const ce = g.current;
|
|
2450
|
+
if (!ce) return;
|
|
2451
|
+
const U = J.lngLat.lng - ce.startLngLat[0], Y = J.lngLat.lat - ce.startLngLat[1], ee = Math.hypot(U, Y);
|
|
2452
|
+
!ce.dragging && ee < 1e-5 || (ce.dragging || (ce.dragging = !0, e.getCanvas().style.cursor = "grabbing", Ce(!0)), ne.schedule(J.lngLat.lng, J.lngLat.lat));
|
|
2453
|
+
}, ie = () => {
|
|
2454
|
+
ne.flush();
|
|
2455
|
+
const J = g.current;
|
|
2456
|
+
if (g.current = null, e.dragPan.enable(), J != null && J.dragging) {
|
|
2457
|
+
const ce = Ge(n.getState().editingMode);
|
|
2458
|
+
if (P.leave(ce), e.getCanvas().style.cursor = ce, bt(e, null, d.current), d.current = null, Ce(!1), Mr(), t.getState().takeSnapshot(), J.duplicate) {
|
|
2459
|
+
const U = [];
|
|
2460
|
+
for (const ee of J.featureIds) {
|
|
2461
|
+
const oe = Z.get(ee);
|
|
2462
|
+
oe && U.push({ sourceId: ee, geometry: oe });
|
|
2463
|
+
}
|
|
2464
|
+
t.getState().duplicateFeaturesAtPosition(U);
|
|
2465
|
+
const Y = e.getSource("elm-drag-ghost");
|
|
2466
|
+
Y == null || Y.setData({ type: "FeatureCollection", features: [] });
|
|
2467
|
+
} else
|
|
2468
|
+
t.getState().updateFeatures(J.featureIds.flatMap((U) => {
|
|
2469
|
+
const Y = Z.get(U);
|
|
2470
|
+
return Y ? [{ id: U, patch: { geometry: Y } }] : [];
|
|
2471
|
+
}));
|
|
2472
|
+
}
|
|
2473
|
+
e.off("mousemove", se), e.off("mouseup", ie);
|
|
2474
|
+
};
|
|
2475
|
+
e.on("mousemove", se), e.on("mouseup", ie);
|
|
2476
|
+
};
|
|
2477
|
+
return e.on("mousedown", y), () => {
|
|
2478
|
+
e.off("mousedown", y);
|
|
2479
|
+
};
|
|
2480
|
+
}, [c, u, i, t, n, e, P]);
|
|
2481
|
+
const q = s.length === 1 ? r.find((a) => a.id === s[0]) ?? null : null, p = r.filter((a) => s.includes(a.id)), f = _.state && /* @__PURE__ */ X(
|
|
2482
|
+
Bo,
|
|
2483
|
+
{
|
|
2484
|
+
x: _.state.x,
|
|
2485
|
+
y: _.state.y,
|
|
2486
|
+
data: _.state.data,
|
|
2487
|
+
onClose: _.close
|
|
2488
|
+
}
|
|
2489
|
+
), b = w ? r.find((a) => a.id === w) ?? null : null, M = b && /* @__PURE__ */ X(
|
|
2490
|
+
ts,
|
|
2491
|
+
{
|
|
2492
|
+
map: e,
|
|
2493
|
+
feature: b,
|
|
2494
|
+
onDone: () => C(null)
|
|
2495
|
+
}
|
|
2496
|
+
), A = T ? r.find((a) => a.id === T) ?? null : null, E = A && A.geometry.type === "Point" && /* @__PURE__ */ X(
|
|
2497
|
+
Un,
|
|
2498
|
+
{
|
|
2499
|
+
map: e,
|
|
2500
|
+
coords: A.geometry.coordinates,
|
|
2501
|
+
onSave: (a) => {
|
|
2502
|
+
t.getState().takeSnapshot(), t.getState().updateFeature(A.id, { geometry: { type: "Point", coordinates: Ve(A.geometry.coordinates, a) } });
|
|
2503
|
+
},
|
|
2504
|
+
onClose: () => F(null)
|
|
2505
|
+
}
|
|
2506
|
+
);
|
|
2507
|
+
return c || u !== "none" ? /* @__PURE__ */ fe(lt, { children: [
|
|
2508
|
+
f,
|
|
2509
|
+
M,
|
|
2510
|
+
E
|
|
2511
|
+
] }) : /* @__PURE__ */ fe(lt, { children: [
|
|
2512
|
+
i && q && /* @__PURE__ */ X(
|
|
2513
|
+
$r,
|
|
2514
|
+
{
|
|
2515
|
+
map: e,
|
|
2516
|
+
feature: q,
|
|
2517
|
+
initialSelectedIndices: k ?? void 0
|
|
2518
|
+
}
|
|
2519
|
+
),
|
|
2520
|
+
/* @__PURE__ */ X(
|
|
2521
|
+
rs,
|
|
2522
|
+
{
|
|
2523
|
+
map: e,
|
|
2524
|
+
onVertexBoxSelect: (a, x) => {
|
|
2525
|
+
if (i && s.length === 1 && s[0] === a) {
|
|
2526
|
+
N(x);
|
|
2527
|
+
return;
|
|
2528
|
+
}
|
|
2529
|
+
t.getState().selectFeature(a), n.getState().setSelectedPartIndex(null), N(x), n.getState().setVertexEditActive(!0);
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
),
|
|
2533
|
+
l && !i && p.length >= 1 && /* @__PURE__ */ X(es, { map: e, features: p }),
|
|
2534
|
+
f,
|
|
2535
|
+
M,
|
|
2536
|
+
E
|
|
2537
|
+
] });
|
|
2538
|
+
}
|
|
2539
|
+
const Me = "elm-snap", eo = [
|
|
2540
|
+
["elm-snap-vertex", "circle-color", (e) => e[500]]
|
|
2541
|
+
];
|
|
2542
|
+
function ds(e) {
|
|
2543
|
+
e.getSource(Me) || (e.addSource(Me, { type: "geojson", data: Ie() }), e.addLayer({
|
|
2544
|
+
id: "elm-snap-vertex",
|
|
2545
|
+
type: "circle",
|
|
2546
|
+
source: Me,
|
|
2547
|
+
filter: ["==", ["get", "_kind"], "vertex"],
|
|
2548
|
+
paint: {
|
|
2549
|
+
"circle-radius": 6,
|
|
2550
|
+
"circle-stroke-width": 2,
|
|
2551
|
+
"circle-stroke-color": "#ffffff"
|
|
2552
|
+
}
|
|
2553
|
+
}), e.addLayer({
|
|
2554
|
+
id: "elm-snap-edge",
|
|
2555
|
+
type: "symbol",
|
|
2556
|
+
source: Me,
|
|
2557
|
+
filter: ["==", ["get", "_kind"], "edge"],
|
|
2558
|
+
layout: {
|
|
2559
|
+
"icon-image": "elm-snap-diamond",
|
|
2560
|
+
"icon-size": 1,
|
|
2561
|
+
"icon-allow-overlap": !0,
|
|
2562
|
+
"icon-ignore-placement": !0
|
|
2563
|
+
}
|
|
2564
|
+
}), Ne(e, eo));
|
|
2565
|
+
}
|
|
2566
|
+
function fs(e) {
|
|
2567
|
+
for (const t of ["elm-snap-edge", "elm-snap-vertex"])
|
|
2568
|
+
e.getLayer(t) && e.removeLayer(t);
|
|
2569
|
+
e.getSource(Me) && e.removeSource(Me);
|
|
2570
|
+
}
|
|
2571
|
+
const bn = /* @__PURE__ */ new WeakMap();
|
|
2572
|
+
function to(e, t) {
|
|
2573
|
+
const n = e.hasImage("elm-snap-diamond");
|
|
2574
|
+
if (n && bn.get(e) === t) return;
|
|
2575
|
+
const o = 16, r = document.createElement("canvas");
|
|
2576
|
+
r.width = o, r.height = o;
|
|
2577
|
+
const s = r.getContext("2d");
|
|
2578
|
+
if (!s) return;
|
|
2579
|
+
s.clearRect(0, 0, o, o), s.save(), s.translate(o / 2, o / 2), s.rotate(Math.PI / 4), s.fillStyle = t, s.strokeStyle = "#ffffff", s.lineWidth = 2;
|
|
2580
|
+
const i = 8;
|
|
2581
|
+
s.fillRect(-i / 2, -i / 2, i, i), s.strokeRect(-i / 2, -i / 2, i, i), s.restore();
|
|
2582
|
+
const l = s.getImageData(0, 0, o, o);
|
|
2583
|
+
n ? e.updateImage("elm-snap-diamond", l) : e.addImage("elm-snap-diamond", l), bn.set(e, t);
|
|
2584
|
+
}
|
|
2585
|
+
function gs({ map: e }) {
|
|
2586
|
+
const { uiStore: t, dataStore: n } = Le(), o = W((u) => u.editingMode), r = W((u) => u.snapEnabled), s = he((u) => u.features), i = W((u) => u.vertexEditActive), l = qe(e, eo);
|
|
2587
|
+
return K(() => {
|
|
2588
|
+
to(e, l[400]);
|
|
2589
|
+
const u = o !== "none" || i, c = () => {
|
|
2590
|
+
t.getState().snappedCoord && t.getState().setSnappedCoord(null);
|
|
2591
|
+
const T = e.getSource(Me);
|
|
2592
|
+
T == null || T.setData(Ie());
|
|
2593
|
+
};
|
|
2594
|
+
if (!u) {
|
|
2595
|
+
c();
|
|
2596
|
+
return;
|
|
2597
|
+
}
|
|
2598
|
+
const d = ze((T) => {
|
|
2599
|
+
var D;
|
|
2600
|
+
if (!r) {
|
|
2601
|
+
c();
|
|
2602
|
+
return;
|
|
2603
|
+
}
|
|
2604
|
+
const F = T.originalEvent;
|
|
2605
|
+
if (F.metaKey || F.ctrlKey) {
|
|
2606
|
+
c();
|
|
2607
|
+
return;
|
|
2608
|
+
}
|
|
2609
|
+
const k = F.target;
|
|
2610
|
+
if ((D = k == null ? void 0 : k.closest) != null && D.call(k, ".elm-midpoint-marker")) {
|
|
2611
|
+
c();
|
|
2612
|
+
return;
|
|
2613
|
+
}
|
|
2614
|
+
const N = Gt(), P = Vn(T.lngLat.lng, T.lngLat.lat, e, s, 15, new Set(N ? [N] : []));
|
|
2615
|
+
if (!P) {
|
|
2616
|
+
c();
|
|
2617
|
+
return;
|
|
2618
|
+
}
|
|
2619
|
+
if (i && P.isVertex) {
|
|
2620
|
+
const q = new Set(n.getState().selectedIds);
|
|
2621
|
+
if (P.featureId && q.has(P.featureId)) {
|
|
2622
|
+
c();
|
|
2623
|
+
return;
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
t.getState().setSnappedCoord(P.lnglat);
|
|
2627
|
+
const _ = e.getSource(Me);
|
|
2628
|
+
_ == null || _.setData({
|
|
2629
|
+
type: "FeatureCollection",
|
|
2630
|
+
features: [{
|
|
2631
|
+
type: "Feature",
|
|
2632
|
+
properties: { _kind: P.isVertex ? "vertex" : "edge" },
|
|
2633
|
+
geometry: { type: "Point", coordinates: P.lnglat }
|
|
2634
|
+
}]
|
|
2635
|
+
});
|
|
2636
|
+
}), g = (T) => d.schedule(T), w = () => d.flush(), C = () => {
|
|
2637
|
+
d.cancel(), c();
|
|
2638
|
+
};
|
|
2639
|
+
return e.on("mousemove", g), e.on("mouseout", C), window.addEventListener("pointerdown", w, !0), window.addEventListener("pointerup", w, !0), () => {
|
|
2640
|
+
d.cancel(), e.off("mousemove", g), e.off("mouseout", C), window.removeEventListener("pointerdown", w, !0), window.removeEventListener("pointerup", w, !0);
|
|
2641
|
+
};
|
|
2642
|
+
}, [o, r, s, i, e, t, n, l]), null;
|
|
2643
|
+
}
|
|
2644
|
+
function ii({ map: e }) {
|
|
2645
|
+
const t = he((n) => n.features);
|
|
2646
|
+
return K(() => {
|
|
2647
|
+
if (t.length === 0) return;
|
|
2648
|
+
let n = 1 / 0, o = 1 / 0, r = -1 / 0, s = -1 / 0;
|
|
2649
|
+
for (const i of t) {
|
|
2650
|
+
const [l, u, c, v] = i.bbox || Nn(i.geometry);
|
|
2651
|
+
l < n && (n = l), u < o && (o = u), c > r && (r = c), v > s && (s = v);
|
|
2652
|
+
}
|
|
2653
|
+
n !== 1 / 0 && e.fitBounds([[n, o], [r, s]], { padding: jt(e.getContainer()), maxZoom: 16, duration: 600 });
|
|
2654
|
+
}, []), null;
|
|
2655
|
+
}
|
|
2656
|
+
function ys({ map: e }) {
|
|
2657
|
+
const t = W((o) => o.boundaryAutofitBbox), n = W((o) => o.setBoundaryAutofitBbox);
|
|
2658
|
+
return K(() => {
|
|
2659
|
+
if (!t) return;
|
|
2660
|
+
const [o, r, s, i] = t;
|
|
2661
|
+
e.fitBounds([[s, o], [i, r]], { padding: jt(e.getContainer()), maxZoom: 10, duration: 1 }), n(null);
|
|
2662
|
+
}, [t, n, e]), null;
|
|
2663
|
+
}
|
|
2664
|
+
const be = "elm-processing-preview", no = [
|
|
2665
|
+
["elm-processing-preview-fill", "fill-color", (e) => e[500]],
|
|
2666
|
+
["elm-processing-preview-line", "line-color", (e) => e[500]]
|
|
2667
|
+
];
|
|
2668
|
+
function ps(e) {
|
|
2669
|
+
e.getSource(be) || (e.addSource(be, { type: "geojson", data: Ie() }), e.addLayer({
|
|
2670
|
+
id: "elm-processing-preview-ghost",
|
|
2671
|
+
type: "fill",
|
|
2672
|
+
source: be,
|
|
2673
|
+
filter: ["==", ["get", "_ghost"], !0],
|
|
2674
|
+
paint: {
|
|
2675
|
+
"fill-color": "#6b7280",
|
|
2676
|
+
"fill-opacity": 0.07
|
|
2677
|
+
}
|
|
2678
|
+
}), e.addLayer({
|
|
2679
|
+
id: "elm-processing-preview-ghost-line",
|
|
2680
|
+
type: "line",
|
|
2681
|
+
source: be,
|
|
2682
|
+
filter: ["==", ["get", "_ghost"], !0],
|
|
2683
|
+
paint: {
|
|
2684
|
+
"line-color": "#6b7280",
|
|
2685
|
+
"line-opacity": 0.35,
|
|
2686
|
+
"line-width": 1.5,
|
|
2687
|
+
"line-dasharray": [4, 4]
|
|
2688
|
+
}
|
|
2689
|
+
}), e.addLayer({
|
|
2690
|
+
id: "elm-processing-preview-fill",
|
|
2691
|
+
type: "fill",
|
|
2692
|
+
source: be,
|
|
2693
|
+
filter: ["!=", ["get", "_ghost"], !0],
|
|
2694
|
+
paint: {
|
|
2695
|
+
"fill-opacity": [
|
|
2696
|
+
"case",
|
|
2697
|
+
["boolean", ["get", "_bufferNew"], !1],
|
|
2698
|
+
0.12,
|
|
2699
|
+
0.2
|
|
2700
|
+
]
|
|
2701
|
+
}
|
|
2702
|
+
}), e.addLayer({
|
|
2703
|
+
id: "elm-processing-preview-line",
|
|
2704
|
+
type: "line",
|
|
2705
|
+
source: be,
|
|
2706
|
+
filter: ["!=", ["get", "_ghost"], !0],
|
|
2707
|
+
paint: {
|
|
2708
|
+
"line-width": [
|
|
2709
|
+
"case",
|
|
2710
|
+
["boolean", ["get", "_bufferNew"], !1],
|
|
2711
|
+
2,
|
|
2712
|
+
2.5
|
|
2713
|
+
],
|
|
2714
|
+
"line-dasharray": [
|
|
2715
|
+
"case",
|
|
2716
|
+
["boolean", ["get", "_bufferNew"], !1],
|
|
2717
|
+
["literal", [8, 5]],
|
|
2718
|
+
["literal", [1, 0]]
|
|
2719
|
+
]
|
|
2720
|
+
}
|
|
2721
|
+
}), Ne(e, no));
|
|
2722
|
+
}
|
|
2723
|
+
function hs(e) {
|
|
2724
|
+
for (const t of [
|
|
2725
|
+
"elm-processing-preview-line",
|
|
2726
|
+
"elm-processing-preview-fill",
|
|
2727
|
+
"elm-processing-preview-ghost-line",
|
|
2728
|
+
"elm-processing-preview-ghost"
|
|
2729
|
+
])
|
|
2730
|
+
e.getLayer(t) && e.removeLayer(t);
|
|
2731
|
+
e.getSource(be) && e.removeSource(be);
|
|
2732
|
+
}
|
|
2733
|
+
function Ln(e, t) {
|
|
2734
|
+
return { type: "Feature", properties: t, geometry: e };
|
|
2735
|
+
}
|
|
2736
|
+
function ms({ map: e }) {
|
|
2737
|
+
qe(e, no);
|
|
2738
|
+
const t = vt(), n = W((l) => l.editingMode), o = W((l) => l.geometryPreview), r = W((l) => l.bufferCreateNew), s = he((l) => l.selectedIds[0] ?? null), i = he((l) => {
|
|
2739
|
+
var u;
|
|
2740
|
+
return s ? ((u = l.features.find((c) => c.id === s)) == null ? void 0 : u.geometry) ?? null : null;
|
|
2741
|
+
});
|
|
2742
|
+
return K(() => {
|
|
2743
|
+
const l = e.getSource(be);
|
|
2744
|
+
if (!l) return;
|
|
2745
|
+
if (!(n === "simplify-shape" || n === "smooth-shape" || n === "buffer-shape") || !o) {
|
|
2746
|
+
l.setData({ type: "FeatureCollection", features: [] });
|
|
2747
|
+
return;
|
|
2748
|
+
}
|
|
2749
|
+
if (!_t(o.type)) {
|
|
2750
|
+
l.setData({ type: "FeatureCollection", features: [] });
|
|
2751
|
+
return;
|
|
2752
|
+
}
|
|
2753
|
+
const c = n === "buffer-shape", v = c && !r && i && _t(i.type), d = [];
|
|
2754
|
+
v && d.push(Ln(i, { _ghost: !0 })), d.push(
|
|
2755
|
+
Ln(o, {
|
|
2756
|
+
_bufferNew: c && r
|
|
2757
|
+
})
|
|
2758
|
+
), l.setData({ type: "FeatureCollection", features: d });
|
|
2759
|
+
}, [n, o, r, i, e, t]), null;
|
|
2760
|
+
}
|
|
2761
|
+
function oo(e, t, n) {
|
|
2762
|
+
const [o, r] = le(null), [s, i] = le(t);
|
|
2763
|
+
return s !== t && (i(t), r(null)), K(() => {
|
|
2764
|
+
const l = (c) => {
|
|
2765
|
+
n && r([c.lngLat.lng, c.lngLat.lat]);
|
|
2766
|
+
}, u = () => r(null);
|
|
2767
|
+
return e.on("mousemove", l), e.on("mouseout", u), () => {
|
|
2768
|
+
e.off("mousemove", l), e.off("mouseout", u);
|
|
2769
|
+
};
|
|
2770
|
+
}, [e, n]), o;
|
|
2771
|
+
}
|
|
2772
|
+
const we = "#e74c3c", En = "#ff2d1a", Pn = "#c0392b", ye = "elm-measure-preview", Rt = [
|
|
2773
|
+
"elm-measure-hit-line",
|
|
2774
|
+
"elm-measure-hit-fill"
|
|
2775
|
+
];
|
|
2776
|
+
function vs(e) {
|
|
2777
|
+
e.getSource(ye) || (e.addSource(ye, { type: "geojson", data: Ie() }), e.addLayer({
|
|
2778
|
+
id: "elm-measure-area-fill",
|
|
2779
|
+
type: "fill",
|
|
2780
|
+
source: ye,
|
|
2781
|
+
filter: ["all", ["==", ["get", "_kind"], "area"], ["==", ["geometry-type"], "Polygon"]],
|
|
2782
|
+
paint: {
|
|
2783
|
+
"fill-color": [
|
|
2784
|
+
"case",
|
|
2785
|
+
["boolean", ["get", "_selected"], !1],
|
|
2786
|
+
Pn,
|
|
2787
|
+
["boolean", ["get", "_hovered"], !1],
|
|
2788
|
+
En,
|
|
2789
|
+
we
|
|
2790
|
+
],
|
|
2791
|
+
"fill-opacity": [
|
|
2792
|
+
"case",
|
|
2793
|
+
["boolean", ["get", "_selected"], !1],
|
|
2794
|
+
0.15,
|
|
2795
|
+
["boolean", ["get", "_hovered"], !1],
|
|
2796
|
+
0.12,
|
|
2797
|
+
0.08
|
|
2798
|
+
]
|
|
2799
|
+
}
|
|
2800
|
+
}), e.addLayer({
|
|
2801
|
+
id: "elm-measure-live-area",
|
|
2802
|
+
type: "fill",
|
|
2803
|
+
source: ye,
|
|
2804
|
+
filter: ["all", ["==", ["get", "_kind"], "live-area"], ["==", ["geometry-type"], "Polygon"]],
|
|
2805
|
+
paint: { "fill-color": we, "fill-opacity": 0.08 }
|
|
2806
|
+
}), e.addLayer({
|
|
2807
|
+
id: "elm-measure-line",
|
|
2808
|
+
type: "line",
|
|
2809
|
+
source: ye,
|
|
2810
|
+
filter: [
|
|
2811
|
+
"all",
|
|
2812
|
+
["in", ["get", "_kind"], ["literal", ["segment", "live-line", "live-perimeter", "live-area"]]],
|
|
2813
|
+
["==", ["geometry-type"], "LineString"]
|
|
2814
|
+
],
|
|
2815
|
+
paint: {
|
|
2816
|
+
"line-color": [
|
|
2817
|
+
"case",
|
|
2818
|
+
["boolean", ["get", "_selected"], !1],
|
|
2819
|
+
Pn,
|
|
2820
|
+
["boolean", ["get", "_hovered"], !1],
|
|
2821
|
+
En,
|
|
2822
|
+
we
|
|
2823
|
+
],
|
|
2824
|
+
"line-width": 3,
|
|
2825
|
+
"line-opacity": [
|
|
2826
|
+
"case",
|
|
2827
|
+
["boolean", ["get", "_selected"], !1],
|
|
2828
|
+
1,
|
|
2829
|
+
["boolean", ["get", "_hovered"], !1],
|
|
2830
|
+
1,
|
|
2831
|
+
0.9
|
|
2832
|
+
],
|
|
2833
|
+
// MapLibre dash values are MULTIPLES of line-width (not pixels). At
|
|
2834
|
+
// line-width 3, [10, 6] would render as 30px dash / 18px gap — way
|
|
2835
|
+
// longer than Leaflet's pixel-based "10 6". Divide by 3 to match.
|
|
2836
|
+
"line-dasharray": [3.33, 2]
|
|
2837
|
+
}
|
|
2838
|
+
}), e.addLayer({
|
|
2839
|
+
id: "elm-measure-ghost",
|
|
2840
|
+
type: "line",
|
|
2841
|
+
source: ye,
|
|
2842
|
+
filter: ["==", ["get", "_kind"], "ghost"],
|
|
2843
|
+
paint: {
|
|
2844
|
+
"line-color": we,
|
|
2845
|
+
"line-width": 3,
|
|
2846
|
+
"line-opacity": 0.45,
|
|
2847
|
+
// MapLibre dash values are MULTIPLES of line-width (not pixels). At
|
|
2848
|
+
// line-width 3, [10, 6] would render as 30px dash / 18px gap — way
|
|
2849
|
+
// longer than Leaflet's pixel-based "10 6". Divide by 3 to match.
|
|
2850
|
+
"line-dasharray": [3.33, 2]
|
|
2851
|
+
}
|
|
2852
|
+
}), e.addLayer({
|
|
2853
|
+
id: "elm-measure-close-hint",
|
|
2854
|
+
type: "line",
|
|
2855
|
+
source: ye,
|
|
2856
|
+
filter: ["==", ["get", "_kind"], "close-hint"],
|
|
2857
|
+
paint: {
|
|
2858
|
+
"line-color": we,
|
|
2859
|
+
"line-width": 2,
|
|
2860
|
+
"line-opacity": 0.25,
|
|
2861
|
+
// line-width is 2 here; pixel-equivalent of leaflet's "6 6" → [3, 3].
|
|
2862
|
+
"line-dasharray": [3, 3]
|
|
2863
|
+
}
|
|
2864
|
+
}), e.addLayer({
|
|
2865
|
+
id: "elm-measure-hit-line",
|
|
2866
|
+
type: "line",
|
|
2867
|
+
source: ye,
|
|
2868
|
+
filter: ["==", ["get", "_kind"], "segment"],
|
|
2869
|
+
paint: {
|
|
2870
|
+
"line-color": we,
|
|
2871
|
+
"line-width": 16,
|
|
2872
|
+
"line-opacity": 0
|
|
2873
|
+
}
|
|
2874
|
+
}), e.addLayer({
|
|
2875
|
+
id: "elm-measure-hit-fill",
|
|
2876
|
+
type: "fill",
|
|
2877
|
+
source: ye,
|
|
2878
|
+
filter: ["all", ["==", ["get", "_kind"], "area"], ["==", ["geometry-type"], "Polygon"]],
|
|
2879
|
+
paint: { "fill-color": we, "fill-opacity": 0 }
|
|
2880
|
+
}), e.addLayer({
|
|
2881
|
+
id: "elm-measure-vertex",
|
|
2882
|
+
type: "circle",
|
|
2883
|
+
source: ye,
|
|
2884
|
+
filter: [
|
|
2885
|
+
"all",
|
|
2886
|
+
["==", ["geometry-type"], "Point"],
|
|
2887
|
+
["!=", ["get", "_isFirst"], !0]
|
|
2888
|
+
],
|
|
2889
|
+
paint: {
|
|
2890
|
+
"circle-radius": 5,
|
|
2891
|
+
"circle-color": we,
|
|
2892
|
+
"circle-stroke-width": 2,
|
|
2893
|
+
"circle-stroke-color": "#ffffff"
|
|
2894
|
+
}
|
|
2895
|
+
}), e.addLayer({
|
|
2896
|
+
id: "elm-measure-first-vertex",
|
|
2897
|
+
type: "circle",
|
|
2898
|
+
source: ye,
|
|
2899
|
+
filter: [
|
|
2900
|
+
"all",
|
|
2901
|
+
["==", ["geometry-type"], "Point"],
|
|
2902
|
+
["==", ["get", "_isFirst"], !0]
|
|
2903
|
+
],
|
|
2904
|
+
paint: {
|
|
2905
|
+
"circle-radius": 5,
|
|
2906
|
+
"circle-color": "#ffffff",
|
|
2907
|
+
"circle-stroke-width": 2.5,
|
|
2908
|
+
"circle-stroke-color": we
|
|
2909
|
+
}
|
|
2910
|
+
}));
|
|
2911
|
+
}
|
|
2912
|
+
function xs(e) {
|
|
2913
|
+
for (const t of [
|
|
2914
|
+
"elm-measure-first-vertex",
|
|
2915
|
+
"elm-measure-vertex",
|
|
2916
|
+
"elm-measure-hit-fill",
|
|
2917
|
+
"elm-measure-hit-line",
|
|
2918
|
+
"elm-measure-close-hint",
|
|
2919
|
+
"elm-measure-ghost",
|
|
2920
|
+
"elm-measure-line",
|
|
2921
|
+
"elm-measure-live-area",
|
|
2922
|
+
"elm-measure-area-fill"
|
|
2923
|
+
])
|
|
2924
|
+
e.getLayer(t) && e.removeLayer(t);
|
|
2925
|
+
e.getSource(ye) && e.removeSource(ye);
|
|
2926
|
+
}
|
|
2927
|
+
function ws(e, t) {
|
|
2928
|
+
const n = e.getSource(ye);
|
|
2929
|
+
n && n.setData({ type: "FeatureCollection", features: t });
|
|
2930
|
+
}
|
|
2931
|
+
let pe = null;
|
|
2932
|
+
function Ss(e, t, n) {
|
|
2933
|
+
pe || (pe = document.createElement("div"), pe.className = "elm-feature-tooltip", pe.style.cssText = "position:fixed;pointer-events:none;z-index:10000;transform:translate(-50%,-100%);margin-top:-12px", document.body.appendChild(pe)), pe.textContent = e, ro(t, n);
|
|
2934
|
+
}
|
|
2935
|
+
function ro(e, t) {
|
|
2936
|
+
pe && (pe.style.left = e + "px", pe.style.top = t + "px");
|
|
2937
|
+
}
|
|
2938
|
+
function Cn() {
|
|
2939
|
+
pe == null || pe.remove(), pe = null;
|
|
2940
|
+
}
|
|
2941
|
+
function bs(e, t, n, o) {
|
|
2942
|
+
try {
|
|
2943
|
+
if (t === "distance" && e.length >= 2) return mt(_e(We(e)) * 1e3, n);
|
|
2944
|
+
if (t === "area" && e.length >= 3) return Ht(dt(ut([[...e, e[0]]])), o);
|
|
2945
|
+
} catch {
|
|
2946
|
+
}
|
|
2947
|
+
return null;
|
|
2948
|
+
}
|
|
2949
|
+
function so({
|
|
2950
|
+
map: e,
|
|
2951
|
+
position: t,
|
|
2952
|
+
parts: n,
|
|
2953
|
+
onRemove: o
|
|
2954
|
+
}) {
|
|
2955
|
+
const r = $(null), [s] = le(() => document.createElement("div"));
|
|
2956
|
+
return K(() => {
|
|
2957
|
+
const i = new De.Marker({
|
|
2958
|
+
element: s,
|
|
2959
|
+
// 'left' anchor → the host's LEFT edge sits on the latlng. Combined
|
|
2960
|
+
// with the offset, the pill begins 12px right of the underlying point.
|
|
2961
|
+
anchor: "left",
|
|
2962
|
+
offset: [12, 0]
|
|
2963
|
+
}).setLngLat(t).addTo(e);
|
|
2964
|
+
return r.current = i, () => {
|
|
2965
|
+
i.remove(), r.current = null;
|
|
2966
|
+
};
|
|
2967
|
+
}, [e, s]), K(() => {
|
|
2968
|
+
var i;
|
|
2969
|
+
(i = r.current) == null || i.setLngLat(t);
|
|
2970
|
+
}, [t[0], t[1]]), Ze(
|
|
2971
|
+
/* @__PURE__ */ fe(
|
|
2972
|
+
"div",
|
|
2973
|
+
{
|
|
2974
|
+
className: "elm-measure-label",
|
|
2975
|
+
style: {
|
|
2976
|
+
display: "inline-flex",
|
|
2977
|
+
alignItems: "center",
|
|
2978
|
+
gap: 7,
|
|
2979
|
+
pointerEvents: o ? "auto" : "none",
|
|
2980
|
+
userSelect: "none",
|
|
2981
|
+
whiteSpace: "nowrap"
|
|
2982
|
+
},
|
|
2983
|
+
children: [
|
|
2984
|
+
/* @__PURE__ */ fe("span", { children: [
|
|
2985
|
+
/* @__PURE__ */ X("span", { style: { fontWeight: 600 }, children: n.value }),
|
|
2986
|
+
/* @__PURE__ */ fe("span", { style: { fontWeight: 400, opacity: 0.85 }, children: [
|
|
2987
|
+
" ",
|
|
2988
|
+
n.unit
|
|
2989
|
+
] })
|
|
2990
|
+
] }),
|
|
2991
|
+
o && /* @__PURE__ */ X(
|
|
2992
|
+
"button",
|
|
2993
|
+
{
|
|
2994
|
+
className: "elm-measure-close",
|
|
2995
|
+
onClick: (i) => {
|
|
2996
|
+
i.stopPropagation(), o();
|
|
2997
|
+
},
|
|
2998
|
+
title: "Clear measurement",
|
|
2999
|
+
style: { marginRight: "-5px" },
|
|
3000
|
+
children: /* @__PURE__ */ fe("svg", { width: "10", height: "10", viewBox: "0 0 10 10", fill: "none", stroke: "rgba(255,255,255,0.8)", strokeWidth: "1.5", strokeLinecap: "round", children: [
|
|
3001
|
+
/* @__PURE__ */ X("line", { x1: "1.5", y1: "1.5", x2: "8.5", y2: "8.5" }),
|
|
3002
|
+
/* @__PURE__ */ X("line", { x1: "8.5", y1: "1.5", x2: "1.5", y2: "8.5" })
|
|
3003
|
+
] })
|
|
3004
|
+
}
|
|
3005
|
+
)
|
|
3006
|
+
]
|
|
3007
|
+
}
|
|
3008
|
+
),
|
|
3009
|
+
s
|
|
3010
|
+
);
|
|
3011
|
+
}
|
|
3012
|
+
const Ls = ao(function({
|
|
3013
|
+
map: t,
|
|
3014
|
+
m: n
|
|
3015
|
+
}) {
|
|
3016
|
+
const o = W((c) => c.removeMeasurement), { units: r } = ke(), s = { unit: r.length, display: r.display, precision: r.precision }, i = { unit: r.area, display: r.display, precision: r.precision }, l = Bt(() => {
|
|
3017
|
+
try {
|
|
3018
|
+
if (n.mode === "distance" && n.points.length >= 2)
|
|
3019
|
+
return mt(_e(We(n.points)) * 1e3, s);
|
|
3020
|
+
if (n.mode === "area" && n.points.length >= 3)
|
|
3021
|
+
return Ht(dt(ut([n.points])), i);
|
|
3022
|
+
} catch {
|
|
3023
|
+
}
|
|
3024
|
+
return null;
|
|
3025
|
+
}, [n, s.unit, s.display, s.precision, i.unit, i.display, i.precision]), u = n.mode === "area" ? n.points[n.points.length - 2] : n.points[n.points.length - 1];
|
|
3026
|
+
return !l || !u ? null : /* @__PURE__ */ X(
|
|
3027
|
+
so,
|
|
3028
|
+
{
|
|
3029
|
+
map: t,
|
|
3030
|
+
position: u,
|
|
3031
|
+
parts: l,
|
|
3032
|
+
onRemove: () => o(n.id)
|
|
3033
|
+
}
|
|
3034
|
+
);
|
|
3035
|
+
});
|
|
3036
|
+
function Es({ map: e }) {
|
|
3037
|
+
const t = vt(), n = W((p) => p.editingMode), o = W((p) => p.measurePoints), r = W((p) => p.measureMode), s = W((p) => p.completedMeasurements), i = W((p) => p.selectedMeasurementId), l = W((p) => p.snappedCoord), u = W((p) => p.toggleMeasurementSelection), c = W((p) => p.setSelectedMeasurementId), v = oo(e, n, n === "measure"), { units: d } = ke(), g = { unit: d.length, display: d.display, precision: d.precision }, w = { unit: d.area, display: d.display, precision: d.precision }, [C, T] = le(null), F = n === "measure", k = F ? l ?? v : null, N = o.length > 0 ? o[o.length - 1] : null;
|
|
3038
|
+
K(() => {
|
|
3039
|
+
const p = [];
|
|
3040
|
+
for (const f of s) {
|
|
3041
|
+
const b = C === f.id, M = i === f.id;
|
|
3042
|
+
if (f.mode === "distance") {
|
|
3043
|
+
for (let E = 0; E < f.points.length - 1; E++)
|
|
3044
|
+
p.push({
|
|
3045
|
+
type: "Feature",
|
|
3046
|
+
properties: { _kind: "segment", _id: f.id, _segIdx: E, _hovered: b, _selected: M },
|
|
3047
|
+
geometry: { type: "LineString", coordinates: [f.points[E], f.points[E + 1]] }
|
|
3048
|
+
});
|
|
3049
|
+
f.points.forEach((E, a) => {
|
|
3050
|
+
p.push({
|
|
3051
|
+
type: "Feature",
|
|
3052
|
+
properties: { _kind: "dot", _id: f.id, _isFirst: a === 0 },
|
|
3053
|
+
geometry: { type: "Point", coordinates: E }
|
|
3054
|
+
});
|
|
3055
|
+
});
|
|
3056
|
+
} else
|
|
3057
|
+
p.push({
|
|
3058
|
+
type: "Feature",
|
|
3059
|
+
properties: { _kind: "area", _id: f.id, _hovered: b, _selected: M },
|
|
3060
|
+
geometry: { type: "Polygon", coordinates: [f.points] }
|
|
3061
|
+
}), p.push({
|
|
3062
|
+
type: "Feature",
|
|
3063
|
+
properties: { _kind: "segment", _id: f.id, _hovered: b, _selected: M },
|
|
3064
|
+
geometry: { type: "LineString", coordinates: f.points }
|
|
3065
|
+
}), f.points.slice(0, -1).forEach((E, a) => {
|
|
3066
|
+
p.push({
|
|
3067
|
+
type: "Feature",
|
|
3068
|
+
properties: { _kind: "dot", _id: f.id, _isFirst: a === 0 },
|
|
3069
|
+
geometry: { type: "Point", coordinates: E }
|
|
3070
|
+
});
|
|
3071
|
+
});
|
|
3072
|
+
}
|
|
3073
|
+
F && o.length >= 2 && p.push({
|
|
3074
|
+
type: "Feature",
|
|
3075
|
+
properties: { _kind: "live-line" },
|
|
3076
|
+
geometry: { type: "LineString", coordinates: o }
|
|
3077
|
+
}), F && r === "area" && o.length >= 3 && p.push({
|
|
3078
|
+
type: "Feature",
|
|
3079
|
+
properties: { _kind: "live-area" },
|
|
3080
|
+
geometry: { type: "Polygon", coordinates: [[...o, o[0]]] }
|
|
3081
|
+
}), F && k && N && p.push({
|
|
3082
|
+
type: "Feature",
|
|
3083
|
+
properties: { _kind: "ghost" },
|
|
3084
|
+
geometry: { type: "LineString", coordinates: [N, k] }
|
|
3085
|
+
}), F && r === "area" && k && o.length >= 2 && p.push({
|
|
3086
|
+
type: "Feature",
|
|
3087
|
+
properties: { _kind: "close-hint" },
|
|
3088
|
+
geometry: { type: "LineString", coordinates: [k, o[0]] }
|
|
3089
|
+
}), F && o.forEach((f, b) => {
|
|
3090
|
+
p.push({
|
|
3091
|
+
type: "Feature",
|
|
3092
|
+
properties: { _kind: "live-dot", _isFirst: b === 0 },
|
|
3093
|
+
geometry: { type: "Point", coordinates: f }
|
|
3094
|
+
});
|
|
3095
|
+
}), ws(e, p);
|
|
3096
|
+
}, [
|
|
3097
|
+
e,
|
|
3098
|
+
F,
|
|
3099
|
+
o,
|
|
3100
|
+
r,
|
|
3101
|
+
s,
|
|
3102
|
+
C,
|
|
3103
|
+
i,
|
|
3104
|
+
k,
|
|
3105
|
+
N,
|
|
3106
|
+
t
|
|
3107
|
+
]), K(() => {
|
|
3108
|
+
const p = (E) => {
|
|
3109
|
+
var y, m;
|
|
3110
|
+
const a = (y = E.features) == null ? void 0 : y[0];
|
|
3111
|
+
if (!a) return;
|
|
3112
|
+
const x = (m = a.properties) == null ? void 0 : m._id;
|
|
3113
|
+
x && (Pr(), E.originalEvent.stopPropagation(), u(x));
|
|
3114
|
+
}, f = (E) => {
|
|
3115
|
+
var R, S, L, B;
|
|
3116
|
+
const a = (R = E.features) == null ? void 0 : R[0];
|
|
3117
|
+
if (!a) return;
|
|
3118
|
+
const x = (S = a.properties) == null ? void 0 : S._id;
|
|
3119
|
+
if (!x) return;
|
|
3120
|
+
T(x);
|
|
3121
|
+
const y = (L = a.properties) == null ? void 0 : L._kind, m = (B = a.properties) == null ? void 0 : B._segIdx;
|
|
3122
|
+
if (y === "segment" && typeof m == "number") {
|
|
3123
|
+
const V = s.find((j) => j.id === x);
|
|
3124
|
+
if (V && V.mode === "distance") {
|
|
3125
|
+
const j = V.points[m], h = V.points[m + 1];
|
|
3126
|
+
if (j && h) {
|
|
3127
|
+
const I = mt(_e(We([j, h])) * 1e3, g);
|
|
3128
|
+
Ss(`${I.value} ${I.unit}`, E.originalEvent.clientX, E.originalEvent.clientY);
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
}, b = (E) => {
|
|
3133
|
+
var y, m;
|
|
3134
|
+
const a = (y = E.features) == null ? void 0 : y[0];
|
|
3135
|
+
if (!a) return;
|
|
3136
|
+
((m = a.properties) == null ? void 0 : m._kind) === "segment" && ro(E.originalEvent.clientX, E.originalEvent.clientY);
|
|
3137
|
+
}, M = () => {
|
|
3138
|
+
T(null), Cn();
|
|
3139
|
+
}, A = (E) => {
|
|
3140
|
+
try {
|
|
3141
|
+
e.queryRenderedFeatures(E.point, { layers: Rt }).length === 0 && c(null);
|
|
3142
|
+
} catch {
|
|
3143
|
+
}
|
|
3144
|
+
};
|
|
3145
|
+
for (const E of Rt)
|
|
3146
|
+
e.on("click", E, p), e.on("mouseenter", E, f), e.on("mousemove", E, b), e.on("mouseleave", E, M);
|
|
3147
|
+
return e.on("click", A), () => {
|
|
3148
|
+
for (const E of Rt)
|
|
3149
|
+
e.off("click", E, p), e.off("mouseenter", E, f), e.off("mousemove", E, b), e.off("mouseleave", E, M);
|
|
3150
|
+
e.off("click", A), Cn();
|
|
3151
|
+
};
|
|
3152
|
+
}, [e, u, c, s, g.unit, g.display, g.precision]);
|
|
3153
|
+
const P = r === "distance" ? 1 : 2, _ = k && o.length >= P ? [...o, k] : o, D = bs(_, r, g, w), q = k ?? N;
|
|
3154
|
+
return /* @__PURE__ */ fe(lt, { children: [
|
|
3155
|
+
s.map((p) => /* @__PURE__ */ X(Ls, { map: e, m: p }, p.id)),
|
|
3156
|
+
D && q && /* @__PURE__ */ X(so, { map: e, position: q, parts: D })
|
|
3157
|
+
] });
|
|
3158
|
+
}
|
|
3159
|
+
const Ae = "elm-osm-trace";
|
|
3160
|
+
let Mn = !1;
|
|
3161
|
+
function Ps() {
|
|
3162
|
+
if (Mn) return;
|
|
3163
|
+
const e = document.createElement("style");
|
|
3164
|
+
e.textContent = `
|
|
3165
|
+
@keyframes elm-osm-pulse {
|
|
3166
|
+
0% { transform: scale(0.6); opacity: 0.7; }
|
|
3167
|
+
100% { transform: scale(3); opacity: 0; }
|
|
3168
|
+
}
|
|
3169
|
+
@keyframes elm-osm-spin {
|
|
3170
|
+
to { transform: rotate(360deg); }
|
|
3171
|
+
}
|
|
3172
|
+
.elm-osm-pulse-ring {
|
|
3173
|
+
width: 64px; height: 64px; border-radius: 50%;
|
|
3174
|
+
background: color-mix(in srgb, var(--color-primary-500) 20%, transparent);
|
|
3175
|
+
animation: elm-osm-pulse 1.4s ease-out infinite;
|
|
3176
|
+
pointer-events: none;
|
|
3177
|
+
}
|
|
3178
|
+
.elm-osm-spinner {
|
|
3179
|
+
width: 24px; height: 24px; border-radius: 50%;
|
|
3180
|
+
border: 4px solid color-mix(in srgb, var(--color-primary-500) 20%, transparent);
|
|
3181
|
+
border-top-color: var(--color-primary-500);
|
|
3182
|
+
animation: elm-osm-spin 0.8s linear infinite;
|
|
3183
|
+
pointer-events: none;
|
|
3184
|
+
}
|
|
3185
|
+
`, document.head.appendChild(e), Mn = !0;
|
|
3186
|
+
}
|
|
3187
|
+
function Cs(e) {
|
|
3188
|
+
e.getSource(Ae) || (e.addSource(Ae, { type: "geojson", data: Ie() }), e.addLayer({
|
|
3189
|
+
id: "elm-osm-trace-fill",
|
|
3190
|
+
type: "fill",
|
|
3191
|
+
source: Ae,
|
|
3192
|
+
paint: {
|
|
3193
|
+
"fill-color": ["get", "_color"],
|
|
3194
|
+
"fill-opacity": [
|
|
3195
|
+
"case",
|
|
3196
|
+
["boolean", ["get", "_hovered"], !1],
|
|
3197
|
+
0.3,
|
|
3198
|
+
0.12
|
|
3199
|
+
]
|
|
3200
|
+
}
|
|
3201
|
+
}), e.addLayer({
|
|
3202
|
+
id: "elm-osm-trace-line",
|
|
3203
|
+
type: "line",
|
|
3204
|
+
source: Ae,
|
|
3205
|
+
paint: {
|
|
3206
|
+
"line-color": ["get", "_color"],
|
|
3207
|
+
"line-width": [
|
|
3208
|
+
"case",
|
|
3209
|
+
["boolean", ["get", "_hovered"], !1],
|
|
3210
|
+
3,
|
|
3211
|
+
2
|
|
3212
|
+
],
|
|
3213
|
+
"line-opacity": [
|
|
3214
|
+
"case",
|
|
3215
|
+
["boolean", ["get", "_hovered"], !1],
|
|
3216
|
+
1,
|
|
3217
|
+
0.7
|
|
3218
|
+
]
|
|
3219
|
+
}
|
|
3220
|
+
}));
|
|
3221
|
+
}
|
|
3222
|
+
function Ms(e) {
|
|
3223
|
+
for (const t of ["elm-osm-trace-line", "elm-osm-trace-fill"])
|
|
3224
|
+
e.getLayer(t) && e.removeLayer(t);
|
|
3225
|
+
e.getSource(Ae) && e.removeSource(Ae);
|
|
3226
|
+
}
|
|
3227
|
+
function ks(e, t, n) {
|
|
3228
|
+
const o = e.getSource(Ae);
|
|
3229
|
+
if (!o) return;
|
|
3230
|
+
if (!t) {
|
|
3231
|
+
o.setData(Ie());
|
|
3232
|
+
return;
|
|
3233
|
+
}
|
|
3234
|
+
const r = t.map((s, i) => ({
|
|
3235
|
+
type: "Feature",
|
|
3236
|
+
properties: {
|
|
3237
|
+
_color: at[i % at.length],
|
|
3238
|
+
_hovered: n === i,
|
|
3239
|
+
_idx: i
|
|
3240
|
+
},
|
|
3241
|
+
geometry: s.geometry
|
|
3242
|
+
}));
|
|
3243
|
+
o.setData({ type: "FeatureCollection", features: r });
|
|
3244
|
+
}
|
|
3245
|
+
const Is = /* @__PURE__ */ new Set(["building", "landuse", "landcover", "park", "water", "aeroway"]);
|
|
3246
|
+
function Rs(e, t) {
|
|
3247
|
+
const n = [], o = /* @__PURE__ */ new Map();
|
|
3248
|
+
for (const s of e.queryRenderedFeatures([t.x, t.y])) {
|
|
3249
|
+
if (!s.sourceLayer || !Is.has(s.sourceLayer) || s.id == null || s.geometry.type !== "Polygon" && s.geometry.type !== "MultiPolygon") continue;
|
|
3250
|
+
n.push({ source: s.source, sourceLayer: s.sourceLayer, id: s.id, properties: s.properties, geometry: s.geometry });
|
|
3251
|
+
const i = `${s.source}
|
|
3252
|
+
${s.sourceLayer}`, l = o.get(i);
|
|
3253
|
+
l ? l.ids.add(s.id) : o.set(i, { source: s.source, sourceLayer: s.sourceLayer, ids: /* @__PURE__ */ new Set([s.id]) });
|
|
3254
|
+
}
|
|
3255
|
+
const r = [];
|
|
3256
|
+
for (const { source: s, sourceLayer: i, ids: l } of o.values())
|
|
3257
|
+
for (const u of e.querySourceFeatures(s, { sourceLayer: i, filter: ["in", ["id"], ["literal", [...l]]] }))
|
|
3258
|
+
r.push({ source: s, sourceLayer: i, id: u.id, properties: u.properties, geometry: u.geometry });
|
|
3259
|
+
return _o(n, r);
|
|
3260
|
+
}
|
|
3261
|
+
async function Fs(e, t) {
|
|
3262
|
+
let n = e.pieces.length === 1 ? e.pieces[0].geometry : null;
|
|
3263
|
+
if (!n)
|
|
3264
|
+
try {
|
|
3265
|
+
n = await $o({ type: "boolean", op: "union", features: e.pieces });
|
|
3266
|
+
} catch {
|
|
3267
|
+
n = await ko(e.pieces);
|
|
3268
|
+
}
|
|
3269
|
+
return Io(e, n, t);
|
|
3270
|
+
}
|
|
3271
|
+
function _s({ map: e }) {
|
|
3272
|
+
const { dataStore: t, uiStore: n } = Le(), o = ke().network, r = $(o);
|
|
3273
|
+
r.current = o;
|
|
3274
|
+
const s = Ue(), i = zt(), l = W((p) => p.editingMode), [u, c] = le(null), [v, d] = le(null), g = Oo(), w = An(), C = $(null), T = $(null), F = $(null), k = $(null);
|
|
3275
|
+
K(() => () => {
|
|
3276
|
+
F.current && (F.current.remove(), F.current = null);
|
|
3277
|
+
}, [e]);
|
|
3278
|
+
const N = vt();
|
|
3279
|
+
K(() => {
|
|
3280
|
+
ks(e, u, v);
|
|
3281
|
+
}, [e, u, v, N]);
|
|
3282
|
+
const P = ve(
|
|
3283
|
+
(p) => Mo(t.getState(), n.getState(), p),
|
|
3284
|
+
[t, n]
|
|
3285
|
+
), _ = ve(() => {
|
|
3286
|
+
F.current && (F.current.remove(), F.current = null);
|
|
3287
|
+
}, []), D = ve(() => {
|
|
3288
|
+
c(null), d(null), C.current = null, _(), T.current && (T.current.abort(), T.current = null);
|
|
3289
|
+
}, [_]), q = ve((p) => {
|
|
3290
|
+
const f = C.current;
|
|
3291
|
+
if (D(), !("pieces" in p)) {
|
|
3292
|
+
P(p);
|
|
3293
|
+
return;
|
|
3294
|
+
}
|
|
3295
|
+
if (!f) return;
|
|
3296
|
+
const b = new AbortController();
|
|
3297
|
+
T.current = b, Fs(p, f).then((M) => {
|
|
3298
|
+
b.signal.aborted || (T.current = null, M && P(M));
|
|
3299
|
+
});
|
|
3300
|
+
}, [P, D]);
|
|
3301
|
+
return K(() => {
|
|
3302
|
+
if (!u && l !== "pick-shape") return;
|
|
3303
|
+
function p(f) {
|
|
3304
|
+
f.key === "Escape" && i(f) && D();
|
|
3305
|
+
}
|
|
3306
|
+
return window.addEventListener("keydown", p), () => window.removeEventListener("keydown", p);
|
|
3307
|
+
}, [u, l, D, i]), K(() => {
|
|
3308
|
+
if (l !== "pick-shape") return;
|
|
3309
|
+
const p = (f) => {
|
|
3310
|
+
if (e.getZoom() < Ro) {
|
|
3311
|
+
s({ type: "warning", message: "Zoom in further to use the picker" });
|
|
3312
|
+
return;
|
|
3313
|
+
}
|
|
3314
|
+
f.originalEvent.preventDefault(), D();
|
|
3315
|
+
const b = new AbortController();
|
|
3316
|
+
T.current = b;
|
|
3317
|
+
const M = f.lngLat.lng, A = f.lngLat.lat;
|
|
3318
|
+
C.current = [M, A], Ps();
|
|
3319
|
+
const E = document.createElement("div");
|
|
3320
|
+
E.style.cssText = "width:64px;height:64px;pointer-events:none;display:flex;align-items:center;justify-content:center;", E.innerHTML = `
|
|
3321
|
+
<div class="elm-osm-pulse-ring" style="position:absolute"></div>
|
|
3322
|
+
<div class="elm-osm-spinner"></div>
|
|
3323
|
+
`, F.current = new De.Marker({ element: E, anchor: "center" }).setLngLat([M, A]).addTo(e);
|
|
3324
|
+
const a = Rs(e, f.point), { overpass: x, fetch: y } = r.current, m = x === !1;
|
|
3325
|
+
(a.length > 0 || m ? Promise.resolve(a) : Qo(A, M, Fo(e.getZoom()), [M, A], { ...x, fetch: y, signal: b.signal })).then((S) => {
|
|
3326
|
+
_(), S.length === 0 ? (s({ type: "warning", message: m ? "No shape here in the basemap" : "No features found here" }), D()) : S.length === 1 ? q(S[0]) : c(S);
|
|
3327
|
+
}).catch((S) => {
|
|
3328
|
+
(S == null ? void 0 : S.name) !== "AbortError" && (_(), s({ type: "error", code: S instanceof tr ? S.code : "unknown", source: "picker", message: er(S), cause: S }), D());
|
|
3329
|
+
});
|
|
3330
|
+
};
|
|
3331
|
+
return e.on("click", p), () => {
|
|
3332
|
+
e.off("click", p);
|
|
3333
|
+
};
|
|
3334
|
+
}, [l, e, D, _, q, s]), K(() => {
|
|
3335
|
+
if (!u || !C.current) return;
|
|
3336
|
+
const p = C.current;
|
|
3337
|
+
let f;
|
|
3338
|
+
function b() {
|
|
3339
|
+
if (!k.current) {
|
|
3340
|
+
f = requestAnimationFrame(b);
|
|
3341
|
+
return;
|
|
3342
|
+
}
|
|
3343
|
+
const M = e.project(p), A = e.getContainer().getBoundingClientRect();
|
|
3344
|
+
k.current.style.left = `${A.left + M.x + 16}px`, k.current.style.top = `${A.top + M.y - 8}px`, f = requestAnimationFrame(b);
|
|
3345
|
+
}
|
|
3346
|
+
return f = requestAnimationFrame(b), () => cancelAnimationFrame(f);
|
|
3347
|
+
}, [u, e]), K(() => {
|
|
3348
|
+
if (!u) return;
|
|
3349
|
+
const p = (E) => {
|
|
3350
|
+
var m, R;
|
|
3351
|
+
const a = (m = E.features) == null ? void 0 : m[0];
|
|
3352
|
+
if (!a) return;
|
|
3353
|
+
const x = (R = a.properties) == null ? void 0 : R._idx;
|
|
3354
|
+
if (typeof x != "number") return;
|
|
3355
|
+
E.originalEvent.stopPropagation();
|
|
3356
|
+
const y = u[x];
|
|
3357
|
+
y && q(y);
|
|
3358
|
+
}, f = (E) => {
|
|
3359
|
+
var y, m;
|
|
3360
|
+
const a = (y = E.features) == null ? void 0 : y[0];
|
|
3361
|
+
if (!a) return;
|
|
3362
|
+
const x = (m = a.properties) == null ? void 0 : m._idx;
|
|
3363
|
+
typeof x == "number" && d(x), e.getCanvas().style.cursor = "pointer";
|
|
3364
|
+
}, b = () => {
|
|
3365
|
+
e.getCanvas().style.cursor = Ge(n.getState().editingMode);
|
|
3366
|
+
}, M = () => {
|
|
3367
|
+
d(null), b();
|
|
3368
|
+
}, A = ["elm-osm-trace-fill", "elm-osm-trace-line"];
|
|
3369
|
+
for (const E of A)
|
|
3370
|
+
e.on("click", E, p), e.on("mouseenter", E, f), e.on("mouseleave", E, M);
|
|
3371
|
+
return () => {
|
|
3372
|
+
for (const E of A)
|
|
3373
|
+
e.off("click", E, p), e.off("mouseenter", E, f), e.off("mouseleave", E, M);
|
|
3374
|
+
b();
|
|
3375
|
+
};
|
|
3376
|
+
}, [u, e, q, n]), K(() => {
|
|
3377
|
+
l !== "pick-shape" && D();
|
|
3378
|
+
}, [l, D]), u ? Ze(
|
|
3379
|
+
/* @__PURE__ */ X("div", { ref: k, "data-elm-portal": !0, "data-elm-theme": w, style: { ...g, position: "fixed", zIndex: 1e4 }, children: /* @__PURE__ */ X("div", { className: "bg-elm-surface/95 backdrop-blur-md border border-elm-border/80 text-elm-text-secondary shadow-elm rounded-elm overflow-hidden min-w-[180px] max-w-[280px] text-sm py-1", children: u.map((p, f) => /* @__PURE__ */ fe(
|
|
3380
|
+
"button",
|
|
3381
|
+
{
|
|
3382
|
+
onClick: () => q(p),
|
|
3383
|
+
onMouseEnter: () => d(f),
|
|
3384
|
+
onMouseLeave: () => d(null),
|
|
3385
|
+
className: `w-full text-left px-3 py-2 flex items-center gap-2 transition-colors ${v === f ? "bg-primary-50 dark:bg-white/5" : "hover:bg-(--elm-surface-hover,var(--color-gray-50)) dark:hover:bg-elm-surface-hover"}`,
|
|
3386
|
+
children: [
|
|
3387
|
+
/* @__PURE__ */ X(
|
|
3388
|
+
"span",
|
|
3389
|
+
{
|
|
3390
|
+
className: "w-2.5 h-2.5 rounded-full shrink-0",
|
|
3391
|
+
style: { background: at[f % at.length] }
|
|
3392
|
+
}
|
|
3393
|
+
),
|
|
3394
|
+
/* @__PURE__ */ fe("span", { className: "flex flex-col min-w-0", children: [
|
|
3395
|
+
/* @__PURE__ */ X("span", { className: "font-medium text-(--elm-text,var(--color-gray-800)) dark:text-(--elm-text,var(--color-gray-100)) truncate", children: p.name || `Unnamed ${p.type.toLowerCase()}` }),
|
|
3396
|
+
/* @__PURE__ */ X("span", { className: "text-xs text-(--elm-text-subtle,var(--color-gray-400))", children: p.type })
|
|
3397
|
+
] })
|
|
3398
|
+
]
|
|
3399
|
+
},
|
|
3400
|
+
"key" in p ? p.key : `${p.osmId}/${f}`
|
|
3401
|
+
)) }) }),
|
|
3402
|
+
document.body
|
|
3403
|
+
) : null;
|
|
3404
|
+
}
|
|
3405
|
+
const kn = "elm-features";
|
|
3406
|
+
function As(e) {
|
|
3407
|
+
br(e), Fr(e), ds(e), ps(e), vs(e), ls(e), Cs(e), to(e, Dn(e.getContainer())[400]);
|
|
3408
|
+
}
|
|
3409
|
+
function Ts(e) {
|
|
3410
|
+
Ms(e), as(e), Lr(e), _r(e), fs(e), hs(e), xs(e), e.hasImage("elm-snap-diamond") && e.removeImage("elm-snap-diamond");
|
|
3411
|
+
}
|
|
3412
|
+
function Ds(e, t) {
|
|
3413
|
+
let n, o = !1;
|
|
3414
|
+
const r = () => {
|
|
3415
|
+
if (o) return;
|
|
3416
|
+
const i = e.getSource(kn);
|
|
3417
|
+
if (!(i && i === n)) {
|
|
3418
|
+
o = !0;
|
|
3419
|
+
try {
|
|
3420
|
+
As(e);
|
|
3421
|
+
} catch {
|
|
3422
|
+
return;
|
|
3423
|
+
} finally {
|
|
3424
|
+
o = !1;
|
|
3425
|
+
}
|
|
3426
|
+
(!ar(e) || n && !i) && ur(e, e.getStyle()), n = e.getSource(kn), t();
|
|
3427
|
+
}
|
|
3428
|
+
};
|
|
3429
|
+
r();
|
|
3430
|
+
const s = ["styledata", "style.load", "load"];
|
|
3431
|
+
for (const i of s) e.on(i, r);
|
|
3432
|
+
return () => {
|
|
3433
|
+
for (const i of s) e.off(i, r);
|
|
3434
|
+
};
|
|
3435
|
+
}
|
|
3436
|
+
function Ks({ map: e }) {
|
|
3437
|
+
const { units: t } = ke(), n = { unit: t.length, display: t.display, precision: t.precision }, o = { unit: t.area, display: t.display, precision: t.precision }, r = (f) => {
|
|
3438
|
+
const { value: b, unit: M } = mt(f * 1e3, n);
|
|
3439
|
+
return `${b} ${M}`;
|
|
3440
|
+
}, s = (f) => {
|
|
3441
|
+
const { value: b, unit: M } = Ht(f, o);
|
|
3442
|
+
return `${b} ${M}`;
|
|
3443
|
+
}, i = W((f) => f.showMeasurements), l = W((f) => f.editingMode), u = W((f) => f.snappedCoord), c = W((f) => f.lineInProgress), v = W((f) => f.polygonInProgress), d = W((f) => f.circleCenter), g = W((f) => f.rectCorner), w = W((f) => f.freehandPoints), C = W((f) => f.freehandClosed), T = W((f) => f.routeWaypoints), F = oo(e, l, l !== "none"), [k, N] = le(null), P = u ?? F;
|
|
3444
|
+
K(() => {
|
|
3445
|
+
if (!P) {
|
|
3446
|
+
N(null);
|
|
3447
|
+
return;
|
|
3448
|
+
}
|
|
3449
|
+
N(e.project(P));
|
|
3450
|
+
const f = () => N(P ? e.project(P) : null);
|
|
3451
|
+
return e.on("move", f), e.on("zoom", f), () => {
|
|
3452
|
+
e.off("move", f), e.off("zoom", f);
|
|
3453
|
+
};
|
|
3454
|
+
}, [e, P == null ? void 0 : P[0], P == null ? void 0 : P[1]]);
|
|
3455
|
+
const _ = $(null), [D, q] = le({ w: 0, h: 0 });
|
|
3456
|
+
if (uo(() => {
|
|
3457
|
+
const f = _.current;
|
|
3458
|
+
f && (f.offsetWidth !== D.w || f.offsetHeight !== D.h) && q({ w: f.offsetWidth, h: f.offsetHeight });
|
|
3459
|
+
}), !i || l === "none" || !P || !k) return null;
|
|
3460
|
+
const p = [];
|
|
3461
|
+
try {
|
|
3462
|
+
if (l === "place-point")
|
|
3463
|
+
p.push({ label: "", value: `${P[1].toFixed(6)}, ${P[0].toFixed(6)}` });
|
|
3464
|
+
else if (l === "draw-line" || l === "slice-shape") {
|
|
3465
|
+
const f = [...c, P];
|
|
3466
|
+
if (f.length >= 2) {
|
|
3467
|
+
const b = We(f);
|
|
3468
|
+
p.push({ label: "Length", value: r(_e(b)) }), p.push({ label: "Segment length", value: r(Pe(f[f.length - 2], f[f.length - 1])) });
|
|
3469
|
+
}
|
|
3470
|
+
p.push({ label: "", value: `${P[1].toFixed(6)}, ${P[0].toFixed(6)}` });
|
|
3471
|
+
} else if (l === "draw-polygon" || l === "cut-hole") {
|
|
3472
|
+
const f = [...v, P];
|
|
3473
|
+
if (f.length >= 3) {
|
|
3474
|
+
const b = [...f, f[0]], M = ut([b]);
|
|
3475
|
+
p.push({ label: "Area", value: s(dt(M)) }), p.push({ label: "Perimeter", value: r(_e(M)) });
|
|
3476
|
+
const A = Bn(M);
|
|
3477
|
+
p.push({ label: "Height", value: r(Pe([A[0], A[1]], [A[0], A[3]])) }), p.push({ label: "Width", value: r(Pe([A[0], A[1]], [A[2], A[1]])) });
|
|
3478
|
+
} else f.length === 2 && p.push({ label: "Segment length", value: r(Pe(f[0], f[1])) });
|
|
3479
|
+
p.push({ label: "", value: `${P[1].toFixed(6)}, ${P[0].toFixed(6)}` });
|
|
3480
|
+
} else if (l === "draw-circle") {
|
|
3481
|
+
if (d) {
|
|
3482
|
+
const f = Pe(d, P);
|
|
3483
|
+
p.push({ label: "Radius", value: r(f) }), p.push({ label: "Area", value: s(Math.PI * (f * 1e3) * (f * 1e3)) });
|
|
3484
|
+
}
|
|
3485
|
+
p.push({ label: "", value: `${P[1].toFixed(6)}, ${P[0].toFixed(6)}` });
|
|
3486
|
+
} else if (l === "draw-rect") {
|
|
3487
|
+
if (g) {
|
|
3488
|
+
const f = Pe([g[0], g[1]], [P[0], g[1]]), b = Pe([g[0], g[1]], [g[0], P[1]]), M = f * b * 1e6;
|
|
3489
|
+
p.push({ label: "Area", value: s(M) }), p.push({ label: "Width", value: r(f) }), p.push({ label: "Height", value: r(b) });
|
|
3490
|
+
}
|
|
3491
|
+
p.push({ label: "", value: `${P[1].toFixed(6)}, ${P[0].toFixed(6)}` });
|
|
3492
|
+
} else if (l === "draw-route") {
|
|
3493
|
+
const f = [...T, P];
|
|
3494
|
+
f.length >= 2 && p.push({ label: "Straight distance", value: r(Pe(f[f.length - 2], f[f.length - 1])) }), p.push({ label: "", value: `${P[1].toFixed(6)}, ${P[0].toFixed(6)}` });
|
|
3495
|
+
} else if (l === "draw-freehand") {
|
|
3496
|
+
if (w.length >= 3 && C) {
|
|
3497
|
+
const f = [...w, w[0]], b = ut([f]);
|
|
3498
|
+
p.push({ label: "Area", value: s(dt(b)) }), p.push({ label: "Perimeter", value: r(_e(b)) });
|
|
3499
|
+
} else if (w.length >= 2) {
|
|
3500
|
+
const f = We(w);
|
|
3501
|
+
p.push({ label: "Length", value: r(_e(f)) });
|
|
3502
|
+
}
|
|
3503
|
+
p.push({ label: "", value: `${P[1].toFixed(6)}, ${P[0].toFixed(6)}` });
|
|
3504
|
+
}
|
|
3505
|
+
} catch {
|
|
3506
|
+
}
|
|
3507
|
+
return p.length === 0 ? null : Ze(
|
|
3508
|
+
/* @__PURE__ */ X(
|
|
3509
|
+
"div",
|
|
3510
|
+
{
|
|
3511
|
+
ref: _,
|
|
3512
|
+
className: "elm-measurement-tooltip",
|
|
3513
|
+
style: {
|
|
3514
|
+
position: "absolute",
|
|
3515
|
+
...Fn(k.x, k.y, D.w, D.h, {
|
|
3516
|
+
x: "after",
|
|
3517
|
+
y: "center",
|
|
3518
|
+
gapX: 20,
|
|
3519
|
+
bounds: { left: 0, top: 0, right: e.getContainer().clientWidth, bottom: e.getContainer().clientHeight }
|
|
3520
|
+
}),
|
|
3521
|
+
zIndex: 700,
|
|
3522
|
+
pointerEvents: "none",
|
|
3523
|
+
whiteSpace: "nowrap",
|
|
3524
|
+
// Light in both modes by default (an on-map label); follows the design tokens once set.
|
|
3525
|
+
background: "var(--elm-surface, white)",
|
|
3526
|
+
border: "1px solid var(--elm-border, rgb(229, 231, 235))",
|
|
3527
|
+
boxShadow: "var(--elm-shadow-control, 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1))",
|
|
3528
|
+
borderRadius: "calc(var(--elm-radius-control, 6px) + 2px)",
|
|
3529
|
+
padding: 12,
|
|
3530
|
+
fontSize: 12,
|
|
3531
|
+
color: "var(--elm-text-secondary, rgb(75, 85, 99))",
|
|
3532
|
+
fontFamily: "var(--elm-font, ui-sans-serif, system-ui, sans-serif)"
|
|
3533
|
+
},
|
|
3534
|
+
children: /* @__PURE__ */ X("div", { style: { display: "flex", flexDirection: "column", gap: 4, textAlign: "left" }, children: p.map((f, b) => /* @__PURE__ */ fe("div", { style: { display: "flex", gap: 8, alignItems: "center", lineHeight: 1.3 }, children: [
|
|
3535
|
+
f.label && /* @__PURE__ */ fe("span", { style: { fontWeight: 600, color: "var(--elm-text, rgb(17, 24, 39))" }, children: [
|
|
3536
|
+
f.label,
|
|
3537
|
+
":"
|
|
3538
|
+
] }),
|
|
3539
|
+
/* @__PURE__ */ X("span", { children: f.value })
|
|
3540
|
+
] }, b)) })
|
|
3541
|
+
}
|
|
3542
|
+
),
|
|
3543
|
+
e.getContainer()
|
|
3544
|
+
);
|
|
3545
|
+
}
|
|
3546
|
+
const Qt = Nt(null);
|
|
3547
|
+
function ci() {
|
|
3548
|
+
const e = pt(Qt);
|
|
3549
|
+
if (!e) throw new Error("useMapLibre must be used inside ElementEditorControls");
|
|
3550
|
+
return e;
|
|
3551
|
+
}
|
|
3552
|
+
const Ns = () => pt(Qt);
|
|
3553
|
+
function Bs({ map: e }) {
|
|
3554
|
+
const t = Wo();
|
|
3555
|
+
return K(() => {
|
|
3556
|
+
t({
|
|
3557
|
+
// MapController's public contract is `[lat, lng]` (Leaflet convention —
|
|
3558
|
+
// the UI package normalises to that). MapLibre natively uses `[lng, lat]`,
|
|
3559
|
+
// so we swap on the boundary. Search "Go" / LocateButton / ZoomIndicator
|
|
3560
|
+
// all pass [lat, lng]; flipping here restores correct flyTo targets.
|
|
3561
|
+
// `offset`, not `padding`: MapLibre keeps a camera padding for good.
|
|
3562
|
+
// Points land in the middle of the visible map (clear of the open
|
|
3563
|
+
// panels / docked inspector / table), not under them.
|
|
3564
|
+
flyTo: ([n, o], r) => e.flyTo({ center: [o, n], zoom: r, offset: cn(e.getContainer()) }),
|
|
3565
|
+
panTo: ([n, o]) => e.panTo([o, n], { offset: cn(e.getContainer()) }),
|
|
3566
|
+
fitBounds: (n) => {
|
|
3567
|
+
const o = Ao(n);
|
|
3568
|
+
o && e.fitBounds(
|
|
3569
|
+
[[o.minLng, o.minLat], [o.maxLng, o.maxLat]],
|
|
3570
|
+
{ padding: jt(e.getContainer()), maxZoom: 16 }
|
|
3571
|
+
);
|
|
3572
|
+
},
|
|
3573
|
+
getCenter: () => {
|
|
3574
|
+
const n = e.getCenter();
|
|
3575
|
+
return [n.lng, n.lat];
|
|
3576
|
+
},
|
|
3577
|
+
setZoom: (n) => {
|
|
3578
|
+
const o = Math.max(e.getMinZoom(), Math.min(e.getMaxZoom(), n));
|
|
3579
|
+
return e.setZoom(o), o;
|
|
3580
|
+
},
|
|
3581
|
+
getZoomBounds: () => ({ min: e.getMinZoom(), max: e.getMaxZoom() }),
|
|
3582
|
+
getMap: () => e
|
|
3583
|
+
});
|
|
3584
|
+
}, [e, t]), null;
|
|
3585
|
+
}
|
|
3586
|
+
const Os = In(
|
|
3587
|
+
function(t, n) {
|
|
3588
|
+
const { map: o, maxBounds: r } = t, { dataStore: s, uiStore: i } = Le(), l = Ho({
|
|
3589
|
+
initialData: t.initialData,
|
|
3590
|
+
schema: t.schema,
|
|
3591
|
+
layout: t.layout,
|
|
3592
|
+
readonly: t.readonly,
|
|
3593
|
+
tools: t.tools,
|
|
3594
|
+
maxFeatures: t.maxFeatures,
|
|
3595
|
+
engine: "maplibre",
|
|
3596
|
+
onChange: t.onChange,
|
|
3597
|
+
onSubmit: t.onSubmit,
|
|
3598
|
+
onValidationError: t.onValidationError,
|
|
3599
|
+
onFeatureAdd: t.onFeatureAdd,
|
|
3600
|
+
onFeatureUpdate: t.onFeatureUpdate,
|
|
3601
|
+
onFeatureDelete: t.onFeatureDelete,
|
|
3602
|
+
onSelectionChange: t.onSelectionChange,
|
|
3603
|
+
onFeatureSelect: t.onFeatureSelect,
|
|
3604
|
+
onZoomChange: t.onZoomChange,
|
|
3605
|
+
onToolChange: t.onToolChange
|
|
3606
|
+
});
|
|
3607
|
+
return fo(n, () => l, [l]), K(() => {
|
|
3608
|
+
}, [s, i, o]), Vo(o.getContainer()), Xo(o.getContainer()), Yo(o.getContainer()), K(() => {
|
|
3609
|
+
Go();
|
|
3610
|
+
}, []), K(() => {
|
|
3611
|
+
o.setMaxBounds(r ?? null);
|
|
3612
|
+
}, [o, r]), K(() => {
|
|
3613
|
+
const u = () => s.getState().setCurrentZoom(o.getZoom());
|
|
3614
|
+
return s.getState().setCurrentZoom(o.getZoom()), o.on("zoomend", u), () => {
|
|
3615
|
+
o.off("zoomend", u);
|
|
3616
|
+
};
|
|
3617
|
+
}, [o, s]), /* @__PURE__ */ fe(Qt.Provider, { value: o, children: [
|
|
3618
|
+
/* @__PURE__ */ fe(gr, { getFeatureStyle: t.getFeatureStyle, children: [
|
|
3619
|
+
/* @__PURE__ */ X(Bs, { map: o }),
|
|
3620
|
+
/* @__PURE__ */ X(ys, { map: o }),
|
|
3621
|
+
/* @__PURE__ */ X(Er, { map: o }),
|
|
3622
|
+
/* @__PURE__ */ X(us, { map: o }),
|
|
3623
|
+
/* @__PURE__ */ X(Rr, { map: o, routingApiKey: t.routingApiKey }),
|
|
3624
|
+
/* @__PURE__ */ X(Ar, { map: o }),
|
|
3625
|
+
/* @__PURE__ */ X(ms, { map: o }),
|
|
3626
|
+
/* @__PURE__ */ X(Es, { map: o }),
|
|
3627
|
+
/* @__PURE__ */ X(Ks, { map: o }),
|
|
3628
|
+
/* @__PURE__ */ X(_s, { map: o }),
|
|
3629
|
+
/* @__PURE__ */ X(gs, { map: o })
|
|
3630
|
+
] }),
|
|
3631
|
+
t.children
|
|
3632
|
+
] });
|
|
3633
|
+
}
|
|
3634
|
+
), li = In(
|
|
3635
|
+
function(t, n) {
|
|
3636
|
+
const [o, r] = le(() => t.map.isStyleLoaded()), [s, i] = le(0);
|
|
3637
|
+
K(() => Ds(t.map, () => {
|
|
3638
|
+
r(!0), i((v) => v + 1);
|
|
3639
|
+
}), [t.map]);
|
|
3640
|
+
const l = $(t.onReady);
|
|
3641
|
+
l.current = t.onReady;
|
|
3642
|
+
const u = $(null);
|
|
3643
|
+
if (K(() => {
|
|
3644
|
+
var v;
|
|
3645
|
+
!o || u.current === t.map || (u.current = t.map, (v = l.current) == null || v.call(l, t.map));
|
|
3646
|
+
}, [o, t.map]), K(() => () => {
|
|
3647
|
+
try {
|
|
3648
|
+
Ts(t.map);
|
|
3649
|
+
} catch {
|
|
3650
|
+
}
|
|
3651
|
+
}, [t.map]), !o) return null;
|
|
3652
|
+
const c = /* @__PURE__ */ X(jn.Provider, { value: s, children: /* @__PURE__ */ X(jo, { children: /* @__PURE__ */ X(Os, { ...t, ref: n }) }) });
|
|
3653
|
+
return t.onEvent || t.onError ? /* @__PURE__ */ X(zo, { onEvent: t.onEvent, onError: t.onError, children: c }) : c;
|
|
3654
|
+
}
|
|
3655
|
+
), $s = ["streets", "terrain", "light", "dark", "osm"], Ft = /* @__PURE__ */ new WeakMap();
|
|
3656
|
+
let js = 0;
|
|
3657
|
+
function je(e, t) {
|
|
3658
|
+
if (typeof e == "string") return e;
|
|
3659
|
+
const n = e.id ?? e.label ?? ("url" in e ? e.url : typeof e.style == "string" ? e.style : void 0);
|
|
3660
|
+
return n || (t >= 0 ? `custom-${t}` : (Ft.has(e) || Ft.set(e, `custom-anon-${++js}`), Ft.get(e)));
|
|
3661
|
+
}
|
|
3662
|
+
const io = () => import("./style-Di9c4u-c.js"), zs = () => Promise.all([io(), import("./catalog-gI-xABuu.js")]).then(([e, t]) => ({ ...e, ...t }));
|
|
3663
|
+
let yt = !1;
|
|
3664
|
+
const co = (e) => new Tt(
|
|
3665
|
+
"network",
|
|
3666
|
+
"basemap",
|
|
3667
|
+
`The basemap catalog could not be loaded (${e instanceof Error ? e.message : String(e)}). Reload the page to try again.`,
|
|
3668
|
+
{ cause: e }
|
|
3669
|
+
);
|
|
3670
|
+
function lo() {
|
|
3671
|
+
const e = Tn(), t = $(e);
|
|
3672
|
+
return t.current = e, ve((n) => {
|
|
3673
|
+
t.current ? t.current({ type: "error", code: n.code, source: "basemap", message: n.message, error: n }) : console.error(`[element-editor] ${n.message}`);
|
|
3674
|
+
}, []);
|
|
3675
|
+
}
|
|
3676
|
+
function Hs(e, t, n) {
|
|
3677
|
+
const { theme: o } = n, r = ke().network, s = $(r);
|
|
3678
|
+
s.current = r;
|
|
3679
|
+
const [i, l] = le(null), u = lo();
|
|
3680
|
+
K(() => {
|
|
3681
|
+
let g = !0;
|
|
3682
|
+
return io().then((w) => g && l(w), (w) => {
|
|
3683
|
+
g && !yt && (yt = !0, u(co(w)));
|
|
3684
|
+
}), () => {
|
|
3685
|
+
g = !1;
|
|
3686
|
+
};
|
|
3687
|
+
}, []);
|
|
3688
|
+
const c = (g) => {
|
|
3689
|
+
const w = (i == null ? void 0 : i.resolveBasemap(g, o)) ?? g;
|
|
3690
|
+
return je(w, -1);
|
|
3691
|
+
}, v = $(void 0), d = $(n.initialApplied ? { basemap: t, theme: o } : null);
|
|
3692
|
+
v.current === void 0 && (v.current = d.current ? "" : null), K(() => {
|
|
3693
|
+
if (!e || !i) return;
|
|
3694
|
+
const g = c(t);
|
|
3695
|
+
if (v.current === "" && (v.current = je(i.resolveBasemap(d.current.basemap, d.current.theme), -1)), v.current === g) return;
|
|
3696
|
+
let w = !1;
|
|
3697
|
+
const C = (D) => D instanceof Error ? D.message : String(D), T = i.resolveBasemap(t, o), F = typeof T == "object" && "style" in T && typeof T.style == "string", k = (D) => {
|
|
3698
|
+
N(), v.current = null, u(new Tt(ln(D.error), "basemap", `The basemap could not be loaded (${C(D.error)}).`, { cause: D.error }));
|
|
3699
|
+
}, N = () => {
|
|
3700
|
+
e.off("error", k), e.off("styledata", N);
|
|
3701
|
+
}, P = () => {
|
|
3702
|
+
w || !(e.isStyleLoaded() || e.getSource("elm-features")) || (w = !0, e.off("styledata", P), v.current = g, i.setBasemap(e, t, { theme: o, network: s.current }).then(() => {
|
|
3703
|
+
F && !_ && (e.on("error", k), e.once("styledata", N));
|
|
3704
|
+
}, (D) => {
|
|
3705
|
+
v.current = null, u(new Tt(ln(D), "basemap", `The basemap could not be switched (${C(D)}). The map keeps the previous one.`, { cause: D }));
|
|
3706
|
+
}));
|
|
3707
|
+
};
|
|
3708
|
+
let _ = !1;
|
|
3709
|
+
return e.on("styledata", P), P(), () => {
|
|
3710
|
+
w = !0, _ = !0, e.off("styledata", P), N();
|
|
3711
|
+
};
|
|
3712
|
+
}, [e, i, t, o]);
|
|
3713
|
+
}
|
|
3714
|
+
function ai(e) {
|
|
3715
|
+
const { basemaps: t, value: n, defaultValue: o = "auto", onChange: r, storageKey: s, initialApplied: i, size: l, tooltipSide: u } = e, c = Ns(), v = e.map ?? c, d = An(), [g, w] = le(null), C = lo();
|
|
3716
|
+
K(() => {
|
|
3717
|
+
let a = !0;
|
|
3718
|
+
return zs().then((x) => a && w(x), (x) => {
|
|
3719
|
+
a && !yt && (yt = !0, C(co(x)));
|
|
3720
|
+
}), () => {
|
|
3721
|
+
a = !1;
|
|
3722
|
+
};
|
|
3723
|
+
}, []);
|
|
3724
|
+
const T = ke(), F = Bt(() => t ?? ["auto", ...$s], [t]), k = F.map(je);
|
|
3725
|
+
(F.filter((a) => typeof a == "object" && !a.id && !a.label && !("url" in a) && typeof a.style != "string").length > 1 || new Set(k).size < k.length) && Rn("basemap-ids", "BasemapControl: give each custom basemap a unique `id` (two entries without one, or with the same id/label, cannot be told apart).");
|
|
3726
|
+
const [N] = le(() => {
|
|
3727
|
+
const a = s ? nr(s, T) : null;
|
|
3728
|
+
return a ? F.find((x, y) => je(x, y) === a) : void 0;
|
|
3729
|
+
}), [P, _] = le(N ?? o), [D, q] = le(n !== void 0 || e.defaultValue !== void 0 || N !== void 0), p = n ?? P, f = F.indexOf(p), b = f >= 0 ? k[f] : je(p, -1);
|
|
3730
|
+
Hs(D || n !== void 0 ? v : null, p, {
|
|
3731
|
+
theme: d,
|
|
3732
|
+
initialApplied: D && i && b === je(o, F.indexOf(o))
|
|
3733
|
+
});
|
|
3734
|
+
const M = ve((a) => {
|
|
3735
|
+
const x = k.indexOf(a);
|
|
3736
|
+
if (x < 0) return;
|
|
3737
|
+
const y = F[x];
|
|
3738
|
+
q(!0), n === void 0 && _(y), s && (typeof y == "string" || y.id) && or(s, a, T), r == null || r(y);
|
|
3739
|
+
}, [k, F, n, s, r, T]);
|
|
3740
|
+
if (!g) return null;
|
|
3741
|
+
const A = (a) => {
|
|
3742
|
+
var x;
|
|
3743
|
+
return (x = g.BASEMAPS.find((y) => y.id === a)) == null ? void 0 : x.thumbnail;
|
|
3744
|
+
}, E = F.map((a, x) => {
|
|
3745
|
+
const y = k[x], m = typeof a == "string" ? g.BASEMAPS.find((R) => R.id === a) : void 0;
|
|
3746
|
+
return {
|
|
3747
|
+
id: y,
|
|
3748
|
+
label: a === "auto" ? "Auto" : (m == null ? void 0 : m.label) ?? (typeof a == "object" && a.label || y),
|
|
3749
|
+
// Auto shows both looks it switches between (light → streets, dark → dark).
|
|
3750
|
+
thumbnail: a === "auto" ? [A("streets"), A("dark")].every(Boolean) ? [A("streets"), A("dark")] : void 0 : typeof a == "string" ? A(a) : a.thumbnail
|
|
3751
|
+
};
|
|
3752
|
+
});
|
|
3753
|
+
return /* @__PURE__ */ X(Uo, { options: E, value: b, onChange: M, size: l, tooltipSide: u });
|
|
3754
|
+
}
|
|
3755
|
+
export {
|
|
3756
|
+
fi as ActiveDrawingToolbar,
|
|
3757
|
+
ai as BasemapControl,
|
|
3758
|
+
ys as BoundaryLayer,
|
|
3759
|
+
rs as BoxSelectHandler,
|
|
3760
|
+
Rr as DrawingLayer,
|
|
3761
|
+
Ar as DrawingPreviewLayer,
|
|
3762
|
+
gi as EditingToolbar,
|
|
3763
|
+
li as ElementEditorControls,
|
|
3764
|
+
Ci as ElementEditorError,
|
|
3765
|
+
yi as ElementEditorUIProvider,
|
|
3766
|
+
us as FeatureInteractionLayer,
|
|
3767
|
+
Er as FeatureLayer,
|
|
3768
|
+
gr as FeatureStyleProvider,
|
|
3769
|
+
ii as FitBounds,
|
|
3770
|
+
pi as FloatingToolbar,
|
|
3771
|
+
hi as GeoStoreProvider,
|
|
3772
|
+
ms as GeometryProcessingPreview,
|
|
3773
|
+
mi as MapControllerProvider,
|
|
3774
|
+
Es as MeasurePreviewLayer,
|
|
3775
|
+
Ks as MeasurementTooltip,
|
|
3776
|
+
_s as OsmTraceHandler,
|
|
3777
|
+
gs as SnapController,
|
|
3778
|
+
vi as StoreContext,
|
|
3779
|
+
es as TransformControls,
|
|
3780
|
+
$r as VertexEditor,
|
|
3781
|
+
Vn as findSnapPoint,
|
|
3782
|
+
Dt as snapToAngle,
|
|
3783
|
+
Hs as useBasemap,
|
|
3784
|
+
xi as useDataStore,
|
|
3785
|
+
yr as useFeatureStyle,
|
|
3786
|
+
wi as useGeoStore,
|
|
3787
|
+
Si as useKeyboardShortcuts,
|
|
3788
|
+
bi as useMapController,
|
|
3789
|
+
ci as useMapLibre,
|
|
3790
|
+
Li as useSetMapController,
|
|
3791
|
+
Ei as useUIStore
|
|
3792
|
+
};
|