@watergis/maplibre-gl-terradraw 0.0.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.
@@ -0,0 +1,2872 @@
1
+ var de = Object.defineProperty;
2
+ var ce = (s, t, e) => t in s ? de(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var k = (s, t, e) => ce(s, typeof t != "symbol" ? t + "" : t, e);
4
+ function f() {
5
+ return f = Object.assign ? Object.assign.bind() : function(s) {
6
+ for (var t = 1; t < arguments.length; t++) {
7
+ var e = arguments[t];
8
+ for (var i in e) Object.prototype.hasOwnProperty.call(e, i) && (s[i] = e[i]);
9
+ }
10
+ return s;
11
+ }, f.apply(this, arguments);
12
+ }
13
+ function b(s, t = 9) {
14
+ const e = Math.pow(10, t);
15
+ return Math.round(s * e) / e;
16
+ }
17
+ const I = (s, t) => {
18
+ const { x: e, y: i } = s, { x: o, y: n } = t, r = o - e, a = n - i;
19
+ return Math.sqrt(a * a + r * r);
20
+ };
21
+ class N {
22
+ constructor({ name: t, callback: e, unregister: i, register: o }) {
23
+ this.name = void 0, this.callback = void 0, this.registered = !1, this.register = void 0, this.unregister = void 0, this.name = t, this.register = () => {
24
+ this.registered || (this.registered = !0, o(e));
25
+ }, this.unregister = () => {
26
+ this.register && (this.registered = !1, i(e));
27
+ }, this.callback = e;
28
+ }
29
+ }
30
+ class Jt {
31
+ constructor(t) {
32
+ this._minPixelDragDistance = void 0, this._minPixelDragDistanceDrawing = void 0, this._minPixelDragDistanceSelecting = void 0, this._lastDrawEvent = void 0, this._coordinatePrecision = void 0, this._heldKeys = /* @__PURE__ */ new Set(), this._listeners = [], this._dragState = "not-dragging", this._currentModeCallbacks = void 0, this._minPixelDragDistance = typeof t.minPixelDragDistance == "number" ? t.minPixelDragDistance : 1, this._minPixelDragDistanceSelecting = typeof t.minPixelDragDistanceSelecting == "number" ? t.minPixelDragDistanceSelecting : 1, this._minPixelDragDistanceDrawing = typeof t.minPixelDragDistanceDrawing == "number" ? t.minPixelDragDistanceDrawing : 8, this._coordinatePrecision = typeof t.coordinatePrecision == "number" ? t.coordinatePrecision : 9;
33
+ }
34
+ getButton(t) {
35
+ return t.button === -1 ? "neither" : t.button === 0 ? "left" : t.button === 1 ? "middle" : t.button === 2 ? "right" : "neither";
36
+ }
37
+ getMapElementXYPosition(t) {
38
+ const e = this.getMapEventElement(), { left: i, top: o } = e.getBoundingClientRect();
39
+ return { containerX: t.clientX - i, containerY: t.clientY - o };
40
+ }
41
+ getDrawEventFromEvent(t) {
42
+ const e = this.getLngLatFromEvent(t);
43
+ if (!e) return null;
44
+ const { lng: i, lat: o } = e, { containerX: n, containerY: r } = this.getMapElementXYPosition(t), a = this.getButton(t), l = Array.from(this._heldKeys);
45
+ return { lng: b(i, this._coordinatePrecision), lat: b(o, this._coordinatePrecision), containerX: n, containerY: r, button: a, heldKeys: l };
46
+ }
47
+ register(t) {
48
+ this._currentModeCallbacks = t, this._listeners = this.getAdapterListeners(), this._listeners.forEach((e) => {
49
+ e.register();
50
+ });
51
+ }
52
+ getCoordinatePrecision() {
53
+ return this._coordinatePrecision;
54
+ }
55
+ getAdapterListeners() {
56
+ return [new N({ name: "pointerdown", callback: (t) => {
57
+ if (!this._currentModeCallbacks || !t.isPrimary) return;
58
+ const e = this.getDrawEventFromEvent(t);
59
+ e && (this._dragState = "pre-dragging", this._lastDrawEvent = e);
60
+ }, register: (t) => {
61
+ this.getMapEventElement().addEventListener("pointerdown", t);
62
+ }, unregister: (t) => {
63
+ this.getMapEventElement().removeEventListener("pointerdown", t);
64
+ } }), new N({ name: "pointermove", callback: (t) => {
65
+ if (!this._currentModeCallbacks || !t.isPrimary) return;
66
+ t.preventDefault();
67
+ const e = this.getDrawEventFromEvent(t);
68
+ if (e) if (this._dragState === "not-dragging") this._currentModeCallbacks.onMouseMove(e), this._lastDrawEvent = e;
69
+ else if (this._dragState === "pre-dragging") {
70
+ if (!this._lastDrawEvent) return;
71
+ const i = { x: this._lastDrawEvent.containerX, y: this._lastDrawEvent.containerY }, o = { x: e.containerX, y: e.containerY }, n = this._currentModeCallbacks.getState(), r = I(i, o);
72
+ let a = !1;
73
+ if (a = n === "drawing" ? r < this._minPixelDragDistanceDrawing : n === "selecting" ? r < this._minPixelDragDistanceSelecting : r < this._minPixelDragDistance, a) return;
74
+ this._dragState = "dragging", this._currentModeCallbacks.onDragStart(e, (l) => {
75
+ this.setDraggability.bind(this)(l);
76
+ });
77
+ } else this._dragState === "dragging" && this._currentModeCallbacks.onDrag(e, (i) => {
78
+ this.setDraggability.bind(this)(i);
79
+ });
80
+ }, register: (t) => {
81
+ this.getMapEventElement().addEventListener("pointermove", t);
82
+ }, unregister: (t) => {
83
+ this.getMapEventElement().removeEventListener("pointermove", t);
84
+ } }), new N({ name: "contextmenu", callback: (t) => {
85
+ this._currentModeCallbacks && t.preventDefault();
86
+ }, register: (t) => {
87
+ this.getMapEventElement().addEventListener("contextmenu", t);
88
+ }, unregister: (t) => {
89
+ this.getMapEventElement().removeEventListener("contextmenu", t);
90
+ } }), new N({ name: "pointerup", callback: (t) => {
91
+ if (!this._currentModeCallbacks || t.target !== this.getMapEventElement() || !t.isPrimary) return;
92
+ const e = this.getDrawEventFromEvent(t);
93
+ e && (this._dragState === "dragging" ? this._currentModeCallbacks.onDragEnd(e, (i) => {
94
+ this.setDraggability.bind(this)(i);
95
+ }) : this._dragState !== "not-dragging" && this._dragState !== "pre-dragging" || this._currentModeCallbacks.onClick(e), this._dragState = "not-dragging", this.setDraggability(!0));
96
+ }, register: (t) => {
97
+ this.getMapEventElement().addEventListener("pointerup", t);
98
+ }, unregister: (t) => {
99
+ this.getMapEventElement().removeEventListener("pointerup", t);
100
+ } }), new N({ name: "keyup", callback: (t) => {
101
+ this._currentModeCallbacks && (this._heldKeys.delete(t.key), this._currentModeCallbacks.onKeyUp({ key: t.key, heldKeys: Array.from(this._heldKeys), preventDefault: () => t.preventDefault() }));
102
+ }, register: (t) => {
103
+ this.getMapEventElement().addEventListener("keyup", t);
104
+ }, unregister: (t) => {
105
+ this.getMapEventElement().removeEventListener("keyup", t);
106
+ } }), new N({ name: "keydown", callback: (t) => {
107
+ this._currentModeCallbacks && (this._heldKeys.add(t.key), this._currentModeCallbacks.onKeyDown({ key: t.key, heldKeys: Array.from(this._heldKeys), preventDefault: () => t.preventDefault() }));
108
+ }, register: (t) => {
109
+ this.getMapEventElement().addEventListener("keydown", t);
110
+ }, unregister: (t) => {
111
+ this.getMapEventElement().removeEventListener("keydown", t);
112
+ } })];
113
+ }
114
+ unregister() {
115
+ this._listeners.forEach((t) => {
116
+ t.unregister();
117
+ }), this.clear();
118
+ }
119
+ }
120
+ class ue extends Jt {
121
+ constructor(t) {
122
+ super(t), this._nextRender = void 0, this._map = void 0, this._container = void 0, this._rendered = !1, this.changedIds = { deletion: !1, points: !1, linestrings: !1, polygons: !1, styling: !1 }, this._map = t.map, this._container = this._map.getContainer();
123
+ }
124
+ clearLayers() {
125
+ this._rendered && (["point", "linestring", "polygon"].forEach((t) => {
126
+ const e = `td-${t.toLowerCase()}`;
127
+ this._map.removeLayer(e), t === "polygon" && this._map.removeLayer(e + "-outline"), this._map.removeSource(e);
128
+ }), this._rendered = !1, this._nextRender && (cancelAnimationFrame(this._nextRender), this._nextRender = void 0));
129
+ }
130
+ _addGeoJSONSource(t, e) {
131
+ this._map.addSource(t, { type: "geojson", data: { type: "FeatureCollection", features: e }, tolerance: 0 });
132
+ }
133
+ _addFillLayer(t) {
134
+ return this._map.addLayer({ id: t, source: t, type: "fill", paint: { "fill-color": ["get", "polygonFillColor"], "fill-opacity": ["get", "polygonFillOpacity"] } });
135
+ }
136
+ _addFillOutlineLayer(t, e) {
137
+ const i = this._map.addLayer({ id: t + "-outline", source: t, type: "line", paint: { "line-width": ["get", "polygonOutlineWidth"], "line-color": ["get", "polygonOutlineColor"] } });
138
+ return e && this._map.moveLayer(t, e), i;
139
+ }
140
+ _addLineLayer(t, e) {
141
+ const i = this._map.addLayer({ id: t, source: t, type: "line", paint: { "line-width": ["get", "lineStringWidth"], "line-color": ["get", "lineStringColor"] } });
142
+ return e && this._map.moveLayer(t, e), i;
143
+ }
144
+ _addPointLayer(t, e) {
145
+ const i = this._map.addLayer({ id: t, source: t, type: "circle", paint: { "circle-stroke-color": ["get", "pointOutlineColor"], "circle-stroke-width": ["get", "pointOutlineWidth"], "circle-radius": ["get", "pointWidth"], "circle-color": ["get", "pointColor"] } });
146
+ return e && this._map.moveLayer(t, e), i;
147
+ }
148
+ _addLayer(t, e, i) {
149
+ e === "Point" && this._addPointLayer(t, i), e === "LineString" && this._addLineLayer(t, i), e === "Polygon" && (this._addFillLayer(t), this._addFillOutlineLayer(t, i));
150
+ }
151
+ _addGeoJSONLayer(t, e) {
152
+ const i = `td-${t.toLowerCase()}`;
153
+ return this._addGeoJSONSource(i, e), this._addLayer(i, t), i;
154
+ }
155
+ _setGeoJSONLayerData(t, e) {
156
+ const i = `td-${t.toLowerCase()}`;
157
+ return this._map.getSource(i).setData({ type: "FeatureCollection", features: e }), i;
158
+ }
159
+ getEmptyGeometries() {
160
+ return { points: [], linestrings: [], polygons: [] };
161
+ }
162
+ updateChangedIds(t) {
163
+ [...t.updated, ...t.created].forEach((e) => {
164
+ e.geometry.type === "Point" ? this.changedIds.points = !0 : e.geometry.type === "LineString" ? this.changedIds.linestrings = !0 : e.geometry.type === "Polygon" && (this.changedIds.polygons = !0);
165
+ }), t.deletedIds.length > 0 && (this.changedIds.deletion = !0), t.created.length === 0 && t.updated.length === 0 && t.deletedIds.length === 0 && (this.changedIds.styling = !0);
166
+ }
167
+ getLngLatFromEvent(t) {
168
+ const { left: e, top: i } = this._container.getBoundingClientRect();
169
+ return this.unproject(t.clientX - e, t.clientY - i);
170
+ }
171
+ getMapEventElement() {
172
+ return this._map.getCanvas();
173
+ }
174
+ setDraggability(t) {
175
+ t ? (this._map.dragRotate.enable(), this._map.dragPan.enable()) : (this._map.dragRotate.disable(), this._map.dragPan.disable());
176
+ }
177
+ project(t, e) {
178
+ const { x: i, y: o } = this._map.project({ lng: t, lat: e });
179
+ return { x: i, y: o };
180
+ }
181
+ unproject(t, e) {
182
+ const { lng: i, lat: o } = this._map.unproject({ x: t, y: e });
183
+ return { lng: i, lat: o };
184
+ }
185
+ setCursor(t) {
186
+ const e = this._map.getCanvas();
187
+ t === "unset" ? e.style.removeProperty("cursor") : e.style.cursor = t;
188
+ }
189
+ setDoubleClickToZoom(t) {
190
+ t ? this._map.doubleClickZoom.enable() : this._map.doubleClickZoom.disable();
191
+ }
192
+ render(t, e) {
193
+ this.updateChangedIds(t), this._nextRender && cancelAnimationFrame(this._nextRender), this._nextRender = requestAnimationFrame(() => {
194
+ const i = [...t.created, ...t.updated, ...t.unchanged], o = this.getEmptyGeometries();
195
+ for (let l = 0; l < i.length; l++) {
196
+ const d = i[l];
197
+ Object.keys(e).forEach((h) => {
198
+ const { properties: c } = d;
199
+ if (c.mode !== h) return;
200
+ const u = e[h](d);
201
+ d.geometry.type === "Point" ? (c.pointColor = u.pointColor, c.pointOutlineColor = u.pointOutlineColor, c.pointOutlineWidth = u.pointOutlineWidth, c.pointWidth = u.pointWidth, o.points.push(d)) : d.geometry.type === "LineString" ? (c.lineStringColor = u.lineStringColor, c.lineStringWidth = u.lineStringWidth, o.linestrings.push(d)) : d.geometry.type === "Polygon" && (c.polygonFillColor = u.polygonFillColor, c.polygonFillOpacity = u.polygonFillOpacity, c.polygonOutlineColor = u.polygonOutlineColor, c.polygonOutlineWidth = u.polygonOutlineWidth, o.polygons.push(d));
202
+ });
203
+ }
204
+ const { points: n, linestrings: r, polygons: a } = o;
205
+ if (this._rendered) {
206
+ const l = this.changedIds.deletion || this.changedIds.styling, d = l || this.changedIds.linestrings, h = l || this.changedIds.polygons;
207
+ let c;
208
+ (l || this.changedIds.points) && (c = this._setGeoJSONLayerData("Point", n)), d && this._setGeoJSONLayerData("LineString", r), h && this._setGeoJSONLayerData("Polygon", a), c && this._map.moveLayer(c);
209
+ } else {
210
+ const l = this._addGeoJSONLayer("Point", n);
211
+ this._addGeoJSONLayer("LineString", r), this._addGeoJSONLayer("Polygon", a), this._rendered = !0, l && this._map.moveLayer(l);
212
+ }
213
+ this.changedIds = { points: !1, linestrings: !1, polygons: !1, deletion: !1, styling: !1 };
214
+ });
215
+ }
216
+ clear() {
217
+ this._currentModeCallbacks && (this._currentModeCallbacks.onClear(), this.clearLayers());
218
+ }
219
+ getCoordinatePrecision() {
220
+ return super.getCoordinatePrecision();
221
+ }
222
+ unregister() {
223
+ return super.unregister();
224
+ }
225
+ register(t) {
226
+ super.register(t), this._currentModeCallbacks && this._currentModeCallbacks.onReady && this._currentModeCallbacks.onReady();
227
+ }
228
+ }
229
+ class ge extends Jt {
230
+ constructor(t) {
231
+ super(t), this.mapboxglAdapter = void 0, this.mapboxglAdapter = new ue(t);
232
+ }
233
+ register(t) {
234
+ this.mapboxglAdapter.register(t);
235
+ }
236
+ unregister() {
237
+ this.mapboxglAdapter.unregister();
238
+ }
239
+ getCoordinatePrecision() {
240
+ return this.mapboxglAdapter.getCoordinatePrecision();
241
+ }
242
+ getLngLatFromEvent(t) {
243
+ return this.mapboxglAdapter.getLngLatFromEvent(t);
244
+ }
245
+ getMapEventElement() {
246
+ return this.mapboxglAdapter.getMapEventElement();
247
+ }
248
+ setDraggability(t) {
249
+ this.mapboxglAdapter.setDraggability(t);
250
+ }
251
+ project(t, e) {
252
+ return this.mapboxglAdapter.project(t, e);
253
+ }
254
+ unproject(t, e) {
255
+ return this.mapboxglAdapter.unproject(t, e);
256
+ }
257
+ setCursor(t) {
258
+ this.mapboxglAdapter.setCursor(t);
259
+ }
260
+ setDoubleClickToZoom(t) {
261
+ this.mapboxglAdapter.setDoubleClickToZoom(t);
262
+ }
263
+ render(t, e) {
264
+ this.mapboxglAdapter.render(t, e);
265
+ }
266
+ clear() {
267
+ this.mapboxglAdapter.clear();
268
+ }
269
+ }
270
+ let pe = 0;
271
+ const L = typeof navigator < "u" && navigator.userAgent !== void 0 ? navigator.userAgent.toLowerCase() : "";
272
+ L.includes("firefox"), L.includes("safari") && !L.includes("chrom") && (L.includes("version/15.4") || /cpu (os|iphone os) 15_4 like mac os x/.test(L)), L.includes("webkit") && L.includes("edge"), L.includes("macintosh");
273
+ typeof WorkerGlobalScope < "u" && typeof OffscreenCanvas < "u" && self instanceof WorkerGlobalScope;
274
+ (function() {
275
+ let s = !1;
276
+ try {
277
+ const t = Object.defineProperty({}, "passive", { get: function() {
278
+ s = !0;
279
+ } });
280
+ window.addEventListener("_", null, t), window.removeEventListener("_", null, t);
281
+ } catch {
282
+ }
283
+ })();
284
+ var ye = class {
285
+ constructor() {
286
+ this.disposed = !1;
287
+ }
288
+ dispose() {
289
+ this.disposed || (this.disposed = !0, this.disposeInternal());
290
+ }
291
+ disposeInternal() {
292
+ }
293
+ }, qt = class {
294
+ constructor(s) {
295
+ this.type = s, this.target = null;
296
+ }
297
+ preventDefault() {
298
+ this.defaultPrevented = !0;
299
+ }
300
+ stopPropagation() {
301
+ this.propagationStopped = !0;
302
+ }
303
+ };
304
+ function wt() {
305
+ }
306
+ function Zt(s) {
307
+ for (const t in s) delete s[t];
308
+ }
309
+ var me = class extends ye {
310
+ constructor(s) {
311
+ super(), this.eventTarget_ = s, this.pendingRemovals_ = null, this.dispatching_ = null, this.listeners_ = null;
312
+ }
313
+ addEventListener(s, t) {
314
+ if (!s || !t) return;
315
+ const e = this.listeners_ || (this.listeners_ = {}), i = e[s] || (e[s] = []);
316
+ i.includes(t) || i.push(t);
317
+ }
318
+ dispatchEvent(s) {
319
+ const t = typeof s == "string", e = t ? s : s.type, i = this.listeners_ && this.listeners_[e];
320
+ if (!i) return;
321
+ const o = t ? new qt(s) : s;
322
+ o.target || (o.target = this.eventTarget_ || this);
323
+ const n = this.dispatching_ || (this.dispatching_ = {}), r = this.pendingRemovals_ || (this.pendingRemovals_ = {});
324
+ let a;
325
+ e in n || (n[e] = 0, r[e] = 0), ++n[e];
326
+ for (let l = 0, d = i.length; l < d; ++l) if (a = "handleEvent" in i[l] ? i[l].handleEvent(o) : i[l].call(this, o), a === !1 || o.propagationStopped) {
327
+ a = !1;
328
+ break;
329
+ }
330
+ if (--n[e] == 0) {
331
+ let l = r[e];
332
+ for (delete r[e]; l--; ) this.removeEventListener(e, wt);
333
+ delete n[e];
334
+ }
335
+ return a;
336
+ }
337
+ disposeInternal() {
338
+ this.listeners_ && Zt(this.listeners_);
339
+ }
340
+ getListeners(s) {
341
+ return this.listeners_ && this.listeners_[s] || void 0;
342
+ }
343
+ hasListener(s) {
344
+ return !!this.listeners_ && (s ? s in this.listeners_ : Object.keys(this.listeners_).length > 0);
345
+ }
346
+ removeEventListener(s, t) {
347
+ if (!this.listeners_) return;
348
+ const e = this.listeners_[s];
349
+ if (!e) return;
350
+ const i = e.indexOf(t);
351
+ i !== -1 && (this.pendingRemovals_ && s in this.pendingRemovals_ ? (e[i] = wt, ++this.pendingRemovals_[s]) : (e.splice(i, 1), e.length === 0 && delete this.listeners_[s]));
352
+ }
353
+ }, fe = "change";
354
+ function Ct(s, t, e, i, o) {
355
+ if (o) {
356
+ const r = e;
357
+ e = function() {
358
+ s.removeEventListener(t, e), r.apply(this, arguments);
359
+ };
360
+ }
361
+ const n = { target: s, type: t, listener: e };
362
+ return s.addEventListener(t, e), n;
363
+ }
364
+ function St(s, t, e, i) {
365
+ return Ct(s, t, e, i, !0);
366
+ }
367
+ function It(s) {
368
+ s && s.target && (s.target.removeEventListener(s.type, s.listener), Zt(s));
369
+ }
370
+ var ve = class extends me {
371
+ constructor() {
372
+ super(), this.on = this.onInternal, this.once = this.onceInternal, this.un = this.unInternal, this.revision_ = 0;
373
+ }
374
+ changed() {
375
+ ++this.revision_, this.dispatchEvent(fe);
376
+ }
377
+ getRevision() {
378
+ return this.revision_;
379
+ }
380
+ onInternal(s, t) {
381
+ if (Array.isArray(s)) {
382
+ const e = s.length, i = new Array(e);
383
+ for (let o = 0; o < e; ++o) i[o] = Ct(this, s[o], t);
384
+ return i;
385
+ }
386
+ return Ct(this, s, t);
387
+ }
388
+ onceInternal(s, t) {
389
+ let e;
390
+ if (Array.isArray(s)) {
391
+ const i = s.length;
392
+ e = new Array(i);
393
+ for (let o = 0; o < i; ++o) e[o] = St(this, s[o], t);
394
+ } else e = St(this, s, t);
395
+ return t.ol_key = e, e;
396
+ }
397
+ unInternal(s, t) {
398
+ const e = t.ol_key;
399
+ if (e) (function(i) {
400
+ if (Array.isArray(i)) for (let o = 0, n = i.length; o < n; ++o) It(i[o]);
401
+ else It(i);
402
+ })(e);
403
+ else if (Array.isArray(s)) for (let i = 0, o = s.length; i < o; ++i) this.removeEventListener(s[i], t);
404
+ else this.removeEventListener(s, t);
405
+ }
406
+ };
407
+ class Dt extends qt {
408
+ constructor(t, e, i) {
409
+ super(t), this.key = e, this.oldValue = i;
410
+ }
411
+ }
412
+ new class extends ve {
413
+ constructor(s) {
414
+ super(), this.ol_uid || (this.ol_uid = String(++pe)), this.values_ = null, s !== void 0 && this.setProperties(s);
415
+ }
416
+ get(s) {
417
+ let t;
418
+ return this.values_ && this.values_.hasOwnProperty(s) && (t = this.values_[s]), t;
419
+ }
420
+ getKeys() {
421
+ return this.values_ && Object.keys(this.values_) || [];
422
+ }
423
+ getProperties() {
424
+ return this.values_ && Object.assign({}, this.values_) || {};
425
+ }
426
+ getPropertiesInternal() {
427
+ return this.values_;
428
+ }
429
+ hasProperties() {
430
+ return !!this.values_;
431
+ }
432
+ notify(s, t) {
433
+ let e;
434
+ e = `change:${s}`, this.hasListener(e) && this.dispatchEvent(new Dt(e, s, t)), e = "propertychange", this.hasListener(e) && this.dispatchEvent(new Dt(e, s, t));
435
+ }
436
+ addChangeListener(s, t) {
437
+ this.addEventListener(`change:${s}`, t);
438
+ }
439
+ removeChangeListener(s, t) {
440
+ this.removeEventListener(`change:${s}`, t);
441
+ }
442
+ set(s, t, e) {
443
+ const i = this.values_ || (this.values_ = {});
444
+ if (e) i[s] = t;
445
+ else {
446
+ const o = i[s];
447
+ i[s] = t, o !== t && this.notify(s, o);
448
+ }
449
+ }
450
+ setProperties(s, t) {
451
+ for (const e in s) this.set(e, s[e], t);
452
+ }
453
+ applyProperties(s) {
454
+ s.values_ && Object.assign(this.values_ || (this.values_ = {}), s.values_);
455
+ }
456
+ unset(s, t) {
457
+ if (this.values_ && s in this.values_) {
458
+ const e = this.values_[s];
459
+ delete this.values_[s], function(i) {
460
+ let o;
461
+ for (o in i) return !1;
462
+ return !o;
463
+ }(this.values_) && (this.values_ = null), t || this.notify(s, e);
464
+ }
465
+ }
466
+ }();
467
+ const Ce = { radians: 6370997 / (2 * Math.PI), degrees: 2 * Math.PI * 6370997 / 360, ft: 0.3048, m: 1, "us-ft": 1200 / 3937 };
468
+ var Qt = class {
469
+ constructor(s) {
470
+ this.code_ = s.code, this.units_ = s.units, this.extent_ = s.extent !== void 0 ? s.extent : null, this.worldExtent_ = s.worldExtent !== void 0 ? s.worldExtent : null, this.axisOrientation_ = s.axisOrientation !== void 0 ? s.axisOrientation : "enu", this.global_ = s.global !== void 0 && s.global, this.canWrapX_ = !(!this.global_ || !this.extent_), this.getPointResolutionFunc_ = s.getPointResolution, this.defaultTileGrid_ = null, this.metersPerUnit_ = s.metersPerUnit;
471
+ }
472
+ canWrapX() {
473
+ return this.canWrapX_;
474
+ }
475
+ getCode() {
476
+ return this.code_;
477
+ }
478
+ getExtent() {
479
+ return this.extent_;
480
+ }
481
+ getUnits() {
482
+ return this.units_;
483
+ }
484
+ getMetersPerUnit() {
485
+ return this.metersPerUnit_ || Ce[this.units_];
486
+ }
487
+ getWorldExtent() {
488
+ return this.worldExtent_;
489
+ }
490
+ getAxisOrientation() {
491
+ return this.axisOrientation_;
492
+ }
493
+ isGlobal() {
494
+ return this.global_;
495
+ }
496
+ setGlobal(s) {
497
+ this.global_ = s, this.canWrapX_ = !(!s || !this.extent_);
498
+ }
499
+ getDefaultTileGrid() {
500
+ return this.defaultTileGrid_;
501
+ }
502
+ setDefaultTileGrid(s) {
503
+ this.defaultTileGrid_ = s;
504
+ }
505
+ setExtent(s) {
506
+ this.extent_ = s, this.canWrapX_ = !(!this.global_ || !s);
507
+ }
508
+ setWorldExtent(s) {
509
+ this.worldExtent_ = s;
510
+ }
511
+ setGetPointResolution(s) {
512
+ this.getPointResolutionFunc_ = s;
513
+ }
514
+ getPointResolutionFunc() {
515
+ return this.getPointResolutionFunc_;
516
+ }
517
+ };
518
+ const J = 6378137, T = Math.PI * J, xe = [-T, -T, T, T], Pe = [-180, -85, 180, 85], et = J * Math.log(Math.tan(Math.PI / 2));
519
+ class A extends Qt {
520
+ constructor(t) {
521
+ super({ code: t, units: "m", extent: xe, global: !0, worldExtent: Pe, getPointResolution: function(e, i) {
522
+ return e / Math.cosh(i[1] / J);
523
+ } });
524
+ }
525
+ }
526
+ const Ft = [new A("EPSG:3857"), new A("EPSG:102100"), new A("EPSG:102113"), new A("EPSG:900913"), new A("http://www.opengis.net/def/crs/EPSG/0/3857"), new A("http://www.opengis.net/gml/srs/epsg.xml#3857")], kt = [-180, -90, 180, 90], Me = 6378137 * Math.PI / 180;
527
+ class G extends Qt {
528
+ constructor(t, e) {
529
+ super({ code: t, units: "degrees", extent: kt, axisOrientation: e, global: !0, metersPerUnit: Me, worldExtent: kt });
530
+ }
531
+ }
532
+ const Ot = [new G("CRS:84"), new G("EPSG:4326", "neu"), new G("urn:ogc:def:crs:OGC:1.3:CRS84"), new G("urn:ogc:def:crs:OGC:2:84"), new G("http://www.opengis.net/def/crs/OGC/1.3/CRS84"), new G("http://www.opengis.net/gml/srs/epsg.xml#4326", "neu"), new G("http://www.opengis.net/def/crs/EPSG/0/4326", "neu")];
533
+ let yt = {};
534
+ function rt(s, t, e) {
535
+ const i = s.getCode(), o = t.getCode();
536
+ i in yt || (yt[i] = {}), yt[i][o] = e;
537
+ }
538
+ function te(s, t) {
539
+ if (t !== void 0) for (let e = 0, i = s.length; e < i; ++e) t[e] = s[e];
540
+ else t = s.slice();
541
+ return t;
542
+ }
543
+ function _e(s) {
544
+ s.getCode(), rt(s, s, te);
545
+ }
546
+ function jt(s) {
547
+ (function(t) {
548
+ t.forEach(_e);
549
+ })(s), s.forEach(function(t) {
550
+ s.forEach(function(e) {
551
+ t !== e && rt(t, e, te);
552
+ });
553
+ });
554
+ }
555
+ var Lt, Bt, Wt, C;
556
+ jt(Ft), jt(Ot), Lt = Ft, Bt = function(s, t, e) {
557
+ const i = s.length;
558
+ e = e > 1 ? e : 2, t === void 0 && (t = e > 2 ? s.slice() : new Array(i));
559
+ for (let o = 0; o < i; o += e) {
560
+ t[o] = T * s[o] / 180;
561
+ let n = J * Math.log(Math.tan(Math.PI * (+s[o + 1] + 90) / 360));
562
+ n > et ? n = et : n < -et && (n = -et), t[o + 1] = n;
563
+ }
564
+ return t;
565
+ }, Wt = function(s, t, e) {
566
+ const i = s.length;
567
+ e = e > 1 ? e : 2, t === void 0 && (t = e > 2 ? s.slice() : new Array(i));
568
+ for (let o = 0; o < i; o += e) t[o] = 180 * s[o] / T, t[o + 1] = 360 * Math.atan(Math.exp(s[o + 1] / J)) / Math.PI - 90;
569
+ return t;
570
+ }, Ot.forEach(function(s) {
571
+ Lt.forEach(function(t) {
572
+ rt(s, t, Bt), rt(t, s, Wt);
573
+ });
574
+ });
575
+ (function(s) {
576
+ s.Commit = "commit", s.Provisional = "provisional", s.Finish = "finish";
577
+ })(C || (C = {}));
578
+ const xt = "selected", H = "midPoint", Gt = "closingPoint";
579
+ function mt(s) {
580
+ return !!(s && typeof s == "object" && s !== null && !Array.isArray(s));
581
+ }
582
+ function Nt(s) {
583
+ if (!function(t) {
584
+ return typeof t == "number" && !isNaN(new Date(t).valueOf());
585
+ }(s)) throw new Error("updatedAt and createdAt are not valid timestamps");
586
+ return !0;
587
+ }
588
+ var U;
589
+ (function(s) {
590
+ s.Drawing = "drawing", s.Select = "select", s.Static = "static", s.Render = "render";
591
+ })(U || (U = {}));
592
+ class j {
593
+ get state() {
594
+ return this._state;
595
+ }
596
+ set state(t) {
597
+ throw new Error("Please use the modes lifecycle methods");
598
+ }
599
+ get styles() {
600
+ return this._styles;
601
+ }
602
+ set styles(t) {
603
+ if (typeof t != "object") throw new Error("Styling must be an object");
604
+ this.onStyleChange([], "styling"), this._styles = t;
605
+ }
606
+ registerBehaviors(t) {
607
+ }
608
+ constructor(t) {
609
+ this._state = void 0, this._styles = void 0, this.behaviors = [], this.validate = void 0, this.pointerDistance = void 0, this.coordinatePrecision = void 0, this.onStyleChange = void 0, this.store = void 0, this.setDoubleClickToZoom = void 0, this.unproject = void 0, this.project = void 0, this.setCursor = void 0, this.projection = void 0, this.type = U.Drawing, this.mode = "base", this._state = "unregistered", this._styles = t && t.styles ? f({}, t.styles) : {}, this.pointerDistance = t && t.pointerDistance || 40, this.validate = t && t.validation, this.projection = t && t.projection || "web-mercator";
610
+ }
611
+ setDrawing() {
612
+ if (this._state !== "started") throw new Error("Mode must be unregistered or stopped to start");
613
+ this._state = "drawing";
614
+ }
615
+ setStarted() {
616
+ if (this._state !== "stopped" && this._state !== "registered" && this._state !== "drawing" && this._state !== "selecting") throw new Error("Mode must be unregistered or stopped to start");
617
+ this._state = "started", this.setDoubleClickToZoom(!1);
618
+ }
619
+ setStopped() {
620
+ if (this._state !== "started") throw new Error("Mode must be started to be stopped");
621
+ this._state = "stopped", this.setDoubleClickToZoom(!0);
622
+ }
623
+ register(t) {
624
+ if (this._state !== "unregistered") throw new Error("Can not register unless mode is unregistered");
625
+ this._state = "registered", this.store = t.store, this.store.registerOnChange(t.onChange), this.setDoubleClickToZoom = t.setDoubleClickToZoom, this.project = t.project, this.unproject = t.unproject, this.onSelect = t.onSelect, this.onDeselect = t.onDeselect, this.setCursor = t.setCursor, this.onStyleChange = t.onChange, this.onFinish = t.onFinish, this.coordinatePrecision = t.coordinatePrecision, this.registerBehaviors({ mode: t.mode, store: this.store, project: this.project, unproject: this.unproject, pointerDistance: this.pointerDistance, coordinatePrecision: t.coordinatePrecision, projection: this.projection });
626
+ }
627
+ validateFeature(t) {
628
+ if (this._state === "unregistered") throw new Error("Mode must be registered");
629
+ const e = function(i, o) {
630
+ let n;
631
+ if (mt(i)) if (i.id == null) n = "Feature has no id";
632
+ else if (typeof i.id != "string" && typeof i.id != "number") n = "Feature must be string or number as per GeoJSON spec";
633
+ else if (o(i.id)) if (mt(i.geometry)) if (mt(i.properties)) if (typeof i.geometry.type == "string" && ["Polygon", "LineString", "Point"].includes(i.geometry.type)) if (Array.isArray(i.geometry.coordinates)) {
634
+ if (!i.properties.mode || typeof i.properties.mode != "string") throw new Error("Feature does not have a valid mode property");
635
+ } else n = "Feature coordinates is not an array";
636
+ else n = "Feature is not Point, LineString or Polygon";
637
+ else n = "Feature has no properties";
638
+ else n = "Feature has no geometry";
639
+ else n = "Feature must match the id strategy (default is UUID4)";
640
+ else n = "Feature is not object";
641
+ if (n) throw new Error(n);
642
+ return !0;
643
+ }(t, this.store.idStrategy.isValidId);
644
+ return this.validate ? this.validate(t, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: C.Provisional }) : e;
645
+ }
646
+ onFinish(t, e) {
647
+ }
648
+ onDeselect(t) {
649
+ }
650
+ onSelect(t) {
651
+ }
652
+ onKeyDown(t) {
653
+ }
654
+ onKeyUp(t) {
655
+ }
656
+ onMouseMove(t) {
657
+ }
658
+ onClick(t) {
659
+ }
660
+ onDragStart(t, e) {
661
+ }
662
+ onDrag(t, e) {
663
+ }
664
+ onDragEnd(t, e) {
665
+ }
666
+ getHexColorStylingValue(t, e, i) {
667
+ return this.getStylingValue(t, e, i);
668
+ }
669
+ getNumericStylingValue(t, e, i) {
670
+ return this.getStylingValue(t, e, i);
671
+ }
672
+ getStylingValue(t, e, i) {
673
+ return t === void 0 ? e : typeof t == "function" ? t(i) : t;
674
+ }
675
+ }
676
+ class be extends j {
677
+ constructor(...t) {
678
+ super(...t), this.type = U.Select;
679
+ }
680
+ }
681
+ function B(s, t) {
682
+ const e = (d) => d * Math.PI / 180, i = e(s[1]), o = e(s[0]), n = e(t[1]), r = n - i, a = e(t[0]) - o, l = Math.sin(r / 2) * Math.sin(r / 2) + Math.cos(i) * Math.cos(n) * Math.sin(a / 2) * Math.sin(a / 2);
683
+ return 2 * Math.atan2(Math.sqrt(l), Math.sqrt(1 - l)) * 6371e3 / 1e3;
684
+ }
685
+ const Pt = 63710088e-1;
686
+ function S(s) {
687
+ return s % 360 * Math.PI / 180;
688
+ }
689
+ function ee(s) {
690
+ return s / (Pt / 1e3);
691
+ }
692
+ function X(s) {
693
+ return s % (2 * Math.PI) * 180 / Math.PI;
694
+ }
695
+ const At = 57.29577951308232, Rt = 0.017453292519943295, at = 6378137, P = (s, t) => ({ x: s === 0 ? 0 : s * Rt * at, y: t === 0 ? 0 : Math.log(Math.tan(Math.PI / 4 + t * Rt / 2)) * at }), O = (s, t) => ({ lng: s === 0 ? 0 : At * (s / at), lat: t === 0 ? 0 : (2 * Math.atan(Math.exp(t / at)) - Math.PI / 2) * At });
696
+ function Ee(s, t, e) {
697
+ const i = S(s[0]), o = S(s[1]), n = S(e), r = ee(t), a = Math.asin(Math.sin(o) * Math.cos(r) + Math.cos(o) * Math.sin(r) * Math.cos(n));
698
+ return [X(i + Math.atan2(Math.sin(n) * Math.sin(r) * Math.cos(o), Math.cos(r) - Math.sin(o) * Math.sin(a))), X(a)];
699
+ }
700
+ function Vt(s) {
701
+ const { center: t, radiusKilometers: e, coordinatePrecision: i } = s, o = s.steps ? s.steps : 64, n = [];
702
+ for (let r = 0; r < o; r++) {
703
+ const a = Ee(t, e, -360 * r / o);
704
+ n.push([b(a[0], i), b(a[1], i)]);
705
+ }
706
+ return n.push(n[0]), { type: "Feature", geometry: { type: "Polygon", coordinates: [n] }, properties: {} };
707
+ }
708
+ function Mt(s) {
709
+ const t = { epsilon: 0 };
710
+ let e;
711
+ if (s.geometry.type === "Polygon") e = s.geometry.coordinates;
712
+ else {
713
+ if (s.geometry.type !== "LineString") throw new Error("Self intersects only accepts Polygons and LineStrings");
714
+ e = [s.geometry.coordinates];
715
+ }
716
+ const i = [];
717
+ for (let r = 0; r < e.length; r++) for (let a = 0; a < e[r].length - 1; a++) for (let l = 0; l < e.length; l++) for (let d = 0; d < e[l].length - 1; d++) n(r, a, l, d);
718
+ return i.length > 0;
719
+ function o(r) {
720
+ return r < 0 - t.epsilon || r > 1 + t.epsilon;
721
+ }
722
+ function n(r, a, l, d) {
723
+ const h = e[r][a], c = e[r][a + 1], u = e[l][d], g = e[l][d + 1], p = function(m, x, M, E) {
724
+ if (it(m, M) || it(m, E) || it(x, M) || it(E, M)) return null;
725
+ const _ = m[0], w = m[1], F = x[0], W = x[1], q = M[0], Z = M[1], Q = E[0], tt = E[1], pt = (_ - F) * (Z - tt) - (w - W) * (q - Q);
726
+ return pt === 0 ? null : [((_ * W - w * F) * (q - Q) - (_ - F) * (q * tt - Z * Q)) / pt, ((_ * W - w * F) * (Z - tt) - (w - W) * (q * tt - Z * Q)) / pt];
727
+ }(h, c, u, g);
728
+ if (p === null) return;
729
+ let y, v;
730
+ y = c[0] !== h[0] ? (p[0] - h[0]) / (c[0] - h[0]) : (p[1] - h[1]) / (c[1] - h[1]), v = g[0] !== u[0] ? (p[0] - u[0]) / (g[0] - u[0]) : (p[1] - u[1]) / (g[1] - u[1]), o(y) || o(v) || (p.toString(), i.push(p));
731
+ }
732
+ }
733
+ function it(s, t) {
734
+ return s[0] === t[0] && s[1] === t[1];
735
+ }
736
+ function _t(s, t) {
737
+ return s.length === 2 && typeof s[0] == "number" && typeof s[1] == "number" && s[0] !== 1 / 0 && s[1] !== 1 / 0 && (i = s[0]) >= -180 && i <= 180 && (e = s[1]) >= -90 && e <= 90 && Tt(s[0]) <= t && Tt(s[1]) <= t;
738
+ var e, i;
739
+ }
740
+ function Tt(s) {
741
+ let t = 1, e = 0;
742
+ for (; Math.round(s * t) / t !== s; ) t *= 10, e++;
743
+ return e;
744
+ }
745
+ function ut(s, t) {
746
+ return s.geometry.type === "Polygon" && s.geometry.coordinates.length === 1 && s.geometry.coordinates[0].length >= 4 && s.geometry.coordinates[0].every((o) => _t(o, t)) && (e = s.geometry.coordinates[0][0])[0] === (i = s.geometry.coordinates[0][s.geometry.coordinates[0].length - 1])[0] && e[1] === i[1];
747
+ var e, i;
748
+ }
749
+ function ie(s, t) {
750
+ return ut(s, t) && !Mt(s);
751
+ }
752
+ class we extends j {
753
+ constructor(t) {
754
+ var e;
755
+ super(t), this.mode = "circle", this.center = void 0, this.clickCount = 0, this.currentCircleId = void 0, this.keyEvents = void 0, this.cursors = void 0, this.startingRadiusKilometers = 1e-5;
756
+ const i = { start: "crosshair" };
757
+ if (this.cursors = t && t.cursors ? f({}, i, t.cursors) : i, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
758
+ else {
759
+ const o = { cancel: "Escape", finish: "Enter" };
760
+ this.keyEvents = t && t.keyEvents ? f({}, o, t.keyEvents) : o;
761
+ }
762
+ this.startingRadiusKilometers = (e = t == null ? void 0 : t.startingRadiusKilometers) != null ? e : 1e-5, this.validate = t == null ? void 0 : t.validation;
763
+ }
764
+ close() {
765
+ if (this.currentCircleId === void 0) return;
766
+ const t = this.currentCircleId;
767
+ if (this.validate && t) {
768
+ const e = this.store.getGeometryCopy(t);
769
+ if (!this.validate({ type: "Feature", id: t, geometry: e, properties: {} }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: C.Finish })) return;
770
+ }
771
+ this.center = void 0, this.currentCircleId = void 0, this.clickCount = 0, this.state === "drawing" && this.setStarted(), this.onFinish(t, { mode: this.mode, action: "draw" });
772
+ }
773
+ start() {
774
+ this.setStarted(), this.setCursor(this.cursors.start);
775
+ }
776
+ stop() {
777
+ this.cleanUp(), this.setStopped(), this.setCursor("unset");
778
+ }
779
+ onClick(t) {
780
+ if (this.clickCount === 0) {
781
+ this.center = [t.lng, t.lat];
782
+ const e = Vt({ center: this.center, radiusKilometers: this.startingRadiusKilometers, coordinatePrecision: this.coordinatePrecision }), [i] = this.store.create([{ geometry: e.geometry, properties: { mode: this.mode, radiusKilometers: this.startingRadiusKilometers } }]);
783
+ this.currentCircleId = i, this.clickCount++, this.setDrawing();
784
+ } else this.clickCount === 1 && this.center && this.currentCircleId !== void 0 && this.updateCircle(t), this.close();
785
+ }
786
+ onMouseMove(t) {
787
+ this.updateCircle(t);
788
+ }
789
+ onKeyDown() {
790
+ }
791
+ onKeyUp(t) {
792
+ t.key === this.keyEvents.cancel ? this.cleanUp() : t.key === this.keyEvents.finish && this.close();
793
+ }
794
+ onDragStart() {
795
+ }
796
+ onDrag() {
797
+ }
798
+ onDragEnd() {
799
+ }
800
+ cleanUp() {
801
+ const t = this.currentCircleId;
802
+ this.center = void 0, this.currentCircleId = void 0, this.clickCount = 0, this.state === "drawing" && this.setStarted();
803
+ try {
804
+ t !== void 0 && this.store.delete([t]);
805
+ } catch {
806
+ }
807
+ }
808
+ styleFeature(t) {
809
+ const e = f({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
810
+ return t.type === "Feature" && t.geometry.type === "Polygon" && t.properties.mode === this.mode && (e.polygonFillColor = this.getHexColorStylingValue(this.styles.fillColor, e.polygonFillColor, t), e.polygonOutlineColor = this.getHexColorStylingValue(this.styles.outlineColor, e.polygonOutlineColor, t), e.polygonOutlineWidth = this.getNumericStylingValue(this.styles.outlineWidth, e.polygonOutlineWidth, t), e.polygonFillOpacity = this.getNumericStylingValue(this.styles.fillOpacity, e.polygonFillOpacity, t), e.zIndex = 10), e;
811
+ }
812
+ validateFeature(t) {
813
+ return !!super.validateFeature(t) && t.properties.mode === this.mode && ie(t, this.coordinatePrecision);
814
+ }
815
+ updateCircle(t) {
816
+ if (this.clickCount === 1 && this.center && this.currentCircleId) {
817
+ const e = B(this.center, [t.lng, t.lat]);
818
+ let i;
819
+ if (this.projection === "web-mercator") {
820
+ const o = function(n, r) {
821
+ const a = 1e3 * B(n, r);
822
+ if (a === 0) return 1;
823
+ const { x: l, y: d } = P(n[0], n[1]), { x: h, y: c } = P(r[0], r[1]);
824
+ return Math.sqrt(Math.pow(h - l, 2) + Math.pow(c - d, 2)) / a;
825
+ }(this.center, [t.lng, t.lat]);
826
+ i = function(n) {
827
+ const { center: r, radiusKilometers: a, coordinatePrecision: l } = n, d = n.steps ? n.steps : 64, h = 1e3 * a, [c, u] = r, { x: g, y: p } = P(c, u), y = [];
828
+ for (let v = 0; v < d; v++) {
829
+ const m = 360 * v / d * Math.PI / 180, x = h * Math.cos(m), M = h * Math.sin(m), [E, _] = [g + x, p + M], { lng: w, lat: F } = O(E, _);
830
+ y.push([b(w, l), b(F, l)]);
831
+ }
832
+ return y.push(y[0]), { type: "Feature", geometry: { type: "Polygon", coordinates: [y] }, properties: {} };
833
+ }({ center: this.center, radiusKilometers: e * o, coordinatePrecision: this.coordinatePrecision });
834
+ } else {
835
+ if (this.projection !== "globe") throw new Error("Invalid projection");
836
+ i = Vt({ center: this.center, radiusKilometers: e, coordinatePrecision: this.coordinatePrecision });
837
+ }
838
+ if (this.validate && !this.validate({ type: "Feature", id: this.currentCircleId, geometry: i.geometry, properties: { radiusKilometers: e } }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: C.Provisional })) return;
839
+ this.store.updateGeometry([{ id: this.currentCircleId, geometry: i.geometry }]), this.store.updateProperty([{ id: this.currentCircleId, property: "radiusKilometers", value: e }]);
840
+ }
841
+ }
842
+ }
843
+ class Se extends j {
844
+ constructor(t) {
845
+ super(t), this.mode = "freehand", this.startingClick = !1, this.currentId = void 0, this.closingPointId = void 0, this.minDistance = void 0, this.keyEvents = void 0, this.cursors = void 0, this.preventPointsNearClose = void 0;
846
+ const e = { start: "crosshair", close: "pointer" };
847
+ if (this.cursors = t && t.cursors ? f({}, e, t.cursors) : e, this.preventPointsNearClose = t && t.preventPointsNearClose || !0, this.minDistance = t && t.minDistance || 20, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
848
+ else {
849
+ const i = { cancel: "Escape", finish: "Enter" };
850
+ this.keyEvents = t && t.keyEvents ? f({}, i, t.keyEvents) : i;
851
+ }
852
+ this.validate = t == null ? void 0 : t.validation;
853
+ }
854
+ close() {
855
+ if (this.currentId === void 0) return;
856
+ const t = this.currentId;
857
+ if (this.validate && t) {
858
+ const e = this.store.getGeometryCopy(t);
859
+ if (!this.validate({ type: "Feature", id: t, geometry: e, properties: {} }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: C.Finish })) return;
860
+ }
861
+ this.closingPointId && this.store.delete([this.closingPointId]), this.startingClick = !1, this.currentId = void 0, this.closingPointId = void 0, this.state === "drawing" && this.setStarted(), this.onFinish(t, { mode: this.mode, action: "draw" });
862
+ }
863
+ start() {
864
+ this.setStarted(), this.setCursor(this.cursors.start);
865
+ }
866
+ stop() {
867
+ this.cleanUp(), this.setStopped(), this.setCursor("unset");
868
+ }
869
+ onMouseMove(t) {
870
+ if (this.currentId === void 0 || this.startingClick === !1) return;
871
+ const e = this.store.getGeometryCopy(this.currentId), i = e.coordinates[0].length - 2, [o, n] = e.coordinates[0][i], { x: r, y: a } = this.project(o, n), l = I({ x: r, y: a }, { x: t.containerX, y: t.containerY }), [d, h] = e.coordinates[0][0], { x: c, y: u } = this.project(d, h);
872
+ if (I({ x: c, y: u }, { x: t.containerX, y: t.containerY }) < this.pointerDistance) {
873
+ if (this.setCursor(this.cursors.close), this.preventPointsNearClose) return;
874
+ } else this.setCursor(this.cursors.start);
875
+ if (l < this.minDistance) return;
876
+ e.coordinates[0].pop();
877
+ const g = { type: "Polygon", coordinates: [[...e.coordinates[0], [t.lng, t.lat], e.coordinates[0][0]]] };
878
+ this.validate && !this.validate({ type: "Feature", id: this.currentId, geometry: g, properties: {} }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: C.Provisional }) || this.store.updateGeometry([{ id: this.currentId, geometry: g }]);
879
+ }
880
+ onClick(t) {
881
+ if (this.startingClick === !1) {
882
+ const [e, i] = this.store.create([{ geometry: { type: "Polygon", coordinates: [[[t.lng, t.lat], [t.lng, t.lat], [t.lng, t.lat], [t.lng, t.lat]]] }, properties: { mode: this.mode } }, { geometry: { type: "Point", coordinates: [t.lng, t.lat] }, properties: { mode: this.mode } }]);
883
+ return this.currentId = e, this.closingPointId = i, this.startingClick = !0, void this.setDrawing();
884
+ }
885
+ this.close();
886
+ }
887
+ onKeyDown() {
888
+ }
889
+ onKeyUp(t) {
890
+ t.key === this.keyEvents.cancel ? this.cleanUp() : t.key === this.keyEvents.finish && this.close();
891
+ }
892
+ onDragStart() {
893
+ }
894
+ onDrag() {
895
+ }
896
+ onDragEnd() {
897
+ }
898
+ cleanUp() {
899
+ const t = this.currentId, e = this.closingPointId;
900
+ this.closingPointId = void 0, this.currentId = void 0, this.startingClick = !1, this.state === "drawing" && this.setStarted();
901
+ try {
902
+ t !== void 0 && this.store.delete([t]), e !== void 0 && this.store.delete([e]);
903
+ } catch {
904
+ }
905
+ }
906
+ styleFeature(t) {
907
+ const e = f({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
908
+ return t.type === "Feature" && t.geometry.type === "Polygon" && t.properties.mode === this.mode ? (e.polygonFillColor = this.getHexColorStylingValue(this.styles.fillColor, e.polygonFillColor, t), e.polygonOutlineColor = this.getHexColorStylingValue(this.styles.outlineColor, e.polygonOutlineColor, t), e.polygonOutlineWidth = this.getNumericStylingValue(this.styles.outlineWidth, e.polygonOutlineWidth, t), e.polygonFillOpacity = this.getNumericStylingValue(this.styles.fillOpacity, e.polygonFillOpacity, t), e.zIndex = 10, e) : (t.type === "Feature" && t.geometry.type === "Point" && t.properties.mode === this.mode && (e.pointWidth = this.getNumericStylingValue(this.styles.closingPointWidth, e.pointWidth, t), e.pointColor = this.getHexColorStylingValue(this.styles.closingPointColor, e.pointColor, t), e.pointOutlineColor = this.getHexColorStylingValue(this.styles.closingPointOutlineColor, e.pointOutlineColor, t), e.pointOutlineWidth = this.getNumericStylingValue(this.styles.closingPointOutlineWidth, 2, t), e.zIndex = 40), e);
909
+ }
910
+ validateFeature(t) {
911
+ return !!super.validateFeature(t) && t.properties.mode === this.mode && ut(t, this.coordinatePrecision);
912
+ }
913
+ }
914
+ class D {
915
+ constructor({ store: t, mode: e, project: i, unproject: o, pointerDistance: n, coordinatePrecision: r, projection: a }) {
916
+ this.store = void 0, this.mode = void 0, this.project = void 0, this.unproject = void 0, this.pointerDistance = void 0, this.coordinatePrecision = void 0, this.projection = void 0, this.store = t, this.mode = e, this.project = i, this.unproject = o, this.pointerDistance = n, this.coordinatePrecision = r, this.projection = a;
917
+ }
918
+ }
919
+ function oe({ unproject: s, point: t, pointerDistance: e }) {
920
+ const i = e / 2, { x: o, y: n } = t;
921
+ return { type: "Feature", properties: {}, geometry: { type: "Polygon", coordinates: [[s(o - i, n - i), s(o + i, n - i), s(o + i, n + i), s(o - i, n + i), s(o - i, n - i)].map((r) => [r.lng, r.lat])] } };
922
+ }
923
+ class bt extends D {
924
+ constructor(t) {
925
+ super(t);
926
+ }
927
+ create(t) {
928
+ const { containerX: e, containerY: i } = t;
929
+ return oe({ unproject: this.unproject, point: { x: e, y: i }, pointerDistance: this.pointerDistance });
930
+ }
931
+ }
932
+ class gt extends D {
933
+ constructor(t) {
934
+ super(t);
935
+ }
936
+ measure(t, e) {
937
+ const { x: i, y: o } = this.project(e[0], e[1]);
938
+ return I({ x: i, y: o }, { x: t.containerX, y: t.containerY });
939
+ }
940
+ }
941
+ class se extends D {
942
+ constructor(t, e, i) {
943
+ super(t), this.config = void 0, this.pixelDistance = void 0, this.clickBoundingBox = void 0, this.getSnappableCoordinateFirstClick = (o) => this.getSnappable(o, (n) => !!(n.properties && n.properties.mode === this.mode)), this.getSnappableCoordinate = (o, n) => this.getSnappable(o, (r) => !!(r.properties && r.properties.mode === this.mode && r.id !== n)), this.config = t, this.pixelDistance = e, this.clickBoundingBox = i;
944
+ }
945
+ getSnappable(t, e) {
946
+ const i = this.clickBoundingBox.create(t), o = this.store.search(i, e), n = { coord: void 0, minDist: 1 / 0 };
947
+ return o.forEach((r) => {
948
+ let a;
949
+ if (r.geometry.type === "Polygon") a = r.geometry.coordinates[0];
950
+ else {
951
+ if (r.geometry.type !== "LineString") return;
952
+ a = r.geometry.coordinates;
953
+ }
954
+ a.forEach((l) => {
955
+ const d = this.pixelDistance.measure(t, l);
956
+ d < n.minDist && d < this.pointerDistance && (n.coord = l, n.minDist = d);
957
+ });
958
+ }), n.coord;
959
+ }
960
+ }
961
+ function Ut(s, t, e) {
962
+ const i = S(s[0]), o = S(s[1]), n = S(e), r = ee(t), a = Math.asin(Math.sin(o) * Math.cos(r) + Math.cos(o) * Math.sin(r) * Math.cos(n));
963
+ return [X(i + Math.atan2(Math.sin(n) * Math.sin(r) * Math.cos(o), Math.cos(r) - Math.sin(o) * Math.sin(a))), X(a)];
964
+ }
965
+ function Xt({ x: s, y: t }, e, i) {
966
+ const o = S(i);
967
+ return { x: s + e * Math.cos(o), y: t + e * Math.sin(o) };
968
+ }
969
+ function Kt(s, t) {
970
+ const e = S(s[0]), i = S(t[0]), o = S(s[1]), n = S(t[1]), r = Math.sin(i - e) * Math.cos(n), a = Math.cos(o) * Math.sin(n) - Math.sin(o) * Math.cos(n) * Math.cos(i - e);
971
+ return X(Math.atan2(r, a));
972
+ }
973
+ function lt({ x: s, y: t }, { x: e, y: i }) {
974
+ let o = Math.atan2(i - t, e - s);
975
+ return o *= 180 / Math.PI, o > 180 ? o -= 360 : o < -180 && (o += 360), o;
976
+ }
977
+ function Ie(s, t, e) {
978
+ const i = [], o = s.length;
979
+ let n, r, a, l = 0;
980
+ for (let h = 0; h < s.length && !(t >= l && h === s.length - 1); h++) {
981
+ if (l > t && i.length === 0) {
982
+ if (n = t - l, !n) return i.push(s[h]), i;
983
+ r = Kt(s[h], s[h - 1]) - 180, a = Ut(s[h], n, r), i.push(a);
984
+ }
985
+ if (l >= e) return n = e - l, n ? (r = Kt(s[h], s[h - 1]) - 180, a = Ut(s[h], n, r), i.push(a), i) : (i.push(s[h]), i);
986
+ if (l >= t && i.push(s[h]), h === s.length - 1) return i;
987
+ l += B(s[h], s[h + 1]);
988
+ }
989
+ if (l < t && s.length === o) throw new Error("Start position is beyond line");
990
+ const d = s[s.length - 1];
991
+ return [d, d];
992
+ }
993
+ function ot(s) {
994
+ return s * (Math.PI / 180);
995
+ }
996
+ function Yt(s) {
997
+ return s * (180 / Math.PI);
998
+ }
999
+ class De extends D {
1000
+ constructor(t) {
1001
+ super(t), this.config = void 0, this.config = t;
1002
+ }
1003
+ generateInsertionCoordinates(t, e, i) {
1004
+ const o = [t, e];
1005
+ let n = 0;
1006
+ for (let d = 0; d < o.length - 1; d++) n += B(o[0], o[1]);
1007
+ if (n <= i) return o;
1008
+ let r = n / i - 1;
1009
+ Number.isInteger(r) || (r = Math.floor(r) + 1);
1010
+ const a = [];
1011
+ for (let d = 0; d < r; d++) {
1012
+ const h = Ie(o, i * d, i * (d + 1));
1013
+ a.push(h);
1014
+ }
1015
+ const l = [];
1016
+ for (let d = 0; d < a.length; d++) l.push(a[d][1]);
1017
+ return this.limitCoordinates(l);
1018
+ }
1019
+ generateInsertionGeodesicCoordinates(t, e, i) {
1020
+ const o = B(t, e), n = function(r, a, l) {
1021
+ const d = [], h = ot(r[1]), c = ot(r[0]), u = ot(a[1]), g = ot(a[0]);
1022
+ l += 1;
1023
+ const p = 2 * Math.asin(Math.sqrt(Math.sin((u - h) / 2) ** 2 + Math.cos(h) * Math.cos(u) * Math.sin((g - c) / 2) ** 2));
1024
+ if (p === 0 || isNaN(p)) return d;
1025
+ for (let y = 0; y <= l; y++) {
1026
+ const v = y / l, m = Math.sin((1 - v) * p) / Math.sin(p), x = Math.sin(v * p) / Math.sin(p), M = m * Math.cos(h) * Math.cos(c) + x * Math.cos(u) * Math.cos(g), E = m * Math.cos(h) * Math.sin(c) + x * Math.cos(u) * Math.sin(g), _ = m * Math.sin(h) + x * Math.sin(u);
1027
+ if (isNaN(M) || isNaN(E) || isNaN(_)) continue;
1028
+ const w = Math.atan2(_, Math.sqrt(M ** 2 + E ** 2)), F = Math.atan2(E, M);
1029
+ isNaN(w) || isNaN(F) || d.push([Yt(F), Yt(w)]);
1030
+ }
1031
+ return d.slice(1, -1);
1032
+ }(t, e, Math.floor(o / i));
1033
+ return this.limitCoordinates(n);
1034
+ }
1035
+ limitCoordinates(t) {
1036
+ return t.map((e) => [b(e[0], this.config.coordinatePrecision), b(e[1], this.config.coordinatePrecision)]);
1037
+ }
1038
+ }
1039
+ function $(s, t) {
1040
+ return s[0] === t[0] && s[1] === t[1];
1041
+ }
1042
+ class Fe extends j {
1043
+ constructor(t) {
1044
+ super(t), this.mode = "linestring", this.currentCoordinate = 0, this.currentId = void 0, this.closingPointId = void 0, this.keyEvents = void 0, this.snappingEnabled = void 0, this.cursors = void 0, this.mouseMove = !1, this.insertCoordinates = void 0, this.lastCommitedCoordinates = void 0, this.snapping = void 0, this.insertPoint = void 0;
1045
+ const e = { start: "crosshair", close: "pointer" };
1046
+ if (this.cursors = t && t.cursors ? f({}, e, t.cursors) : e, this.snappingEnabled = !(!t || t.snapping === void 0) && t.snapping, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
1047
+ else {
1048
+ const i = { cancel: "Escape", finish: "Enter" };
1049
+ this.keyEvents = t && t.keyEvents ? f({}, i, t.keyEvents) : i;
1050
+ }
1051
+ this.validate = t == null ? void 0 : t.validation, this.insertCoordinates = t == null ? void 0 : t.insertCoordinates;
1052
+ }
1053
+ close() {
1054
+ if (this.currentId === void 0) return;
1055
+ const t = this.store.getGeometryCopy(this.currentId);
1056
+ t.coordinates.pop(), this.updateGeometries([...t.coordinates], void 0, C.Commit);
1057
+ const e = this.currentId;
1058
+ this.closingPointId && this.store.delete([this.closingPointId]), this.currentCoordinate = 0, this.currentId = void 0, this.closingPointId = void 0, this.lastCommitedCoordinates = void 0, this.state === "drawing" && this.setStarted(), this.onFinish(e, { mode: this.mode, action: "draw" });
1059
+ }
1060
+ updateGeometries(t, e, i) {
1061
+ if (!this.currentId) return;
1062
+ const o = { type: "LineString", coordinates: t };
1063
+ if (this.validate && !this.validate({ type: "Feature", geometry: o }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: i })) return;
1064
+ const n = [{ id: this.currentId, geometry: o }];
1065
+ this.closingPointId && e && n.push({ id: this.closingPointId, geometry: { type: "Point", coordinates: e } }), i === "commit" && (this.lastCommitedCoordinates = o.coordinates), this.store.updateGeometry(n);
1066
+ }
1067
+ generateInsertCoordinates(t, e) {
1068
+ if (!this.insertCoordinates || !this.lastCommitedCoordinates) throw new Error("Not able to insert coordinates");
1069
+ if (this.insertCoordinates.strategy !== "amount") throw new Error("Strategy does not exist");
1070
+ const i = B(t, e) / (this.insertCoordinates.value + 1);
1071
+ let o = [];
1072
+ return this.projection === "globe" ? o = this.insertPoint.generateInsertionGeodesicCoordinates(t, e, i) : this.projection === "web-mercator" && (o = this.insertPoint.generateInsertionCoordinates(t, e, i)), o;
1073
+ }
1074
+ createLine(t) {
1075
+ const [e] = this.store.create([{ geometry: { type: "LineString", coordinates: [t, t] }, properties: { mode: this.mode } }]);
1076
+ this.lastCommitedCoordinates = [t, t], this.currentId = e, this.currentCoordinate++, this.setDrawing();
1077
+ }
1078
+ firstUpdateToLine(t) {
1079
+ if (!this.currentId) return;
1080
+ const e = this.store.getGeometryCopy(this.currentId).coordinates, [i] = this.store.create([{ geometry: { type: "Point", coordinates: [...t] }, properties: { mode: this.mode } }]);
1081
+ this.closingPointId = i, this.setCursor(this.cursors.close);
1082
+ const o = [...e, t];
1083
+ this.updateGeometries(o, void 0, C.Commit), this.currentCoordinate++;
1084
+ }
1085
+ updateToLine(t, e) {
1086
+ if (!this.currentId) return;
1087
+ const i = this.store.getGeometryCopy(this.currentId).coordinates, [o, n] = this.lastCommitedCoordinates ? this.lastCommitedCoordinates[this.lastCommitedCoordinates.length - 1] : i[i.length - 2], { x: r, y: a } = this.project(o, n);
1088
+ if (I({ x: r, y: a }, { x: e.x, y: e.y }) < this.pointerDistance) return void this.close();
1089
+ this.setCursor(this.cursors.close);
1090
+ const l = [...i, t];
1091
+ this.updateGeometries(l, i[i.length - 1], C.Commit), this.currentCoordinate++;
1092
+ }
1093
+ registerBehaviors(t) {
1094
+ this.snapping = new se(t, new gt(t), new bt(t)), this.insertPoint = new De(t);
1095
+ }
1096
+ start() {
1097
+ this.setStarted(), this.setCursor(this.cursors.start);
1098
+ }
1099
+ stop() {
1100
+ this.cleanUp(), this.setStopped(), this.setCursor("unset");
1101
+ }
1102
+ onMouseMove(t) {
1103
+ if (this.mouseMove = !0, this.setCursor(this.cursors.start), this.currentId === void 0 || this.currentCoordinate === 0) return;
1104
+ const e = this.store.getGeometryCopy(this.currentId).coordinates;
1105
+ e.pop();
1106
+ const i = this.snappingEnabled && this.snapping.getSnappableCoordinate(t, this.currentId) || [t.lng, t.lat];
1107
+ if (this.closingPointId) {
1108
+ const [n, r] = e[e.length - 1], { x: a, y: l } = this.project(n, r);
1109
+ I({ x: a, y: l }, { x: t.containerX, y: t.containerY }) < this.pointerDistance && this.setCursor(this.cursors.close);
1110
+ }
1111
+ let o = [...e, i];
1112
+ if (this.insertCoordinates && this.currentId && this.lastCommitedCoordinates) {
1113
+ const n = this.lastCommitedCoordinates[this.lastCommitedCoordinates.length - 1], r = i;
1114
+ if (!$(n, r)) {
1115
+ const a = this.generateInsertCoordinates(n, r);
1116
+ o = [...this.lastCommitedCoordinates.slice(0, -1), ...a, i];
1117
+ }
1118
+ }
1119
+ this.updateGeometries(o, void 0, C.Provisional);
1120
+ }
1121
+ onClick(t) {
1122
+ this.currentCoordinate > 0 && !this.mouseMove && this.onMouseMove(t), this.mouseMove = !1;
1123
+ const e = this.currentId && this.snappingEnabled && this.snapping.getSnappableCoordinate(t, this.currentId) || [t.lng, t.lat];
1124
+ this.currentCoordinate === 0 ? this.createLine(e) : this.currentCoordinate === 1 && this.currentId ? this.firstUpdateToLine(e) : this.currentId && this.updateToLine(e, { x: t.containerX, y: t.containerY });
1125
+ }
1126
+ onKeyDown() {
1127
+ }
1128
+ onKeyUp(t) {
1129
+ t.key === this.keyEvents.cancel && this.cleanUp(), t.key === this.keyEvents.finish && this.close();
1130
+ }
1131
+ onDragStart() {
1132
+ }
1133
+ onDrag() {
1134
+ }
1135
+ onDragEnd() {
1136
+ }
1137
+ cleanUp() {
1138
+ const t = this.currentId;
1139
+ this.closingPointId = void 0, this.currentId = void 0, this.currentCoordinate = 0, this.state === "drawing" && this.setStarted();
1140
+ try {
1141
+ t !== void 0 && this.store.delete([t]), this.closingPointId !== void 0 && this.store.delete([this.closingPointId]);
1142
+ } catch {
1143
+ }
1144
+ }
1145
+ styleFeature(t) {
1146
+ const e = f({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1147
+ return t.type === "Feature" && t.geometry.type === "LineString" && t.properties.mode === this.mode ? (e.lineStringColor = this.getHexColorStylingValue(this.styles.lineStringColor, e.lineStringColor, t), e.lineStringWidth = this.getNumericStylingValue(this.styles.lineStringWidth, e.lineStringWidth, t), e.zIndex = 10, e) : (t.type === "Feature" && t.geometry.type === "Point" && t.properties.mode === this.mode && (e.pointColor = this.getHexColorStylingValue(this.styles.closingPointColor, e.pointColor, t), e.pointWidth = this.getNumericStylingValue(this.styles.closingPointWidth, e.pointWidth, t), e.pointOutlineColor = this.getHexColorStylingValue(this.styles.closingPointOutlineColor, "#ffffff", t), e.pointOutlineWidth = this.getNumericStylingValue(this.styles.closingPointOutlineWidth, 2, t), e.zIndex = 40), e);
1148
+ }
1149
+ validateFeature(t) {
1150
+ return !!super.validateFeature(t) && t.geometry.type === "LineString" && t.properties.mode === this.mode && t.geometry.coordinates.length >= 2;
1151
+ }
1152
+ }
1153
+ function ke(s, t) {
1154
+ return s.geometry.type === "Point" && _t(s.geometry.coordinates, t);
1155
+ }
1156
+ class Oe extends j {
1157
+ constructor(t) {
1158
+ super(t), this.mode = "point", this.cursors = void 0;
1159
+ const e = { create: "crosshair" };
1160
+ this.cursors = t && t.cursors ? f({}, e, t.cursors) : e;
1161
+ }
1162
+ start() {
1163
+ this.setStarted(), this.setCursor(this.cursors.create);
1164
+ }
1165
+ stop() {
1166
+ this.cleanUp(), this.setStopped(), this.setCursor("unset");
1167
+ }
1168
+ onClick(t) {
1169
+ if (!this.store) throw new Error("Mode must be registered first");
1170
+ const e = { type: "Point", coordinates: [t.lng, t.lat] }, i = { mode: this.mode };
1171
+ if (this.validate && !this.validate({ type: "Feature", geometry: e, properties: i }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: C.Finish })) return;
1172
+ const [o] = this.store.create([{ geometry: e, properties: i }]);
1173
+ this.onFinish(o, { mode: this.mode, action: "draw" });
1174
+ }
1175
+ onMouseMove() {
1176
+ }
1177
+ onKeyDown() {
1178
+ }
1179
+ onKeyUp() {
1180
+ }
1181
+ cleanUp() {
1182
+ }
1183
+ onDragStart() {
1184
+ }
1185
+ onDrag() {
1186
+ }
1187
+ onDragEnd() {
1188
+ }
1189
+ styleFeature(t) {
1190
+ const e = f({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1191
+ return t.type === "Feature" && t.geometry.type === "Point" && t.properties.mode === this.mode && (e.pointWidth = this.getNumericStylingValue(this.styles.pointWidth, e.pointWidth, t), e.pointColor = this.getHexColorStylingValue(this.styles.pointColor, e.pointColor, t), e.pointOutlineColor = this.getHexColorStylingValue(this.styles.pointOutlineColor, e.pointOutlineColor, t), e.pointOutlineWidth = this.getNumericStylingValue(this.styles.pointOutlineWidth, 2, t), e.zIndex = 30), e;
1192
+ }
1193
+ validateFeature(t) {
1194
+ return !!super.validateFeature(t) && t.properties.mode === this.mode && ke(t, this.coordinatePrecision);
1195
+ }
1196
+ }
1197
+ class je extends D {
1198
+ constructor(t, e) {
1199
+ super(t), this.config = void 0, this.pixelDistance = void 0, this._startEndPoints = [], this.config = t, this.pixelDistance = e;
1200
+ }
1201
+ get ids() {
1202
+ return this._startEndPoints.concat();
1203
+ }
1204
+ set ids(t) {
1205
+ }
1206
+ create(t, e) {
1207
+ if (this.ids.length) throw new Error("Opening and closing points already created");
1208
+ if (t.length <= 3) throw new Error("Requires at least 4 coordinates");
1209
+ this._startEndPoints = this.store.create([{ geometry: { type: "Point", coordinates: t[0] }, properties: { mode: e, [Gt]: !0 } }, { geometry: { type: "Point", coordinates: t[t.length - 2] }, properties: { mode: e, [Gt]: !0 } }]);
1210
+ }
1211
+ delete() {
1212
+ this.ids.length && (this.store.delete(this.ids), this._startEndPoints = []);
1213
+ }
1214
+ update(t) {
1215
+ if (this.ids.length !== 2) throw new Error("No closing points to update");
1216
+ this.store.updateGeometry([{ id: this.ids[0], geometry: { type: "Point", coordinates: t[0] } }, { id: this.ids[1], geometry: { type: "Point", coordinates: t[t.length - 3] } }]);
1217
+ }
1218
+ isClosingPoint(t) {
1219
+ const e = this.store.getGeometryCopy(this.ids[0]), i = this.store.getGeometryCopy(this.ids[1]), o = this.pixelDistance.measure(t, e.coordinates), n = this.pixelDistance.measure(t, i.coordinates);
1220
+ return { isClosing: o < this.pointerDistance, isPreviousClosing: n < this.pointerDistance };
1221
+ }
1222
+ }
1223
+ class Le extends j {
1224
+ constructor(t) {
1225
+ super(t), this.mode = "polygon", this.currentCoordinate = 0, this.currentId = void 0, this.keyEvents = void 0, this.snappingEnabled = void 0, this.snapping = void 0, this.pixelDistance = void 0, this.closingPoints = void 0, this.cursors = void 0, this.mouseMove = !1;
1226
+ const e = { start: "crosshair", close: "pointer" };
1227
+ if (this.cursors = t && t.cursors ? f({}, e, t.cursors) : e, this.snappingEnabled = !(!t || t.snapping === void 0) && t.snapping, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
1228
+ else {
1229
+ const i = { cancel: "Escape", finish: "Enter" };
1230
+ this.keyEvents = t && t.keyEvents ? f({}, i, t.keyEvents) : i;
1231
+ }
1232
+ }
1233
+ close() {
1234
+ if (this.currentId === void 0) return;
1235
+ const t = this.store.getGeometryCopy(this.currentId).coordinates[0];
1236
+ if (t.length < 5 || !this.updatePolygonGeometry([...t.slice(0, -2), t[0]], C.Finish)) return;
1237
+ const e = this.currentId;
1238
+ this.currentCoordinate = 0, this.currentId = void 0, this.closingPoints.delete(), this.state === "drawing" && this.setStarted(), this.onFinish(e, { mode: this.mode, action: "draw" });
1239
+ }
1240
+ registerBehaviors(t) {
1241
+ this.pixelDistance = new gt(t), this.snapping = new se(t, this.pixelDistance, new bt(t)), this.closingPoints = new je(t, this.pixelDistance);
1242
+ }
1243
+ start() {
1244
+ this.setStarted(), this.setCursor(this.cursors.start);
1245
+ }
1246
+ stop() {
1247
+ this.cleanUp(), this.setStopped(), this.setCursor("unset");
1248
+ }
1249
+ onMouseMove(t) {
1250
+ if (this.mouseMove = !0, this.setCursor(this.cursors.start), this.currentId === void 0 || this.currentCoordinate === 0) return;
1251
+ const e = this.snappingEnabled ? this.snapping.getSnappableCoordinate(t, this.currentId) : void 0, i = this.store.getGeometryCopy(this.currentId).coordinates[0];
1252
+ let o;
1253
+ if (e && (t.lng = e[0], t.lat = e[1]), this.currentCoordinate === 1) {
1254
+ const n = 1 / Math.pow(10, this.coordinatePrecision - 1), r = Math.max(1e-6, n);
1255
+ o = [i[0], [t.lng, t.lat], [t.lng, t.lat - r], i[0]];
1256
+ } else if (this.currentCoordinate === 2) o = [i[0], i[1], [t.lng, t.lat], i[0]];
1257
+ else {
1258
+ const { isClosing: n, isPreviousClosing: r } = this.closingPoints.isClosingPoint(t);
1259
+ r || n ? (this.setCursor(this.cursors.close), o = [...i.slice(0, -2), i[0], i[0]]) : o = [...i.slice(0, -2), [t.lng, t.lat], i[0]];
1260
+ }
1261
+ this.updatePolygonGeometry(o, C.Provisional);
1262
+ }
1263
+ updatePolygonGeometry(t, e) {
1264
+ if (!this.currentId) return !1;
1265
+ const i = { type: "Polygon", coordinates: [t] };
1266
+ return !(this.validate && !this.validate({ type: "Feature", geometry: i }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: e }) || (this.store.updateGeometry([{ id: this.currentId, geometry: i }]), 0));
1267
+ }
1268
+ onClick(t) {
1269
+ if (this.currentCoordinate > 0 && !this.mouseMove && this.onMouseMove(t), this.mouseMove = !1, this.currentCoordinate === 0) {
1270
+ const e = this.snappingEnabled ? this.snapping.getSnappableCoordinateFirstClick(t) : void 0;
1271
+ e && (t.lng = e[0], t.lat = e[1]);
1272
+ const [i] = this.store.create([{ geometry: { type: "Polygon", coordinates: [[[t.lng, t.lat], [t.lng, t.lat], [t.lng, t.lat], [t.lng, t.lat]]] }, properties: { mode: this.mode } }]);
1273
+ this.currentId = i, this.currentCoordinate++, this.setDrawing();
1274
+ } else if (this.currentCoordinate === 1 && this.currentId) {
1275
+ const e = this.snappingEnabled ? this.snapping.getSnappableCoordinate(t, this.currentId) : void 0;
1276
+ e && (t.lng = e[0], t.lat = e[1]);
1277
+ const i = this.store.getGeometryCopy(this.currentId);
1278
+ if ($([t.lng, t.lat], i.coordinates[0][0]) || !this.updatePolygonGeometry([i.coordinates[0][0], [t.lng, t.lat], [t.lng, t.lat], i.coordinates[0][0]], C.Commit)) return;
1279
+ this.currentCoordinate++;
1280
+ } else if (this.currentCoordinate === 2 && this.currentId) {
1281
+ const e = this.snappingEnabled ? this.snapping.getSnappableCoordinate(t, this.currentId) : void 0;
1282
+ e && (t.lng = e[0], t.lat = e[1]);
1283
+ const i = this.store.getGeometryCopy(this.currentId).coordinates[0];
1284
+ if ($([t.lng, t.lat], i[1]) || !this.updatePolygonGeometry([i[0], i[1], [t.lng, t.lat], [t.lng, t.lat], i[0]], C.Commit)) return;
1285
+ this.currentCoordinate === 2 && this.closingPoints.create(i, "polygon"), this.currentCoordinate++;
1286
+ } else if (this.currentId) {
1287
+ const e = this.snappingEnabled ? this.snapping.getSnappableCoordinate(t, this.currentId) : void 0, i = this.store.getGeometryCopy(this.currentId).coordinates[0], { isClosing: o, isPreviousClosing: n } = this.closingPoints.isClosingPoint(t);
1288
+ if (n || o) this.close();
1289
+ else {
1290
+ if (e && (t.lng = e[0], t.lat = e[1]), $([t.lng, t.lat], i[this.currentCoordinate - 1])) return;
1291
+ const r = /* @__PURE__ */ function(a = [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]) {
1292
+ return { type: "Feature", geometry: { type: "Polygon", coordinates: a }, properties: {} };
1293
+ }([[...i.slice(0, -1), [t.lng, t.lat], i[0]]]);
1294
+ if (!this.updatePolygonGeometry(r.geometry.coordinates[0], C.Commit)) return;
1295
+ this.currentCoordinate++, this.closingPoints.ids.length && this.closingPoints.update(r.geometry.coordinates[0]);
1296
+ }
1297
+ }
1298
+ }
1299
+ onKeyUp(t) {
1300
+ t.key === this.keyEvents.cancel ? this.cleanUp() : t.key === this.keyEvents.finish && this.close();
1301
+ }
1302
+ onKeyDown() {
1303
+ }
1304
+ onDragStart() {
1305
+ this.setCursor("unset");
1306
+ }
1307
+ onDrag() {
1308
+ }
1309
+ onDragEnd() {
1310
+ this.setCursor(this.cursors.start);
1311
+ }
1312
+ cleanUp() {
1313
+ const t = this.currentId;
1314
+ this.currentId = void 0, this.currentCoordinate = 0, this.state === "drawing" && this.setStarted();
1315
+ try {
1316
+ t !== void 0 && this.store.delete([t]), this.closingPoints.ids.length && this.closingPoints.delete();
1317
+ } catch {
1318
+ }
1319
+ }
1320
+ styleFeature(t) {
1321
+ const e = f({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1322
+ if (t.properties.mode === this.mode) {
1323
+ if (t.geometry.type === "Polygon") return e.polygonFillColor = this.getHexColorStylingValue(this.styles.fillColor, e.polygonFillColor, t), e.polygonOutlineColor = this.getHexColorStylingValue(this.styles.outlineColor, e.polygonOutlineColor, t), e.polygonOutlineWidth = this.getNumericStylingValue(this.styles.outlineWidth, e.polygonOutlineWidth, t), e.polygonFillOpacity = this.getNumericStylingValue(this.styles.fillOpacity, e.polygonFillOpacity, t), e.zIndex = 10, e;
1324
+ if (t.geometry.type === "Point") return e.pointWidth = this.getNumericStylingValue(this.styles.closingPointWidth, e.pointWidth, t), e.pointColor = this.getHexColorStylingValue(this.styles.closingPointColor, e.pointColor, t), e.pointOutlineColor = this.getHexColorStylingValue(this.styles.closingPointOutlineColor, e.pointOutlineColor, t), e.pointOutlineWidth = this.getNumericStylingValue(this.styles.closingPointOutlineWidth, 2, t), e.zIndex = 30, e;
1325
+ }
1326
+ return e;
1327
+ }
1328
+ validateFeature(t) {
1329
+ return !!super.validateFeature(t) && t.properties.mode === this.mode && ut(t, this.coordinatePrecision);
1330
+ }
1331
+ }
1332
+ class Be extends j {
1333
+ constructor(t) {
1334
+ super(t), this.mode = "rectangle", this.center = void 0, this.clickCount = 0, this.currentRectangleId = void 0, this.keyEvents = void 0, this.cursors = void 0;
1335
+ const e = { start: "crosshair" };
1336
+ if (this.cursors = t && t.cursors ? f({}, e, t.cursors) : e, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
1337
+ else {
1338
+ const i = { cancel: "Escape", finish: "Enter" };
1339
+ this.keyEvents = t && t.keyEvents ? f({}, i, t.keyEvents) : i;
1340
+ }
1341
+ }
1342
+ updateRectangle(t, e) {
1343
+ if (this.clickCount === 1 && this.center && this.currentRectangleId) {
1344
+ const i = this.store.getGeometryCopy(this.currentRectangleId).coordinates[0][0], o = { type: "Polygon", coordinates: [[i, [t.lng, i[1]], [t.lng, t.lat], [i[0], t.lat], i]] };
1345
+ if (this.validate && !this.validate({ id: this.currentRectangleId, geometry: o }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: e })) return;
1346
+ this.store.updateGeometry([{ id: this.currentRectangleId, geometry: o }]);
1347
+ }
1348
+ }
1349
+ close() {
1350
+ const t = this.currentRectangleId;
1351
+ this.center = void 0, this.currentRectangleId = void 0, this.clickCount = 0, this.state === "drawing" && this.setStarted(), t && this.onFinish(t, { mode: this.mode, action: "draw" });
1352
+ }
1353
+ start() {
1354
+ this.setStarted(), this.setCursor(this.cursors.start);
1355
+ }
1356
+ stop() {
1357
+ this.cleanUp(), this.setStopped(), this.setCursor("unset");
1358
+ }
1359
+ onClick(t) {
1360
+ if (this.clickCount === 0) {
1361
+ this.center = [t.lng, t.lat];
1362
+ const [e] = this.store.create([{ geometry: { type: "Polygon", coordinates: [[[t.lng, t.lat], [t.lng, t.lat], [t.lng, t.lat], [t.lng, t.lat]]] }, properties: { mode: this.mode } }]);
1363
+ this.currentRectangleId = e, this.clickCount++, this.setDrawing();
1364
+ } else this.updateRectangle(t, C.Finish), this.close();
1365
+ }
1366
+ onMouseMove(t) {
1367
+ this.updateRectangle(t, C.Provisional);
1368
+ }
1369
+ onKeyDown() {
1370
+ }
1371
+ onKeyUp(t) {
1372
+ t.key === this.keyEvents.cancel ? this.cleanUp() : t.key === this.keyEvents.finish && this.close();
1373
+ }
1374
+ onDragStart() {
1375
+ }
1376
+ onDrag() {
1377
+ }
1378
+ onDragEnd() {
1379
+ }
1380
+ cleanUp() {
1381
+ const t = this.currentRectangleId;
1382
+ this.center = void 0, this.currentRectangleId = void 0, this.clickCount = 0, this.state === "drawing" && this.setStarted(), t !== void 0 && this.store.delete([t]);
1383
+ }
1384
+ styleFeature(t) {
1385
+ const e = f({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1386
+ return t.type === "Feature" && t.geometry.type === "Polygon" && t.properties.mode === this.mode && (e.polygonFillColor = this.getHexColorStylingValue(this.styles.fillColor, e.polygonFillColor, t), e.polygonOutlineColor = this.getHexColorStylingValue(this.styles.outlineColor, e.polygonOutlineColor, t), e.polygonOutlineWidth = this.getNumericStylingValue(this.styles.outlineWidth, e.polygonOutlineWidth, t), e.polygonFillOpacity = this.getNumericStylingValue(this.styles.fillOpacity, e.polygonFillOpacity, t), e.zIndex = 10), e;
1387
+ }
1388
+ validateFeature(t) {
1389
+ return !!super.validateFeature(t) && t.properties.mode === this.mode && ie(t, this.coordinatePrecision);
1390
+ }
1391
+ }
1392
+ function ht(s, t) {
1393
+ const e = s, i = t, o = S(e[1]), n = S(i[1]);
1394
+ let r = S(i[0] - e[0]);
1395
+ r > Math.PI && (r -= 2 * Math.PI), r < -Math.PI && (r += 2 * Math.PI);
1396
+ const a = Math.log(Math.tan(n / 2 + Math.PI / 4) / Math.tan(o / 2 + Math.PI / 4)), l = (X(Math.atan2(r, a)) + 360) % 360;
1397
+ return l > 180 ? -(360 - l) : l;
1398
+ }
1399
+ function Et(s, t, e) {
1400
+ let i = t;
1401
+ t < 0 && (i = -Math.abs(i));
1402
+ const o = i / Pt, n = s[0] * Math.PI / 180, r = S(s[1]), a = S(e), l = o * Math.cos(a);
1403
+ let d = r + l;
1404
+ Math.abs(d) > Math.PI / 2 && (d = d > 0 ? Math.PI - d : -Math.PI - d);
1405
+ const h = Math.log(Math.tan(d / 2 + Math.PI / 4) / Math.tan(r / 2 + Math.PI / 4)), c = Math.abs(h) > 1e-11 ? l / h : Math.cos(r), u = [(180 * (n + o * Math.sin(a) / c) / Math.PI + 540) % 360 - 180, 180 * d / Math.PI];
1406
+ return u[0] += u[0] - s[0] > 180 ? -360 : s[0] - u[0] > 180 ? 360 : 0, u;
1407
+ }
1408
+ function ne(s, t, e, i, o) {
1409
+ const n = i(s[0], s[1]), r = i(t[0], t[1]), { lng: a, lat: l } = o((n.x + r.x) / 2, (n.y + r.y) / 2);
1410
+ return [b(a, e), b(l, e)];
1411
+ }
1412
+ function We(s, t, e) {
1413
+ const i = Et(s, 1e3 * B(s, t) / 2, ht(s, t));
1414
+ return [b(i[0], e), b(i[1], e)];
1415
+ }
1416
+ function zt({ featureCoords: s, precision: t, unproject: e, project: i, projection: o }) {
1417
+ const n = [];
1418
+ for (let r = 0; r < s.length - 1; r++) {
1419
+ let a;
1420
+ if (o === "web-mercator") a = ne(s[r], s[r + 1], t, i, e);
1421
+ else {
1422
+ if (o !== "globe") throw new Error("Invalid projection");
1423
+ a = We(s[r], s[r + 1], t);
1424
+ }
1425
+ n.push(a);
1426
+ }
1427
+ return n;
1428
+ }
1429
+ class Ge extends D {
1430
+ constructor(t, e) {
1431
+ super(t), this.config = void 0, this.selectionPointBehavior = void 0, this._midPoints = [], this.config = t, this.selectionPointBehavior = e;
1432
+ }
1433
+ get ids() {
1434
+ return this._midPoints.concat();
1435
+ }
1436
+ set ids(t) {
1437
+ }
1438
+ insert(t, e) {
1439
+ const i = this.store.getGeometryCopy(t), { midPointFeatureId: o, midPointSegment: n } = this.store.getPropertiesCopy(t), r = this.store.getGeometryCopy(o), a = r.type === "Polygon" ? r.coordinates[0] : r.coordinates;
1440
+ a.splice(n + 1, 0, i.coordinates), r.coordinates = r.type === "Polygon" ? [a] : a, this.store.updateGeometry([{ id: o, geometry: r }]), this.store.delete([...this._midPoints, ...this.selectionPointBehavior.ids]), this.create(a, o, e), this.selectionPointBehavior.create(a, r.type, o);
1441
+ }
1442
+ create(t, e, i) {
1443
+ if (!this.store.has(e)) throw new Error("Store does not have feature with this id");
1444
+ this._midPoints = this.store.create(function(o, n, r, a, l, d) {
1445
+ return zt({ featureCoords: o, precision: r, project: a, unproject: l, projection: d }).map((h, c) => ({ geometry: { type: "Point", coordinates: h }, properties: n(c) }));
1446
+ }(t, (o) => ({ mode: this.mode, [H]: !0, midPointSegment: o, midPointFeatureId: e }), i, this.config.project, this.config.unproject, this.projection));
1447
+ }
1448
+ delete() {
1449
+ this._midPoints.length && (this.store.delete(this._midPoints), this._midPoints = []);
1450
+ }
1451
+ getUpdated(t) {
1452
+ if (this._midPoints.length !== 0) return zt({ featureCoords: t, precision: this.coordinatePrecision, project: this.config.project, unproject: this.config.unproject, projection: this.config.projection }).map((e, i) => ({ id: this._midPoints[i], geometry: { type: "Point", coordinates: e } }));
1453
+ }
1454
+ }
1455
+ class Ne extends D {
1456
+ constructor(t) {
1457
+ super(t), this._selectionPoints = [];
1458
+ }
1459
+ get ids() {
1460
+ return this._selectionPoints.concat();
1461
+ }
1462
+ set ids(t) {
1463
+ }
1464
+ create(t, e, i) {
1465
+ this._selectionPoints = this.store.create(function(o, n, r) {
1466
+ const a = [], l = n === "Polygon" ? o.length - 1 : o.length;
1467
+ for (let d = 0; d < l; d++) a.push({ geometry: { type: "Point", coordinates: o[d] }, properties: r(d) });
1468
+ return a;
1469
+ }(t, e, (o) => ({ mode: this.mode, selectionPoint: !0, selectionPointFeatureId: i, index: o })));
1470
+ }
1471
+ delete() {
1472
+ this.ids.length && (this.store.delete(this.ids), this._selectionPoints = []);
1473
+ }
1474
+ getUpdated(t) {
1475
+ if (this._selectionPoints.length !== 0) return this._selectionPoints.map((e, i) => ({ id: e, geometry: { type: "Point", coordinates: t[i] } }));
1476
+ }
1477
+ getOneUpdated(t, e) {
1478
+ if (this._selectionPoints[t] !== void 0) return { id: this._selectionPoints[t], geometry: { type: "Point", coordinates: e } };
1479
+ }
1480
+ }
1481
+ function re(s, t) {
1482
+ let e = !1;
1483
+ for (let r = 0, a = t.length; r < a; r++) {
1484
+ const l = t[r];
1485
+ for (let d = 0, h = l.length, c = h - 1; d < h; c = d++) (o = l[d])[1] > (i = s)[1] != (n = l[c])[1] > i[1] && i[0] < (n[0] - o[0]) * (i[1] - o[1]) / (n[1] - o[1]) + o[0] && (e = !e);
1486
+ }
1487
+ var i, o, n;
1488
+ return e;
1489
+ }
1490
+ const ae = (s, t, e) => {
1491
+ const i = (n) => n * n, o = (n, r) => i(n.x - r.x) + i(n.y - r.y);
1492
+ return Math.sqrt(((n, r, a) => {
1493
+ const l = o(r, a);
1494
+ if (l === 0) return o(n, r);
1495
+ let d = ((n.x - r.x) * (a.x - r.x) + (n.y - r.y) * (a.y - r.y)) / l;
1496
+ return d = Math.max(0, Math.min(1, d)), o(n, { x: r.x + d * (a.x - r.x), y: r.y + d * (a.y - r.y) });
1497
+ })(s, t, e));
1498
+ };
1499
+ class Ae extends D {
1500
+ constructor(t, e, i) {
1501
+ super(t), this.config = void 0, this.createClickBoundingBox = void 0, this.pixelDistance = void 0, this.config = t, this.createClickBoundingBox = e, this.pixelDistance = i;
1502
+ }
1503
+ find(t, e) {
1504
+ let i, o, n = 1 / 0, r = 1 / 0;
1505
+ const a = this.createClickBoundingBox.create(t), l = this.store.search(a);
1506
+ for (let d = 0; d < l.length; d++) {
1507
+ const h = l[d], c = h.geometry;
1508
+ if (c.type === "Point") {
1509
+ if (h.properties.selectionPoint || !e && h.properties[H]) continue;
1510
+ const u = this.pixelDistance.measure(t, c.coordinates);
1511
+ h.properties[H] && u < this.pointerDistance && u < r ? (r = u, o = h) : !h.properties[H] && u < this.pointerDistance && u < n && (n = u, i = h);
1512
+ } else if (c.type === "LineString") for (let u = 0; u < c.coordinates.length - 1; u++) {
1513
+ const g = c.coordinates[u], p = c.coordinates[u + 1], y = ae({ x: t.containerX, y: t.containerY }, this.project(g[0], g[1]), this.project(p[0], p[1]));
1514
+ y < this.pointerDistance && y < n && (n = y, i = h);
1515
+ }
1516
+ else c.type === "Polygon" && re([t.lng, t.lat], c.coordinates) && (n = 0, i = h);
1517
+ }
1518
+ return { clickedFeature: i, clickedMidPoint: o };
1519
+ }
1520
+ }
1521
+ class Re extends D {
1522
+ constructor(t, e, i, o) {
1523
+ super(t), this.config = void 0, this.featuresAtMouseEvent = void 0, this.selectionPoints = void 0, this.midPoints = void 0, this.draggedFeatureId = null, this.dragPosition = void 0, this.config = t, this.featuresAtMouseEvent = e, this.selectionPoints = i, this.midPoints = o;
1524
+ }
1525
+ startDragging(t, e) {
1526
+ this.draggedFeatureId = e, this.dragPosition = [t.lng, t.lat];
1527
+ }
1528
+ stopDragging() {
1529
+ this.draggedFeatureId = null, this.dragPosition = void 0;
1530
+ }
1531
+ isDragging() {
1532
+ return this.draggedFeatureId !== null;
1533
+ }
1534
+ canDrag(t, e) {
1535
+ const { clickedFeature: i } = this.featuresAtMouseEvent.find(t, !0);
1536
+ return !(!i || i.id !== e);
1537
+ }
1538
+ drag(t, e) {
1539
+ if (!this.draggedFeatureId) return;
1540
+ const i = this.store.getGeometryCopy(this.draggedFeatureId), o = [t.lng, t.lat];
1541
+ if (i.type === "Polygon" || i.type === "LineString") {
1542
+ let n, r;
1543
+ if (i.type === "Polygon" ? (n = i.coordinates[0], r = n.length - 1) : (n = i.coordinates, r = n.length), !this.dragPosition) return !1;
1544
+ for (let d = 0; d < r; d++) {
1545
+ const h = n[d], c = [this.dragPosition[0] - o[0], this.dragPosition[1] - o[1]], u = b(h[0] - c[0], this.config.coordinatePrecision), g = b(h[1] - c[1], this.config.coordinatePrecision);
1546
+ if (u > 180 || u < -180 || g > 90 || g < -90) return !1;
1547
+ n[d] = [u, g];
1548
+ }
1549
+ i.type === "Polygon" && (n[n.length - 1] = [n[0][0], n[0][1]]);
1550
+ const a = this.selectionPoints.getUpdated(n) || [], l = this.midPoints.getUpdated(n) || [];
1551
+ if (e && !e({ type: "Feature", id: this.draggedFeatureId, geometry: i, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: C.Provisional })) return !1;
1552
+ this.store.updateGeometry([{ id: this.draggedFeatureId, geometry: i }, ...a, ...l]), this.dragPosition = [t.lng, t.lat];
1553
+ } else i.type === "Point" && (this.store.updateGeometry([{ id: this.draggedFeatureId, geometry: { type: "Point", coordinates: o } }]), this.dragPosition = [t.lng, t.lat]);
1554
+ }
1555
+ }
1556
+ class Ve extends D {
1557
+ constructor(t, e, i, o) {
1558
+ super(t), this.config = void 0, this.pixelDistance = void 0, this.selectionPoints = void 0, this.midPoints = void 0, this.draggedCoordinate = { id: null, index: -1 }, this.config = t, this.pixelDistance = e, this.selectionPoints = i, this.midPoints = o;
1559
+ }
1560
+ getClosestCoordinate(t, e) {
1561
+ const i = { dist: 1 / 0, index: -1, isFirstOrLastPolygonCoord: !1 };
1562
+ let o;
1563
+ if (e.type === "LineString") o = e.coordinates;
1564
+ else {
1565
+ if (e.type !== "Polygon") return i;
1566
+ o = e.coordinates[0];
1567
+ }
1568
+ for (let n = 0; n < o.length; n++) {
1569
+ const r = this.pixelDistance.measure(t, o[n]);
1570
+ if (r < this.pointerDistance && r < i.dist) {
1571
+ const a = e.type === "Polygon" && (n === o.length - 1 || n === 0);
1572
+ i.dist = r, i.index = a ? 0 : n, i.isFirstOrLastPolygonCoord = a;
1573
+ }
1574
+ }
1575
+ return i;
1576
+ }
1577
+ getDraggableIndex(t, e) {
1578
+ const i = this.store.getGeometryCopy(e), o = this.getClosestCoordinate(t, i);
1579
+ return o.index === -1 ? -1 : o.index;
1580
+ }
1581
+ drag(t, e, i) {
1582
+ if (!this.draggedCoordinate.id) return !1;
1583
+ const o = this.draggedCoordinate.index, n = this.store.getGeometryCopy(this.draggedCoordinate.id), r = n.type === "LineString" ? n.coordinates : n.coordinates[0], a = [t.lng, t.lat];
1584
+ if (t.lng > 180 || t.lng < -180 || t.lat > 90 || t.lat < -90) return !1;
1585
+ if (n.type !== "Polygon" || o !== r.length - 1 && o !== 0) r[o] = a;
1586
+ else {
1587
+ const c = r.length - 1;
1588
+ r[0] = a, r[c] = a;
1589
+ }
1590
+ const l = this.selectionPoints.getOneUpdated(o, a), d = l ? [l] : [], h = this.midPoints.getUpdated(r) || [];
1591
+ return !(n.type !== "Point" && !e && Mt({ type: "Feature", geometry: n, properties: {} }) || i && !i({ type: "Feature", id: this.draggedCoordinate.id, geometry: n, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: C.Provisional }) || (this.store.updateGeometry([{ id: this.draggedCoordinate.id, geometry: n }, ...d, ...h]), 0));
1592
+ }
1593
+ isDragging() {
1594
+ return this.draggedCoordinate.id !== null;
1595
+ }
1596
+ startDragging(t, e) {
1597
+ this.draggedCoordinate = { id: t, index: e };
1598
+ }
1599
+ stopDragging() {
1600
+ this.draggedCoordinate = { id: null, index: -1 };
1601
+ }
1602
+ }
1603
+ function dt(s) {
1604
+ let t = 0, e = 0, i = 0;
1605
+ return (s.geometry.type === "Polygon" ? s.geometry.coordinates[0].slice(0, -1) : s.geometry.coordinates).forEach((o) => {
1606
+ t += o[0], e += o[1], i++;
1607
+ }, !0), [t / i, e / i];
1608
+ }
1609
+ function le(s, t) {
1610
+ s[0] += s[0] - t[0] > 180 ? -360 : t[0] - s[0] > 180 ? 360 : 0;
1611
+ const e = Pt, i = t[1] * Math.PI / 180, o = s[1] * Math.PI / 180, n = o - i;
1612
+ let r = Math.abs(s[0] - t[0]) * Math.PI / 180;
1613
+ r > Math.PI && (r -= 2 * Math.PI);
1614
+ const a = Math.log(Math.tan(o / 2 + Math.PI / 4) / Math.tan(i / 2 + Math.PI / 4)), l = Math.abs(a) > 1e-11 ? n / a : Math.cos(i);
1615
+ return Math.sqrt(n * n + l * l * r * r) * e;
1616
+ }
1617
+ function ct(s) {
1618
+ const t = (s.geometry.type === "Polygon" ? s.geometry.coordinates[0] : s.geometry.coordinates).map((e) => {
1619
+ const { x: i, y: o } = P(e[0], e[1]);
1620
+ return [i, o];
1621
+ });
1622
+ return s.geometry.type === "Polygon" ? function(e) {
1623
+ let i = 0, o = 0, n = 0;
1624
+ const r = e.length;
1625
+ for (let a = 0; a < r - 1; a++) {
1626
+ const [l, d] = e[a], [h, c] = e[a + 1], u = l * c - h * d;
1627
+ i += u, o += (l + h) * u, n += (d + c) * u;
1628
+ }
1629
+ return i /= 2, o /= 6 * i, n /= 6 * i, { x: o, y: n };
1630
+ }(t) : function(e) {
1631
+ const i = e.length;
1632
+ let o = 0, n = 0;
1633
+ for (let r = 0; r < i; r++) {
1634
+ const [a, l] = e[r];
1635
+ o += a, n += l;
1636
+ }
1637
+ return { x: o / i, y: n / i };
1638
+ }(t);
1639
+ }
1640
+ class Te extends D {
1641
+ constructor(t, e, i) {
1642
+ super(t), this.config = void 0, this.selectionPoints = void 0, this.midPoints = void 0, this.lastBearing = void 0, this.config = t, this.selectionPoints = e, this.midPoints = i;
1643
+ }
1644
+ reset() {
1645
+ this.lastBearing = void 0;
1646
+ }
1647
+ rotate(t, e, i) {
1648
+ const o = this.store.getGeometryCopy(e);
1649
+ if (o.type !== "Polygon" && o.type !== "LineString") return;
1650
+ const n = [t.lng, t.lat];
1651
+ let r;
1652
+ const a = { type: "Feature", geometry: o, properties: {} };
1653
+ if (this.config.projection === "web-mercator") {
1654
+ if (r = lt(ct(a), P(t.lng, t.lat)), !this.lastBearing) return void (this.lastBearing = r);
1655
+ ((c, u) => {
1656
+ if (u === 0 || u === 360 || u === -360) return c;
1657
+ const g = 0.017453292519943295 * u, p = (c.geometry.type === "Polygon" ? c.geometry.coordinates[0] : c.geometry.coordinates).map(([m, x]) => P(m, x)), y = p.reduce((m, x) => ({ x: m.x + x.x, y: m.y + x.y }), { x: 0, y: 0 });
1658
+ y.x /= p.length, y.y /= p.length;
1659
+ const v = p.map((m) => ({ x: y.x + (m.x - y.x) * Math.cos(g) - (m.y - y.y) * Math.sin(g), y: y.y + (m.x - y.x) * Math.sin(g) + (m.y - y.y) * Math.cos(g) })).map(({ x: m, y: x }) => [O(m, x).lng, O(m, x).lat]);
1660
+ c.geometry.type === "Polygon" ? c.geometry.coordinates[0] = v : (console.log("rotatedCoordinates linestring", v), c.geometry.coordinates = v);
1661
+ })(a, -(this.lastBearing - r));
1662
+ } else {
1663
+ if (this.config.projection !== "globe") throw new Error("Unsupported projection");
1664
+ if (r = ht(dt({ type: "Feature", geometry: o, properties: {} }), n), !this.lastBearing) return void (this.lastBearing = r + 180);
1665
+ (function(c, u) {
1666
+ if (u === 0 || u === 360 || u === -360) return c;
1667
+ const g = dt(c);
1668
+ (c.geometry.type === "Polygon" ? c.geometry.coordinates[0] : c.geometry.coordinates).forEach((p) => {
1669
+ const y = ht(g, p) + u, v = le(g, p), m = Et(g, v, y);
1670
+ p[0] = m[0], p[1] = m[1];
1671
+ });
1672
+ })(a, -(this.lastBearing - (r + 180)));
1673
+ }
1674
+ const l = o.type === "Polygon" ? o.coordinates[0] : o.coordinates;
1675
+ l.forEach((c) => {
1676
+ c[0] = b(c[0], this.coordinatePrecision), c[1] = b(c[1], this.coordinatePrecision);
1677
+ });
1678
+ const d = this.midPoints.getUpdated(l) || [], h = this.selectionPoints.getUpdated(l) || [];
1679
+ if (i && !i({ id: e, type: "Feature", geometry: o, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: C.Provisional })) return !1;
1680
+ this.store.updateGeometry([{ id: e, geometry: o }, ...h, ...d]), this.projection === "web-mercator" ? this.lastBearing = r : this.projection === "globe" && (this.lastBearing = r + 180);
1681
+ }
1682
+ }
1683
+ class Ue extends D {
1684
+ constructor(t, e, i) {
1685
+ super(t), this.config = void 0, this.selectionPoints = void 0, this.midPoints = void 0, this.lastDistance = void 0, this.config = t, this.selectionPoints = e, this.midPoints = i;
1686
+ }
1687
+ reset() {
1688
+ this.lastDistance = void 0;
1689
+ }
1690
+ scale(t, e, i) {
1691
+ const o = this.store.getGeometryCopy(e);
1692
+ if (o.type !== "Polygon" && o.type !== "LineString") return;
1693
+ const n = [t.lng, t.lat], r = { type: "Feature", geometry: o, properties: {} };
1694
+ let a;
1695
+ const l = ct(r);
1696
+ if (this.config.projection === "web-mercator") {
1697
+ const g = P(t.lng, t.lat);
1698
+ a = I(l, g);
1699
+ } else {
1700
+ if (this.config.projection !== "globe") throw new Error("Invalid projection");
1701
+ a = B(dt({ type: "Feature", geometry: o, properties: {} }), n);
1702
+ }
1703
+ if (!this.lastDistance) return void (this.lastDistance = a);
1704
+ const d = 1 - (this.lastDistance - a) / a;
1705
+ if (this.config.projection === "web-mercator") {
1706
+ const { lng: g, lat: p } = O(l.x, l.y);
1707
+ (function(y, v, m) {
1708
+ if (v === 1) return y;
1709
+ const x = (y.geometry.type === "Polygon" ? y.geometry.coordinates[0] : y.geometry.coordinates).map(([_, w]) => P(_, w)), M = P(m[0], m[1]), E = x.map((_) => ({ x: M.x + (_.x - M.x) * v, y: M.y + (_.y - M.y) * v })).map(({ x: _, y: w }) => [O(_, w).lng, O(_, w).lat]);
1710
+ y.geometry.type === "Polygon" ? y.geometry.coordinates[0] = E : y.geometry.coordinates = E;
1711
+ })(r, d, [g, p]);
1712
+ } else this.config.projection === "globe" && function(g, p, y, v = "xy") {
1713
+ p === 1 || (g.geometry.type === "Polygon" ? g.geometry.coordinates[0] : g.geometry.coordinates).forEach((m) => {
1714
+ const x = le(y, m), M = ht(y, m), E = Et(y, x * p, M);
1715
+ v !== "x" && v !== "xy" || (m[0] = E[0]), v !== "y" && v !== "xy" || (m[1] = E[1]);
1716
+ });
1717
+ }(r, d, dt(r));
1718
+ const h = o.type === "Polygon" ? o.coordinates[0] : o.coordinates;
1719
+ h.forEach((g) => {
1720
+ g[0] = b(g[0], this.coordinatePrecision), g[1] = b(g[1], this.coordinatePrecision);
1721
+ });
1722
+ const c = this.midPoints.getUpdated(h) || [], u = this.selectionPoints.getUpdated(h) || [];
1723
+ if (i && !i({ id: e, type: "Feature", geometry: o, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: C.Provisional })) return !1;
1724
+ this.store.updateGeometry([{ id: e, geometry: o }, ...u, ...c]), this.lastDistance = a;
1725
+ }
1726
+ }
1727
+ class Xe extends D {
1728
+ constructor(t, e, i, o) {
1729
+ super(t), this.config = void 0, this.pixelDistance = void 0, this.selectionPoints = void 0, this.midPoints = void 0, this.minimumScale = 1e-4, this.draggedCoordinate = { id: null, index: -1 }, this.boundingBoxMaps = { opposite: { 0: 4, 1: 5, 2: 6, 3: 7, 4: 0, 5: 1, 6: 2, 7: 3 } }, this.config = t, this.pixelDistance = e, this.selectionPoints = i, this.midPoints = o;
1730
+ }
1731
+ getClosestCoordinate(t, e) {
1732
+ const i = { dist: 1 / 0, index: -1, isFirstOrLastPolygonCoord: !1 };
1733
+ let o;
1734
+ if (e.type === "LineString") o = e.coordinates;
1735
+ else {
1736
+ if (e.type !== "Polygon") return i;
1737
+ o = e.coordinates[0];
1738
+ }
1739
+ for (let n = 0; n < o.length; n++) {
1740
+ const r = this.pixelDistance.measure(t, o[n]);
1741
+ if (r < this.pointerDistance && r < i.dist) {
1742
+ const a = e.type === "Polygon" && (n === o.length - 1 || n === 0);
1743
+ i.dist = r, i.index = a ? 0 : n, i.isFirstOrLastPolygonCoord = a;
1744
+ }
1745
+ }
1746
+ return i;
1747
+ }
1748
+ isValidDragWebMercator(t, e, i) {
1749
+ switch (t) {
1750
+ case 0:
1751
+ if (e <= 0 || i >= 0) return !1;
1752
+ break;
1753
+ case 1:
1754
+ if (i >= 0) return !1;
1755
+ break;
1756
+ case 2:
1757
+ if (e >= 0 || i >= 0) return !1;
1758
+ break;
1759
+ case 3:
1760
+ if (e >= 0) return !1;
1761
+ break;
1762
+ case 4:
1763
+ if (e >= 0 || i <= 0) return !1;
1764
+ break;
1765
+ case 5:
1766
+ if (i <= 0) return !1;
1767
+ break;
1768
+ case 6:
1769
+ if (e <= 0 || i <= 0) return !1;
1770
+ break;
1771
+ case 7:
1772
+ if (e <= 0) return !1;
1773
+ }
1774
+ return !0;
1775
+ }
1776
+ getSelectedFeatureDataWebMercator() {
1777
+ if (!this.draggedCoordinate.id || this.draggedCoordinate.index === -1) return null;
1778
+ const t = this.getFeature(this.draggedCoordinate.id);
1779
+ if (!t) return null;
1780
+ const e = this.getNormalisedCoordinates(t.geometry);
1781
+ return { boundingBox: this.getBBoxWebMercator(e), feature: t, updatedCoords: e, selectedCoordinate: e[this.draggedCoordinate.index] };
1782
+ }
1783
+ centerWebMercatorDrag(t) {
1784
+ const e = this.getSelectedFeatureDataWebMercator();
1785
+ if (!e) return null;
1786
+ const { feature: i, boundingBox: o, updatedCoords: n, selectedCoordinate: r } = e, a = ct(i);
1787
+ if (!a) return null;
1788
+ const l = P(r[0], r[1]), { closestBBoxIndex: d } = this.getIndexesWebMercator(o, l), h = P(t.lng, t.lat);
1789
+ return this.scaleWebMercator({ closestBBoxIndex: d, updatedCoords: n, webMercatorCursor: h, webMercatorSelected: l, webMercatorOrigin: a }), n;
1790
+ }
1791
+ centerFixedWebMercatorDrag(t) {
1792
+ const e = this.getSelectedFeatureDataWebMercator();
1793
+ if (!e) return null;
1794
+ const { feature: i, boundingBox: o, updatedCoords: n, selectedCoordinate: r } = e, a = ct(i);
1795
+ if (!a) return null;
1796
+ const l = P(r[0], r[1]), { closestBBoxIndex: d } = this.getIndexesWebMercator(o, l), h = P(t.lng, t.lat);
1797
+ return this.scaleFixedWebMercator({ closestBBoxIndex: d, updatedCoords: n, webMercatorCursor: h, webMercatorSelected: l, webMercatorOrigin: a }), n;
1798
+ }
1799
+ scaleFixedWebMercator({ closestBBoxIndex: t, webMercatorOrigin: e, webMercatorSelected: i, webMercatorCursor: o, updatedCoords: n }) {
1800
+ if (!this.isValidDragWebMercator(t, e.x - o.x, e.y - o.y)) return null;
1801
+ let r = I(e, o) / I(e, i);
1802
+ return r < 0 && (r = this.minimumScale), this.performWebMercatorScale(n, e.x, e.y, r, r), n;
1803
+ }
1804
+ oppositeFixedWebMercatorDrag(t) {
1805
+ const e = this.getSelectedFeatureDataWebMercator();
1806
+ if (!e) return null;
1807
+ const { boundingBox: i, updatedCoords: o, selectedCoordinate: n } = e, r = P(n[0], n[1]), { oppositeBboxIndex: a, closestBBoxIndex: l } = this.getIndexesWebMercator(i, r), d = { x: i[a][0], y: i[a][1] }, h = P(t.lng, t.lat);
1808
+ return this.scaleFixedWebMercator({ closestBBoxIndex: l, updatedCoords: o, webMercatorCursor: h, webMercatorSelected: r, webMercatorOrigin: d }), o;
1809
+ }
1810
+ oppositeWebMercatorDrag(t) {
1811
+ const e = this.getSelectedFeatureDataWebMercator();
1812
+ if (!e) return null;
1813
+ const { boundingBox: i, updatedCoords: o, selectedCoordinate: n } = e, r = P(n[0], n[1]), { oppositeBboxIndex: a, closestBBoxIndex: l } = this.getIndexesWebMercator(i, r), d = { x: i[a][0], y: i[a][1] }, h = P(t.lng, t.lat);
1814
+ return this.scaleWebMercator({ closestBBoxIndex: l, updatedCoords: o, webMercatorCursor: h, webMercatorSelected: r, webMercatorOrigin: d }), o;
1815
+ }
1816
+ scaleWebMercator({ closestBBoxIndex: t, webMercatorOrigin: e, webMercatorSelected: i, webMercatorCursor: o, updatedCoords: n }) {
1817
+ const r = e.x - o.x, a = e.y - o.y;
1818
+ if (!this.isValidDragWebMercator(t, r, a)) return null;
1819
+ let l = 1;
1820
+ r !== 0 && t !== 1 && t !== 5 && (l = 1 - (e.x - i.x - r) / r);
1821
+ let d = 1;
1822
+ return a !== 0 && t !== 3 && t !== 7 && (d = 1 - (e.y - i.y - a) / a), this.validateScale(l, d) ? (l < 0 && (l = this.minimumScale), d < 0 && (d = this.minimumScale), this.performWebMercatorScale(n, e.x, e.y, l, d), n) : null;
1823
+ }
1824
+ getFeature(t) {
1825
+ if (this.draggedCoordinate.id === null) return null;
1826
+ const e = this.store.getGeometryCopy(t);
1827
+ return e.type !== "Polygon" && e.type !== "LineString" ? null : { type: "Feature", geometry: e, properties: {} };
1828
+ }
1829
+ getNormalisedCoordinates(t) {
1830
+ return t.type === "Polygon" ? t.coordinates[0] : t.coordinates;
1831
+ }
1832
+ validateScale(t, e) {
1833
+ const i = !isNaN(t) && e < Number.MAX_SAFE_INTEGER, o = !isNaN(e) && e < Number.MAX_SAFE_INTEGER;
1834
+ return i && o;
1835
+ }
1836
+ performWebMercatorScale(t, e, i, o, n) {
1837
+ t.forEach((r) => {
1838
+ const { x: a, y: l } = P(r[0], r[1]), d = e + (a - e) * o, h = i + (l - i) * n, { lng: c, lat: u } = O(d, h);
1839
+ r[0] = c, r[1] = u;
1840
+ });
1841
+ }
1842
+ getBBoxWebMercator(t) {
1843
+ const e = [1 / 0, 1 / 0, -1 / 0, -1 / 0];
1844
+ (t = t.map((a) => {
1845
+ const { x: l, y: d } = P(a[0], a[1]);
1846
+ return [l, d];
1847
+ })).forEach(([a, l]) => {
1848
+ a < e[0] && (e[0] = a), l < e[1] && (e[1] = l), a > e[2] && (e[2] = a), l > e[3] && (e[3] = l);
1849
+ });
1850
+ const [i, o, n, r] = e;
1851
+ return [[i, r], [(i + n) / 2, r], [n, r], [n, r + (o - r) / 2], [n, o], [(i + n) / 2, o], [i, o], [i, r + (o - r) / 2]];
1852
+ }
1853
+ getIndexesWebMercator(t, e) {
1854
+ let i, o = 1 / 0;
1855
+ for (let n = 0; n < t.length; n++) {
1856
+ const r = I({ x: e.x, y: e.y }, { x: t[n][0], y: t[n][1] });
1857
+ r < o && (i = n, o = r);
1858
+ }
1859
+ if (i === void 0) throw new Error("No closest coordinate found");
1860
+ return { oppositeBboxIndex: this.boundingBoxMaps.opposite[i], closestBBoxIndex: i };
1861
+ }
1862
+ isDragging() {
1863
+ return this.draggedCoordinate.id !== null;
1864
+ }
1865
+ startDragging(t, e) {
1866
+ this.draggedCoordinate = { id: t, index: e };
1867
+ }
1868
+ stopDragging() {
1869
+ this.draggedCoordinate = { id: null, index: -1 };
1870
+ }
1871
+ getDraggableIndex(t, e) {
1872
+ const i = this.store.getGeometryCopy(e), o = this.getClosestCoordinate(t, i);
1873
+ return o.index === -1 ? -1 : o.index;
1874
+ }
1875
+ drag(t, e, i) {
1876
+ if (!this.draggedCoordinate.id) return !1;
1877
+ const o = this.getFeature(this.draggedCoordinate.id);
1878
+ if (!o) return !1;
1879
+ let n = null;
1880
+ if (e === "center" ? n = this.centerWebMercatorDrag(t) : e === "opposite" ? n = this.oppositeWebMercatorDrag(t) : e === "center-fixed" ? n = this.centerFixedWebMercatorDrag(t) : e === "opposite-fixed" && (n = this.oppositeFixedWebMercatorDrag(t)), !n) return !1;
1881
+ for (let d = 0; d < n.length; d++) {
1882
+ const h = n[d];
1883
+ if (h[0] = b(h[0], this.coordinatePrecision), h[1] = b(h[1], this.coordinatePrecision), !_t(h, this.coordinatePrecision)) return !1;
1884
+ }
1885
+ const r = this.midPoints.getUpdated(n) || [], a = this.selectionPoints.getUpdated(n) || [], l = { type: o.geometry.type, coordinates: o.geometry.type === "Polygon" ? [n] : n };
1886
+ return !(i && !i({ id: this.draggedCoordinate.id, type: "Feature", geometry: l, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: C.Provisional }) || (this.store.updateGeometry([{ id: this.draggedCoordinate.id, geometry: l }, ...a, ...r]), 0));
1887
+ }
1888
+ }
1889
+ class Ke extends be {
1890
+ constructor(t) {
1891
+ var e;
1892
+ super(t), this.mode = "select", this.allowManualDeselection = !0, this.dragEventThrottle = 5, this.dragEventCount = 0, this.selected = [], this.flags = void 0, this.keyEvents = void 0, this.selectionPoints = void 0, this.midPoints = void 0, this.featuresAtMouseEvent = void 0, this.pixelDistance = void 0, this.clickBoundingBox = void 0, this.dragFeature = void 0, this.dragCoordinate = void 0, this.rotateFeature = void 0, this.scaleFeature = void 0, this.dragCoordinateResizeFeature = void 0, this.cursors = void 0, this.validations = {}, this.flags = t && t.flags ? t.flags : {};
1893
+ const i = { pointerOver: "move", dragStart: "move", dragEnd: "move", insertMidpoint: "crosshair" };
1894
+ if (this.cursors = t && t.cursors ? f({}, i, t.cursors) : i, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { deselect: null, delete: null, rotate: null, scale: null };
1895
+ else {
1896
+ const o = { deselect: "Escape", delete: "Delete", rotate: ["Control", "r"], scale: ["Control", "s"] };
1897
+ this.keyEvents = t && t.keyEvents ? f({}, o, t.keyEvents) : o;
1898
+ }
1899
+ if (this.dragEventThrottle = t && t.dragEventThrottle !== void 0 && t.dragEventThrottle || 5, this.allowManualDeselection = (e = t == null ? void 0 : t.allowManualDeselection) == null || e, t && t.flags && t.flags) for (const o in t.flags) {
1900
+ const n = t.flags[o].feature;
1901
+ n && n.validation && (this.validations[o] = n.validation);
1902
+ }
1903
+ }
1904
+ selectFeature(t) {
1905
+ this.select(t, !1);
1906
+ }
1907
+ setSelecting() {
1908
+ if (this._state !== "started") throw new Error("Mode must be started to move to selecting state");
1909
+ this._state = "selecting";
1910
+ }
1911
+ registerBehaviors(t) {
1912
+ this.pixelDistance = new gt(t), this.clickBoundingBox = new bt(t), this.featuresAtMouseEvent = new Ae(t, this.clickBoundingBox, this.pixelDistance), this.selectionPoints = new Ne(t), this.midPoints = new Ge(t, this.selectionPoints), this.rotateFeature = new Te(t, this.selectionPoints, this.midPoints), this.scaleFeature = new Ue(t, this.selectionPoints, this.midPoints), this.dragFeature = new Re(t, this.featuresAtMouseEvent, this.selectionPoints, this.midPoints), this.dragCoordinate = new Ve(t, this.pixelDistance, this.selectionPoints, this.midPoints), this.dragCoordinateResizeFeature = new Xe(t, this.pixelDistance, this.selectionPoints, this.midPoints);
1913
+ }
1914
+ deselectFeature() {
1915
+ this.deselect();
1916
+ }
1917
+ deselect() {
1918
+ const t = this.selected.filter((e) => this.store.has(e)).map((e) => ({ id: e, property: xt, value: !1 }));
1919
+ this.store.updateProperty(t), this.onDeselect(this.selected[0]), this.selected = [], this.selectionPoints.delete(), this.midPoints.delete();
1920
+ }
1921
+ deleteSelected() {
1922
+ this.store.delete(this.selected), this.selected = [];
1923
+ }
1924
+ onRightClick(t) {
1925
+ if (!this.selectionPoints.ids.length) return;
1926
+ let e, i = 1 / 0;
1927
+ if (this.selectionPoints.ids.forEach((c) => {
1928
+ const u = this.store.getGeometryCopy(c), g = this.pixelDistance.measure(t, u.coordinates);
1929
+ g < this.pointerDistance && g < i && (i = g, e = this.store.getPropertiesCopy(c));
1930
+ }), !e) return;
1931
+ const o = e.selectionPointFeatureId, n = e.index, r = this.store.getPropertiesCopy(o), a = this.flags[r.mode], l = this.validations[r.mode];
1932
+ if (!(a && a.feature && a.feature.coordinates && a.feature.coordinates.deletable)) return;
1933
+ const d = this.store.getGeometryCopy(o);
1934
+ let h;
1935
+ if (d.type === "Polygon") {
1936
+ if (h = d.coordinates[0], h.length <= 4) return;
1937
+ } else if (d.type === "LineString" && (h = d.coordinates, h.length <= 3)) return;
1938
+ if (h) {
1939
+ if (d.type === "Polygon" && n === 0 || n === h.length - 1 ? (h.shift(), h.pop(), h.push([h[0][0], h[0][1]])) : h.splice(n, 1), l && !l({ id: o, type: "Feature", geometry: d, properties: r }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: C.Commit })) return;
1940
+ this.store.delete([...this.midPoints.ids, ...this.selectionPoints.ids]), this.store.updateGeometry([{ id: o, geometry: d }]), this.selectionPoints.create(h, d.type, o), a && a.feature && a.feature.coordinates && a.feature.coordinates.midpoints && this.midPoints.create(h, o, this.coordinatePrecision);
1941
+ }
1942
+ }
1943
+ select(t, e = !0) {
1944
+ if (this.selected[0] === t) return;
1945
+ const { mode: i } = this.store.getPropertiesCopy(t), o = this.flags[i];
1946
+ if (!o || !o.feature) return;
1947
+ const n = this.selected[0];
1948
+ if (n) {
1949
+ if (n === t) return;
1950
+ this.deselect();
1951
+ }
1952
+ e && this.setCursor(this.cursors.pointerOver), this.selected = [t], this.store.updateProperty([{ id: t, property: "selected", value: !0 }]), this.onSelect(t);
1953
+ const { type: r, coordinates: a } = this.store.getGeometryCopy(t);
1954
+ if (r !== "LineString" && r !== "Polygon") return;
1955
+ const l = r === "LineString" ? a : a[0];
1956
+ l && o && o.feature.coordinates && (this.selectionPoints.create(l, r, t), o.feature.coordinates.midpoints && this.midPoints.create(l, t, this.coordinatePrecision));
1957
+ }
1958
+ onLeftClick(t) {
1959
+ const { clickedFeature: e, clickedMidPoint: i } = this.featuresAtMouseEvent.find(t, this.selected.length > 0);
1960
+ if (this.selected.length && i) this.midPoints.insert(i.id, this.coordinatePrecision);
1961
+ else if (e && e.id) this.select(e.id, !0);
1962
+ else if (this.selected.length && this.allowManualDeselection) return void this.deselect();
1963
+ }
1964
+ start() {
1965
+ this.setStarted(), this.setSelecting();
1966
+ }
1967
+ stop() {
1968
+ this.cleanUp(), this.setStarted(), this.setStopped();
1969
+ }
1970
+ onClick(t) {
1971
+ t.button !== "right" ? t.button === "left" && this.onLeftClick(t) : this.onRightClick(t);
1972
+ }
1973
+ canScale(t) {
1974
+ return this.keyEvents.scale && this.keyEvents.scale.every((e) => t.heldKeys.includes(e));
1975
+ }
1976
+ canRotate(t) {
1977
+ return this.keyEvents.rotate && this.keyEvents.rotate.every((e) => t.heldKeys.includes(e));
1978
+ }
1979
+ preventDefaultKeyEvent(t) {
1980
+ const e = this.canRotate(t), i = this.canScale(t);
1981
+ (e || i) && t.preventDefault();
1982
+ }
1983
+ onKeyDown(t) {
1984
+ this.preventDefaultKeyEvent(t);
1985
+ }
1986
+ onKeyUp(t) {
1987
+ if (this.preventDefaultKeyEvent(t), this.keyEvents.delete && t.key === this.keyEvents.delete) {
1988
+ if (!this.selected.length) return;
1989
+ this.onDeselect(this.selected[0]), this.deleteSelected(), this.selectionPoints.delete(), this.midPoints.delete();
1990
+ } else this.keyEvents.deselect && t.key === this.keyEvents.deselect && this.cleanUp();
1991
+ }
1992
+ cleanUp() {
1993
+ this.selected.length && this.deselect();
1994
+ }
1995
+ onDragStart(t, e) {
1996
+ if (!this.selected.length) return;
1997
+ const i = this.store.getPropertiesCopy(this.selected[0]), o = this.flags[i.mode];
1998
+ if (!(o && o.feature && (o.feature.draggable || o.feature.coordinates && o.feature.coordinates.draggable || o.feature.coordinates && o.feature.coordinates.resizable))) return;
1999
+ this.dragEventCount = 0;
2000
+ const n = this.selected[0], r = this.dragCoordinate.getDraggableIndex(t, n);
2001
+ return o && o.feature && o.feature.coordinates && (o.feature.coordinates.draggable || o.feature.coordinates.resizable) && r !== -1 ? (this.setCursor(this.cursors.dragStart), o.feature.coordinates.resizable ? this.dragCoordinateResizeFeature.startDragging(n, r) : this.dragCoordinate.startDragging(n, r), void e(!1)) : o && o.feature && o.feature.draggable && this.dragFeature.canDrag(t, n) ? (this.setCursor(this.cursors.dragStart), this.dragFeature.startDragging(t, n), void e(!1)) : void 0;
2002
+ }
2003
+ onDrag(t, e) {
2004
+ const i = this.selected[0];
2005
+ if (!i) return;
2006
+ const o = this.store.getPropertiesCopy(i), n = this.flags[o.mode], r = (n && n.feature && n.feature.selfIntersectable) === !0;
2007
+ if (this.dragEventCount++, this.dragEventCount % this.dragEventThrottle == 0) return;
2008
+ const a = this.validations[o.mode];
2009
+ if (n && n.feature && n.feature.rotateable && this.canRotate(t)) return e(!1), void this.rotateFeature.rotate(t, i, a);
2010
+ if (n && n.feature && n.feature.scaleable && this.canScale(t)) return e(!1), void this.scaleFeature.scale(t, i, a);
2011
+ if (this.dragCoordinateResizeFeature.isDragging() && n.feature && n.feature.coordinates && n.feature.coordinates.resizable) {
2012
+ if (this.projection === "globe") throw new Error("Globe is currently unsupported projection for resizable");
2013
+ return e(!1), void this.dragCoordinateResizeFeature.drag(t, n.feature.coordinates.resizable, a);
2014
+ }
2015
+ this.dragCoordinate.isDragging() ? this.dragCoordinate.drag(t, r, a) : this.dragFeature.isDragging() ? this.dragFeature.drag(t, a) : e(!0);
2016
+ }
2017
+ onDragEnd(t, e) {
2018
+ this.setCursor(this.cursors.dragEnd), this.dragCoordinate.isDragging() ? this.onFinish(this.selected[0], { mode: this.mode, action: "dragCoordinate" }) : this.dragFeature.isDragging() ? this.onFinish(this.selected[0], { mode: this.mode, action: "dragFeature" }) : this.dragCoordinateResizeFeature.isDragging() && this.onFinish(this.selected[0], { mode: this.mode, action: "dragCoordinateResize" }), this.dragCoordinate.stopDragging(), this.dragFeature.stopDragging(), this.dragCoordinateResizeFeature.stopDragging(), this.rotateFeature.reset(), this.scaleFeature.reset(), e(!0);
2019
+ }
2020
+ onMouseMove(t) {
2021
+ if (!this.selected.length) return void this.setCursor("unset");
2022
+ if (this.dragFeature.isDragging()) return;
2023
+ let e = !1;
2024
+ this.midPoints.ids.forEach((n) => {
2025
+ if (e) return;
2026
+ const r = this.store.getGeometryCopy(n);
2027
+ this.pixelDistance.measure(t, r.coordinates) < this.pointerDistance && (e = !0);
2028
+ });
2029
+ let i = !1;
2030
+ if (this.selectionPoints.ids.forEach((n) => {
2031
+ const r = this.store.getGeometryCopy(n);
2032
+ this.pixelDistance.measure(t, r.coordinates) < this.pointerDistance && (e = !1, i = !0);
2033
+ }), e) return void this.setCursor(this.cursors.insertMidpoint);
2034
+ const { clickedFeature: o } = this.featuresAtMouseEvent.find(t, !0);
2035
+ this.setCursor(this.selected.length > 0 && (o && o.id === this.selected[0] || i) ? this.cursors.pointerOver : "unset");
2036
+ }
2037
+ styleFeature(t) {
2038
+ const e = f({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
2039
+ if (t.properties.mode === this.mode && t.geometry.type === "Point") {
2040
+ if (t.properties.selectionPoint) return e.pointColor = this.getHexColorStylingValue(this.styles.selectionPointColor, e.pointColor, t), e.pointOutlineColor = this.getHexColorStylingValue(this.styles.selectionPointOutlineColor, e.pointOutlineColor, t), e.pointWidth = this.getNumericStylingValue(this.styles.selectionPointWidth, e.pointWidth, t), e.pointOutlineWidth = this.getNumericStylingValue(this.styles.selectionPointOutlineWidth, 2, t), e.zIndex = 30, e;
2041
+ if (t.properties.midPoint) return e.pointColor = this.getHexColorStylingValue(this.styles.midPointColor, e.pointColor, t), e.pointOutlineColor = this.getHexColorStylingValue(this.styles.midPointOutlineColor, e.pointOutlineColor, t), e.pointWidth = this.getNumericStylingValue(this.styles.midPointWidth, 4, t), e.pointOutlineWidth = this.getNumericStylingValue(this.styles.midPointOutlineWidth, 2, t), e.zIndex = 40, e;
2042
+ } else if (t.properties[xt]) {
2043
+ if (t.geometry.type === "Polygon") return e.polygonFillColor = this.getHexColorStylingValue(this.styles.selectedPolygonColor, e.polygonFillColor, t), e.polygonOutlineWidth = this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth, e.polygonOutlineWidth, t), e.polygonOutlineColor = this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor, e.polygonOutlineColor, t), e.polygonFillOpacity = this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity, e.polygonFillOpacity, t), e.zIndex = 10, e;
2044
+ if (t.geometry.type === "LineString") return e.lineStringColor = this.getHexColorStylingValue(this.styles.selectedLineStringColor, e.lineStringColor, t), e.lineStringWidth = this.getNumericStylingValue(this.styles.selectedLineStringWidth, e.lineStringWidth, t), e.zIndex = 10, e;
2045
+ if (t.geometry.type === "Point") return e.pointWidth = this.getNumericStylingValue(this.styles.selectedPointWidth, e.pointWidth, t), e.pointColor = this.getHexColorStylingValue(this.styles.selectedPointColor, e.pointColor, t), e.pointOutlineColor = this.getHexColorStylingValue(this.styles.selectedPointOutlineColor, e.pointOutlineColor, t), e.pointOutlineWidth = this.getNumericStylingValue(this.styles.selectedPointOutlineWidth, e.pointOutlineWidth, t), e.zIndex = 10, e;
2046
+ }
2047
+ return e;
2048
+ }
2049
+ }
2050
+ class Ye extends j {
2051
+ constructor(...t) {
2052
+ super(...t), this.type = U.Static, this.mode = "static";
2053
+ }
2054
+ start() {
2055
+ }
2056
+ stop() {
2057
+ }
2058
+ onKeyUp() {
2059
+ }
2060
+ onKeyDown() {
2061
+ }
2062
+ onClick() {
2063
+ }
2064
+ onDragStart() {
2065
+ }
2066
+ onDrag() {
2067
+ }
2068
+ onDragEnd() {
2069
+ }
2070
+ onMouseMove() {
2071
+ }
2072
+ cleanUp() {
2073
+ }
2074
+ styleFeature() {
2075
+ return f({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
2076
+ }
2077
+ }
2078
+ function he(s, t, e, i, o) {
2079
+ for (; i > e; ) {
2080
+ if (i - e > 600) {
2081
+ const l = i - e + 1, d = t - e + 1, h = Math.log(l), c = 0.5 * Math.exp(2 * h / 3), u = 0.5 * Math.sqrt(h * c * (l - c) / l) * (d - l / 2 < 0 ? -1 : 1);
2082
+ he(s, t, Math.max(e, Math.floor(t - d * c / l + u)), Math.min(i, Math.floor(t + (l - d) * c / l + u)), o);
2083
+ }
2084
+ const n = s[t];
2085
+ let r = e, a = i;
2086
+ for (K(s, e, t), o(s[i], n) > 0 && K(s, e, i); r < a; ) {
2087
+ for (K(s, r, a), r++, a--; o(s[r], n) < 0; ) r++;
2088
+ for (; o(s[a], n) > 0; ) a--;
2089
+ }
2090
+ o(s[e], n) === 0 ? K(s, e, a) : (a++, K(s, a, i)), a <= t && (e = a + 1), t <= a && (i = a - 1);
2091
+ }
2092
+ }
2093
+ function K(s, t, e) {
2094
+ const i = s[t];
2095
+ s[t] = s[e], s[e] = i;
2096
+ }
2097
+ function R(s, t) {
2098
+ Y(s, 0, s.children.length, t, s);
2099
+ }
2100
+ function Y(s, t, e, i, o) {
2101
+ o || (o = V([])), o.minX = 1 / 0, o.minY = 1 / 0, o.maxX = -1 / 0, o.maxY = -1 / 0;
2102
+ for (let n = t; n < e; n++) {
2103
+ const r = s.children[n];
2104
+ z(o, s.leaf ? i(r) : r);
2105
+ }
2106
+ return o;
2107
+ }
2108
+ function z(s, t) {
2109
+ return s.minX = Math.min(s.minX, t.minX), s.minY = Math.min(s.minY, t.minY), s.maxX = Math.max(s.maxX, t.maxX), s.maxY = Math.max(s.maxY, t.maxY), s;
2110
+ }
2111
+ function ze(s, t) {
2112
+ return s.minX - t.minX;
2113
+ }
2114
+ function He(s, t) {
2115
+ return s.minY - t.minY;
2116
+ }
2117
+ function ft(s) {
2118
+ return (s.maxX - s.minX) * (s.maxY - s.minY);
2119
+ }
2120
+ function st(s) {
2121
+ return s.maxX - s.minX + (s.maxY - s.minY);
2122
+ }
2123
+ function $e(s, t) {
2124
+ const e = Math.max(s.minX, t.minX), i = Math.max(s.minY, t.minY), o = Math.min(s.maxX, t.maxX), n = Math.min(s.maxY, t.maxY);
2125
+ return Math.max(0, o - e) * Math.max(0, n - i);
2126
+ }
2127
+ function vt(s, t) {
2128
+ return s.minX <= t.minX && s.minY <= t.minY && t.maxX <= s.maxX && t.maxY <= s.maxY;
2129
+ }
2130
+ function nt(s, t) {
2131
+ return t.minX <= s.maxX && t.minY <= s.maxY && t.maxX >= s.minX && t.maxY >= s.minY;
2132
+ }
2133
+ function V(s) {
2134
+ return { children: s, height: 1, leaf: !0, minX: 1 / 0, minY: 1 / 0, maxX: -1 / 0, maxY: -1 / 0 };
2135
+ }
2136
+ function Ht(s, t, e, i, o) {
2137
+ const n = [t, e];
2138
+ for (; n.length; ) {
2139
+ if ((e = n.pop()) - (t = n.pop()) <= i) continue;
2140
+ const r = t + Math.ceil((e - t) / i / 2) * i;
2141
+ he(s, r, t, e, o), n.push(t, r, r, e);
2142
+ }
2143
+ }
2144
+ class Je {
2145
+ constructor(t) {
2146
+ this._maxEntries = void 0, this._minEntries = void 0, this.data = void 0, this._maxEntries = Math.max(4, t), this._minEntries = Math.max(2, Math.ceil(0.4 * this._maxEntries)), this.clear();
2147
+ }
2148
+ search(t) {
2149
+ let e = this.data;
2150
+ const i = [];
2151
+ if (!nt(t, e)) return i;
2152
+ const o = this.toBBox, n = [];
2153
+ for (; e; ) {
2154
+ for (let r = 0; r < e.children.length; r++) {
2155
+ const a = e.children[r], l = e.leaf ? o(a) : a;
2156
+ nt(t, l) && (e.leaf ? i.push(a) : vt(t, l) ? this._all(a, i) : n.push(a));
2157
+ }
2158
+ e = n.pop();
2159
+ }
2160
+ return i;
2161
+ }
2162
+ collides(t) {
2163
+ let e = this.data;
2164
+ if (nt(t, e)) {
2165
+ const i = [];
2166
+ for (; e; ) {
2167
+ for (let o = 0; o < e.children.length; o++) {
2168
+ const n = e.children[o], r = e.leaf ? this.toBBox(n) : n;
2169
+ if (nt(t, r)) {
2170
+ if (e.leaf || vt(t, r)) return !0;
2171
+ i.push(n);
2172
+ }
2173
+ }
2174
+ e = i.pop();
2175
+ }
2176
+ }
2177
+ return !1;
2178
+ }
2179
+ load(t) {
2180
+ if (t.length < this._minEntries) {
2181
+ for (let i = 0; i < t.length; i++) this.insert(t[i]);
2182
+ return;
2183
+ }
2184
+ let e = this._build(t.slice(), 0, t.length - 1, 0);
2185
+ if (this.data.children.length) if (this.data.height === e.height) this._splitRoot(this.data, e);
2186
+ else {
2187
+ if (this.data.height < e.height) {
2188
+ const i = this.data;
2189
+ this.data = e, e = i;
2190
+ }
2191
+ this._insert(e, this.data.height - e.height - 1, !0);
2192
+ }
2193
+ else this.data = e;
2194
+ }
2195
+ insert(t) {
2196
+ this._insert(t, this.data.height - 1);
2197
+ }
2198
+ clear() {
2199
+ this.data = V([]);
2200
+ }
2201
+ remove(t) {
2202
+ let e = this.data;
2203
+ const i = this.toBBox(t), o = [], n = [];
2204
+ let r, a, l = !1;
2205
+ for (; e || o.length; ) {
2206
+ if (e || (e = o.pop(), a = o[o.length - 1], r = n.pop(), l = !0), e.leaf) {
2207
+ const d = e.children.indexOf(t);
2208
+ d !== -1 && (e.children.splice(d, 1), o.push(e), this._condense(o));
2209
+ }
2210
+ l || e.leaf || !vt(e, i) ? a ? (r++, e = a.children[r], l = !1) : e = null : (o.push(e), n.push(r), r = 0, a = e, e = e.children[0]);
2211
+ }
2212
+ }
2213
+ toBBox(t) {
2214
+ return t;
2215
+ }
2216
+ compareMinX(t, e) {
2217
+ return t.minX - e.minX;
2218
+ }
2219
+ compareMinY(t, e) {
2220
+ return t.minY - e.minY;
2221
+ }
2222
+ _all(t, e) {
2223
+ const i = [];
2224
+ for (; t; ) t.leaf ? e.push(...t.children) : i.push(...t.children), t = i.pop();
2225
+ return e;
2226
+ }
2227
+ _build(t, e, i, o) {
2228
+ const n = i - e + 1;
2229
+ let r, a = this._maxEntries;
2230
+ if (n <= a) return r = V(t.slice(e, i + 1)), R(r, this.toBBox), r;
2231
+ o || (o = Math.ceil(Math.log(n) / Math.log(a)), a = Math.ceil(n / Math.pow(a, o - 1))), r = V([]), r.leaf = !1, r.height = o;
2232
+ const l = Math.ceil(n / a), d = l * Math.ceil(Math.sqrt(a));
2233
+ Ht(t, e, i, d, this.compareMinX);
2234
+ for (let h = e; h <= i; h += d) {
2235
+ const c = Math.min(h + d - 1, i);
2236
+ Ht(t, h, c, l, this.compareMinY);
2237
+ for (let u = h; u <= c; u += l) {
2238
+ const g = Math.min(u + l - 1, c);
2239
+ r.children.push(this._build(t, u, g, o - 1));
2240
+ }
2241
+ }
2242
+ return R(r, this.toBBox), r;
2243
+ }
2244
+ _chooseSubtree(t, e, i, o) {
2245
+ for (; o.push(e), !e.leaf && o.length - 1 !== i; ) {
2246
+ let a, l = 1 / 0, d = 1 / 0;
2247
+ for (let h = 0; h < e.children.length; h++) {
2248
+ const c = e.children[h], u = ft(c), g = (n = t, r = c, (Math.max(r.maxX, n.maxX) - Math.min(r.minX, n.minX)) * (Math.max(r.maxY, n.maxY) - Math.min(r.minY, n.minY)) - u);
2249
+ g < d ? (d = g, l = u < l ? u : l, a = c) : g === d && u < l && (l = u, a = c);
2250
+ }
2251
+ e = a || e.children[0];
2252
+ }
2253
+ var n, r;
2254
+ return e;
2255
+ }
2256
+ _insert(t, e, i) {
2257
+ const o = i ? t : this.toBBox(t), n = [], r = this._chooseSubtree(o, this.data, e, n);
2258
+ for (r.children.push(t), z(r, o); e >= 0 && n[e].children.length > this._maxEntries; ) this._split(n, e), e--;
2259
+ this._adjustParentBBoxes(o, n, e);
2260
+ }
2261
+ _split(t, e) {
2262
+ const i = t[e], o = i.children.length, n = this._minEntries;
2263
+ this._chooseSplitAxis(i, n, o);
2264
+ const r = this._chooseSplitIndex(i, n, o), a = V(i.children.splice(r, i.children.length - r));
2265
+ a.height = i.height, a.leaf = i.leaf, R(i, this.toBBox), R(a, this.toBBox), e ? t[e - 1].children.push(a) : this._splitRoot(i, a);
2266
+ }
2267
+ _splitRoot(t, e) {
2268
+ this.data = V([t, e]), this.data.height = t.height + 1, this.data.leaf = !1, R(this.data, this.toBBox);
2269
+ }
2270
+ _chooseSplitIndex(t, e, i) {
2271
+ let o, n = 1 / 0, r = 1 / 0;
2272
+ for (let a = e; a <= i - e; a++) {
2273
+ const l = Y(t, 0, a, this.toBBox), d = Y(t, a, i, this.toBBox), h = $e(l, d), c = ft(l) + ft(d);
2274
+ h < n ? (n = h, o = a, r = c < r ? c : r) : h === n && c < r && (r = c, o = a);
2275
+ }
2276
+ return o || i - e;
2277
+ }
2278
+ _chooseSplitAxis(t, e, i) {
2279
+ const o = t.leaf ? this.compareMinX : ze, n = t.leaf ? this.compareMinY : He;
2280
+ this._allDistMargin(t, e, i, o) < this._allDistMargin(t, e, i, n) && t.children.sort(o);
2281
+ }
2282
+ _allDistMargin(t, e, i, o) {
2283
+ t.children.sort(o);
2284
+ const n = this.toBBox, r = Y(t, 0, e, n), a = Y(t, i - e, i, n);
2285
+ let l = st(r) + st(a);
2286
+ for (let d = e; d < i - e; d++) {
2287
+ const h = t.children[d];
2288
+ z(r, t.leaf ? n(h) : h), l += st(r);
2289
+ }
2290
+ for (let d = i - e - 1; d >= e; d--) {
2291
+ const h = t.children[d];
2292
+ z(a, t.leaf ? n(h) : h), l += st(a);
2293
+ }
2294
+ return l;
2295
+ }
2296
+ _adjustParentBBoxes(t, e, i) {
2297
+ for (let o = i; o >= 0; o--) z(e[o], t);
2298
+ }
2299
+ _condense(t) {
2300
+ for (let e, i = t.length - 1; i >= 0; i--) t[i].children.length === 0 ? i > 0 ? (e = t[i - 1].children, e.splice(e.indexOf(t[i]), 1)) : this.clear() : R(t[i], this.toBBox);
2301
+ }
2302
+ }
2303
+ class qe {
2304
+ constructor(t) {
2305
+ this.tree = void 0, this.idToNode = void 0, this.nodeToId = void 0, this.tree = new Je(t && t.maxEntries ? t.maxEntries : 9), this.idToNode = /* @__PURE__ */ new Map(), this.nodeToId = /* @__PURE__ */ new Map();
2306
+ }
2307
+ setMaps(t, e) {
2308
+ this.idToNode.set(t.id, e), this.nodeToId.set(e, t.id);
2309
+ }
2310
+ toBBox(t) {
2311
+ const e = [], i = [];
2312
+ let o;
2313
+ if (t.geometry.type === "Polygon") o = t.geometry.coordinates[0];
2314
+ else if (t.geometry.type === "LineString") o = t.geometry.coordinates;
2315
+ else {
2316
+ if (t.geometry.type !== "Point") throw new Error("Not a valid feature to turn into a bounding box");
2317
+ o = [t.geometry.coordinates];
2318
+ }
2319
+ for (let a = 0; a < o.length; a++) i.push(o[a][1]), e.push(o[a][0]);
2320
+ const n = Math.min(...i), r = Math.max(...i);
2321
+ return { minX: Math.min(...e), minY: n, maxX: Math.max(...e), maxY: r };
2322
+ }
2323
+ insert(t) {
2324
+ if (this.idToNode.get(String(t.id))) throw new Error("Feature already exists");
2325
+ const e = this.toBBox(t);
2326
+ this.setMaps(t, e), this.tree.insert(e);
2327
+ }
2328
+ load(t) {
2329
+ const e = [], i = /* @__PURE__ */ new Set();
2330
+ t.forEach((o) => {
2331
+ const n = this.toBBox(o);
2332
+ if (this.setMaps(o, n), i.has(String(o.id))) throw new Error(`Duplicate feature ID found ${o.id}`);
2333
+ i.add(String(o.id)), e.push(n);
2334
+ }), this.tree.load(e);
2335
+ }
2336
+ update(t) {
2337
+ this.remove(t.id);
2338
+ const e = this.toBBox(t);
2339
+ this.setMaps(t, e), this.tree.insert(e);
2340
+ }
2341
+ remove(t) {
2342
+ const e = this.idToNode.get(t);
2343
+ if (!e) throw new Error(`${t} not inserted into the spatial index`);
2344
+ this.tree.remove(e);
2345
+ }
2346
+ clear() {
2347
+ this.tree.clear();
2348
+ }
2349
+ search(t) {
2350
+ return this.tree.search(this.toBBox(t)).map((e) => this.nodeToId.get(e));
2351
+ }
2352
+ collides(t) {
2353
+ return this.tree.collides(this.toBBox(t));
2354
+ }
2355
+ }
2356
+ const Ze = { getId: () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(s) {
2357
+ const t = 16 * Math.random() | 0;
2358
+ return (s == "x" ? t : 3 & t | 8).toString(16);
2359
+ }), isValidId: (s) => typeof s == "string" && s.length === 36 };
2360
+ class Qe {
2361
+ constructor(t) {
2362
+ this.idStrategy = void 0, this.tracked = void 0, this.spatialIndex = void 0, this.store = void 0, this._onChange = () => {
2363
+ }, this.store = {}, this.spatialIndex = new qe(), this.tracked = !t || t.tracked !== !1, this.idStrategy = t && t.idStrategy ? t.idStrategy : Ze;
2364
+ }
2365
+ clone(t) {
2366
+ return JSON.parse(JSON.stringify(t));
2367
+ }
2368
+ getId() {
2369
+ return this.idStrategy.getId();
2370
+ }
2371
+ has(t) {
2372
+ return !!this.store[t];
2373
+ }
2374
+ load(t, e) {
2375
+ if (t.length === 0) return;
2376
+ const i = this.clone(t);
2377
+ i.forEach((n) => {
2378
+ n.id == null && (n.id = this.idStrategy.getId()), this.tracked && (n.properties.createdAt ? Nt(n.properties.createdAt) : n.properties.createdAt = +/* @__PURE__ */ new Date(), n.properties.updatedAt ? Nt(n.properties.updatedAt) : n.properties.updatedAt = +/* @__PURE__ */ new Date());
2379
+ });
2380
+ const o = [];
2381
+ i.forEach((n) => {
2382
+ const r = n.id;
2383
+ if (e && !e(n)) throw new Error(`Feature is not ${r} valid: ${JSON.stringify(n)}`);
2384
+ if (this.has(r)) throw new Error(`Feature already exists with this id: ${r}`);
2385
+ this.store[r] = n, o.push(r);
2386
+ }), this.spatialIndex.load(i), this._onChange(o, "create");
2387
+ }
2388
+ search(t, e) {
2389
+ const i = this.spatialIndex.search(t).map((o) => this.store[o]);
2390
+ return this.clone(e ? i.filter(e) : i);
2391
+ }
2392
+ registerOnChange(t) {
2393
+ this._onChange = (e, i) => {
2394
+ t(e, i);
2395
+ };
2396
+ }
2397
+ getGeometryCopy(t) {
2398
+ const e = this.store[t];
2399
+ if (!e) throw new Error(`No feature with this id (${t}), can not get geometry copy`);
2400
+ return this.clone(e.geometry);
2401
+ }
2402
+ getPropertiesCopy(t) {
2403
+ const e = this.store[t];
2404
+ if (!e) throw new Error(`No feature with this id (${t}), can not get properties copy`);
2405
+ return this.clone(e.properties);
2406
+ }
2407
+ updateProperty(t) {
2408
+ const e = [];
2409
+ t.forEach(({ id: i, property: o, value: n }) => {
2410
+ const r = this.store[i];
2411
+ if (!r) throw new Error(`No feature with this (${i}), can not update geometry`);
2412
+ e.push(i), r.properties[o] = n, this.tracked && (r.properties.updatedAt = +/* @__PURE__ */ new Date());
2413
+ }), this._onChange && this._onChange(e, "update");
2414
+ }
2415
+ updateGeometry(t) {
2416
+ const e = [];
2417
+ t.forEach(({ id: i, geometry: o }) => {
2418
+ e.push(i);
2419
+ const n = this.store[i];
2420
+ if (!n) throw new Error(`No feature with this (${i}), can not update geometry`);
2421
+ n.geometry = this.clone(o), this.spatialIndex.update(n), this.tracked && (n.properties.updatedAt = +/* @__PURE__ */ new Date());
2422
+ }), this._onChange && this._onChange(e, "update");
2423
+ }
2424
+ create(t) {
2425
+ const e = [];
2426
+ return t.forEach(({ geometry: i, properties: o }) => {
2427
+ let n, r = f({}, o);
2428
+ this.tracked && (n = +/* @__PURE__ */ new Date(), o ? (r.createdAt = typeof o.createdAt == "number" ? o.createdAt : n, r.updatedAt = typeof o.updatedAt == "number" ? o.updatedAt : n) : r = { createdAt: n, updatedAt: n });
2429
+ const a = this.getId(), l = { id: a, type: "Feature", geometry: i, properties: r };
2430
+ this.store[a] = l, this.spatialIndex.insert(l), e.push(a);
2431
+ }), this._onChange && this._onChange([...e], "create"), e;
2432
+ }
2433
+ delete(t) {
2434
+ t.forEach((e) => {
2435
+ if (!this.store[e]) throw new Error("No feature with this id, can not delete");
2436
+ delete this.store[e], this.spatialIndex.remove(e);
2437
+ }), this._onChange && this._onChange([...t], "delete");
2438
+ }
2439
+ copyAll() {
2440
+ return this.clone(Object.keys(this.store).map((t) => this.store[t]));
2441
+ }
2442
+ clear() {
2443
+ this.store = {}, this.spatialIndex.clear();
2444
+ }
2445
+ size() {
2446
+ return Object.keys(this.store).length;
2447
+ }
2448
+ }
2449
+ const ti = (s) => (s.geometry.type === "Polygon" || s.geometry.type === "LineString") && !Mt(s);
2450
+ function $t(s, t, e) {
2451
+ const i = lt(s, t);
2452
+ let o = lt(t, e) - i;
2453
+ return o < 0 && (o += 360), 180 - Math.abs(o - 90 - 90);
2454
+ }
2455
+ class ei extends j {
2456
+ constructor(t) {
2457
+ super(t), this.mode = "angled-rectangle", this.currentCoordinate = 0, this.currentId = void 0, this.keyEvents = void 0, this.pixelDistance = void 0, this.cursors = void 0, this.mouseMove = !1;
2458
+ const e = { start: "crosshair", close: "pointer" };
2459
+ if (this.cursors = t && t.cursors ? f({}, e, t.cursors) : e, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
2460
+ else {
2461
+ const i = { cancel: "Escape", finish: "Enter" };
2462
+ this.keyEvents = t && t.keyEvents ? f({}, i, t.keyEvents) : i;
2463
+ }
2464
+ }
2465
+ close() {
2466
+ if (this.currentId === void 0) return;
2467
+ const t = this.currentId;
2468
+ this.currentCoordinate = 0, this.currentId = void 0, this.state === "drawing" && this.setStarted(), this.onFinish(t, { mode: this.mode, action: "draw" });
2469
+ }
2470
+ registerBehaviors(t) {
2471
+ this.pixelDistance = new gt(t);
2472
+ }
2473
+ start() {
2474
+ this.setStarted(), this.setCursor(this.cursors.start);
2475
+ }
2476
+ stop() {
2477
+ this.cleanUp(), this.setStopped(), this.setCursor("unset");
2478
+ }
2479
+ onMouseMove(t) {
2480
+ if (this.mouseMove = !0, this.setCursor(this.cursors.start), this.currentId === void 0 || this.currentCoordinate === 0) return;
2481
+ const e = this.store.getGeometryCopy(this.currentId).coordinates[0];
2482
+ let i;
2483
+ if (this.currentCoordinate === 1) {
2484
+ const o = 1 / Math.pow(10, this.coordinatePrecision - 1), n = Math.max(1e-6, o);
2485
+ i = [e[0], [t.lng, t.lat], [t.lng, t.lat - n], e[0]];
2486
+ } else if (this.currentCoordinate === 2) {
2487
+ const o = e[0], n = e[1], r = ne(o, n, this.coordinatePrecision, this.project, this.unproject), a = P(o[0], o[1]), l = P(r[0], r[1]), d = P(n[0], n[1]), h = P(t.lng, t.lat), c = I(h, a) < I(h, d), u = $t(a, l, h), g = c ? 90 - u : $t(a, l, h) - 90, p = I(l, h), y = Math.cos(S(g)) * p, v = lt(a, d) + (function(_, w, F) {
2488
+ const W = (F.x - w.x) * (_.y - w.y) - (F.y - w.y) * (_.x - w.x);
2489
+ return W > 1e-10 ? "left" : W < -1e-10 ? "right" : "left";
2490
+ }(a, d, h) === "right" ? -90 : 90), m = Xt(a, y, v), x = Xt(d, y, v), M = O(m.x, m.y), E = O(x.x, x.y);
2491
+ i = [e[0], e[1], [E.lng, E.lat], [M.lng, M.lat], e[0]];
2492
+ }
2493
+ i && this.updatePolygonGeometry(this.currentId, i, C.Provisional);
2494
+ }
2495
+ updatePolygonGeometry(t, e, i) {
2496
+ const o = { type: "Polygon", coordinates: [e] };
2497
+ return !(this.validate && !this.validate({ type: "Feature", geometry: o }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: i }) || (this.store.updateGeometry([{ id: t, geometry: o }]), 0));
2498
+ }
2499
+ onClick(t) {
2500
+ if (this.currentCoordinate > 0 && !this.mouseMove && this.onMouseMove(t), this.mouseMove = !1, this.currentCoordinate === 0) {
2501
+ const [e] = this.store.create([{ geometry: { type: "Polygon", coordinates: [[[t.lng, t.lat], [t.lng, t.lat], [t.lng, t.lat], [t.lng, t.lat]]] }, properties: { mode: this.mode } }]);
2502
+ this.currentId = e, this.currentCoordinate++, this.setDrawing();
2503
+ } else if (this.currentCoordinate === 1 && this.currentId) {
2504
+ const e = this.store.getGeometryCopy(this.currentId);
2505
+ if ($([t.lng, t.lat], e.coordinates[0][0]) || !this.updatePolygonGeometry(this.currentId, [e.coordinates[0][0], [t.lng, t.lat], [t.lng, t.lat], e.coordinates[0][0]], C.Commit)) return;
2506
+ this.currentCoordinate++;
2507
+ } else this.currentCoordinate === 2 && this.currentId && this.close();
2508
+ }
2509
+ onKeyUp(t) {
2510
+ t.key === this.keyEvents.cancel ? this.cleanUp() : t.key === this.keyEvents.finish && this.close();
2511
+ }
2512
+ onKeyDown() {
2513
+ }
2514
+ onDragStart() {
2515
+ }
2516
+ onDrag() {
2517
+ }
2518
+ onDragEnd() {
2519
+ }
2520
+ cleanUp() {
2521
+ try {
2522
+ this.currentId && this.store.delete([this.currentId]);
2523
+ } catch {
2524
+ }
2525
+ this.currentId = void 0, this.currentCoordinate = 0, this.state === "drawing" && this.setStarted();
2526
+ }
2527
+ styleFeature(t) {
2528
+ const e = f({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
2529
+ return t.properties.mode === this.mode && t.geometry.type === "Polygon" && (e.polygonFillColor = this.getHexColorStylingValue(this.styles.fillColor, e.polygonFillColor, t), e.polygonOutlineColor = this.getHexColorStylingValue(this.styles.outlineColor, e.polygonOutlineColor, t), e.polygonOutlineWidth = this.getNumericStylingValue(this.styles.outlineWidth, e.polygonOutlineWidth, t), e.polygonFillOpacity = this.getNumericStylingValue(this.styles.fillOpacity, e.polygonFillOpacity, t), e.zIndex = 10), e;
2530
+ }
2531
+ validateFeature(t) {
2532
+ return !!super.validateFeature(t) && t.properties.mode === this.mode && ut(t, this.coordinatePrecision);
2533
+ }
2534
+ }
2535
+ class ii {
2536
+ constructor(t) {
2537
+ this._modes = void 0, this._mode = void 0, this._adapter = void 0, this._enabled = !1, this._store = void 0, this._eventListeners = void 0, this._instanceSelectMode = void 0, this._adapter = t.adapter, this._mode = new Ye();
2538
+ const e = /* @__PURE__ */ new Set(), i = t.modes.reduce((h, c) => {
2539
+ if (e.has(c.mode)) throw new Error(`There is already a ${c.mode} mode provided`);
2540
+ return e.add(c.mode), h[c.mode] = c, h;
2541
+ }, {}), o = Object.keys(i);
2542
+ if (o.length === 0) throw new Error("No modes provided");
2543
+ o.forEach((h) => {
2544
+ if (i[h].type === U.Select) {
2545
+ if (this._instanceSelectMode) throw new Error("only one type of select mode can be provided");
2546
+ this._instanceSelectMode = h;
2547
+ }
2548
+ }), this._modes = f({}, i, { static: this._mode }), this._eventListeners = { change: [], select: [], deselect: [], finish: [], ready: [] }, this._store = new Qe({ tracked: !!t.tracked, idStrategy: t.idStrategy ? t.idStrategy : void 0 });
2549
+ const n = (h) => {
2550
+ const c = [], u = this._store.copyAll().filter((g) => !h.includes(g.id) || (c.push(g), !1));
2551
+ return { changed: c, unchanged: u };
2552
+ }, r = (h, c) => {
2553
+ this._enabled && this._eventListeners.finish.forEach((u) => {
2554
+ u(h, c);
2555
+ });
2556
+ }, a = (h, c) => {
2557
+ if (!this._enabled) return;
2558
+ this._eventListeners.change.forEach((p) => {
2559
+ p(h, c);
2560
+ });
2561
+ const { changed: u, unchanged: g } = n(h);
2562
+ c === "create" ? this._adapter.render({ created: u, deletedIds: [], unchanged: g, updated: [] }, this.getModeStyles()) : c === "update" ? this._adapter.render({ created: [], deletedIds: [], unchanged: g, updated: u }, this.getModeStyles()) : c === "delete" ? this._adapter.render({ created: [], deletedIds: h, unchanged: g, updated: [] }, this.getModeStyles()) : c === "styling" && this._adapter.render({ created: [], deletedIds: [], unchanged: g, updated: [] }, this.getModeStyles());
2563
+ }, l = (h) => {
2564
+ if (!this._enabled) return;
2565
+ this._eventListeners.select.forEach((g) => {
2566
+ g(h);
2567
+ });
2568
+ const { changed: c, unchanged: u } = n([h]);
2569
+ this._adapter.render({ created: [], deletedIds: [], unchanged: u, updated: c }, this.getModeStyles());
2570
+ }, d = (h) => {
2571
+ if (!this._enabled) return;
2572
+ this._eventListeners.deselect.forEach((g) => {
2573
+ g();
2574
+ });
2575
+ const { changed: c, unchanged: u } = n([h]);
2576
+ c && this._adapter.render({ created: [], deletedIds: [], unchanged: u, updated: c }, this.getModeStyles());
2577
+ };
2578
+ Object.keys(this._modes).forEach((h) => {
2579
+ this._modes[h].register({ mode: h, store: this._store, setCursor: this._adapter.setCursor.bind(this._adapter), project: this._adapter.project.bind(this._adapter), unproject: this._adapter.unproject.bind(this._adapter), setDoubleClickToZoom: this._adapter.setDoubleClickToZoom.bind(this._adapter), onChange: a, onSelect: l, onDeselect: d, onFinish: r, coordinatePrecision: this._adapter.getCoordinatePrecision() });
2580
+ });
2581
+ }
2582
+ checkEnabled() {
2583
+ if (!this._enabled) throw new Error("Terra Draw is not enabled");
2584
+ }
2585
+ getModeStyles() {
2586
+ const t = {};
2587
+ return Object.keys(this._modes).forEach((e) => {
2588
+ t[e] = (i) => this._instanceSelectMode && i.properties[xt] ? this._modes[this._instanceSelectMode].styleFeature.bind(this._modes[this._instanceSelectMode])(i) : this._modes[e].styleFeature.bind(this._modes[e])(i);
2589
+ }), t;
2590
+ }
2591
+ featuresAtLocation({ lng: t, lat: e }, i) {
2592
+ const o = i && i.pointerDistance !== void 0 ? i.pointerDistance : 30, n = !i || i.ignoreSelectFeatures === void 0 || i.ignoreSelectFeatures, r = this._adapter.unproject.bind(this._adapter), a = this._adapter.project.bind(this._adapter), l = a(t, e), d = oe({ unproject: r, point: l, pointerDistance: o });
2593
+ return this._store.search(d).filter((h) => {
2594
+ if (n && (h.properties[H] || h.properties.selectionPoint)) return !1;
2595
+ if (h.geometry.type === "Point") {
2596
+ const c = h.geometry.coordinates, u = a(c[0], c[1]);
2597
+ return I(l, u) < o;
2598
+ }
2599
+ if (h.geometry.type === "LineString") {
2600
+ const c = h.geometry.coordinates;
2601
+ for (let u = 0; u < c.length - 1; u++) {
2602
+ const g = c[u], p = c[u + 1];
2603
+ if (ae(l, a(g[0], g[1]), a(p[0], p[1])) < o) return !0;
2604
+ }
2605
+ return !1;
2606
+ }
2607
+ return !!re([t, e], h.geometry.coordinates) || void 0;
2608
+ });
2609
+ }
2610
+ getSelectMode() {
2611
+ if (this.checkEnabled(), !this._instanceSelectMode) throw new Error("No select mode defined in instance");
2612
+ return this.getMode() !== this._instanceSelectMode && this.setMode(this._instanceSelectMode), this._modes[this._instanceSelectMode];
2613
+ }
2614
+ setModeStyles(t, e) {
2615
+ if (this.checkEnabled(), !this._modes[t]) throw new Error("No mode with this name present");
2616
+ this._modes[t].styles = e;
2617
+ }
2618
+ getSnapshot() {
2619
+ return this._store.copyAll();
2620
+ }
2621
+ clear() {
2622
+ this.checkEnabled(), this._adapter.clear();
2623
+ }
2624
+ get enabled() {
2625
+ return this._enabled;
2626
+ }
2627
+ set enabled(t) {
2628
+ throw new Error("Enabled is read only");
2629
+ }
2630
+ getMode() {
2631
+ return this._mode.mode;
2632
+ }
2633
+ setMode(t) {
2634
+ if (this.checkEnabled(), !this._modes[t]) throw new Error("No mode with this name present");
2635
+ this._mode.stop(), this._mode = this._modes[t], this._mode.start();
2636
+ }
2637
+ removeFeatures(t) {
2638
+ this.checkEnabled(), this._store.delete(t);
2639
+ }
2640
+ selectFeature(t) {
2641
+ this.getSelectMode().selectFeature(t);
2642
+ }
2643
+ deselectFeature(t) {
2644
+ this.getSelectMode().deselectFeature(t);
2645
+ }
2646
+ getFeatureId() {
2647
+ return this._store.getId();
2648
+ }
2649
+ hasFeature(t) {
2650
+ return this._store.has(t);
2651
+ }
2652
+ addFeatures(t) {
2653
+ this.checkEnabled(), t.length !== 0 && this._store.load(t, (e) => {
2654
+ if (e && typeof e == "object" && "properties" in e && typeof e.properties == "object" && e.properties !== null && "mode" in e.properties) {
2655
+ const i = this._modes[e.properties.mode];
2656
+ return !!i && i.validateFeature.bind(i)(e);
2657
+ }
2658
+ return !1;
2659
+ });
2660
+ }
2661
+ start() {
2662
+ this._enabled = !0, this._adapter.register({ onReady: () => {
2663
+ this._eventListeners.ready.forEach((t) => {
2664
+ t();
2665
+ });
2666
+ }, getState: () => this._mode.state, onClick: (t) => {
2667
+ this._mode.onClick(t);
2668
+ }, onMouseMove: (t) => {
2669
+ this._mode.onMouseMove(t);
2670
+ }, onKeyDown: (t) => {
2671
+ this._mode.onKeyDown(t);
2672
+ }, onKeyUp: (t) => {
2673
+ this._mode.onKeyUp(t);
2674
+ }, onDragStart: (t, e) => {
2675
+ this._mode.onDragStart(t, e);
2676
+ }, onDrag: (t, e) => {
2677
+ this._mode.onDrag(t, e);
2678
+ }, onDragEnd: (t, e) => {
2679
+ this._mode.onDragEnd(t, e);
2680
+ }, onClear: () => {
2681
+ this._mode.cleanUp(), this._store.clear();
2682
+ } });
2683
+ }
2684
+ getFeaturesAtLngLat(t, e) {
2685
+ const { lng: i, lat: o } = t;
2686
+ return this.featuresAtLocation({ lng: i, lat: o }, e);
2687
+ }
2688
+ getFeaturesAtPointerEvent(t, e) {
2689
+ const i = this._adapter.getLngLatFromEvent.bind(this._adapter)(t);
2690
+ return i === null ? [] : this.featuresAtLocation(i, e);
2691
+ }
2692
+ stop() {
2693
+ this._enabled = !1, this._adapter.unregister();
2694
+ }
2695
+ on(t, e) {
2696
+ const i = this._eventListeners[t];
2697
+ i.includes(e) || i.push(e);
2698
+ }
2699
+ off(t, e) {
2700
+ const i = this._eventListeners[t];
2701
+ i.includes(e) && i.splice(i.indexOf(e), 1);
2702
+ }
2703
+ }
2704
+ const oi = {
2705
+ point: !0,
2706
+ line: !0,
2707
+ polygon: !0,
2708
+ rectangle: !0,
2709
+ circle: !0,
2710
+ freehand: !0,
2711
+ angledRectangle: !0,
2712
+ select: !0
2713
+ }, si = (s) => {
2714
+ const t = [];
2715
+ return s.point === !0 && t.push(new Oe()), s.line === !0 && t.push(new Fe()), s.polygon === !0 && t.push(
2716
+ new Le({
2717
+ validation: (e, i) => {
2718
+ const o = i.updateType;
2719
+ return o === "finish" || o === "commit" ? ti(e) : !0;
2720
+ }
2721
+ })
2722
+ ), s.rectangle === !0 && t.push(new Be()), s.angledRectangle === !0 && t.push(new ei()), s.circle === !0 && t.push(new we()), s.freehand === !0 && t.push(new Se()), s.select === !0 && t.push(
2723
+ new Ke({
2724
+ flags: {
2725
+ point: {
2726
+ feature: {
2727
+ draggable: !0
2728
+ }
2729
+ },
2730
+ polygon: {
2731
+ feature: {
2732
+ draggable: !0,
2733
+ rotateable: !0,
2734
+ scaleable: !0,
2735
+ coordinates: {
2736
+ midpoints: !0,
2737
+ draggable: !0,
2738
+ deletable: !0
2739
+ }
2740
+ }
2741
+ },
2742
+ linestring: {
2743
+ feature: {
2744
+ draggable: !0,
2745
+ coordinates: {
2746
+ midpoints: !0,
2747
+ draggable: !0,
2748
+ deletable: !0
2749
+ }
2750
+ }
2751
+ },
2752
+ freehand: {
2753
+ feature: {
2754
+ draggable: !0,
2755
+ coordinates: {
2756
+ midpoints: !0,
2757
+ draggable: !0,
2758
+ deletable: !0
2759
+ }
2760
+ }
2761
+ },
2762
+ circle: {
2763
+ feature: {
2764
+ draggable: !0,
2765
+ coordinates: {
2766
+ midpoints: !0,
2767
+ draggable: !0,
2768
+ deletable: !0
2769
+ }
2770
+ }
2771
+ },
2772
+ rectangle: {
2773
+ feature: {
2774
+ draggable: !0,
2775
+ rotateable: !0,
2776
+ scaleable: !0,
2777
+ coordinates: {
2778
+ midpoints: !0,
2779
+ draggable: !0,
2780
+ deletable: !0
2781
+ }
2782
+ }
2783
+ },
2784
+ "angled-rectangle": {
2785
+ feature: {
2786
+ draggable: !0,
2787
+ rotateable: !0,
2788
+ scaleable: !0,
2789
+ coordinates: {
2790
+ midpoints: !0,
2791
+ draggable: !0,
2792
+ deletable: !0
2793
+ }
2794
+ }
2795
+ }
2796
+ }
2797
+ })
2798
+ ), t;
2799
+ };
2800
+ class ri {
2801
+ constructor(t) {
2802
+ k(this, "controlContainer");
2803
+ k(this, "map");
2804
+ k(this, "addButton");
2805
+ k(this, "modeButtons", {});
2806
+ k(this, "deleteButton");
2807
+ k(this, "isExpanded", !1);
2808
+ k(this, "activeMode");
2809
+ k(this, "terradraw");
2810
+ k(this, "options", oi);
2811
+ this.modeButtons = {}, this.activeMode = "", t && (this.options = Object.assign(this.options, t));
2812
+ }
2813
+ getDefaultPosition() {
2814
+ return "top-right";
2815
+ }
2816
+ onAdd(t) {
2817
+ this.map = t;
2818
+ const e = si(this.options);
2819
+ if (e.length === 0)
2820
+ throw new Error("At least a mode must be enabled.");
2821
+ return this.terradraw = new ii({
2822
+ adapter: new ge({ map: t }),
2823
+ modes: e
2824
+ }), this.terradraw.start(), this.controlContainer = document.createElement("div"), this.controlContainer.classList.add("maplibregl-ctrl"), this.controlContainer.classList.add("maplibregl-ctrl-group"), this.addButton = document.createElement("button"), this.addButton.classList.add("maplibregl-terradraw-add-button"), this.addButton.type = "button", this.addButton.addEventListener("click", () => {
2825
+ var o, n;
2826
+ if (!this.terradraw) return;
2827
+ const i = document.getElementsByClassName("maplibregl-terradraw-add-control");
2828
+ for (let r = 0; r < i.length; r++) {
2829
+ const a = i.item(r);
2830
+ a && (this.isExpanded ? (a.classList.add("hidden"), (o = this.addButton) == null || o.classList.remove("enabled"), this.resetActiveMode()) : (a.classList.remove("hidden"), (n = this.addButton) == null || n.classList.add("enabled")));
2831
+ }
2832
+ this.isExpanded = !this.isExpanded;
2833
+ }), e.forEach((i) => {
2834
+ this.addTerradrawButton(i.mode);
2835
+ }), this.deleteButton = document.createElement("button"), this.deleteButton.classList.add("maplibregl-terradraw-add-control"), this.deleteButton.classList.add("maplibregl-terradraw-delete-button"), this.deleteButton.classList.add("hidden"), this.deleteButton.type = "button", this.deleteButton.addEventListener("click", () => {
2836
+ this.terradraw && this.terradraw.enabled && (this.terradraw.clear(), this.deactivate());
2837
+ }), this.controlContainer.appendChild(this.addButton), Object.values(this.modeButtons).forEach((i) => {
2838
+ var o;
2839
+ (o = this.controlContainer) == null || o.appendChild(i);
2840
+ }), this.controlContainer.appendChild(this.deleteButton), this.controlContainer;
2841
+ }
2842
+ onRemove() {
2843
+ !this.controlContainer || !this.controlContainer.parentNode || !this.map || !this.addButton || (this.modeButtons = {}, this.terradraw = void 0, this.map = void 0);
2844
+ }
2845
+ activate() {
2846
+ this.terradraw && (this.terradraw.enabled || this.terradraw.start());
2847
+ }
2848
+ deactivate() {
2849
+ this.terradraw && this.terradraw.enabled && (this.terradraw.stop(), this.deactivate(), this.resetActiveMode());
2850
+ }
2851
+ getTerraDrawInstance() {
2852
+ return this.terradraw;
2853
+ }
2854
+ resetActiveMode() {
2855
+ this.activeMode = "";
2856
+ const t = document.getElementsByClassName("maplibregl-terradraw-add-control");
2857
+ for (let e = 0; e < t.length; e++) {
2858
+ const i = t.item(e);
2859
+ i && i.classList.remove("active");
2860
+ }
2861
+ }
2862
+ addTerradrawButton(t) {
2863
+ const e = document.createElement("button");
2864
+ e.classList.add("maplibregl-terradraw-add-control"), e.classList.add(`maplibregl-terradraw-add-${t}-button`), e.classList.add("hidden"), e.type = "button", e.addEventListener("click", () => {
2865
+ this.terradraw && (this.activate(), this.resetActiveMode(), this.terradraw.setMode(t), this.activeMode = t, e.classList.add("active"));
2866
+ }), this.modeButtons[t] = e;
2867
+ }
2868
+ }
2869
+ export {
2870
+ ri as default
2871
+ };
2872
+ //# sourceMappingURL=maplibre-gl-terradraw.es.js.map