@watergis/maplibre-gl-terradraw 0.6.4 → 0.6.6

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.
@@ -1,24 +1,24 @@
1
1
  var Me = Object.defineProperty;
2
2
  var be = (s, t, e) => t in s ? Me(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var k = (s, t, e) => be(s, typeof t != "symbol" ? t + "" : t, e);
4
- function x() {
5
- return x = Object.assign ? Object.assign.bind() : function(s) {
3
+ var L = (s, t, e) => be(s, typeof t != "symbol" ? t + "" : t, e);
4
+ function M() {
5
+ return M = Object.assign ? Object.assign.bind() : function(s) {
6
6
  for (var t = 1; t < arguments.length; t++) {
7
7
  var e = arguments[t];
8
8
  for (var i in e) Object.prototype.hasOwnProperty.call(e, i) && (s[i] = e[i]);
9
9
  }
10
10
  return s;
11
- }, x.apply(this, arguments);
11
+ }, M.apply(this, arguments);
12
12
  }
13
- function E(s, t = 9) {
13
+ function F(s, t = 9) {
14
14
  const e = Math.pow(10, t);
15
15
  return Math.round(s * e) / e;
16
16
  }
17
- const F = (s, t) => {
17
+ const I = (s, t) => {
18
18
  const { x: e, y: i } = s, { x: o, y: r } = t, n = o - e, a = r - i;
19
19
  return Math.sqrt(a * a + n * n);
20
20
  };
21
- class K {
21
+ class X {
22
22
  constructor({ name: t, callback: e, unregister: i, register: o }) {
23
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
24
  this.registered || (this.registered = !0, o(e));
@@ -27,7 +27,7 @@ class K {
27
27
  }, this.callback = e;
28
28
  }
29
29
  }
30
- class Qt {
30
+ class te {
31
31
  constructor(t) {
32
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
33
  }
@@ -42,7 +42,7 @@ class Qt {
42
42
  const e = this.getLngLatFromEvent(t);
43
43
  if (!e) return null;
44
44
  const { lng: i, lat: o } = e, { containerX: r, containerY: n } = this.getMapElementXYPosition(t), a = this.getButton(t), l = Array.from(this._heldKeys);
45
- return { lng: E(i, this._coordinatePrecision), lat: E(o, this._coordinatePrecision), containerX: r, containerY: n, button: a, heldKeys: l };
45
+ return { lng: F(i, this._coordinatePrecision), lat: F(o, this._coordinatePrecision), containerX: r, containerY: n, button: a, heldKeys: l };
46
46
  }
47
47
  register(t) {
48
48
  this._currentModeCallbacks = t, this._listeners = this.getAdapterListeners(), this._listeners.forEach((e) => {
@@ -53,7 +53,7 @@ class Qt {
53
53
  return this._coordinatePrecision;
54
54
  }
55
55
  getAdapterListeners() {
56
- return [new K({ name: "pointerdown", callback: (t) => {
56
+ return [new X({ name: "pointerdown", callback: (t) => {
57
57
  if (!this._currentModeCallbacks || !t.isPrimary) return;
58
58
  const e = this.getDrawEventFromEvent(t);
59
59
  e && (this._dragState = "pre-dragging", this._lastDrawEvent = e);
@@ -61,14 +61,14 @@ class Qt {
61
61
  this.getMapEventElement().addEventListener("pointerdown", t);
62
62
  }, unregister: (t) => {
63
63
  this.getMapEventElement().removeEventListener("pointerdown", t);
64
- } }), new K({ name: "pointermove", callback: (t) => {
64
+ } }), new X({ name: "pointermove", callback: (t) => {
65
65
  if (!this._currentModeCallbacks || !t.isPrimary) return;
66
66
  t.preventDefault();
67
67
  const e = this.getDrawEventFromEvent(t);
68
68
  if (e) if (this._dragState === "not-dragging") this._currentModeCallbacks.onMouseMove(e), this._lastDrawEvent = e;
69
69
  else if (this._dragState === "pre-dragging") {
70
70
  if (!this._lastDrawEvent) return;
71
- const i = { x: this._lastDrawEvent.containerX, y: this._lastDrawEvent.containerY }, o = { x: e.containerX, y: e.containerY }, r = this._currentModeCallbacks.getState(), n = F(i, o);
71
+ const i = { x: this._lastDrawEvent.containerX, y: this._lastDrawEvent.containerY }, o = { x: e.containerX, y: e.containerY }, r = this._currentModeCallbacks.getState(), n = I(i, o);
72
72
  let a = !1;
73
73
  if (a = r === "drawing" ? n < this._minPixelDragDistanceDrawing : r === "selecting" ? n < this._minPixelDragDistanceSelecting : n < this._minPixelDragDistance, a) return;
74
74
  this._dragState = "dragging", this._currentModeCallbacks.onDragStart(e, (l) => {
@@ -81,13 +81,13 @@ class Qt {
81
81
  this.getMapEventElement().addEventListener("pointermove", t);
82
82
  }, unregister: (t) => {
83
83
  this.getMapEventElement().removeEventListener("pointermove", t);
84
- } }), new K({ name: "contextmenu", callback: (t) => {
84
+ } }), new X({ name: "contextmenu", callback: (t) => {
85
85
  this._currentModeCallbacks && t.preventDefault();
86
86
  }, register: (t) => {
87
87
  this.getMapEventElement().addEventListener("contextmenu", t);
88
88
  }, unregister: (t) => {
89
89
  this.getMapEventElement().removeEventListener("contextmenu", t);
90
- } }), new K({ name: "pointerup", callback: (t) => {
90
+ } }), new X({ name: "pointerup", callback: (t) => {
91
91
  if (!this._currentModeCallbacks || t.target !== this.getMapEventElement() || !t.isPrimary) return;
92
92
  const e = this.getDrawEventFromEvent(t);
93
93
  e && (this._dragState === "dragging" ? this._currentModeCallbacks.onDragEnd(e, (i) => {
@@ -97,13 +97,13 @@ class Qt {
97
97
  this.getMapEventElement().addEventListener("pointerup", t);
98
98
  }, unregister: (t) => {
99
99
  this.getMapEventElement().removeEventListener("pointerup", t);
100
- } }), new K({ name: "keyup", callback: (t) => {
100
+ } }), new X({ name: "keyup", callback: (t) => {
101
101
  this._currentModeCallbacks && (this._heldKeys.delete(t.key), this._currentModeCallbacks.onKeyUp({ key: t.key, heldKeys: Array.from(this._heldKeys), preventDefault: () => t.preventDefault() }));
102
102
  }, register: (t) => {
103
103
  this.getMapEventElement().addEventListener("keyup", t);
104
104
  }, unregister: (t) => {
105
105
  this.getMapEventElement().removeEventListener("keyup", t);
106
- } }), new K({ name: "keydown", callback: (t) => {
106
+ } }), new X({ name: "keydown", callback: (t) => {
107
107
  this._currentModeCallbacks && (this._heldKeys.add(t.key), this._currentModeCallbacks.onKeyDown({ key: t.key, heldKeys: Array.from(this._heldKeys), preventDefault: () => t.preventDefault() }));
108
108
  }, register: (t) => {
109
109
  this.getMapEventElement().addEventListener("keydown", t);
@@ -117,7 +117,7 @@ class Qt {
117
117
  }), this.clear();
118
118
  }
119
119
  }
120
- class we extends Qt {
120
+ class we extends te {
121
121
  constructor(t) {
122
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
123
  }
@@ -187,13 +187,13 @@ class we extends Qt {
187
187
  this.updateChangedIds(t), this._nextRender && cancelAnimationFrame(this._nextRender), this._nextRender = requestAnimationFrame(() => {
188
188
  const i = [...t.created, ...t.updated, ...t.unchanged], o = [], r = [], n = [];
189
189
  for (let a = 0; a < i.length; a++) {
190
- const l = i[a], { properties: c } = l, h = e[c.mode](l);
191
- l.geometry.type === "Point" ? (c.pointColor = h.pointColor, c.pointOutlineColor = h.pointOutlineColor, c.pointOutlineWidth = h.pointOutlineWidth, c.pointWidth = h.pointWidth, o.push(l)) : l.geometry.type === "LineString" ? (c.lineStringColor = h.lineStringColor, c.lineStringWidth = h.lineStringWidth, r.push(l)) : l.geometry.type === "Polygon" && (c.polygonFillColor = h.polygonFillColor, c.polygonFillOpacity = h.polygonFillOpacity, c.polygonOutlineColor = h.polygonOutlineColor, c.polygonOutlineWidth = h.polygonOutlineWidth, n.push(l));
190
+ const l = i[a], { properties: d } = l, c = e[d.mode](l);
191
+ l.geometry.type === "Point" ? (d.pointColor = c.pointColor, d.pointOutlineColor = c.pointOutlineColor, d.pointOutlineWidth = c.pointOutlineWidth, d.pointWidth = c.pointWidth, o.push(l)) : l.geometry.type === "LineString" ? (d.lineStringColor = c.lineStringColor, d.lineStringWidth = c.lineStringWidth, r.push(l)) : l.geometry.type === "Polygon" && (d.polygonFillColor = c.polygonFillColor, d.polygonFillOpacity = c.polygonFillOpacity, d.polygonOutlineColor = c.polygonOutlineColor, d.polygonOutlineWidth = c.polygonOutlineWidth, n.push(l));
192
192
  }
193
193
  if (this._rendered) {
194
- const a = this.changedIds.deletion || this.changedIds.styling, l = a || this.changedIds.linestrings, c = a || this.changedIds.polygons;
195
- let h;
196
- (a || this.changedIds.points) && (h = this._setGeoJSONLayerData("Point", o)), l && this._setGeoJSONLayerData("LineString", r), c && this._setGeoJSONLayerData("Polygon", n), h && this._map.moveLayer(h);
194
+ const a = this.changedIds.deletion || this.changedIds.styling, l = a || this.changedIds.linestrings, d = a || this.changedIds.polygons;
195
+ let c;
196
+ (a || this.changedIds.points) && (c = this._setGeoJSONLayerData("Point", o)), l && this._setGeoJSONLayerData("LineString", r), d && this._setGeoJSONLayerData("Polygon", n), c && this._map.moveLayer(c);
197
197
  } else {
198
198
  const a = this._addGeoJSONLayer("Point", o);
199
199
  this._addGeoJSONLayer("LineString", r), this._addGeoJSONLayer("Polygon", n), this._rendered = !0, a && this._map.moveLayer(a);
@@ -211,10 +211,11 @@ class we extends Qt {
211
211
  return super.unregister();
212
212
  }
213
213
  register(t) {
214
- super.register(t), this._currentModeCallbacks && this._currentModeCallbacks.onReady && this._currentModeCallbacks.onReady();
214
+ var e;
215
+ super.register(t), (e = this._currentModeCallbacks) != null && e.onReady && this._currentModeCallbacks.onReady();
215
216
  }
216
217
  }
217
- class Ee extends Qt {
218
+ class Fe extends te {
218
219
  constructor(t) {
219
220
  super(t), this.mapboxglAdapter = void 0, this.mapboxglAdapter = new we(t);
220
221
  }
@@ -255,8 +256,8 @@ class Ee extends Qt {
255
256
  this.mapboxglAdapter.clear();
256
257
  }
257
258
  }
258
- const Ie = { radians: 6370997 / (2 * Math.PI), degrees: 2 * Math.PI * 6370997 / 360, ft: 0.3048, m: 1, "us-ft": 1200 / 3937 };
259
- var te = class {
259
+ const Ee = { radians: 6370997 / (2 * Math.PI), degrees: 2 * Math.PI * 6370997 / 360, ft: 0.3048, m: 1, "us-ft": 1200 / 3937 };
260
+ var ee = class {
260
261
  constructor(s) {
261
262
  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;
262
263
  }
@@ -273,7 +274,7 @@ var te = class {
273
274
  return this.units_;
274
275
  }
275
276
  getMetersPerUnit() {
276
- return this.metersPerUnit_ || Ie[this.units_];
277
+ return this.metersPerUnit_ || Ee[this.units_];
277
278
  }
278
279
  getWorldExtent() {
279
280
  return this.worldExtent_;
@@ -306,76 +307,76 @@ var te = class {
306
307
  return this.getPointResolutionFunc_;
307
308
  }
308
309
  };
309
- const it = 6378137, J = Math.PI * it, Fe = [-J, -J, J, J], _e = [-180, -85, 180, 85], st = it * Math.log(Math.tan(Math.PI / 2));
310
- class z extends te {
310
+ const et = 6378137, H = Math.PI * et, Ie = [-H, -H, H, H], _e = [-180, -85, 180, 85], st = et * Math.log(Math.tan(Math.PI / 2));
311
+ class K extends ee {
311
312
  constructor(t) {
312
- super({ code: t, units: "m", extent: Fe, global: !0, worldExtent: _e, getPointResolution: function(e, i) {
313
- return e / Math.cosh(i[1] / it);
313
+ super({ code: t, units: "m", extent: Ie, global: !0, worldExtent: _e, getPointResolution: function(e, i) {
314
+ return e / Math.cosh(i[1] / et);
314
315
  } });
315
316
  }
316
317
  }
317
- const Dt = [new z("EPSG:3857"), new z("EPSG:102100"), new z("EPSG:102113"), new z("EPSG:900913"), new z("http://www.opengis.net/def/crs/EPSG/0/3857"), new z("http://www.opengis.net/gml/srs/epsg.xml#3857")], Ot = [-180, -90, 180, 90], De = 6378137 * Math.PI / 180;
318
- class A extends te {
318
+ const kt = [new K("EPSG:3857"), new K("EPSG:102100"), new K("EPSG:102113"), new K("EPSG:900913"), new K("http://www.opengis.net/def/crs/EPSG/0/3857"), new K("http://www.opengis.net/gml/srs/epsg.xml#3857")], Lt = [-180, -90, 180, 90], De = 6378137 * Math.PI / 180;
319
+ class A extends ee {
319
320
  constructor(t, e) {
320
- super({ code: t, units: "degrees", extent: Ot, axisOrientation: e, global: !0, metersPerUnit: De, worldExtent: Ot });
321
+ super({ code: t, units: "degrees", extent: Lt, axisOrientation: e, global: !0, metersPerUnit: De, worldExtent: Lt });
321
322
  }
322
323
  }
323
- const kt = [new A("CRS:84"), new A("EPSG:4326", "neu"), new A("urn:ogc:def:crs:OGC:1.3:CRS84"), new A("urn:ogc:def:crs:OGC:2:84"), new A("http://www.opengis.net/def/crs/OGC/1.3/CRS84"), new A("http://www.opengis.net/gml/srs/epsg.xml#4326", "neu"), new A("http://www.opengis.net/def/crs/EPSG/0/4326", "neu")];
324
- let vt = {};
324
+ const Wt = [new A("CRS:84"), new A("EPSG:4326", "neu"), new A("urn:ogc:def:crs:OGC:1.3:CRS84"), new A("urn:ogc:def:crs:OGC:2:84"), new A("http://www.opengis.net/def/crs/OGC/1.3/CRS84"), new A("http://www.opengis.net/gml/srs/epsg.xml#4326", "neu"), new A("http://www.opengis.net/def/crs/EPSG/0/4326", "neu")];
325
+ let Pt = {};
325
326
  function ut(s, t, e) {
326
327
  const i = s.getCode(), o = t.getCode();
327
- i in vt || (vt[i] = {}), vt[i][o] = e;
328
+ i in Pt || (Pt[i] = {}), Pt[i][o] = e;
328
329
  }
329
- function ee(s, t) {
330
+ function ie(s, t) {
330
331
  if (t !== void 0) for (let e = 0, i = s.length; e < i; ++e) t[e] = s[e];
331
332
  else t = s.slice();
332
333
  return t;
333
334
  }
334
335
  function Oe(s) {
335
- s.getCode(), ut(s, s, ee);
336
+ s.getCode(), ut(s, s, ie);
336
337
  }
337
- function Lt(s) {
338
+ function jt(s) {
338
339
  (function(t) {
339
340
  t.forEach(Oe);
340
341
  })(s), s.forEach(function(t) {
341
342
  s.forEach(function(e) {
342
- t !== e && ut(t, e, ee);
343
+ t !== e && ut(t, e, ie);
343
344
  });
344
345
  });
345
346
  }
346
- var Wt, jt, Bt, b;
347
- Lt(Dt), Lt(kt), Wt = Dt, jt = function(s, t, e) {
347
+ var Bt, Nt, Gt, b;
348
+ jt(kt), jt(Wt), Bt = kt, Nt = function(s, t, e) {
348
349
  const i = s.length;
349
350
  e = e > 1 ? e : 2, t === void 0 && (t = e > 2 ? s.slice() : new Array(i));
350
351
  for (let o = 0; o < i; o += e) {
351
- t[o] = J * s[o] / 180;
352
- let r = it * Math.log(Math.tan(Math.PI * (+s[o + 1] + 90) / 360));
352
+ t[o] = H * s[o] / 180;
353
+ let r = et * Math.log(Math.tan(Math.PI * (+s[o + 1] + 90) / 360));
353
354
  r > st ? r = st : r < -st && (r = -st), t[o + 1] = r;
354
355
  }
355
356
  return t;
356
- }, Bt = function(s, t, e) {
357
+ }, Gt = function(s, t, e) {
357
358
  const i = s.length;
358
359
  e = e > 1 ? e : 2, t === void 0 && (t = e > 2 ? s.slice() : new Array(i));
359
- for (let o = 0; o < i; o += e) t[o] = 180 * s[o] / J, t[o + 1] = 360 * Math.atan(Math.exp(s[o + 1] / it)) / Math.PI - 90;
360
+ for (let o = 0; o < i; o += e) t[o] = 180 * s[o] / H, t[o + 1] = 360 * Math.atan(Math.exp(s[o + 1] / et)) / Math.PI - 90;
360
361
  return t;
361
- }, kt.forEach(function(s) {
362
- Wt.forEach(function(t) {
363
- ut(s, t, jt), ut(t, s, Bt);
362
+ }, Wt.forEach(function(s) {
363
+ Bt.forEach(function(t) {
364
+ ut(s, t, Nt), ut(t, s, Gt);
364
365
  });
365
366
  });
366
367
  (function(s) {
367
368
  s.Commit = "commit", s.Provisional = "provisional", s.Finish = "finish";
368
369
  })(b || (b = {}));
369
- const bt = "selected", et = "midPoint", Nt = "closingPoint";
370
- function Pt(s) {
370
+ const wt = "selected", tt = "midPoint", Ft = "closingPoint";
371
+ function xt(s) {
371
372
  return !!(s && typeof s == "object" && s !== null && !Array.isArray(s));
372
373
  }
373
- function Gt(s) {
374
- if (!function(t) {
374
+ function At(s) {
375
+ return !!function(t) {
375
376
  return typeof t == "number" && !isNaN(new Date(t).valueOf());
376
- }(s)) throw new Error("updatedAt and createdAt are not valid timestamps");
377
- return !0;
377
+ }(s);
378
378
  }
379
+ const ke = "Feature mode property does not match the mode being added to";
379
380
  var U;
380
381
  (function(s) {
381
382
  s.Drawing = "drawing", s.Select = "select", s.Static = "static", s.Render = "render";
@@ -397,7 +398,7 @@ class W {
397
398
  registerBehaviors(t) {
398
399
  }
399
400
  constructor(t) {
400
- 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 ? x({}, t.styles) : {}, this.pointerDistance = t && t.pointerDistance || 40, this.validate = t && t.validation, this.projection = t && t.projection || "web-mercator";
401
+ 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 ? M({}, t.styles) : {}, this.pointerDistance = t && t.pointerDistance || 40, this.validate = t && t.validation, this.projection = t && t.projection || "web-mercator";
401
402
  }
402
403
  setDrawing() {
403
404
  if (this._state !== "started") throw new Error("Mode must be unregistered or stopped to start");
@@ -416,23 +417,33 @@ class W {
416
417
  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 });
417
418
  }
418
419
  validateFeature(t) {
420
+ return this.performFeatureValidation(t);
421
+ }
422
+ performFeatureValidation(t) {
419
423
  if (this._state === "unregistered") throw new Error("Mode must be registered");
420
424
  const e = function(i, o) {
421
425
  let r;
422
- if (Pt(i)) if (i.id == null) r = "Feature has no id";
426
+ if (xt(i)) if (i.id == null) r = "Feature has no id";
423
427
  else if (typeof i.id != "string" && typeof i.id != "number") r = "Feature must be string or number as per GeoJSON spec";
424
- else if (o(i.id)) if (Pt(i.geometry)) if (Pt(i.properties)) if (typeof i.geometry.type == "string" && ["Polygon", "LineString", "Point"].includes(i.geometry.type)) if (Array.isArray(i.geometry.coordinates)) {
425
- if (!i.properties.mode || typeof i.properties.mode != "string") throw new Error("Feature does not have a valid mode property");
428
+ else if (o(i.id)) if (xt(i.geometry)) if (xt(i.properties)) if (typeof i.geometry.type == "string" && ["Polygon", "LineString", "Point"].includes(i.geometry.type)) if (Array.isArray(i.geometry.coordinates)) {
429
+ if (!i.properties.mode || typeof i.properties.mode != "string") return { valid: !1, reason: "Feature does not have a valid mode property" };
426
430
  } else r = "Feature coordinates is not an array";
427
431
  else r = "Feature is not Point, LineString or Polygon";
428
432
  else r = "Feature has no properties";
429
433
  else r = "Feature has no geometry";
430
434
  else r = "Feature must match the id strategy (default is UUID4)";
431
435
  else r = "Feature is not object";
432
- if (r) throw new Error(r);
433
- return !0;
436
+ return r ? { valid: !1, reason: r } : { valid: !0 };
434
437
  }(t, this.store.idStrategy.isValidId);
435
- return this.validate ? this.validate(t, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: b.Provisional }) : e;
438
+ if (this.validate) {
439
+ const i = this.validate(t, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: b.Provisional });
440
+ return { valid: e.valid && i.valid, reason: i.reason };
441
+ }
442
+ return { valid: e.valid, reason: e.reason };
443
+ }
444
+ validateModeFeature(t, e) {
445
+ const i = this.performFeatureValidation(t);
446
+ return i.valid ? t.properties.mode !== this.mode ? { valid: !1, reason: ke } : e(t) : { valid: !1, reason: i.reason };
436
447
  }
437
448
  onFinish(t, e) {
438
449
  }
@@ -464,39 +475,39 @@ class W {
464
475
  return t === void 0 ? e : typeof t == "function" ? t(i) : t;
465
476
  }
466
477
  }
467
- class ke extends W {
478
+ class Le extends W {
468
479
  constructor(...t) {
469
480
  super(...t), this.type = U.Select;
470
481
  }
471
482
  }
472
483
  function G(s, t) {
473
- const e = (c) => c * Math.PI / 180, i = e(s[1]), o = e(s[0]), r = e(t[1]), n = r - i, a = e(t[0]) - o, l = Math.sin(n / 2) * Math.sin(n / 2) + Math.cos(i) * Math.cos(r) * Math.sin(a / 2) * Math.sin(a / 2);
484
+ const e = (d) => d * Math.PI / 180, i = e(s[1]), o = e(s[0]), r = e(t[1]), n = r - i, a = e(t[0]) - o, l = Math.sin(n / 2) * Math.sin(n / 2) + Math.cos(i) * Math.cos(r) * Math.sin(a / 2) * Math.sin(a / 2);
474
485
  return 2 * Math.atan2(Math.sqrt(l), Math.sqrt(1 - l)) * 6371e3 / 1e3;
475
486
  }
476
- const wt = 63710088e-1;
487
+ const Et = 63710088e-1;
477
488
  function _(s) {
478
489
  return s % 360 * Math.PI / 180;
479
490
  }
480
- function ie(s) {
481
- return s / (wt / 1e3);
491
+ function oe(s) {
492
+ return s / (Et / 1e3);
482
493
  }
483
- function q(s) {
494
+ function $(s) {
484
495
  return s % (2 * Math.PI) * 180 / Math.PI;
485
496
  }
486
- const At = 57.29577951308232, Vt = 0.017453292519943295, gt = 6378137, M = (s, t) => ({ x: s === 0 ? 0 : s * Vt * gt, y: t === 0 ? 0 : Math.log(Math.tan(Math.PI / 4 + t * Vt / 2)) * gt }), L = (s, t) => ({ lng: s === 0 ? 0 : At * (s / gt), lat: t === 0 ? 0 : (2 * Math.atan(Math.exp(t / gt)) - Math.PI / 2) * At });
487
- function Le(s, t, e) {
488
- const i = _(s[0]), o = _(s[1]), r = _(e), n = ie(t), a = Math.asin(Math.sin(o) * Math.cos(n) + Math.cos(o) * Math.sin(n) * Math.cos(r));
489
- return [q(i + Math.atan2(Math.sin(r) * Math.sin(n) * Math.cos(o), Math.cos(n) - Math.sin(o) * Math.sin(a))), q(a)];
497
+ const Vt = 57.29577951308232, Ut = 0.017453292519943295, gt = 6378137, x = (s, t) => ({ x: s === 0 ? 0 : s * Ut * gt, y: t === 0 ? 0 : Math.log(Math.tan(Math.PI / 4 + t * Ut / 2)) * gt }), O = (s, t) => ({ lng: s === 0 ? 0 : Vt * (s / gt), lat: t === 0 ? 0 : (2 * Math.atan(Math.exp(t / gt)) - Math.PI / 2) * Vt });
498
+ function We(s, t, e) {
499
+ const i = _(s[0]), o = _(s[1]), r = _(e), n = oe(t), a = Math.asin(Math.sin(o) * Math.cos(n) + Math.cos(o) * Math.sin(n) * Math.cos(r));
500
+ return [$(i + Math.atan2(Math.sin(r) * Math.sin(n) * Math.cos(o), Math.cos(n) - Math.sin(o) * Math.sin(a))), $(a)];
490
501
  }
491
- function Ut(s) {
502
+ function Tt(s) {
492
503
  const { center: t, radiusKilometers: e, coordinatePrecision: i } = s, o = s.steps ? s.steps : 64, r = [];
493
504
  for (let n = 0; n < o; n++) {
494
- const a = Le(t, e, -360 * n / o);
495
- r.push([E(a[0], i), E(a[1], i)]);
505
+ const a = We(t, e, -360 * n / o);
506
+ r.push([F(a[0], i), F(a[1], i)]);
496
507
  }
497
508
  return r.push(r[0]), { type: "Feature", geometry: { type: "Polygon", coordinates: [r] }, properties: {} };
498
509
  }
499
- function Et(s) {
510
+ function It(s) {
500
511
  const t = { epsilon: 0 };
501
512
  let e;
502
513
  if (s.geometry.type === "Polygon") e = s.geometry.coordinates;
@@ -505,20 +516,20 @@ function Et(s) {
505
516
  e = [s.geometry.coordinates];
506
517
  }
507
518
  const i = [];
508
- for (let n = 0; n < e.length; n++) for (let a = 0; a < e[n].length - 1; a++) for (let l = 0; l < e.length; l++) for (let c = 0; c < e[l].length - 1; c++) r(n, a, l, c);
519
+ for (let n = 0; n < e.length; n++) for (let a = 0; a < e[n].length - 1; a++) for (let l = 0; l < e.length; l++) for (let d = 0; d < e[l].length - 1; d++) r(n, a, l, d);
509
520
  return i.length > 0;
510
521
  function o(n) {
511
522
  return n < 0 - t.epsilon || n > 1 + t.epsilon;
512
523
  }
513
- function r(n, a, l, c) {
514
- const h = e[n][a], d = e[n][a + 1], u = e[l][c], g = e[l][c + 1], p = function(f, v, C, S) {
515
- if (nt(f, C) || nt(f, S) || nt(v, C) || nt(S, C)) return null;
516
- const P = f[0], w = f[1], I = v[0], B = v[1], T = C[0], X = C[1], N = S[0], rt = S[1], Ct = (P - I) * (X - rt) - (w - B) * (T - N);
517
- return Ct === 0 ? null : [((P * B - w * I) * (T - N) - (P - I) * (T * rt - X * N)) / Ct, ((P * B - w * I) * (X - rt) - (w - B) * (T * rt - X * N)) / Ct];
518
- }(h, d, u, g);
524
+ function r(n, a, l, d) {
525
+ const c = e[n][a], h = e[n][a + 1], u = e[l][d], g = e[l][d + 1], p = function(f, C, v, P) {
526
+ if (nt(f, v) || nt(f, P) || nt(C, v) || nt(P, v)) return null;
527
+ const S = f[0], w = f[1], E = C[0], B = C[1], T = v[0], R = v[1], N = P[0], rt = P[1], Ct = (S - E) * (R - rt) - (w - B) * (T - N);
528
+ return Ct === 0 ? null : [((S * B - w * E) * (T - N) - (S - E) * (T * rt - R * N)) / Ct, ((S * B - w * E) * (R - rt) - (w - B) * (T * rt - R * N)) / Ct];
529
+ }(c, h, u, g);
519
530
  if (p === null) return;
520
531
  let y, m;
521
- y = d[0] !== h[0] ? (p[0] - h[0]) / (d[0] - h[0]) : (p[1] - h[1]) / (d[1] - h[1]), m = g[0] !== u[0] ? (p[0] - u[0]) / (g[0] - u[0]) : (p[1] - u[1]) / (g[1] - u[1]), o(y) || o(m) || (p.toString(), i.push(p));
532
+ y = h[0] !== c[0] ? (p[0] - c[0]) / (h[0] - c[0]) : (p[1] - c[1]) / (h[1] - c[1]), m = g[0] !== u[0] ? (p[0] - u[0]) / (g[0] - u[0]) : (p[1] - u[1]) / (g[1] - u[1]), o(y) || o(m) || (p.toString(), i.push(p));
522
533
  }
523
534
  }
524
535
  function nt(s, t) {
@@ -533,22 +544,24 @@ function Rt(s) {
533
544
  for (; Math.round(s * t) / t !== s; ) t *= 10, e++;
534
545
  return e;
535
546
  }
536
- function R(s, t) {
537
- return s.geometry.type === "Polygon" && s.geometry.coordinates.length === 1 && s.geometry.coordinates[0].length >= 4 && s.geometry.coordinates[0].every((o) => mt(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];
547
+ const je = "Feature is not a Polygon", Be = "Feature has holes", Ne = "Feature has less than 4 coordinates", Ge = "Feature has invalid coordinates", Ae = "Feature coordinates are not closed";
548
+ function vt(s, t) {
549
+ return s.geometry.type !== "Polygon" ? { valid: !1, reason: je } : s.geometry.coordinates.length !== 1 ? { valid: !1, reason: Be } : s.geometry.coordinates[0].length < 4 ? { valid: !1, reason: Ne } : s.geometry.coordinates[0].every((o) => mt(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] ? { valid: !1, reason: Ae } : { valid: !0 } : { valid: !1, reason: Ge };
538
550
  var e, i;
539
551
  }
540
- function oe(s, t) {
541
- return R(s, t) && !Et(s);
552
+ function ot(s, t) {
553
+ const e = vt(s, t);
554
+ return e.valid ? It(s) ? { valid: !1, reason: "Feature intersects itself" } : { valid: !0 } : e;
542
555
  }
543
556
  class re extends W {
544
557
  constructor(t) {
545
558
  var e;
546
- 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;
559
+ 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, this.cursorMovedAfterInitialCursorDown = !1;
547
560
  const i = { start: "crosshair" };
548
- if (this.cursors = t && t.cursors ? x({}, i, t.cursors) : i, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
561
+ if (this.cursors = t && t.cursors ? M({}, i, t.cursors) : i, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
549
562
  else {
550
563
  const o = { cancel: "Escape", finish: "Enter" };
551
- this.keyEvents = t && t.keyEvents ? x({}, o, t.keyEvents) : o;
564
+ this.keyEvents = t && t.keyEvents ? M({}, o, t.keyEvents) : o;
552
565
  }
553
566
  this.startingRadiusKilometers = (e = t == null ? void 0 : t.startingRadiusKilometers) != null ? e : 1e-5, this.validate = t == null ? void 0 : t.validation;
554
567
  }
@@ -557,9 +570,9 @@ class re extends W {
557
570
  const t = this.currentCircleId;
558
571
  if (this.validate && t) {
559
572
  const e = this.store.getGeometryCopy(t);
560
- if (!this.validate({ type: "Feature", id: t, geometry: e, properties: {} }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: b.Finish })) return;
573
+ if (!this.validate({ type: "Feature", id: t, geometry: e, properties: {} }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: b.Finish }).valid) return;
561
574
  }
562
- this.center = void 0, this.currentCircleId = void 0, this.clickCount = 0, this.state === "drawing" && this.setStarted(), this.onFinish(t, { mode: this.mode, action: "draw" });
575
+ this.cursorMovedAfterInitialCursorDown = !1, this.center = void 0, this.currentCircleId = void 0, this.clickCount = 0, this.state === "drawing" && this.setStarted(), this.onFinish(t, { mode: this.mode, action: "draw" });
563
576
  }
564
577
  start() {
565
578
  this.setStarted(), this.setCursor(this.cursors.start);
@@ -570,12 +583,12 @@ class re extends W {
570
583
  onClick(t) {
571
584
  if (this.clickCount === 0) {
572
585
  this.center = [t.lng, t.lat];
573
- const e = Ut({ center: this.center, radiusKilometers: this.startingRadiusKilometers, coordinatePrecision: this.coordinatePrecision }), [i] = this.store.create([{ geometry: e.geometry, properties: { mode: this.mode, radiusKilometers: this.startingRadiusKilometers } }]);
574
- this.currentCircleId = i, this.clickCount++, this.setDrawing();
575
- } else this.clickCount === 1 && this.center && this.currentCircleId !== void 0 && this.updateCircle(t), this.close();
586
+ const e = Tt({ center: this.center, radiusKilometers: this.startingRadiusKilometers, coordinatePrecision: this.coordinatePrecision }), [i] = this.store.create([{ geometry: e.geometry, properties: { mode: this.mode, radiusKilometers: this.startingRadiusKilometers } }]);
587
+ this.currentCircleId = i, this.clickCount++, this.cursorMovedAfterInitialCursorDown = !1, this.setDrawing();
588
+ } else this.clickCount === 1 && this.center && this.currentCircleId !== void 0 && this.cursorMovedAfterInitialCursorDown && this.updateCircle(t), this.close();
576
589
  }
577
590
  onMouseMove(t) {
578
- this.updateCircle(t);
591
+ this.cursorMovedAfterInitialCursorDown = !0, this.updateCircle(t);
579
592
  }
580
593
  onKeyDown() {
581
594
  }
@@ -597,11 +610,11 @@ class re extends W {
597
610
  }
598
611
  }
599
612
  styleFeature(t) {
600
- const e = x({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
613
+ const e = M({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
601
614
  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;
602
615
  }
603
616
  validateFeature(t) {
604
- return !!super.validateFeature(t) && t.properties.mode === this.mode && oe(t, this.coordinatePrecision);
617
+ return this.validateModeFeature(t, (e) => ot(e, this.coordinatePrecision));
605
618
  }
606
619
  updateCircle(t) {
607
620
  if (this.clickCount === 1 && this.center && this.currentCircleId) {
@@ -611,34 +624,35 @@ class re extends W {
611
624
  const o = function(r, n) {
612
625
  const a = 1e3 * G(r, n);
613
626
  if (a === 0) return 1;
614
- const { x: l, y: c } = M(r[0], r[1]), { x: h, y: d } = M(n[0], n[1]);
615
- return Math.sqrt(Math.pow(h - l, 2) + Math.pow(d - c, 2)) / a;
627
+ const { x: l, y: d } = x(r[0], r[1]), { x: c, y: h } = x(n[0], n[1]);
628
+ return Math.sqrt(Math.pow(c - l, 2) + Math.pow(h - d, 2)) / a;
616
629
  }(this.center, [t.lng, t.lat]);
617
630
  i = function(r) {
618
- const { center: n, radiusKilometers: a, coordinatePrecision: l } = r, c = r.steps ? r.steps : 64, h = 1e3 * a, [d, u] = n, { x: g, y: p } = M(d, u), y = [];
619
- for (let m = 0; m < c; m++) {
620
- const f = 360 * m / c * Math.PI / 180, v = h * Math.cos(f), C = h * Math.sin(f), [S, P] = [g + v, p + C], { lng: w, lat: I } = L(S, P);
621
- y.push([E(w, l), E(I, l)]);
631
+ const { center: n, radiusKilometers: a, coordinatePrecision: l } = r, d = r.steps ? r.steps : 64, c = 1e3 * a, [h, u] = n, { x: g, y: p } = x(h, u), y = [];
632
+ for (let m = 0; m < d; m++) {
633
+ const f = 360 * m / d * Math.PI / 180, C = c * Math.cos(f), v = c * Math.sin(f), [P, S] = [g + C, p + v], { lng: w, lat: E } = O(P, S);
634
+ y.push([F(w, l), F(E, l)]);
622
635
  }
623
636
  return y.push(y[0]), { type: "Feature", geometry: { type: "Polygon", coordinates: [y] }, properties: {} };
624
637
  }({ center: this.center, radiusKilometers: e * o, coordinatePrecision: this.coordinatePrecision });
625
638
  } else {
626
639
  if (this.projection !== "globe") throw new Error("Invalid projection");
627
- i = Ut({ center: this.center, radiusKilometers: e, coordinatePrecision: this.coordinatePrecision });
640
+ i = Tt({ center: this.center, radiusKilometers: e, coordinatePrecision: this.coordinatePrecision });
628
641
  }
629
- 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: b.Provisional })) return;
642
+ 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: b.Provisional }).valid) return;
630
643
  this.store.updateGeometry([{ id: this.currentCircleId, geometry: i.geometry }]), this.store.updateProperty([{ id: this.currentCircleId, property: "radiusKilometers", value: e }]);
631
644
  }
632
645
  }
633
646
  }
634
647
  class se extends W {
635
648
  constructor(t) {
636
- 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;
649
+ 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, this.autoClose = void 0, this.autoCloseTimeout = 500, this.hasLeftStartingPoint = !1, this.preventNewFeature = !1;
637
650
  const e = { start: "crosshair", close: "pointer" };
638
- if (this.cursors = t && t.cursors ? x({}, 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 };
651
+ if (this.cursors = t && t.cursors ? M({}, e, t.cursors) : e, this.preventPointsNearClose = t && t.preventPointsNearClose || !0, t && t.autoCloseTimeout && !t.autoClose) throw new Error("autoCloseTimeout is set, but autoClose is not enabled");
652
+ if (this.autoClose = t && t.autoClose || !1, this.autoCloseTimeout = t && t.autoCloseTimeout || 500, this.minDistance = t && t.minDistance || 20, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
639
653
  else {
640
654
  const i = { cancel: "Escape", finish: "Enter" };
641
- this.keyEvents = t && t.keyEvents ? x({}, i, t.keyEvents) : i;
655
+ this.keyEvents = t && t.keyEvents ? M({}, i, t.keyEvents) : i;
642
656
  }
643
657
  this.validate = t == null ? void 0 : t.validation;
644
658
  }
@@ -647,9 +661,9 @@ class se extends W {
647
661
  const t = this.currentId;
648
662
  if (this.validate && t) {
649
663
  const e = this.store.getGeometryCopy(t);
650
- if (!this.validate({ type: "Feature", id: t, geometry: e, properties: {} }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: b.Finish })) return;
664
+ if (!this.validate({ type: "Feature", id: t, geometry: e, properties: {} }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: b.Finish }).valid) return;
651
665
  }
652
- 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" });
666
+ this.closingPointId && this.store.delete([this.closingPointId]), this.startingClick = !1, this.currentId = void 0, this.closingPointId = void 0, this.hasLeftStartingPoint = !1, this.state === "drawing" && this.setStarted(), this.onFinish(t, { mode: this.mode, action: "draw" });
653
667
  }
654
668
  start() {
655
669
  this.setStarted(), this.setCursor(this.cursors.start);
@@ -659,21 +673,25 @@ class se extends W {
659
673
  }
660
674
  onMouseMove(t) {
661
675
  if (this.currentId === void 0 || this.startingClick === !1) return;
662
- const e = this.store.getGeometryCopy(this.currentId), i = e.coordinates[0].length - 2, [o, r] = e.coordinates[0][i], { x: n, y: a } = this.project(o, r), l = F({ x: n, y: a }, { x: t.containerX, y: t.containerY }), [c, h] = e.coordinates[0][0], { x: d, y: u } = this.project(c, h);
663
- if (F({ x: d, y: u }, { x: t.containerX, y: t.containerY }) < this.pointerDistance) {
664
- if (this.setCursor(this.cursors.close), this.preventPointsNearClose) return;
665
- } else this.setCursor(this.cursors.start);
676
+ const e = this.store.getGeometryCopy(this.currentId), i = e.coordinates[0].length - 2, [o, r] = e.coordinates[0][i], { x: n, y: a } = this.project(o, r), l = I({ x: n, y: a }, { x: t.containerX, y: t.containerY }), [d, c] = e.coordinates[0][0], { x: h, y: u } = this.project(d, c);
677
+ if (I({ x: h, y: u }, { x: t.containerX, y: t.containerY }) < this.pointerDistance) {
678
+ if (this.autoClose && this.hasLeftStartingPoint && (this.preventNewFeature = !0, setTimeout(() => {
679
+ this.preventNewFeature = !1;
680
+ }, this.autoCloseTimeout), this.close()), this.setCursor(this.cursors.close), this.preventPointsNearClose) return;
681
+ } else this.hasLeftStartingPoint = !0, this.setCursor(this.cursors.start);
666
682
  if (l < this.minDistance) return;
667
683
  e.coordinates[0].pop();
668
684
  const g = { type: "Polygon", coordinates: [[...e.coordinates[0], [t.lng, t.lat], e.coordinates[0][0]]] };
669
- this.validate && !this.validate({ type: "Feature", id: this.currentId, geometry: g, properties: {} }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: b.Provisional }) || this.store.updateGeometry([{ id: this.currentId, geometry: g }]);
685
+ this.validate && !this.validate({ type: "Feature", id: this.currentId, geometry: g, properties: {} }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: b.Provisional }).valid || this.store.updateGeometry([{ id: this.currentId, geometry: g }]);
670
686
  }
671
687
  onClick(t) {
672
- if (this.startingClick === !1) {
673
- 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 } }]);
674
- return this.currentId = e, this.closingPointId = i, this.startingClick = !0, void this.setDrawing();
688
+ if (!this.preventNewFeature) {
689
+ if (this.startingClick === !1) {
690
+ 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, [Ft]: !0 } }]);
691
+ return this.currentId = e, this.closingPointId = i, this.startingClick = !0, void this.setDrawing();
692
+ }
693
+ this.close();
675
694
  }
676
- this.close();
677
695
  }
678
696
  onKeyDown() {
679
697
  }
@@ -695,14 +713,14 @@ class se extends W {
695
713
  }
696
714
  }
697
715
  styleFeature(t) {
698
- const e = x({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
716
+ const e = M({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
699
717
  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);
700
718
  }
701
719
  validateFeature(t) {
702
- return !!super.validateFeature(t) && t.properties.mode === this.mode && R(t, this.coordinatePrecision);
720
+ return this.validateModeFeature(t, (e) => vt(e, this.coordinatePrecision));
703
721
  }
704
722
  }
705
- class O {
723
+ class k {
706
724
  constructor({ store: t, mode: e, project: i, unproject: o, pointerDistance: r, coordinatePrecision: n, projection: a }) {
707
725
  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 = r, this.coordinatePrecision = n, this.projection = a;
708
726
  }
@@ -711,7 +729,7 @@ function ne({ unproject: s, point: t, pointerDistance: e }) {
711
729
  const i = e / 2, { x: o, y: r } = t;
712
730
  return { type: "Feature", properties: {}, geometry: { type: "Polygon", coordinates: [[s(o - i, r - i), s(o + i, r - i), s(o + i, r + i), s(o - i, r + i), s(o - i, r - i)].map((n) => [n.lng, n.lat])] } };
713
731
  }
714
- class It extends O {
732
+ class _t extends k {
715
733
  constructor(t) {
716
734
  super(t);
717
735
  }
@@ -720,16 +738,16 @@ class It extends O {
720
738
  return ne({ unproject: this.unproject, point: { x: e, y: i }, pointerDistance: this.pointerDistance });
721
739
  }
722
740
  }
723
- class Ft extends O {
741
+ class Dt extends k {
724
742
  constructor(t) {
725
743
  super(t);
726
744
  }
727
745
  measure(t, e) {
728
746
  const { x: i, y: o } = this.project(e[0], e[1]);
729
- return F({ x: i, y: o }, { x: t.containerX, y: t.containerY });
747
+ return I({ x: i, y: o }, { x: t.containerX, y: t.containerY });
730
748
  }
731
749
  }
732
- class ae extends O {
750
+ class ae extends k {
733
751
  constructor(t, e, i) {
734
752
  super(t), this.config = void 0, this.pixelDistance = void 0, this.clickBoundingBox = void 0, this.getSnappableCoordinateFirstClick = (o) => this.getSnappable(o, (r) => !!(r.properties && r.properties.mode === this.mode)), this.getSnappableCoordinate = (o, r) => this.getSnappable(o, (n) => !!(n.properties && n.properties.mode === this.mode && n.id !== r)), this.config = t, this.pixelDistance = e, this.clickBoundingBox = i;
735
753
  }
@@ -743,23 +761,23 @@ class ae extends O {
743
761
  a = n.geometry.coordinates;
744
762
  }
745
763
  a.forEach((l) => {
746
- const c = this.pixelDistance.measure(t, l);
747
- c < r.minDist && c < this.pointerDistance && (r.coord = l, r.minDist = c);
764
+ const d = this.pixelDistance.measure(t, l);
765
+ d < r.minDist && d < this.pointerDistance && (r.coord = l, r.minDist = d);
748
766
  });
749
767
  }), r.coord;
750
768
  }
751
769
  }
752
- function Tt(s, t, e) {
753
- const i = _(s[0]), o = _(s[1]), r = _(e), n = ie(t), a = Math.asin(Math.sin(o) * Math.cos(n) + Math.cos(o) * Math.sin(n) * Math.cos(r));
754
- return [q(i + Math.atan2(Math.sin(r) * Math.sin(n) * Math.cos(o), Math.cos(n) - Math.sin(o) * Math.sin(a))), q(a)];
770
+ function Xt(s, t, e) {
771
+ const i = _(s[0]), o = _(s[1]), r = _(e), n = oe(t), a = Math.asin(Math.sin(o) * Math.cos(n) + Math.cos(o) * Math.sin(n) * Math.cos(r));
772
+ return [$(i + Math.atan2(Math.sin(r) * Math.sin(n) * Math.cos(o), Math.cos(n) - Math.sin(o) * Math.sin(a))), $(a)];
755
773
  }
756
- function ot({ x: s, y: t }, e, i) {
774
+ function it({ x: s, y: t }, e, i) {
757
775
  const o = _(i);
758
776
  return { x: s + e * Math.cos(o), y: t + e * Math.sin(o) };
759
777
  }
760
- function Xt(s, t) {
778
+ function Kt(s, t) {
761
779
  const e = _(s[0]), i = _(t[0]), o = _(s[1]), r = _(t[1]), n = Math.sin(i - e) * Math.cos(r), a = Math.cos(o) * Math.sin(r) - Math.sin(o) * Math.cos(r) * Math.cos(i - e);
762
- return q(Math.atan2(n, a));
780
+ return $(Math.atan2(n, a));
763
781
  }
764
782
  function j({ x: s, y: t }, { x: e, y: i }) {
765
783
  let o = Math.atan2(i - t, e - s);
@@ -768,79 +786,82 @@ function j({ x: s, y: t }, { x: e, y: i }) {
768
786
  function V(s) {
769
787
  return (s + 360) % 360;
770
788
  }
771
- function We(s, t, e) {
789
+ function Ve(s, t, e) {
772
790
  const i = [], o = s.length;
773
791
  let r, n, a, l = 0;
774
- for (let h = 0; h < s.length && !(t >= l && h === s.length - 1); h++) {
792
+ for (let c = 0; c < s.length && !(t >= l && c === s.length - 1); c++) {
775
793
  if (l > t && i.length === 0) {
776
- if (r = t - l, !r) return i.push(s[h]), i;
777
- n = Xt(s[h], s[h - 1]) - 180, a = Tt(s[h], r, n), i.push(a);
794
+ if (r = t - l, !r) return i.push(s[c]), i;
795
+ n = Kt(s[c], s[c - 1]) - 180, a = Xt(s[c], r, n), i.push(a);
778
796
  }
779
- if (l >= e) return r = e - l, r ? (n = Xt(s[h], s[h - 1]) - 180, a = Tt(s[h], r, n), i.push(a), i) : (i.push(s[h]), i);
780
- if (l >= t && i.push(s[h]), h === s.length - 1) return i;
781
- l += G(s[h], s[h + 1]);
797
+ if (l >= e) return r = e - l, r ? (n = Kt(s[c], s[c - 1]) - 180, a = Xt(s[c], r, n), i.push(a), i) : (i.push(s[c]), i);
798
+ if (l >= t && i.push(s[c]), c === s.length - 1) return i;
799
+ l += G(s[c], s[c + 1]);
782
800
  }
783
801
  if (l < t && s.length === o) throw new Error("Start position is beyond line");
784
- const c = s[s.length - 1];
785
- return [c, c];
802
+ const d = s[s.length - 1];
803
+ return [d, d];
786
804
  }
787
805
  function at(s) {
788
806
  return s * (Math.PI / 180);
789
807
  }
790
- function Kt(s) {
808
+ function zt(s) {
791
809
  return s * (180 / Math.PI);
792
810
  }
793
- class je extends O {
811
+ class Ue extends k {
794
812
  constructor(t) {
795
813
  super(t), this.config = void 0, this.config = t;
796
814
  }
797
815
  generateInsertionCoordinates(t, e, i) {
798
816
  const o = [t, e];
799
817
  let r = 0;
800
- for (let c = 0; c < o.length - 1; c++) r += G(o[0], o[1]);
818
+ for (let d = 0; d < o.length - 1; d++) r += G(o[0], o[1]);
801
819
  if (r <= i) return o;
802
820
  let n = r / i - 1;
803
821
  Number.isInteger(n) || (n = Math.floor(n) + 1);
804
822
  const a = [];
805
- for (let c = 0; c < n; c++) {
806
- const h = We(o, i * c, i * (c + 1));
807
- a.push(h);
823
+ for (let d = 0; d < n; d++) {
824
+ const c = Ve(o, i * d, i * (d + 1));
825
+ a.push(c);
808
826
  }
809
827
  const l = [];
810
- for (let c = 0; c < a.length; c++) l.push(a[c][1]);
828
+ for (let d = 0; d < a.length; d++) l.push(a[d][1]);
811
829
  return this.limitCoordinates(l);
812
830
  }
813
831
  generateInsertionGeodesicCoordinates(t, e, i) {
814
832
  const o = G(t, e), r = function(n, a, l) {
815
- const c = [], h = at(n[1]), d = at(n[0]), u = at(a[1]), g = at(a[0]);
833
+ const d = [], c = at(n[1]), h = at(n[0]), u = at(a[1]), g = at(a[0]);
816
834
  l += 1;
817
- const p = 2 * Math.asin(Math.sqrt(Math.sin((u - h) / 2) ** 2 + Math.cos(h) * Math.cos(u) * Math.sin((g - d) / 2) ** 2));
818
- if (p === 0 || isNaN(p)) return c;
835
+ const p = 2 * Math.asin(Math.sqrt(Math.sin((u - c) / 2) ** 2 + Math.cos(c) * Math.cos(u) * Math.sin((g - h) / 2) ** 2));
836
+ if (p === 0 || isNaN(p)) return d;
819
837
  for (let y = 0; y <= l; y++) {
820
- const m = y / l, f = Math.sin((1 - m) * p) / Math.sin(p), v = Math.sin(m * p) / Math.sin(p), C = f * Math.cos(h) * Math.cos(d) + v * Math.cos(u) * Math.cos(g), S = f * Math.cos(h) * Math.sin(d) + v * Math.cos(u) * Math.sin(g), P = f * Math.sin(h) + v * Math.sin(u);
821
- if (isNaN(C) || isNaN(S) || isNaN(P)) continue;
822
- const w = Math.atan2(P, Math.sqrt(C ** 2 + S ** 2)), I = Math.atan2(S, C);
823
- isNaN(w) || isNaN(I) || c.push([Kt(I), Kt(w)]);
838
+ const m = y / l, f = Math.sin((1 - m) * p) / Math.sin(p), C = Math.sin(m * p) / Math.sin(p), v = f * Math.cos(c) * Math.cos(h) + C * Math.cos(u) * Math.cos(g), P = f * Math.cos(c) * Math.sin(h) + C * Math.cos(u) * Math.sin(g), S = f * Math.sin(c) + C * Math.sin(u);
839
+ if (isNaN(v) || isNaN(P) || isNaN(S)) continue;
840
+ const w = Math.atan2(S, Math.sqrt(v ** 2 + P ** 2)), E = Math.atan2(P, v);
841
+ isNaN(w) || isNaN(E) || d.push([zt(E), zt(w)]);
824
842
  }
825
- return c.slice(1, -1);
843
+ return d.slice(1, -1);
826
844
  }(t, e, Math.floor(o / i));
827
845
  return this.limitCoordinates(r);
828
846
  }
829
847
  limitCoordinates(t) {
830
- return t.map((e) => [E(e[0], this.config.coordinatePrecision), E(e[1], this.config.coordinatePrecision)]);
848
+ return t.map((e) => [F(e[0], this.config.coordinatePrecision), F(e[1], this.config.coordinatePrecision)]);
831
849
  }
832
850
  }
833
- function $(s, t) {
851
+ function J(s, t) {
834
852
  return s[0] === t[0] && s[1] === t[1];
835
853
  }
836
- class le extends W {
854
+ function le(s, t) {
855
+ return s.geometry.type !== "LineString" ? { valid: !1, reason: "Feature is not a LineString" } : s.geometry.coordinates.length < 2 ? { valid: !1, reason: "Feature has less than 2 coordinates" } : s.geometry.coordinates.every((e) => mt(e, t)) ? { valid: !0 } : { valid: !1, reason: "Feature has invalid coordinates" };
856
+ }
857
+ class de extends W {
837
858
  constructor(t) {
838
859
  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;
839
860
  const e = { start: "crosshair", close: "pointer" };
840
- if (this.cursors = t && t.cursors ? x({}, 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 };
861
+ if (this.cursors = t && t.cursors ? M({}, 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 };
841
862
  else {
842
863
  const i = { cancel: "Escape", finish: "Enter" };
843
- this.keyEvents = t && t.keyEvents ? x({}, i, t.keyEvents) : i;
864
+ this.keyEvents = t && t.keyEvents ? M({}, i, t.keyEvents) : i;
844
865
  }
845
866
  this.validate = t == null ? void 0 : t.validation, this.insertCoordinates = t == null ? void 0 : t.insertCoordinates;
846
867
  }
@@ -854,7 +875,7 @@ class le extends W {
854
875
  updateGeometries(t, e, i) {
855
876
  if (!this.currentId) return;
856
877
  const o = { type: "LineString", coordinates: t };
857
- if (this.validate && !this.validate({ type: "Feature", geometry: o }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: i })) return;
878
+ if (this.validate && !this.validate({ type: "Feature", geometry: o }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: i }).valid) return;
858
879
  const r = [{ id: this.currentId, geometry: o }];
859
880
  this.closingPointId && e && r.push({ id: this.closingPointId, geometry: { type: "Point", coordinates: e } }), i === "commit" && (this.lastCommitedCoordinates = o.coordinates), this.store.updateGeometry(r);
860
881
  }
@@ -879,13 +900,13 @@ class le extends W {
879
900
  updateToLine(t, e) {
880
901
  if (!this.currentId) return;
881
902
  const i = this.store.getGeometryCopy(this.currentId).coordinates, [o, r] = this.lastCommitedCoordinates ? this.lastCommitedCoordinates[this.lastCommitedCoordinates.length - 1] : i[i.length - 2], { x: n, y: a } = this.project(o, r);
882
- if (F({ x: n, y: a }, { x: e.x, y: e.y }) < this.pointerDistance) return void this.close();
903
+ if (I({ x: n, y: a }, { x: e.x, y: e.y }) < this.pointerDistance) return void this.close();
883
904
  this.setCursor(this.cursors.close);
884
905
  const l = [...i, t];
885
906
  this.updateGeometries(l, i[i.length - 1], b.Commit), this.currentCoordinate++;
886
907
  }
887
908
  registerBehaviors(t) {
888
- this.snapping = new ae(t, new Ft(t), new It(t)), this.insertPoint = new je(t);
909
+ this.snapping = new ae(t, new Dt(t), new _t(t)), this.insertPoint = new Ue(t);
889
910
  }
890
911
  start() {
891
912
  this.setStarted(), this.setCursor(this.cursors.start);
@@ -900,12 +921,12 @@ class le extends W {
900
921
  const i = this.snappingEnabled && this.snapping.getSnappableCoordinate(t, this.currentId) || [t.lng, t.lat];
901
922
  if (this.closingPointId) {
902
923
  const [r, n] = e[e.length - 1], { x: a, y: l } = this.project(r, n);
903
- F({ x: a, y: l }, { x: t.containerX, y: t.containerY }) < this.pointerDistance && this.setCursor(this.cursors.close);
924
+ I({ x: a, y: l }, { x: t.containerX, y: t.containerY }) < this.pointerDistance && this.setCursor(this.cursors.close);
904
925
  }
905
926
  let o = [...e, i];
906
927
  if (this.insertCoordinates && this.currentId && this.lastCommitedCoordinates) {
907
928
  const r = this.lastCommitedCoordinates[this.lastCommitedCoordinates.length - 1], n = i;
908
- if (!$(r, n)) {
929
+ if (!J(r, n)) {
909
930
  const a = this.generateInsertCoordinates(r, n);
910
931
  o = [...this.lastCommitedCoordinates.slice(0, -1), ...a, i];
911
932
  }
@@ -937,21 +958,22 @@ class le extends W {
937
958
  }
938
959
  }
939
960
  styleFeature(t) {
940
- const e = x({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
961
+ const e = M({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
941
962
  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);
942
963
  }
943
964
  validateFeature(t) {
944
- return !!super.validateFeature(t) && t.geometry.type === "LineString" && t.properties.mode === this.mode && t.geometry.coordinates.length >= 2;
965
+ return this.validateModeFeature(t, (e) => le(e, this.coordinatePrecision));
945
966
  }
946
967
  }
968
+ const Te = "Feature is not a Point", Re = "Feature has invalid coordinates";
947
969
  function ce(s, t) {
948
- return s.geometry.type === "Point" && mt(s.geometry.coordinates, t);
970
+ return s.geometry.type !== "Point" ? { valid: !1, reason: Te } : mt(s.geometry.coordinates, t) ? { valid: !0 } : { valid: !1, reason: Re };
949
971
  }
950
- class Be extends W {
972
+ class Xe extends W {
951
973
  constructor(t) {
952
974
  super(t), this.mode = "point", this.cursors = void 0;
953
975
  const e = { create: "crosshair" };
954
- this.cursors = t && t.cursors ? x({}, e, t.cursors) : e;
976
+ this.cursors = t && t.cursors ? M({}, e, t.cursors) : e;
955
977
  }
956
978
  start() {
957
979
  this.setStarted(), this.setCursor(this.cursors.create);
@@ -962,7 +984,7 @@ class Be extends W {
962
984
  onClick(t) {
963
985
  if (!this.store) throw new Error("Mode must be registered first");
964
986
  const e = { type: "Point", coordinates: [t.lng, t.lat] }, i = { mode: this.mode };
965
- if (this.validate && !this.validate({ type: "Feature", geometry: e, properties: i }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: b.Finish })) return;
987
+ if (this.validate && !this.validate({ type: "Feature", geometry: e, properties: i }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: b.Finish }).valid) return;
966
988
  const [o] = this.store.create([{ geometry: e, properties: i }]);
967
989
  this.onFinish(o, { mode: this.mode, action: "draw" });
968
990
  }
@@ -981,14 +1003,14 @@ class Be extends W {
981
1003
  onDragEnd() {
982
1004
  }
983
1005
  styleFeature(t) {
984
- const e = x({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1006
+ const e = M({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
985
1007
  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;
986
1008
  }
987
1009
  validateFeature(t) {
988
- return !!super.validateFeature(t) && t.properties.mode === this.mode && ce(t, this.coordinatePrecision);
1010
+ return this.validateModeFeature(t, (e) => ce(e, this.coordinatePrecision));
989
1011
  }
990
1012
  }
991
- class Ne extends O {
1013
+ class Ke extends k {
992
1014
  constructor(t, e) {
993
1015
  super(t), this.config = void 0, this.pixelDistance = void 0, this._startEndPoints = [], this.config = t, this.pixelDistance = e;
994
1016
  }
@@ -1000,7 +1022,7 @@ class Ne extends O {
1000
1022
  create(t, e) {
1001
1023
  if (this.ids.length) throw new Error("Opening and closing points already created");
1002
1024
  if (t.length <= 3) throw new Error("Requires at least 4 coordinates");
1003
- this._startEndPoints = this.store.create([{ geometry: { type: "Point", coordinates: t[0] }, properties: { mode: e, [Nt]: !0 } }, { geometry: { type: "Point", coordinates: t[t.length - 2] }, properties: { mode: e, [Nt]: !0 } }]);
1025
+ this._startEndPoints = this.store.create([{ geometry: { type: "Point", coordinates: t[0] }, properties: { mode: e, [Ft]: !0 } }, { geometry: { type: "Point", coordinates: t[t.length - 2] }, properties: { mode: e, [Ft]: !0 } }]);
1004
1026
  }
1005
1027
  delete() {
1006
1028
  this.ids.length && (this.store.delete(this.ids), this._startEndPoints = []);
@@ -1018,10 +1040,10 @@ class he extends W {
1018
1040
  constructor(t) {
1019
1041
  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;
1020
1042
  const e = { start: "crosshair", close: "pointer" };
1021
- if (this.cursors = t && t.cursors ? x({}, 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 };
1043
+ if (this.cursors = t && t.cursors ? M({}, 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 };
1022
1044
  else {
1023
1045
  const i = { cancel: "Escape", finish: "Enter" };
1024
- this.keyEvents = t && t.keyEvents ? x({}, i, t.keyEvents) : i;
1046
+ this.keyEvents = t && t.keyEvents ? M({}, i, t.keyEvents) : i;
1025
1047
  }
1026
1048
  }
1027
1049
  close() {
@@ -1032,7 +1054,7 @@ class he extends W {
1032
1054
  this.currentCoordinate = 0, this.currentId = void 0, this.closingPoints.delete(), this.state === "drawing" && this.setStarted(), this.onFinish(e, { mode: this.mode, action: "draw" });
1033
1055
  }
1034
1056
  registerBehaviors(t) {
1035
- this.pixelDistance = new Ft(t), this.snapping = new ae(t, this.pixelDistance, new It(t)), this.closingPoints = new Ne(t, this.pixelDistance);
1057
+ this.pixelDistance = new Dt(t), this.snapping = new ae(t, this.pixelDistance, new _t(t)), this.closingPoints = new Ke(t, this.pixelDistance);
1036
1058
  }
1037
1059
  start() {
1038
1060
  this.setStarted(), this.setCursor(this.cursors.start);
@@ -1057,7 +1079,7 @@ class he extends W {
1057
1079
  updatePolygonGeometry(t, e) {
1058
1080
  if (!this.currentId) return !1;
1059
1081
  const i = { type: "Polygon", coordinates: [t] };
1060
- 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));
1082
+ return !(this.validate && !this.validate({ type: "Feature", geometry: i }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: e }).valid || (this.store.updateGeometry([{ id: this.currentId, geometry: i }]), 0));
1061
1083
  }
1062
1084
  onClick(t) {
1063
1085
  if (this.currentCoordinate > 0 && !this.mouseMove && this.onMouseMove(t), this.mouseMove = !1, this.currentCoordinate === 0) {
@@ -1069,19 +1091,19 @@ class he extends W {
1069
1091
  const e = this.snappingEnabled ? this.snapping.getSnappableCoordinate(t, this.currentId) : void 0;
1070
1092
  e && (t.lng = e[0], t.lat = e[1]);
1071
1093
  const i = this.store.getGeometryCopy(this.currentId);
1072
- 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]], b.Commit)) return;
1094
+ if (J([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]], b.Commit)) return;
1073
1095
  this.currentCoordinate++;
1074
1096
  } else if (this.currentCoordinate === 2 && this.currentId) {
1075
1097
  const e = this.snappingEnabled ? this.snapping.getSnappableCoordinate(t, this.currentId) : void 0;
1076
1098
  e && (t.lng = e[0], t.lat = e[1]);
1077
1099
  const i = this.store.getGeometryCopy(this.currentId).coordinates[0];
1078
- if ($([t.lng, t.lat], i[1]) || !this.updatePolygonGeometry([i[0], i[1], [t.lng, t.lat], [t.lng, t.lat], i[0]], b.Commit)) return;
1100
+ if (J([t.lng, t.lat], i[1]) || !this.updatePolygonGeometry([i[0], i[1], [t.lng, t.lat], [t.lng, t.lat], i[0]], b.Commit)) return;
1079
1101
  this.currentCoordinate === 2 && this.closingPoints.create(i, "polygon"), this.currentCoordinate++;
1080
1102
  } else if (this.currentId) {
1081
1103
  const e = this.snappingEnabled ? this.snapping.getSnappableCoordinate(t, this.currentId) : void 0, i = this.store.getGeometryCopy(this.currentId).coordinates[0], { isClosing: o, isPreviousClosing: r } = this.closingPoints.isClosingPoint(t);
1082
1104
  if (r || o) this.close();
1083
1105
  else {
1084
- if (e && (t.lng = e[0], t.lat = e[1]), $([t.lng, t.lat], i[this.currentCoordinate - 1])) return;
1106
+ if (e && (t.lng = e[0], t.lat = e[1]), J([t.lng, t.lat], i[this.currentCoordinate - 1])) return;
1085
1107
  const n = /* @__PURE__ */ function(a = [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]) {
1086
1108
  return { type: "Feature", geometry: { type: "Polygon", coordinates: a }, properties: {} };
1087
1109
  }([[...i.slice(0, -1), [t.lng, t.lat], i[0]]]);
@@ -1112,7 +1134,7 @@ class he extends W {
1112
1134
  }
1113
1135
  }
1114
1136
  styleFeature(t) {
1115
- const e = x({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1137
+ const e = M({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1116
1138
  if (t.properties.mode === this.mode) {
1117
1139
  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;
1118
1140
  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;
@@ -1120,29 +1142,29 @@ class he extends W {
1120
1142
  return e;
1121
1143
  }
1122
1144
  validateFeature(t) {
1123
- return !!super.validateFeature(t) && t.properties.mode === this.mode && R(t, this.coordinatePrecision);
1145
+ return this.validateModeFeature(t, (e) => vt(e, this.coordinatePrecision));
1124
1146
  }
1125
1147
  }
1126
- class de extends W {
1148
+ class ue extends W {
1127
1149
  constructor(t) {
1128
1150
  super(t), this.mode = "rectangle", this.center = void 0, this.clickCount = 0, this.currentRectangleId = void 0, this.keyEvents = void 0, this.cursors = void 0;
1129
1151
  const e = { start: "crosshair" };
1130
- if (this.cursors = t && t.cursors ? x({}, e, t.cursors) : e, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
1152
+ if (this.cursors = t && t.cursors ? M({}, e, t.cursors) : e, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
1131
1153
  else {
1132
1154
  const i = { cancel: "Escape", finish: "Enter" };
1133
- this.keyEvents = t && t.keyEvents ? x({}, i, t.keyEvents) : i;
1155
+ this.keyEvents = t && t.keyEvents ? M({}, i, t.keyEvents) : i;
1134
1156
  }
1135
1157
  }
1136
1158
  updateRectangle(t, e) {
1137
1159
  if (this.clickCount === 1 && this.center && this.currentRectangleId) {
1138
1160
  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]] };
1139
- if (this.validate && !this.validate({ id: this.currentRectangleId, geometry: o }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: e })) return;
1161
+ if (this.validate && !this.validate({ id: this.currentRectangleId, geometry: o }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: e }).valid) return;
1140
1162
  this.store.updateGeometry([{ id: this.currentRectangleId, geometry: o }]);
1141
1163
  }
1142
1164
  }
1143
1165
  close() {
1144
1166
  const t = this.currentRectangleId;
1145
- 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" });
1167
+ this.center = void 0, this.currentRectangleId = void 0, this.clickCount = 0, this.state === "drawing" && this.setStarted(), t !== void 0 && this.onFinish(t, { mode: this.mode, action: "draw" });
1146
1168
  }
1147
1169
  start() {
1148
1170
  this.setStarted(), this.setCursor(this.cursors.start);
@@ -1176,14 +1198,14 @@ class de extends W {
1176
1198
  this.center = void 0, this.currentRectangleId = void 0, this.clickCount = 0, this.state === "drawing" && this.setStarted(), t !== void 0 && this.store.delete([t]);
1177
1199
  }
1178
1200
  styleFeature(t) {
1179
- const e = x({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1201
+ const e = M({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1180
1202
  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;
1181
1203
  }
1182
1204
  validateFeature(t) {
1183
- return !!super.validateFeature(t) && t.properties.mode === this.mode && oe(t, this.coordinatePrecision);
1205
+ return this.validateModeFeature(t, (e) => ot(e, this.coordinatePrecision));
1184
1206
  }
1185
1207
  }
1186
- class dt extends W {
1208
+ class ht extends W {
1187
1209
  constructor(t) {
1188
1210
  super({ styles: t.styles }), this.type = U.Render, this.mode = "render", this.mode = t.modeName;
1189
1211
  }
@@ -1216,49 +1238,52 @@ class dt extends W {
1216
1238
  return { pointColor: this.getHexColorStylingValue(this.styles.pointColor, "#3f97e0", t), pointWidth: this.getNumericStylingValue(this.styles.pointWidth, 6, t), pointOutlineColor: this.getHexColorStylingValue(this.styles.pointOutlineColor, "#ffffff", t), pointOutlineWidth: this.getNumericStylingValue(this.styles.pointOutlineWidth, 0, t), polygonFillColor: this.getHexColorStylingValue(this.styles.polygonFillColor, "#3f97e0", t), polygonFillOpacity: this.getNumericStylingValue(this.styles.polygonFillOpacity, 0.3, t), polygonOutlineColor: this.getHexColorStylingValue(this.styles.polygonOutlineColor, "#3f97e0", t), polygonOutlineWidth: this.getNumericStylingValue(this.styles.polygonOutlineWidth, 4, t), lineStringWidth: this.getNumericStylingValue(this.styles.lineStringWidth, 4, t), lineStringColor: this.getHexColorStylingValue(this.styles.lineStringColor, "#3f97e0", t), zIndex: this.getNumericStylingValue(this.styles.zIndex, 0, t) };
1217
1239
  }
1218
1240
  validateFeature(t) {
1219
- return super.validateFeature(t) && (ce(t, this.coordinatePrecision) || R(t, this.coordinatePrecision) || function(e, i) {
1220
- return e.geometry.type === "LineString" && e.geometry.coordinates.length >= 2 && e.geometry.coordinates.every((o) => mt(o, i));
1221
- }(t, this.coordinatePrecision));
1241
+ const e = super.validateFeature(t);
1242
+ if (e.valid) {
1243
+ const i = t, o = ce(i, this.coordinatePrecision).valid || vt(i, this.coordinatePrecision).valid || le(i, this.coordinatePrecision).valid;
1244
+ return o ? { valid: !0 } : { valid: o, reason: "Feature is not a valid Point, Polygon or LineString feature" };
1245
+ }
1246
+ return e;
1222
1247
  }
1223
1248
  }
1224
1249
  function pt(s, t) {
1225
1250
  const e = s, i = t, o = _(e[1]), r = _(i[1]);
1226
1251
  let n = _(i[0] - e[0]);
1227
1252
  n > Math.PI && (n -= 2 * Math.PI), n < -Math.PI && (n += 2 * Math.PI);
1228
- const a = Math.log(Math.tan(r / 2 + Math.PI / 4) / Math.tan(o / 2 + Math.PI / 4)), l = (q(Math.atan2(n, a)) + 360) % 360;
1253
+ const a = Math.log(Math.tan(r / 2 + Math.PI / 4) / Math.tan(o / 2 + Math.PI / 4)), l = ($(Math.atan2(n, a)) + 360) % 360;
1229
1254
  return l > 180 ? -(360 - l) : l;
1230
1255
  }
1231
- function _t(s, t, e) {
1256
+ function Ot(s, t, e) {
1232
1257
  let i = t;
1233
1258
  t < 0 && (i = -Math.abs(i));
1234
- const o = i / wt, r = s[0] * Math.PI / 180, n = _(s[1]), a = _(e), l = o * Math.cos(a);
1235
- let c = n + l;
1236
- Math.abs(c) > Math.PI / 2 && (c = c > 0 ? Math.PI - c : -Math.PI - c);
1237
- const h = Math.log(Math.tan(c / 2 + Math.PI / 4) / Math.tan(n / 2 + Math.PI / 4)), d = Math.abs(h) > 1e-11 ? l / h : Math.cos(n), u = [(180 * (r + o * Math.sin(a) / d) / Math.PI + 540) % 360 - 180, 180 * c / Math.PI];
1259
+ const o = i / Et, r = s[0] * Math.PI / 180, n = _(s[1]), a = _(e), l = o * Math.cos(a);
1260
+ let d = n + l;
1261
+ Math.abs(d) > Math.PI / 2 && (d = d > 0 ? Math.PI - d : -Math.PI - d);
1262
+ const c = Math.log(Math.tan(d / 2 + Math.PI / 4) / Math.tan(n / 2 + Math.PI / 4)), h = Math.abs(c) > 1e-11 ? l / c : Math.cos(n), u = [(180 * (r + o * Math.sin(a) / h) / Math.PI + 540) % 360 - 180, 180 * d / Math.PI];
1238
1263
  return u[0] += u[0] - s[0] > 180 ? -360 : s[0] - u[0] > 180 ? 360 : 0, u;
1239
1264
  }
1240
- function ue(s, t, e, i, o) {
1265
+ function ge(s, t, e, i, o) {
1241
1266
  const r = i(s[0], s[1]), n = i(t[0], t[1]), { lng: a, lat: l } = o((r.x + n.x) / 2, (r.y + n.y) / 2);
1242
- return [E(a, e), E(l, e)];
1267
+ return [F(a, e), F(l, e)];
1243
1268
  }
1244
- function Ge(s, t, e) {
1245
- const i = _t(s, 1e3 * G(s, t) / 2, pt(s, t));
1246
- return [E(i[0], e), E(i[1], e)];
1269
+ function ze(s, t, e) {
1270
+ const i = Ot(s, 1e3 * G(s, t) / 2, pt(s, t));
1271
+ return [F(i[0], e), F(i[1], e)];
1247
1272
  }
1248
- function zt({ featureCoords: s, precision: t, unproject: e, project: i, projection: o }) {
1273
+ function Yt({ featureCoords: s, precision: t, unproject: e, project: i, projection: o }) {
1249
1274
  const r = [];
1250
1275
  for (let n = 0; n < s.length - 1; n++) {
1251
1276
  let a;
1252
- if (o === "web-mercator") a = ue(s[n], s[n + 1], t, i, e);
1277
+ if (o === "web-mercator") a = ge(s[n], s[n + 1], t, i, e);
1253
1278
  else {
1254
1279
  if (o !== "globe") throw new Error("Invalid projection");
1255
- a = Ge(s[n], s[n + 1], t);
1280
+ a = ze(s[n], s[n + 1], t);
1256
1281
  }
1257
1282
  r.push(a);
1258
1283
  }
1259
1284
  return r;
1260
1285
  }
1261
- class Ae extends O {
1286
+ class Ye extends k {
1262
1287
  constructor(t, e) {
1263
1288
  super(t), this.config = void 0, this.selectionPointBehavior = void 0, this._midPoints = [], this.config = t, this.selectionPointBehavior = e;
1264
1289
  }
@@ -1273,18 +1298,18 @@ class Ae extends O {
1273
1298
  }
1274
1299
  create(t, e, i) {
1275
1300
  if (!this.store.has(e)) throw new Error("Store does not have feature with this id");
1276
- this._midPoints = this.store.create(function(o, r, n, a, l, c) {
1277
- return zt({ featureCoords: o, precision: n, project: a, unproject: l, projection: c }).map((h, d) => ({ geometry: { type: "Point", coordinates: h }, properties: r(d) }));
1278
- }(t, (o) => ({ mode: this.mode, [et]: !0, midPointSegment: o, midPointFeatureId: e }), i, this.config.project, this.config.unproject, this.projection));
1301
+ this._midPoints = this.store.create(function(o, r, n, a, l, d) {
1302
+ return Yt({ featureCoords: o, precision: n, project: a, unproject: l, projection: d }).map((c, h) => ({ geometry: { type: "Point", coordinates: c }, properties: r(h) }));
1303
+ }(t, (o) => ({ mode: this.mode, [tt]: !0, midPointSegment: o, midPointFeatureId: e }), i, this.config.project, this.config.unproject, this.projection));
1279
1304
  }
1280
1305
  delete() {
1281
1306
  this._midPoints.length && (this.store.delete(this._midPoints), this._midPoints = []);
1282
1307
  }
1283
1308
  getUpdated(t) {
1284
- 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 } }));
1309
+ if (this._midPoints.length !== 0) return Yt({ 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 } }));
1285
1310
  }
1286
1311
  }
1287
- class Ve extends O {
1312
+ class He extends k {
1288
1313
  constructor(t) {
1289
1314
  super(t), this._selectionPoints = [];
1290
1315
  }
@@ -1296,7 +1321,7 @@ class Ve extends O {
1296
1321
  create(t, e, i) {
1297
1322
  this._selectionPoints = this.store.create(function(o, r, n) {
1298
1323
  const a = [], l = r === "Polygon" ? o.length - 1 : o.length;
1299
- for (let c = 0; c < l; c++) a.push({ geometry: { type: "Point", coordinates: o[c] }, properties: n(c) });
1324
+ for (let d = 0; d < l; d++) a.push({ geometry: { type: "Point", coordinates: o[d] }, properties: n(d) });
1300
1325
  return a;
1301
1326
  }(t, e, (o) => ({ mode: this.mode, selectionPoint: !0, selectionPointFeatureId: i, index: o })));
1302
1327
  }
@@ -1310,54 +1335,54 @@ class Ve extends O {
1310
1335
  if (this._selectionPoints[t] !== void 0) return { id: this._selectionPoints[t], geometry: { type: "Point", coordinates: e } };
1311
1336
  }
1312
1337
  }
1313
- function ge(s, t) {
1338
+ function pe(s, t) {
1314
1339
  let e = !1;
1315
1340
  for (let n = 0, a = t.length; n < a; n++) {
1316
1341
  const l = t[n];
1317
- for (let c = 0, h = l.length, d = h - 1; c < h; d = c++) (o = l[c])[1] > (i = s)[1] != (r = l[d])[1] > i[1] && i[0] < (r[0] - o[0]) * (i[1] - o[1]) / (r[1] - o[1]) + o[0] && (e = !e);
1342
+ for (let d = 0, c = l.length, h = c - 1; d < c; h = d++) (o = l[d])[1] > (i = s)[1] != (r = l[h])[1] > i[1] && i[0] < (r[0] - o[0]) * (i[1] - o[1]) / (r[1] - o[1]) + o[0] && (e = !e);
1318
1343
  }
1319
1344
  var i, o, r;
1320
1345
  return e;
1321
1346
  }
1322
- const pe = (s, t, e) => {
1347
+ const ye = (s, t, e) => {
1323
1348
  const i = (r) => r * r, o = (r, n) => i(r.x - n.x) + i(r.y - n.y);
1324
1349
  return Math.sqrt(((r, n, a) => {
1325
1350
  const l = o(n, a);
1326
1351
  if (l === 0) return o(r, n);
1327
- let c = ((r.x - n.x) * (a.x - n.x) + (r.y - n.y) * (a.y - n.y)) / l;
1328
- return c = Math.max(0, Math.min(1, c)), o(r, { x: n.x + c * (a.x - n.x), y: n.y + c * (a.y - n.y) });
1352
+ let d = ((r.x - n.x) * (a.x - n.x) + (r.y - n.y) * (a.y - n.y)) / l;
1353
+ return d = Math.max(0, Math.min(1, d)), o(r, { x: n.x + d * (a.x - n.x), y: n.y + d * (a.y - n.y) });
1329
1354
  })(s, t, e));
1330
1355
  };
1331
- class Ue extends O {
1356
+ class Je extends k {
1332
1357
  constructor(t, e, i) {
1333
1358
  super(t), this.config = void 0, this.createClickBoundingBox = void 0, this.pixelDistance = void 0, this.config = t, this.createClickBoundingBox = e, this.pixelDistance = i;
1334
1359
  }
1335
1360
  find(t, e) {
1336
- let i, o, r, n, a = 1 / 0, l = 1 / 0, c = 1 / 0;
1337
- const h = this.createClickBoundingBox.create(t), d = this.store.search(h);
1338
- for (let u = 0; u < d.length; u++) {
1339
- const g = d[u], p = g.geometry;
1361
+ let i, o, r, n, a = 1 / 0, l = 1 / 0, d = 1 / 0;
1362
+ const c = this.createClickBoundingBox.create(t), h = this.store.search(c);
1363
+ for (let u = 0; u < h.length; u++) {
1364
+ const g = h[u], p = g.geometry;
1340
1365
  if (p.type === "Point") {
1341
- if (g.properties.selectionPoint || !e && g.properties[et]) continue;
1366
+ if (g.properties.selectionPoint || !e && g.properties[tt]) continue;
1342
1367
  const y = this.pixelDistance.measure(t, p.coordinates);
1343
- g.properties[et] && y < this.pointerDistance && y < c ? (c = y, r = g) : !g.properties[et] && y < this.pointerDistance && y < a && (a = y, i = g);
1368
+ g.properties[tt] && y < this.pointerDistance && y < d ? (d = y, r = g) : !g.properties[tt] && y < this.pointerDistance && y < a && (a = y, i = g);
1344
1369
  } else if (p.type === "LineString") {
1345
1370
  if (i) continue;
1346
1371
  for (let y = 0; y < p.coordinates.length - 1; y++) {
1347
- const m = p.coordinates[y], f = p.coordinates[y + 1], v = pe({ x: t.containerX, y: t.containerY }, this.project(m[0], m[1]), this.project(f[0], f[1]));
1348
- v < this.pointerDistance && v < l && (l = v, o = g);
1372
+ const m = p.coordinates[y], f = p.coordinates[y + 1], C = ye({ x: t.containerX, y: t.containerY }, this.project(m[0], m[1]), this.project(f[0], f[1]));
1373
+ C < this.pointerDistance && C < l && (l = C, o = g);
1349
1374
  }
1350
1375
  } else if (p.type === "Polygon") {
1351
1376
  if (i || o) continue;
1352
- ge([t.lng, t.lat], p.coordinates) && (n = g);
1377
+ pe([t.lng, t.lat], p.coordinates) && (n = g);
1353
1378
  }
1354
1379
  }
1355
1380
  return { clickedFeature: i || o || n, clickedMidPoint: r };
1356
1381
  }
1357
1382
  }
1358
- class Re extends O {
1383
+ class $e extends k {
1359
1384
  constructor(t, e, i, o) {
1360
- 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;
1385
+ super(t), this.config = void 0, this.featuresAtCursorEvent = void 0, this.selectionPoints = void 0, this.midPoints = void 0, this.draggedFeatureId = null, this.dragPosition = void 0, this.config = t, this.featuresAtCursorEvent = e, this.selectionPoints = i, this.midPoints = o;
1361
1386
  }
1362
1387
  startDragging(t, e) {
1363
1388
  this.draggedFeatureId = e, this.dragPosition = [t.lng, t.lat];
@@ -1369,7 +1394,7 @@ class Re extends O {
1369
1394
  return this.draggedFeatureId !== null;
1370
1395
  }
1371
1396
  canDrag(t, e) {
1372
- const { clickedFeature: i } = this.featuresAtMouseEvent.find(t, !0);
1397
+ const { clickedFeature: i } = this.featuresAtCursorEvent.find(t, !0);
1373
1398
  return !(!i || i.id !== e);
1374
1399
  }
1375
1400
  drag(t, e) {
@@ -1378,19 +1403,27 @@ class Re extends O {
1378
1403
  if (i.type === "Polygon" || i.type === "LineString") {
1379
1404
  let r, n;
1380
1405
  if (i.type === "Polygon" ? (r = i.coordinates[0], n = r.length - 1) : (r = i.coordinates, n = r.length), !this.dragPosition) return !1;
1381
- for (let c = 0; c < n; c++) {
1382
- const h = r[c], d = [this.dragPosition[0] - o[0], this.dragPosition[1] - o[1]], u = E(h[0] - d[0], this.config.coordinatePrecision), g = E(h[1] - d[1], this.config.coordinatePrecision);
1383
- if (u > 180 || u < -180 || g > 90 || g < -90) return !1;
1384
- r[c] = [u, g];
1406
+ for (let d = 0; d < n; d++) {
1407
+ const c = r[d];
1408
+ let h, u;
1409
+ if (this.config.projection === "web-mercator") {
1410
+ const g = x(this.dragPosition[0], this.dragPosition[1]), p = x(o[0], o[1]), y = x(c[0], c[1]), m = { x: g.x - p.x, y: g.y - p.y }, f = y.x - m.x, C = y.y - m.y, { lng: v, lat: P } = O(f, C);
1411
+ h = v, u = P;
1412
+ } else {
1413
+ const g = [this.dragPosition[0] - o[0], this.dragPosition[1] - o[1]];
1414
+ h = c[0] - g[0], u = c[1] - g[1];
1415
+ }
1416
+ if (h = F(h, this.config.coordinatePrecision), u = F(u, this.config.coordinatePrecision), h > 180 || h < -180 || u > 90 || u < -90) return !1;
1417
+ r[d] = [h, u];
1385
1418
  }
1386
1419
  i.type === "Polygon" && (r[r.length - 1] = [r[0][0], r[0][1]]);
1387
1420
  const a = this.selectionPoints.getUpdated(r) || [], l = this.midPoints.getUpdated(r) || [];
1388
- if (e && !e({ type: "Feature", id: this.draggedFeatureId, geometry: i, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: b.Provisional })) return !1;
1421
+ if (e && !e({ type: "Feature", id: this.draggedFeatureId, geometry: i, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: b.Provisional }).valid) return !1;
1389
1422
  this.store.updateGeometry([{ id: this.draggedFeatureId, geometry: i }, ...a, ...l]), this.dragPosition = [t.lng, t.lat];
1390
1423
  } else i.type === "Point" && (this.store.updateGeometry([{ id: this.draggedFeatureId, geometry: { type: "Point", coordinates: o } }]), this.dragPosition = [t.lng, t.lat]);
1391
1424
  }
1392
1425
  }
1393
- class Te extends O {
1426
+ class qe extends k {
1394
1427
  constructor(t, e, i, o) {
1395
1428
  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;
1396
1429
  }
@@ -1421,11 +1454,11 @@ class Te extends O {
1421
1454
  if (t.lng > 180 || t.lng < -180 || t.lat > 90 || t.lat < -90) return !1;
1422
1455
  if (r.type !== "Polygon" || o !== n.length - 1 && o !== 0) n[o] = a;
1423
1456
  else {
1424
- const d = n.length - 1;
1425
- n[0] = a, n[d] = a;
1457
+ const h = n.length - 1;
1458
+ n[0] = a, n[h] = a;
1426
1459
  }
1427
- const l = this.selectionPoints.getOneUpdated(o, a), c = l ? [l] : [], h = this.midPoints.getUpdated(n) || [];
1428
- return !(r.type !== "Point" && !e && Et({ type: "Feature", geometry: r, properties: {} }) || i && !i({ type: "Feature", id: this.draggedCoordinate.id, geometry: r, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: b.Provisional }) || (this.store.updateGeometry([{ id: this.draggedCoordinate.id, geometry: r }, ...c, ...h]), 0));
1460
+ const l = this.selectionPoints.getOneUpdated(o, a), d = l ? [l] : [], c = this.midPoints.getUpdated(n) || [];
1461
+ return !(r.type !== "Point" && !e && It({ type: "Feature", geometry: r, properties: {} }) || i && !i({ type: "Feature", id: this.draggedCoordinate.id, geometry: r, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: b.Provisional }).valid || (this.store.updateGeometry([{ id: this.draggedCoordinate.id, geometry: r }, ...d, ...c]), 0));
1429
1462
  }
1430
1463
  isDragging() {
1431
1464
  return this.draggedCoordinate.id !== null;
@@ -1443,9 +1476,9 @@ function yt(s) {
1443
1476
  t += o[0], e += o[1], i++;
1444
1477
  }, !0), [t / i, e / i];
1445
1478
  }
1446
- function ye(s, t) {
1479
+ function fe(s, t) {
1447
1480
  s[0] += s[0] - t[0] > 180 ? -360 : t[0] - s[0] > 180 ? 360 : 0;
1448
- const e = wt, i = t[1] * Math.PI / 180, o = s[1] * Math.PI / 180, r = o - i;
1481
+ const e = Et, i = t[1] * Math.PI / 180, o = s[1] * Math.PI / 180, r = o - i;
1449
1482
  let n = Math.abs(s[0] - t[0]) * Math.PI / 180;
1450
1483
  n > Math.PI && (n -= 2 * Math.PI);
1451
1484
  const a = Math.log(Math.tan(o / 2 + Math.PI / 4) / Math.tan(i / 2 + Math.PI / 4)), l = Math.abs(a) > 1e-11 ? r / a : Math.cos(i);
@@ -1453,15 +1486,15 @@ function ye(s, t) {
1453
1486
  }
1454
1487
  function ft(s) {
1455
1488
  const t = (s.geometry.type === "Polygon" ? s.geometry.coordinates[0] : s.geometry.coordinates).map((e) => {
1456
- const { x: i, y: o } = M(e[0], e[1]);
1489
+ const { x: i, y: o } = x(e[0], e[1]);
1457
1490
  return [i, o];
1458
1491
  });
1459
1492
  return s.geometry.type === "Polygon" ? function(e) {
1460
1493
  let i = 0, o = 0, r = 0;
1461
1494
  const n = e.length;
1462
1495
  for (let a = 0; a < n - 1; a++) {
1463
- const [l, c] = e[a], [h, d] = e[a + 1], u = l * d - h * c;
1464
- i += u, o += (l + h) * u, r += (c + d) * u;
1496
+ const [l, d] = e[a], [c, h] = e[a + 1], u = l * h - c * d;
1497
+ i += u, o += (l + c) * u, r += (d + h) * u;
1465
1498
  }
1466
1499
  return i /= 2, o /= 6 * i, r /= 6 * i, { x: o, y: r };
1467
1500
  }(t) : function(e) {
@@ -1474,7 +1507,7 @@ function ft(s) {
1474
1507
  return { x: o / i, y: r / i };
1475
1508
  }(t);
1476
1509
  }
1477
- class Xe extends O {
1510
+ class Ze extends k {
1478
1511
  constructor(t, e, i) {
1479
1512
  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;
1480
1513
  }
@@ -1488,36 +1521,36 @@ class Xe extends O {
1488
1521
  let n;
1489
1522
  const a = { type: "Feature", geometry: o, properties: {} };
1490
1523
  if (this.config.projection === "web-mercator") {
1491
- if (n = j(ft(a), M(t.lng, t.lat)), !this.lastBearing) return void (this.lastBearing = n);
1492
- ((d, u) => {
1493
- if (u === 0 || u === 360 || u === -360) return d;
1494
- const g = 0.017453292519943295 * u, p = (d.geometry.type === "Polygon" ? d.geometry.coordinates[0] : d.geometry.coordinates).map(([f, v]) => M(f, v)), y = p.reduce((f, v) => ({ x: f.x + v.x, y: f.y + v.y }), { x: 0, y: 0 });
1524
+ if (n = j(ft(a), x(t.lng, t.lat)), !this.lastBearing) return void (this.lastBearing = n);
1525
+ ((h, u) => {
1526
+ if (u === 0 || u === 360 || u === -360) return h;
1527
+ const g = 0.017453292519943295 * u, p = (h.geometry.type === "Polygon" ? h.geometry.coordinates[0] : h.geometry.coordinates).map(([f, C]) => x(f, C)), y = p.reduce((f, C) => ({ x: f.x + C.x, y: f.y + C.y }), { x: 0, y: 0 });
1495
1528
  y.x /= p.length, y.y /= p.length;
1496
- const m = p.map((f) => ({ x: y.x + (f.x - y.x) * Math.cos(g) - (f.y - y.y) * Math.sin(g), y: y.y + (f.x - y.x) * Math.sin(g) + (f.y - y.y) * Math.cos(g) })).map(({ x: f, y: v }) => [L(f, v).lng, L(f, v).lat]);
1497
- d.geometry.type === "Polygon" ? d.geometry.coordinates[0] = m : d.geometry.coordinates = m;
1529
+ const m = p.map((f) => ({ x: y.x + (f.x - y.x) * Math.cos(g) - (f.y - y.y) * Math.sin(g), y: y.y + (f.x - y.x) * Math.sin(g) + (f.y - y.y) * Math.cos(g) })).map(({ x: f, y: C }) => [O(f, C).lng, O(f, C).lat]);
1530
+ h.geometry.type === "Polygon" ? h.geometry.coordinates[0] = m : h.geometry.coordinates = m;
1498
1531
  })(a, -(this.lastBearing - n));
1499
1532
  } else {
1500
1533
  if (this.config.projection !== "globe") throw new Error("Unsupported projection");
1501
1534
  if (n = pt(yt({ type: "Feature", geometry: o, properties: {} }), r), !this.lastBearing) return void (this.lastBearing = n + 180);
1502
- (function(d, u) {
1503
- if (u === 0 || u === 360 || u === -360) return d;
1504
- const g = yt(d);
1505
- (d.geometry.type === "Polygon" ? d.geometry.coordinates[0] : d.geometry.coordinates).forEach((p) => {
1506
- const y = pt(g, p) + u, m = ye(g, p), f = _t(g, m, y);
1535
+ (function(h, u) {
1536
+ if (u === 0 || u === 360 || u === -360) return h;
1537
+ const g = yt(h);
1538
+ (h.geometry.type === "Polygon" ? h.geometry.coordinates[0] : h.geometry.coordinates).forEach((p) => {
1539
+ const y = pt(g, p) + u, m = fe(g, p), f = Ot(g, m, y);
1507
1540
  p[0] = f[0], p[1] = f[1];
1508
1541
  });
1509
1542
  })(a, -(this.lastBearing - (n + 180)));
1510
1543
  }
1511
1544
  const l = o.type === "Polygon" ? o.coordinates[0] : o.coordinates;
1512
- l.forEach((d) => {
1513
- d[0] = E(d[0], this.coordinatePrecision), d[1] = E(d[1], this.coordinatePrecision);
1545
+ l.forEach((h) => {
1546
+ h[0] = F(h[0], this.coordinatePrecision), h[1] = F(h[1], this.coordinatePrecision);
1514
1547
  });
1515
- const c = this.midPoints.getUpdated(l) || [], h = this.selectionPoints.getUpdated(l) || [];
1548
+ const d = this.midPoints.getUpdated(l) || [], c = this.selectionPoints.getUpdated(l) || [];
1516
1549
  if (i && !i({ id: e, type: "Feature", geometry: o, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: b.Provisional })) return !1;
1517
- this.store.updateGeometry([{ id: e, geometry: o }, ...h, ...c]), this.projection === "web-mercator" ? this.lastBearing = n : this.projection === "globe" && (this.lastBearing = n + 180);
1550
+ this.store.updateGeometry([{ id: e, geometry: o }, ...c, ...d]), this.projection === "web-mercator" ? this.lastBearing = n : this.projection === "globe" && (this.lastBearing = n + 180);
1518
1551
  }
1519
1552
  }
1520
- class Ke extends O {
1553
+ class Qe extends k {
1521
1554
  constructor(t, e, i) {
1522
1555
  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;
1523
1556
  }
@@ -1531,37 +1564,37 @@ class Ke extends O {
1531
1564
  let a;
1532
1565
  const l = ft(n);
1533
1566
  if (this.config.projection === "web-mercator") {
1534
- const g = M(t.lng, t.lat);
1535
- a = F(l, g);
1567
+ const g = x(t.lng, t.lat);
1568
+ a = I(l, g);
1536
1569
  } else {
1537
1570
  if (this.config.projection !== "globe") throw new Error("Invalid projection");
1538
1571
  a = G(yt({ type: "Feature", geometry: o, properties: {} }), r);
1539
1572
  }
1540
1573
  if (!this.lastDistance) return void (this.lastDistance = a);
1541
- const c = 1 - (this.lastDistance - a) / a;
1574
+ const d = 1 - (this.lastDistance - a) / a;
1542
1575
  if (this.config.projection === "web-mercator") {
1543
- const { lng: g, lat: p } = L(l.x, l.y);
1576
+ const { lng: g, lat: p } = O(l.x, l.y);
1544
1577
  (function(y, m, f) {
1545
1578
  if (m === 1) return y;
1546
- const v = (y.geometry.type === "Polygon" ? y.geometry.coordinates[0] : y.geometry.coordinates).map(([P, w]) => M(P, w)), C = M(f[0], f[1]), S = v.map((P) => ({ x: C.x + (P.x - C.x) * m, y: C.y + (P.y - C.y) * m })).map(({ x: P, y: w }) => [L(P, w).lng, L(P, w).lat]);
1547
- y.geometry.type === "Polygon" ? y.geometry.coordinates[0] = S : y.geometry.coordinates = S;
1548
- })(n, c, [g, p]);
1579
+ const C = (y.geometry.type === "Polygon" ? y.geometry.coordinates[0] : y.geometry.coordinates).map(([S, w]) => x(S, w)), v = x(f[0], f[1]), P = C.map((S) => ({ x: v.x + (S.x - v.x) * m, y: v.y + (S.y - v.y) * m })).map(({ x: S, y: w }) => [O(S, w).lng, O(S, w).lat]);
1580
+ y.geometry.type === "Polygon" ? y.geometry.coordinates[0] = P : y.geometry.coordinates = P;
1581
+ })(n, d, [g, p]);
1549
1582
  } else this.config.projection === "globe" && function(g, p, y, m = "xy") {
1550
1583
  p === 1 || (g.geometry.type === "Polygon" ? g.geometry.coordinates[0] : g.geometry.coordinates).forEach((f) => {
1551
- const v = ye(y, f), C = pt(y, f), S = _t(y, v * p, C);
1552
- m !== "x" && m !== "xy" || (f[0] = S[0]), m !== "y" && m !== "xy" || (f[1] = S[1]);
1584
+ const C = fe(y, f), v = pt(y, f), P = Ot(y, C * p, v);
1585
+ m !== "x" && m !== "xy" || (f[0] = P[0]), m !== "y" && m !== "xy" || (f[1] = P[1]);
1553
1586
  });
1554
- }(n, c, yt(n));
1555
- const h = o.type === "Polygon" ? o.coordinates[0] : o.coordinates;
1556
- h.forEach((g) => {
1557
- g[0] = E(g[0], this.coordinatePrecision), g[1] = E(g[1], this.coordinatePrecision);
1587
+ }(n, d, yt(n));
1588
+ const c = o.type === "Polygon" ? o.coordinates[0] : o.coordinates;
1589
+ c.forEach((g) => {
1590
+ g[0] = F(g[0], this.coordinatePrecision), g[1] = F(g[1], this.coordinatePrecision);
1558
1591
  });
1559
- const d = this.midPoints.getUpdated(h) || [], u = this.selectionPoints.getUpdated(h) || [];
1592
+ const h = this.midPoints.getUpdated(c) || [], u = this.selectionPoints.getUpdated(c) || [];
1560
1593
  if (i && !i({ id: e, type: "Feature", geometry: o, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: b.Provisional })) return !1;
1561
- this.store.updateGeometry([{ id: e, geometry: o }, ...u, ...d]), this.lastDistance = a;
1594
+ this.store.updateGeometry([{ id: e, geometry: o }, ...u, ...h]), this.lastDistance = a;
1562
1595
  }
1563
1596
  }
1564
- class ze extends O {
1597
+ class ti extends k {
1565
1598
  constructor(t, e, i, o) {
1566
1599
  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;
1567
1600
  }
@@ -1622,41 +1655,41 @@ class ze extends O {
1622
1655
  if (!e) return null;
1623
1656
  const { feature: i, boundingBox: o, updatedCoords: r, selectedCoordinate: n } = e, a = ft(i);
1624
1657
  if (!a) return null;
1625
- const l = M(n[0], n[1]), { closestBBoxIndex: c } = this.getIndexesWebMercator(o, l), h = M(t.lng, t.lat);
1626
- return this.scaleWebMercator({ closestBBoxIndex: c, updatedCoords: r, webMercatorCursor: h, webMercatorSelected: l, webMercatorOrigin: a }), r;
1658
+ const l = x(n[0], n[1]), { closestBBoxIndex: d } = this.getIndexesWebMercator(o, l), c = x(t.lng, t.lat);
1659
+ return this.scaleWebMercator({ closestBBoxIndex: d, updatedCoords: r, webMercatorCursor: c, webMercatorSelected: l, webMercatorOrigin: a }), r;
1627
1660
  }
1628
1661
  centerFixedWebMercatorDrag(t) {
1629
1662
  const e = this.getSelectedFeatureDataWebMercator();
1630
1663
  if (!e) return null;
1631
1664
  const { feature: i, boundingBox: o, updatedCoords: r, selectedCoordinate: n } = e, a = ft(i);
1632
1665
  if (!a) return null;
1633
- const l = M(n[0], n[1]), { closestBBoxIndex: c } = this.getIndexesWebMercator(o, l), h = M(t.lng, t.lat);
1634
- return this.scaleFixedWebMercator({ closestBBoxIndex: c, updatedCoords: r, webMercatorCursor: h, webMercatorSelected: l, webMercatorOrigin: a }), r;
1666
+ const l = x(n[0], n[1]), { closestBBoxIndex: d } = this.getIndexesWebMercator(o, l), c = x(t.lng, t.lat);
1667
+ return this.scaleFixedWebMercator({ closestBBoxIndex: d, updatedCoords: r, webMercatorCursor: c, webMercatorSelected: l, webMercatorOrigin: a }), r;
1635
1668
  }
1636
1669
  scaleFixedWebMercator({ closestBBoxIndex: t, webMercatorOrigin: e, webMercatorSelected: i, webMercatorCursor: o, updatedCoords: r }) {
1637
1670
  if (!this.isValidDragWebMercator(t, e.x - o.x, e.y - o.y)) return null;
1638
- let n = F(e, o) / F(e, i);
1671
+ let n = I(e, o) / I(e, i);
1639
1672
  return n < 0 && (n = this.minimumScale), this.performWebMercatorScale(r, e.x, e.y, n, n), r;
1640
1673
  }
1641
1674
  oppositeFixedWebMercatorDrag(t) {
1642
1675
  const e = this.getSelectedFeatureDataWebMercator();
1643
1676
  if (!e) return null;
1644
- const { boundingBox: i, updatedCoords: o, selectedCoordinate: r } = e, n = M(r[0], r[1]), { oppositeBboxIndex: a, closestBBoxIndex: l } = this.getIndexesWebMercator(i, n), c = { x: i[a][0], y: i[a][1] }, h = M(t.lng, t.lat);
1645
- return this.scaleFixedWebMercator({ closestBBoxIndex: l, updatedCoords: o, webMercatorCursor: h, webMercatorSelected: n, webMercatorOrigin: c }), o;
1677
+ const { boundingBox: i, updatedCoords: o, selectedCoordinate: r } = e, n = x(r[0], r[1]), { oppositeBboxIndex: a, closestBBoxIndex: l } = this.getIndexesWebMercator(i, n), d = { x: i[a][0], y: i[a][1] }, c = x(t.lng, t.lat);
1678
+ return this.scaleFixedWebMercator({ closestBBoxIndex: l, updatedCoords: o, webMercatorCursor: c, webMercatorSelected: n, webMercatorOrigin: d }), o;
1646
1679
  }
1647
1680
  oppositeWebMercatorDrag(t) {
1648
1681
  const e = this.getSelectedFeatureDataWebMercator();
1649
1682
  if (!e) return null;
1650
- const { boundingBox: i, updatedCoords: o, selectedCoordinate: r } = e, n = M(r[0], r[1]), { oppositeBboxIndex: a, closestBBoxIndex: l } = this.getIndexesWebMercator(i, n), c = { x: i[a][0], y: i[a][1] }, h = M(t.lng, t.lat);
1651
- return this.scaleWebMercator({ closestBBoxIndex: l, updatedCoords: o, webMercatorCursor: h, webMercatorSelected: n, webMercatorOrigin: c }), o;
1683
+ const { boundingBox: i, updatedCoords: o, selectedCoordinate: r } = e, n = x(r[0], r[1]), { oppositeBboxIndex: a, closestBBoxIndex: l } = this.getIndexesWebMercator(i, n), d = { x: i[a][0], y: i[a][1] }, c = x(t.lng, t.lat);
1684
+ return this.scaleWebMercator({ closestBBoxIndex: l, updatedCoords: o, webMercatorCursor: c, webMercatorSelected: n, webMercatorOrigin: d }), o;
1652
1685
  }
1653
1686
  scaleWebMercator({ closestBBoxIndex: t, webMercatorOrigin: e, webMercatorSelected: i, webMercatorCursor: o, updatedCoords: r }) {
1654
1687
  const n = e.x - o.x, a = e.y - o.y;
1655
1688
  if (!this.isValidDragWebMercator(t, n, a)) return null;
1656
1689
  let l = 1;
1657
1690
  n !== 0 && t !== 1 && t !== 5 && (l = 1 - (e.x - i.x - n) / n);
1658
- let c = 1;
1659
- return a !== 0 && t !== 3 && t !== 7 && (c = 1 - (e.y - i.y - a) / a), this.validateScale(l, c) ? (l < 0 && (l = this.minimumScale), c < 0 && (c = this.minimumScale), this.performWebMercatorScale(r, e.x, e.y, l, c), r) : null;
1691
+ let d = 1;
1692
+ 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(r, e.x, e.y, l, d), r) : null;
1660
1693
  }
1661
1694
  getFeature(t) {
1662
1695
  if (this.draggedCoordinate.id === null) return null;
@@ -1672,15 +1705,15 @@ class ze extends O {
1672
1705
  }
1673
1706
  performWebMercatorScale(t, e, i, o, r) {
1674
1707
  t.forEach((n) => {
1675
- const { x: a, y: l } = M(n[0], n[1]), c = e + (a - e) * o, h = i + (l - i) * r, { lng: d, lat: u } = L(c, h);
1676
- n[0] = d, n[1] = u;
1708
+ const { x: a, y: l } = x(n[0], n[1]), d = e + (a - e) * o, c = i + (l - i) * r, { lng: h, lat: u } = O(d, c);
1709
+ n[0] = h, n[1] = u;
1677
1710
  });
1678
1711
  }
1679
1712
  getBBoxWebMercator(t) {
1680
1713
  const e = [1 / 0, 1 / 0, -1 / 0, -1 / 0];
1681
1714
  (t = t.map((a) => {
1682
- const { x: l, y: c } = M(a[0], a[1]);
1683
- return [l, c];
1715
+ const { x: l, y: d } = x(a[0], a[1]);
1716
+ return [l, d];
1684
1717
  })).forEach(([a, l]) => {
1685
1718
  a < e[0] && (e[0] = a), l < e[1] && (e[1] = l), a > e[2] && (e[2] = a), l > e[3] && (e[3] = l);
1686
1719
  });
@@ -1690,7 +1723,7 @@ class ze extends O {
1690
1723
  getIndexesWebMercator(t, e) {
1691
1724
  let i, o = 1 / 0;
1692
1725
  for (let r = 0; r < t.length; r++) {
1693
- const n = F({ x: e.x, y: e.y }, { x: t[r][0], y: t[r][1] });
1726
+ const n = I({ x: e.x, y: e.y }, { x: t[r][0], y: t[r][1] });
1694
1727
  n < o && (i = r, o = n);
1695
1728
  }
1696
1729
  if (i === void 0) throw new Error("No closest coordinate found");
@@ -1715,23 +1748,23 @@ class ze extends O {
1715
1748
  if (!o) return !1;
1716
1749
  let r = null;
1717
1750
  if (e === "center" ? r = this.centerWebMercatorDrag(t) : e === "opposite" ? r = this.oppositeWebMercatorDrag(t) : e === "center-fixed" ? r = this.centerFixedWebMercatorDrag(t) : e === "opposite-fixed" && (r = this.oppositeFixedWebMercatorDrag(t)), !r) return !1;
1718
- for (let c = 0; c < r.length; c++) {
1719
- const h = r[c];
1720
- if (h[0] = E(h[0], this.coordinatePrecision), h[1] = E(h[1], this.coordinatePrecision), !mt(h, this.coordinatePrecision)) return !1;
1751
+ for (let d = 0; d < r.length; d++) {
1752
+ const c = r[d];
1753
+ if (c[0] = F(c[0], this.coordinatePrecision), c[1] = F(c[1], this.coordinatePrecision), !mt(c, this.coordinatePrecision)) return !1;
1721
1754
  }
1722
1755
  const n = this.midPoints.getUpdated(r) || [], a = this.selectionPoints.getUpdated(r) || [], l = { type: o.geometry.type, coordinates: o.geometry.type === "Polygon" ? [r] : r };
1723
- 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: b.Provisional }) || (this.store.updateGeometry([{ id: this.draggedCoordinate.id, geometry: l }, ...a, ...n]), 0));
1756
+ 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: b.Provisional }).valid || (this.store.updateGeometry([{ id: this.draggedCoordinate.id, geometry: l }, ...a, ...n]), 0));
1724
1757
  }
1725
1758
  }
1726
- class Ye extends ke {
1759
+ class ei extends Le {
1727
1760
  constructor(t) {
1728
1761
  var e;
1729
1762
  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 : {};
1730
1763
  const i = { pointerOver: "move", dragStart: "move", dragEnd: "move", insertMidpoint: "crosshair" };
1731
- if (this.cursors = t && t.cursors ? x({}, i, t.cursors) : i, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { deselect: null, delete: null, rotate: null, scale: null };
1764
+ if (this.cursors = t && t.cursors ? M({}, i, t.cursors) : i, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { deselect: null, delete: null, rotate: null, scale: null };
1732
1765
  else {
1733
1766
  const o = { deselect: "Escape", delete: "Delete", rotate: ["Control", "r"], scale: ["Control", "s"] };
1734
- this.keyEvents = t && t.keyEvents ? x({}, o, t.keyEvents) : o;
1767
+ this.keyEvents = t && t.keyEvents ? M({}, o, t.keyEvents) : o;
1735
1768
  }
1736
1769
  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) {
1737
1770
  const r = t.flags[o].feature;
@@ -1746,13 +1779,13 @@ class Ye extends ke {
1746
1779
  this._state = "selecting";
1747
1780
  }
1748
1781
  registerBehaviors(t) {
1749
- this.pixelDistance = new Ft(t), this.clickBoundingBox = new It(t), this.featuresAtMouseEvent = new Ue(t, this.clickBoundingBox, this.pixelDistance), this.selectionPoints = new Ve(t), this.midPoints = new Ae(t, this.selectionPoints), this.rotateFeature = new Xe(t, this.selectionPoints, this.midPoints), this.scaleFeature = new Ke(t, this.selectionPoints, this.midPoints), this.dragFeature = new Re(t, this.featuresAtMouseEvent, this.selectionPoints, this.midPoints), this.dragCoordinate = new Te(t, this.pixelDistance, this.selectionPoints, this.midPoints), this.dragCoordinateResizeFeature = new ze(t, this.pixelDistance, this.selectionPoints, this.midPoints);
1782
+ this.pixelDistance = new Dt(t), this.clickBoundingBox = new _t(t), this.featuresAtMouseEvent = new Je(t, this.clickBoundingBox, this.pixelDistance), this.selectionPoints = new He(t), this.midPoints = new Ye(t, this.selectionPoints), this.rotateFeature = new Ze(t, this.selectionPoints, this.midPoints), this.scaleFeature = new Qe(t, this.selectionPoints, this.midPoints), this.dragFeature = new $e(t, this.featuresAtMouseEvent, this.selectionPoints, this.midPoints), this.dragCoordinate = new qe(t, this.pixelDistance, this.selectionPoints, this.midPoints), this.dragCoordinateResizeFeature = new ti(t, this.pixelDistance, this.selectionPoints, this.midPoints);
1750
1783
  }
1751
1784
  deselectFeature() {
1752
1785
  this.deselect();
1753
1786
  }
1754
1787
  deselect() {
1755
- const t = this.selected.filter((e) => this.store.has(e)).map((e) => ({ id: e, property: bt, value: !1 }));
1788
+ const t = this.selected.filter((e) => this.store.has(e)).map((e) => ({ id: e, property: wt, value: !1 }));
1756
1789
  this.store.updateProperty(t), this.onDeselect(this.selected[0]), this.selected = [], this.selectionPoints.delete(), this.midPoints.delete();
1757
1790
  }
1758
1791
  deleteSelected() {
@@ -1761,20 +1794,20 @@ class Ye extends ke {
1761
1794
  onRightClick(t) {
1762
1795
  if (!this.selectionPoints.ids.length) return;
1763
1796
  let e, i = 1 / 0;
1764
- if (this.selectionPoints.ids.forEach((d) => {
1765
- const u = this.store.getGeometryCopy(d), g = this.pixelDistance.measure(t, u.coordinates);
1766
- g < this.pointerDistance && g < i && (i = g, e = this.store.getPropertiesCopy(d));
1797
+ if (this.selectionPoints.ids.forEach((h) => {
1798
+ const u = this.store.getGeometryCopy(h), g = this.pixelDistance.measure(t, u.coordinates);
1799
+ g < this.pointerDistance && g < i && (i = g, e = this.store.getPropertiesCopy(h));
1767
1800
  }), !e) return;
1768
1801
  const o = e.selectionPointFeatureId, r = e.index, n = this.store.getPropertiesCopy(o), a = this.flags[n.mode], l = this.validations[n.mode];
1769
1802
  if (!(a && a.feature && a.feature.coordinates && a.feature.coordinates.deletable)) return;
1770
- const c = this.store.getGeometryCopy(o);
1771
- let h;
1772
- if (c.type === "Polygon") {
1773
- if (h = c.coordinates[0], h.length <= 4) return;
1774
- } else if (c.type === "LineString" && (h = c.coordinates, h.length <= 3)) return;
1775
- if (h) {
1776
- if (c.type === "Polygon" && r === 0 || r === h.length - 1 ? (h.shift(), h.pop(), h.push([h[0][0], h[0][1]])) : h.splice(r, 1), l && !l({ id: o, type: "Feature", geometry: c, properties: n }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: b.Commit })) return;
1777
- this.store.delete([...this.midPoints.ids, ...this.selectionPoints.ids]), this.store.updateGeometry([{ id: o, geometry: c }]), this.selectionPoints.create(h, c.type, o), a && a.feature && a.feature.coordinates && a.feature.coordinates.midpoints && this.midPoints.create(h, o, this.coordinatePrecision);
1803
+ const d = this.store.getGeometryCopy(o);
1804
+ let c;
1805
+ if (d.type === "Polygon") {
1806
+ if (c = d.coordinates[0], c.length <= 4) return;
1807
+ } else if (d.type === "LineString" && (c = d.coordinates, c.length <= 3)) return;
1808
+ if (c) {
1809
+ if (d.type === "Polygon" && r === 0 || r === c.length - 1 ? (c.shift(), c.pop(), c.push([c[0][0], c[0][1]])) : c.splice(r, 1), l && !l({ id: o, type: "Feature", geometry: d, properties: n }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: b.Commit }).valid) return;
1810
+ this.store.delete([...this.midPoints.ids, ...this.selectionPoints.ids]), this.store.updateGeometry([{ id: o, geometry: d }]), this.selectionPoints.create(c, d.type, o), a && a.feature && a.feature.coordinates && a.feature.coordinates.midpoints && this.midPoints.create(c, o, this.coordinatePrecision);
1778
1811
  }
1779
1812
  }
1780
1813
  select(t, e = !0) {
@@ -1872,11 +1905,11 @@ class Ye extends ke {
1872
1905
  this.setCursor(this.selected.length > 0 && (o && o.id === this.selected[0] || i) ? this.cursors.pointerOver : "unset");
1873
1906
  }
1874
1907
  styleFeature(t) {
1875
- const e = x({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1908
+ const e = M({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1876
1909
  if (t.properties.mode === this.mode && t.geometry.type === "Point") {
1877
1910
  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;
1878
1911
  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;
1879
- } else if (t.properties[bt]) {
1912
+ } else if (t.properties[wt]) {
1880
1913
  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;
1881
1914
  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;
1882
1915
  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;
@@ -1884,7 +1917,7 @@ class Ye extends ke {
1884
1917
  return e;
1885
1918
  }
1886
1919
  }
1887
- class He extends W {
1920
+ class ii extends W {
1888
1921
  constructor(...t) {
1889
1922
  super(...t), this.type = U.Static, this.mode = "static";
1890
1923
  }
@@ -1909,88 +1942,88 @@ class He extends W {
1909
1942
  cleanUp() {
1910
1943
  }
1911
1944
  styleFeature() {
1912
- return x({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1945
+ return M({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1913
1946
  }
1914
1947
  }
1915
- function fe(s, t, e, i, o) {
1948
+ function me(s, t, e, i, o) {
1916
1949
  for (; i > e; ) {
1917
1950
  if (i - e > 600) {
1918
- const l = i - e + 1, c = t - e + 1, h = Math.log(l), d = 0.5 * Math.exp(2 * h / 3), u = 0.5 * Math.sqrt(h * d * (l - d) / l) * (c - l / 2 < 0 ? -1 : 1);
1919
- fe(s, t, Math.max(e, Math.floor(t - c * d / l + u)), Math.min(i, Math.floor(t + (l - c) * d / l + u)), o);
1951
+ const l = i - e + 1, d = t - e + 1, c = Math.log(l), h = 0.5 * Math.exp(2 * c / 3), u = 0.5 * Math.sqrt(c * h * (l - h) / l) * (d - l / 2 < 0 ? -1 : 1);
1952
+ me(s, t, Math.max(e, Math.floor(t - d * h / l + u)), Math.min(i, Math.floor(t + (l - d) * h / l + u)), o);
1920
1953
  }
1921
1954
  const r = s[t];
1922
1955
  let n = e, a = i;
1923
- for (Z(s, e, t), o(s[i], r) > 0 && Z(s, e, i); n < a; ) {
1924
- for (Z(s, n, a), n++, a--; o(s[n], r) < 0; ) n++;
1956
+ for (q(s, e, t), o(s[i], r) > 0 && q(s, e, i); n < a; ) {
1957
+ for (q(s, n, a), n++, a--; o(s[n], r) < 0; ) n++;
1925
1958
  for (; o(s[a], r) > 0; ) a--;
1926
1959
  }
1927
- o(s[e], r) === 0 ? Z(s, e, a) : (a++, Z(s, a, i)), a <= t && (e = a + 1), t <= a && (i = a - 1);
1960
+ o(s[e], r) === 0 ? q(s, e, a) : (a++, q(s, a, i)), a <= t && (e = a + 1), t <= a && (i = a - 1);
1928
1961
  }
1929
1962
  }
1930
- function Z(s, t, e) {
1963
+ function q(s, t, e) {
1931
1964
  const i = s[t];
1932
1965
  s[t] = s[e], s[e] = i;
1933
1966
  }
1934
- function Y(s, t) {
1935
- Q(s, 0, s.children.length, t, s);
1967
+ function z(s, t) {
1968
+ Z(s, 0, s.children.length, t, s);
1936
1969
  }
1937
- function Q(s, t, e, i, o) {
1938
- o || (o = H([])), o.minX = 1 / 0, o.minY = 1 / 0, o.maxX = -1 / 0, o.maxY = -1 / 0;
1970
+ function Z(s, t, e, i, o) {
1971
+ o || (o = Y([])), o.minX = 1 / 0, o.minY = 1 / 0, o.maxX = -1 / 0, o.maxY = -1 / 0;
1939
1972
  for (let r = t; r < e; r++) {
1940
1973
  const n = s.children[r];
1941
- tt(o, s.leaf ? i(n) : n);
1974
+ Q(o, s.leaf ? i(n) : n);
1942
1975
  }
1943
1976
  return o;
1944
1977
  }
1945
- function tt(s, t) {
1978
+ function Q(s, t) {
1946
1979
  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;
1947
1980
  }
1948
- function Je(s, t) {
1981
+ function oi(s, t) {
1949
1982
  return s.minX - t.minX;
1950
1983
  }
1951
- function $e(s, t) {
1984
+ function ri(s, t) {
1952
1985
  return s.minY - t.minY;
1953
1986
  }
1954
- function xt(s) {
1987
+ function St(s) {
1955
1988
  return (s.maxX - s.minX) * (s.maxY - s.minY);
1956
1989
  }
1957
1990
  function lt(s) {
1958
1991
  return s.maxX - s.minX + (s.maxY - s.minY);
1959
1992
  }
1960
- function qe(s, t) {
1993
+ function si(s, t) {
1961
1994
  const e = Math.max(s.minX, t.minX), i = Math.max(s.minY, t.minY), o = Math.min(s.maxX, t.maxX), r = Math.min(s.maxY, t.maxY);
1962
1995
  return Math.max(0, o - e) * Math.max(0, r - i);
1963
1996
  }
1964
- function St(s, t) {
1997
+ function Mt(s, t) {
1965
1998
  return s.minX <= t.minX && s.minY <= t.minY && t.maxX <= s.maxX && t.maxY <= s.maxY;
1966
1999
  }
1967
- function ct(s, t) {
2000
+ function dt(s, t) {
1968
2001
  return t.minX <= s.maxX && t.minY <= s.maxY && t.maxX >= s.minX && t.maxY >= s.minY;
1969
2002
  }
1970
- function H(s) {
2003
+ function Y(s) {
1971
2004
  return { children: s, height: 1, leaf: !0, minX: 1 / 0, minY: 1 / 0, maxX: -1 / 0, maxY: -1 / 0 };
1972
2005
  }
1973
- function Yt(s, t, e, i, o) {
2006
+ function Ht(s, t, e, i, o) {
1974
2007
  const r = [t, e];
1975
2008
  for (; r.length; ) {
1976
2009
  if ((e = r.pop()) - (t = r.pop()) <= i) continue;
1977
2010
  const n = t + Math.ceil((e - t) / i / 2) * i;
1978
- fe(s, n, t, e, o), r.push(t, n, n, e);
2011
+ me(s, n, t, e, o), r.push(t, n, n, e);
1979
2012
  }
1980
2013
  }
1981
- class Ze {
2014
+ class ni {
1982
2015
  constructor(t) {
1983
2016
  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();
1984
2017
  }
1985
2018
  search(t) {
1986
2019
  let e = this.data;
1987
2020
  const i = [];
1988
- if (!ct(t, e)) return i;
2021
+ if (!dt(t, e)) return i;
1989
2022
  const o = this.toBBox, r = [];
1990
2023
  for (; e; ) {
1991
2024
  for (let n = 0; n < e.children.length; n++) {
1992
2025
  const a = e.children[n], l = e.leaf ? o(a) : a;
1993
- ct(t, l) && (e.leaf ? i.push(a) : St(t, l) ? this._all(a, i) : r.push(a));
2026
+ dt(t, l) && (e.leaf ? i.push(a) : Mt(t, l) ? this._all(a, i) : r.push(a));
1994
2027
  }
1995
2028
  e = r.pop();
1996
2029
  }
@@ -1998,13 +2031,13 @@ class Ze {
1998
2031
  }
1999
2032
  collides(t) {
2000
2033
  let e = this.data;
2001
- if (ct(t, e)) {
2034
+ if (dt(t, e)) {
2002
2035
  const i = [];
2003
2036
  for (; e; ) {
2004
2037
  for (let o = 0; o < e.children.length; o++) {
2005
2038
  const r = e.children[o], n = e.leaf ? this.toBBox(r) : r;
2006
- if (ct(t, n)) {
2007
- if (e.leaf || St(t, n)) return !0;
2039
+ if (dt(t, n)) {
2040
+ if (e.leaf || Mt(t, n)) return !0;
2008
2041
  i.push(r);
2009
2042
  }
2010
2043
  }
@@ -2033,7 +2066,7 @@ class Ze {
2033
2066
  this._insert(t, this.data.height - 1);
2034
2067
  }
2035
2068
  clear() {
2036
- this.data = H([]);
2069
+ this.data = Y([]);
2037
2070
  }
2038
2071
  remove(t) {
2039
2072
  let e = this.data;
@@ -2041,10 +2074,10 @@ class Ze {
2041
2074
  let n, a, l = !1;
2042
2075
  for (; e || o.length; ) {
2043
2076
  if (e || (e = o.pop(), a = o[o.length - 1], n = r.pop(), l = !0), e.leaf) {
2044
- const c = e.children.indexOf(t);
2045
- c !== -1 && (e.children.splice(c, 1), o.push(e), this._condense(o));
2077
+ const d = e.children.indexOf(t);
2078
+ d !== -1 && (e.children.splice(d, 1), o.push(e), this._condense(o));
2046
2079
  }
2047
- l || e.leaf || !St(e, i) ? a ? (n++, e = a.children[n], l = !1) : e = null : (o.push(e), r.push(n), n = 0, a = e, e = e.children[0]);
2080
+ l || e.leaf || !Mt(e, i) ? a ? (n++, e = a.children[n], l = !1) : e = null : (o.push(e), r.push(n), n = 0, a = e, e = e.children[0]);
2048
2081
  }
2049
2082
  }
2050
2083
  toBBox(t) {
@@ -2064,26 +2097,26 @@ class Ze {
2064
2097
  _build(t, e, i, o) {
2065
2098
  const r = i - e + 1;
2066
2099
  let n, a = this._maxEntries;
2067
- if (r <= a) return n = H(t.slice(e, i + 1)), Y(n, this.toBBox), n;
2068
- o || (o = Math.ceil(Math.log(r) / Math.log(a)), a = Math.ceil(r / Math.pow(a, o - 1))), n = H([]), n.leaf = !1, n.height = o;
2069
- const l = Math.ceil(r / a), c = l * Math.ceil(Math.sqrt(a));
2070
- Yt(t, e, i, c, this.compareMinX);
2071
- for (let h = e; h <= i; h += c) {
2072
- const d = Math.min(h + c - 1, i);
2073
- Yt(t, h, d, l, this.compareMinY);
2074
- for (let u = h; u <= d; u += l) {
2075
- const g = Math.min(u + l - 1, d);
2100
+ if (r <= a) return n = Y(t.slice(e, i + 1)), z(n, this.toBBox), n;
2101
+ o || (o = Math.ceil(Math.log(r) / Math.log(a)), a = Math.ceil(r / Math.pow(a, o - 1))), n = Y([]), n.leaf = !1, n.height = o;
2102
+ const l = Math.ceil(r / a), d = l * Math.ceil(Math.sqrt(a));
2103
+ Ht(t, e, i, d, this.compareMinX);
2104
+ for (let c = e; c <= i; c += d) {
2105
+ const h = Math.min(c + d - 1, i);
2106
+ Ht(t, c, h, l, this.compareMinY);
2107
+ for (let u = c; u <= h; u += l) {
2108
+ const g = Math.min(u + l - 1, h);
2076
2109
  n.children.push(this._build(t, u, g, o - 1));
2077
2110
  }
2078
2111
  }
2079
- return Y(n, this.toBBox), n;
2112
+ return z(n, this.toBBox), n;
2080
2113
  }
2081
2114
  _chooseSubtree(t, e, i, o) {
2082
2115
  for (; o.push(e), !e.leaf && o.length - 1 !== i; ) {
2083
- let a, l = 1 / 0, c = 1 / 0;
2084
- for (let h = 0; h < e.children.length; h++) {
2085
- const d = e.children[h], u = xt(d), g = (r = t, n = d, (Math.max(n.maxX, r.maxX) - Math.min(n.minX, r.minX)) * (Math.max(n.maxY, r.maxY) - Math.min(n.minY, r.minY)) - u);
2086
- g < c ? (c = g, l = u < l ? u : l, a = d) : g === c && u < l && (l = u, a = d);
2116
+ let a, l = 1 / 0, d = 1 / 0;
2117
+ for (let c = 0; c < e.children.length; c++) {
2118
+ const h = e.children[c], u = St(h), g = (r = t, n = h, (Math.max(n.maxX, r.maxX) - Math.min(n.minX, r.minX)) * (Math.max(n.maxY, r.maxY) - Math.min(n.minY, r.minY)) - u);
2119
+ g < d ? (d = g, l = u < l ? u : l, a = h) : g === d && u < l && (l = u, a = h);
2087
2120
  }
2088
2121
  e = a || e.children[0];
2089
2122
  }
@@ -2092,54 +2125,54 @@ class Ze {
2092
2125
  }
2093
2126
  _insert(t, e, i) {
2094
2127
  const o = i ? t : this.toBBox(t), r = [], n = this._chooseSubtree(o, this.data, e, r);
2095
- for (n.children.push(t), tt(n, o); e >= 0 && r[e].children.length > this._maxEntries; ) this._split(r, e), e--;
2128
+ for (n.children.push(t), Q(n, o); e >= 0 && r[e].children.length > this._maxEntries; ) this._split(r, e), e--;
2096
2129
  this._adjustParentBBoxes(o, r, e);
2097
2130
  }
2098
2131
  _split(t, e) {
2099
2132
  const i = t[e], o = i.children.length, r = this._minEntries;
2100
2133
  this._chooseSplitAxis(i, r, o);
2101
- const n = this._chooseSplitIndex(i, r, o), a = H(i.children.splice(n, i.children.length - n));
2102
- a.height = i.height, a.leaf = i.leaf, Y(i, this.toBBox), Y(a, this.toBBox), e ? t[e - 1].children.push(a) : this._splitRoot(i, a);
2134
+ const n = this._chooseSplitIndex(i, r, o), a = Y(i.children.splice(n, i.children.length - n));
2135
+ a.height = i.height, a.leaf = i.leaf, z(i, this.toBBox), z(a, this.toBBox), e ? t[e - 1].children.push(a) : this._splitRoot(i, a);
2103
2136
  }
2104
2137
  _splitRoot(t, e) {
2105
- this.data = H([t, e]), this.data.height = t.height + 1, this.data.leaf = !1, Y(this.data, this.toBBox);
2138
+ this.data = Y([t, e]), this.data.height = t.height + 1, this.data.leaf = !1, z(this.data, this.toBBox);
2106
2139
  }
2107
2140
  _chooseSplitIndex(t, e, i) {
2108
2141
  let o, r = 1 / 0, n = 1 / 0;
2109
2142
  for (let a = e; a <= i - e; a++) {
2110
- const l = Q(t, 0, a, this.toBBox), c = Q(t, a, i, this.toBBox), h = qe(l, c), d = xt(l) + xt(c);
2111
- h < r ? (r = h, o = a, n = d < n ? d : n) : h === r && d < n && (n = d, o = a);
2143
+ const l = Z(t, 0, a, this.toBBox), d = Z(t, a, i, this.toBBox), c = si(l, d), h = St(l) + St(d);
2144
+ c < r ? (r = c, o = a, n = h < n ? h : n) : c === r && h < n && (n = h, o = a);
2112
2145
  }
2113
2146
  return o || i - e;
2114
2147
  }
2115
2148
  _chooseSplitAxis(t, e, i) {
2116
- const o = t.leaf ? this.compareMinX : Je, r = t.leaf ? this.compareMinY : $e;
2149
+ const o = t.leaf ? this.compareMinX : oi, r = t.leaf ? this.compareMinY : ri;
2117
2150
  this._allDistMargin(t, e, i, o) < this._allDistMargin(t, e, i, r) && t.children.sort(o);
2118
2151
  }
2119
2152
  _allDistMargin(t, e, i, o) {
2120
2153
  t.children.sort(o);
2121
- const r = this.toBBox, n = Q(t, 0, e, r), a = Q(t, i - e, i, r);
2154
+ const r = this.toBBox, n = Z(t, 0, e, r), a = Z(t, i - e, i, r);
2122
2155
  let l = lt(n) + lt(a);
2123
- for (let c = e; c < i - e; c++) {
2124
- const h = t.children[c];
2125
- tt(n, t.leaf ? r(h) : h), l += lt(n);
2156
+ for (let d = e; d < i - e; d++) {
2157
+ const c = t.children[d];
2158
+ Q(n, t.leaf ? r(c) : c), l += lt(n);
2126
2159
  }
2127
- for (let c = i - e - 1; c >= e; c--) {
2128
- const h = t.children[c];
2129
- tt(a, t.leaf ? r(h) : h), l += lt(a);
2160
+ for (let d = i - e - 1; d >= e; d--) {
2161
+ const c = t.children[d];
2162
+ Q(a, t.leaf ? r(c) : c), l += lt(a);
2130
2163
  }
2131
2164
  return l;
2132
2165
  }
2133
2166
  _adjustParentBBoxes(t, e, i) {
2134
- for (let o = i; o >= 0; o--) tt(e[o], t);
2167
+ for (let o = i; o >= 0; o--) Q(e[o], t);
2135
2168
  }
2136
2169
  _condense(t) {
2137
- 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() : Y(t[i], this.toBBox);
2170
+ 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() : z(t[i], this.toBBox);
2138
2171
  }
2139
2172
  }
2140
- class Qe {
2173
+ class ai {
2141
2174
  constructor(t) {
2142
- this.tree = void 0, this.idToNode = void 0, this.nodeToId = void 0, this.tree = new Ze(t && t.maxEntries ? t.maxEntries : 9), this.idToNode = /* @__PURE__ */ new Map(), this.nodeToId = /* @__PURE__ */ new Map();
2175
+ this.tree = void 0, this.idToNode = void 0, this.nodeToId = void 0, this.tree = new ni(t && t.maxEntries ? t.maxEntries : 9), this.idToNode = /* @__PURE__ */ new Map(), this.nodeToId = /* @__PURE__ */ new Map();
2143
2176
  }
2144
2177
  setMaps(t, e) {
2145
2178
  this.idToNode.set(t.id, e), this.nodeToId.set(e, t.id);
@@ -2190,14 +2223,14 @@ class Qe {
2190
2223
  return this.tree.collides(this.toBBox(t));
2191
2224
  }
2192
2225
  }
2193
- const ti = { getId: () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(s) {
2226
+ const li = { getId: () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(s) {
2194
2227
  const t = 16 * Math.random() | 0;
2195
2228
  return (s == "x" ? t : 3 & t | 8).toString(16);
2196
2229
  }), isValidId: (s) => typeof s == "string" && s.length === 36 };
2197
- class ei {
2230
+ class di {
2198
2231
  constructor(t) {
2199
2232
  this.idStrategy = void 0, this.tracked = void 0, this.spatialIndex = void 0, this.store = void 0, this._onChange = () => {
2200
- }, this.store = {}, this.spatialIndex = new Qe(), this.tracked = !t || t.tracked !== !1, this.idStrategy = t && t.idStrategy ? t.idStrategy : ti;
2233
+ }, this.store = {}, this.spatialIndex = new ai(), this.tracked = !t || t.tracked !== !1, this.idStrategy = t && t.idStrategy ? t.idStrategy : li;
2201
2234
  }
2202
2235
  clone(t) {
2203
2236
  return JSON.parse(JSON.stringify(t));
@@ -2209,18 +2242,26 @@ class ei {
2209
2242
  return !!this.store[t];
2210
2243
  }
2211
2244
  load(t, e) {
2212
- if (t.length === 0) return;
2213
- const i = this.clone(t);
2214
- i.forEach((r) => {
2215
- r.id == null && (r.id = this.idStrategy.getId()), this.tracked && (r.properties.createdAt ? Gt(r.properties.createdAt) : r.properties.createdAt = +/* @__PURE__ */ new Date(), r.properties.updatedAt ? Gt(r.properties.updatedAt) : r.properties.updatedAt = +/* @__PURE__ */ new Date());
2216
- });
2217
- const o = [];
2218
- i.forEach((r) => {
2219
- const n = r.id;
2220
- if (e && !e(r)) throw new Error(`Feature ${n} is not valid: ${JSON.stringify(r)}`);
2221
- if (this.has(n)) throw new Error(`Feature already exists with this id: ${n}`);
2222
- this.store[n] = r, o.push(n);
2223
- }), this.spatialIndex.load(i), this._onChange(o, "create");
2245
+ if (t.length === 0) return [];
2246
+ let i = this.clone(t);
2247
+ const o = [], r = [];
2248
+ return i = i.filter((n) => {
2249
+ n.id == null && (n.id = this.idStrategy.getId());
2250
+ const a = n.id;
2251
+ if (e) {
2252
+ const l = e(n);
2253
+ if (!l.valid) return r.push({ id: a, valid: !1, reason: l.reason }), !1;
2254
+ }
2255
+ if (this.tracked) {
2256
+ if (n.properties.createdAt) {
2257
+ if (!At(n.properties.createdAt)) return r.push({ id: n.id, valid: !1, reason: "createdAt is not a valid numeric timestamp" }), !1;
2258
+ } else n.properties.createdAt = +/* @__PURE__ */ new Date();
2259
+ if (n.properties.updatedAt) {
2260
+ if (!At(n.properties.updatedAt)) return r.push({ id: n.id, valid: !1, reason: "updatedAt is not a valid numeric timestamp" }), !1;
2261
+ } else n.properties.updatedAt = +/* @__PURE__ */ new Date();
2262
+ }
2263
+ return this.has(a) ? (r.push({ id: a, valid: !1, reason: `Feature already exists with this id: ${a}` }), !1) : (this.store[a] = n, o.push(a), r.push({ id: a, valid: !0 }), !0);
2264
+ }), this.spatialIndex.load(i), this._onChange(o, "create"), r;
2224
2265
  }
2225
2266
  search(t, e) {
2226
2267
  const i = this.spatialIndex.search(t).map((o) => this.store[o]);
@@ -2261,7 +2302,7 @@ class ei {
2261
2302
  create(t) {
2262
2303
  const e = [];
2263
2304
  return t.forEach(({ geometry: i, properties: o }) => {
2264
- let r, n = x({}, o);
2305
+ let r, n = M({}, o);
2265
2306
  this.tracked && (r = +/* @__PURE__ */ new Date(), o ? (n.createdAt = typeof o.createdAt == "number" ? o.createdAt : r, n.updatedAt = typeof o.updatedAt == "number" ? o.updatedAt : r) : n = { createdAt: r, updatedAt: r });
2266
2307
  const a = this.getId(), l = { id: a, type: "Feature", geometry: i, properties: n };
2267
2308
  this.store[a] = l, this.spatialIndex.insert(l), e.push(a);
@@ -2283,20 +2324,20 @@ class ei {
2283
2324
  return Object.keys(this.store).length;
2284
2325
  }
2285
2326
  }
2286
- const me = (s) => (s.geometry.type === "Polygon" || s.geometry.type === "LineString") && !Et(s);
2287
- function Ht(s, t, e) {
2327
+ const ci = "Feature is not a Polygon or LineString", hi = "Feature intersects itself", ui = (s) => s.geometry.type !== "Polygon" && s.geometry.type !== "LineString" ? { valid: !1, reason: ci } : It(s) ? { valid: !1, reason: hi } : { valid: !0 };
2328
+ function Jt(s, t, e) {
2288
2329
  const i = j(s, t);
2289
2330
  let o = j(t, e) - i;
2290
2331
  return o < 0 && (o += 360), 180 - Math.abs(o - 90 - 90);
2291
2332
  }
2292
- class Ce extends W {
2333
+ class ve extends W {
2293
2334
  constructor(t) {
2294
2335
  super(t), this.mode = "angled-rectangle", this.currentCoordinate = 0, this.currentId = void 0, this.keyEvents = void 0, this.cursors = void 0, this.mouseMove = !1;
2295
2336
  const e = { start: "crosshair", close: "pointer" };
2296
- if (this.cursors = t && t.cursors ? x({}, e, t.cursors) : e, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
2337
+ if (this.cursors = t && t.cursors ? M({}, e, t.cursors) : e, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
2297
2338
  else {
2298
2339
  const i = { cancel: "Escape", finish: "Enter" };
2299
- this.keyEvents = t && t.keyEvents ? x({}, i, t.keyEvents) : i;
2340
+ this.keyEvents = t && t.keyEvents ? M({}, i, t.keyEvents) : i;
2300
2341
  }
2301
2342
  }
2302
2343
  close() {
@@ -2318,17 +2359,17 @@ class Ce extends W {
2318
2359
  const o = 1 / Math.pow(10, this.coordinatePrecision - 1), r = Math.max(1e-6, o);
2319
2360
  i = [e[0], [t.lng, t.lat], [t.lng, t.lat - r], e[0]];
2320
2361
  } else if (this.currentCoordinate === 2) {
2321
- const o = e[0], r = e[1], n = ue(o, r, this.coordinatePrecision, this.project, this.unproject), a = M(o[0], o[1]), l = M(n[0], n[1]), c = M(r[0], r[1]), h = M(t.lng, t.lat), d = F(h, a) < F(h, c), u = Ht(a, l, h), g = d ? 90 - u : Ht(a, l, h) - 90, p = F(l, h), y = Math.cos(_(g)) * p, m = j(a, c) + (function(P, w, I) {
2322
- const B = (I.x - w.x) * (P.y - w.y) - (I.y - w.y) * (P.x - w.x);
2362
+ const o = e[0], r = e[1], n = ge(o, r, this.coordinatePrecision, this.project, this.unproject), a = x(o[0], o[1]), l = x(n[0], n[1]), d = x(r[0], r[1]), c = x(t.lng, t.lat), h = I(c, a) < I(c, d), u = Jt(a, l, c), g = h ? 90 - u : Jt(a, l, c) - 90, p = I(l, c), y = Math.cos(_(g)) * p, m = j(a, d) + (function(S, w, E) {
2363
+ const B = (E.x - w.x) * (S.y - w.y) - (E.y - w.y) * (S.x - w.x);
2323
2364
  return B > 1e-10 ? "left" : B < -1e-10 ? "right" : "left";
2324
- }(a, c, h) === "right" ? -90 : 90), f = ot(a, y, m), v = ot(c, y, m), C = L(f.x, f.y), S = L(v.x, v.y);
2325
- i = [e[0], e[1], [S.lng, S.lat], [C.lng, C.lat], e[0]];
2365
+ }(a, d, c) === "right" ? -90 : 90), f = it(a, y, m), C = it(d, y, m), v = O(f.x, f.y), P = O(C.x, C.y);
2366
+ i = [e[0], e[1], [P.lng, P.lat], [v.lng, v.lat], e[0]];
2326
2367
  }
2327
2368
  i && this.updatePolygonGeometry(this.currentId, i, b.Provisional);
2328
2369
  }
2329
2370
  updatePolygonGeometry(t, e, i) {
2330
2371
  const o = { type: "Polygon", coordinates: [e] };
2331
- 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));
2372
+ return !(this.validate && !this.validate({ type: "Feature", geometry: o }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: i }).valid || (this.store.updateGeometry([{ id: t, geometry: o }]), 0));
2332
2373
  }
2333
2374
  onClick(t) {
2334
2375
  if (this.currentCoordinate > 0 && !this.mouseMove && this.onMouseMove(t), this.mouseMove = !1, this.currentCoordinate === 0) {
@@ -2336,7 +2377,7 @@ class Ce extends W {
2336
2377
  this.currentId = e, this.currentCoordinate++, this.setDrawing();
2337
2378
  } else if (this.currentCoordinate === 1 && this.currentId) {
2338
2379
  const e = this.store.getGeometryCopy(this.currentId);
2339
- 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]], b.Commit)) return;
2380
+ if (J([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]], b.Commit)) return;
2340
2381
  this.currentCoordinate++;
2341
2382
  } else this.currentCoordinate === 2 && this.currentId && this.close();
2342
2383
  }
@@ -2359,24 +2400,24 @@ class Ce extends W {
2359
2400
  this.currentId = void 0, this.currentCoordinate = 0, this.state === "drawing" && this.setStarted();
2360
2401
  }
2361
2402
  styleFeature(t) {
2362
- const e = x({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
2403
+ const e = M({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
2363
2404
  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;
2364
2405
  }
2365
2406
  validateFeature(t) {
2366
- return !!super.validateFeature(t) && t.properties.mode === this.mode && R(t, this.coordinatePrecision);
2407
+ return this.validateModeFeature(t, (e) => ot(e, this.coordinatePrecision));
2367
2408
  }
2368
2409
  }
2369
- function ve(s, t, e) {
2410
+ function Ce(s, t, e) {
2370
2411
  return (t.x - s.x) * (e.y - s.y) - (t.y - s.y) * (e.x - s.x) <= 0;
2371
2412
  }
2372
2413
  class Pe extends W {
2373
2414
  constructor(t) {
2374
2415
  super(t), this.mode = "sector", this.currentCoordinate = 0, this.currentId = void 0, this.keyEvents = void 0, this.direction = void 0, this.arcPoints = void 0, this.cursors = void 0, this.mouseMove = !1;
2375
2416
  const e = { start: "crosshair", close: "pointer" };
2376
- if (this.cursors = t && t.cursors ? x({}, e, t.cursors) : e, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
2417
+ if (this.cursors = t && t.cursors ? M({}, e, t.cursors) : e, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
2377
2418
  else {
2378
2419
  const i = { cancel: "Escape", finish: "Enter" };
2379
- this.keyEvents = t && t.keyEvents ? x({}, i, t.keyEvents) : i;
2420
+ this.keyEvents = t && t.keyEvents ? M({}, i, t.keyEvents) : i;
2380
2421
  }
2381
2422
  this.arcPoints = (t == null ? void 0 : t.arcPoints) || 64;
2382
2423
  }
@@ -2399,19 +2440,19 @@ class Pe extends W {
2399
2440
  const o = 1 / Math.pow(10, this.coordinatePrecision - 1), r = Math.max(1e-6, o);
2400
2441
  i = [e[0], [t.lng, t.lat], [t.lng, t.lat - r], e[0]];
2401
2442
  } else if (this.currentCoordinate === 2) {
2402
- const o = e[0], r = e[1], n = [t.lng, t.lat], a = M(o[0], o[1]), l = M(r[0], r[1]), c = M(n[0], n[1]);
2443
+ const o = e[0], r = e[1], n = [t.lng, t.lat], a = x(o[0], o[1]), l = x(r[0], r[1]), d = x(n[0], n[1]);
2403
2444
  if (this.direction === void 0) {
2404
- const C = ve(a, l, c);
2405
- this.direction = C ? "clockwise" : "anticlockwise";
2445
+ const v = Ce(a, l, d);
2446
+ this.direction = v ? "clockwise" : "anticlockwise";
2406
2447
  }
2407
- const h = F(a, l), d = j(a, l), u = j(a, c), g = this.arcPoints, p = [o], y = V(d), m = V(u);
2448
+ const c = I(a, l), h = j(a, l), u = j(a, d), g = this.arcPoints, p = [o], y = V(h), m = V(u);
2408
2449
  let f;
2409
2450
  this.direction === "anticlockwise" ? (f = m - y, f < 0 && (f += 360)) : (f = y - m, f < 0 && (f += 360));
2410
- const v = (this.direction === "anticlockwise" ? 1 : -1) * f / g;
2451
+ const C = (this.direction === "anticlockwise" ? 1 : -1) * f / g;
2411
2452
  p.push(r);
2412
- for (let C = 0; C <= g; C++) {
2413
- const S = ot(a, h, y + C * v), { lng: P, lat: w } = L(S.x, S.y), I = [E(P, this.coordinatePrecision), E(w, this.coordinatePrecision)];
2414
- I[0] !== p[p.length - 1][0] && I[1] !== p[p.length - 1][1] && p.push(I);
2453
+ for (let v = 0; v <= g; v++) {
2454
+ const P = it(a, c, y + v * C), { lng: S, lat: w } = O(P.x, P.y), E = [F(S, this.coordinatePrecision), F(w, this.coordinatePrecision)];
2455
+ E[0] !== p[p.length - 1][0] && E[1] !== p[p.length - 1][1] && p.push(E);
2415
2456
  }
2416
2457
  p.push(o), i = [...p];
2417
2458
  }
@@ -2419,7 +2460,7 @@ class Pe extends W {
2419
2460
  }
2420
2461
  updatePolygonGeometry(t, e, i) {
2421
2462
  const o = { type: "Polygon", coordinates: [e] };
2422
- 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));
2463
+ return !(this.validate && !this.validate({ type: "Feature", geometry: o }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: i }).valid || (this.store.updateGeometry([{ id: t, geometry: o }]), 0));
2423
2464
  }
2424
2465
  onClick(t) {
2425
2466
  if (this.currentCoordinate > 0 && !this.mouseMove && this.onMouseMove(t), this.mouseMove = !1, this.currentCoordinate === 0) {
@@ -2427,7 +2468,7 @@ class Pe extends W {
2427
2468
  this.currentId = e, this.currentCoordinate++, this.setDrawing();
2428
2469
  } else if (this.currentCoordinate === 1 && this.currentId) {
2429
2470
  const e = this.store.getGeometryCopy(this.currentId);
2430
- 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]], b.Commit)) return;
2471
+ if (J([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]], b.Commit)) return;
2431
2472
  this.currentCoordinate++;
2432
2473
  } else this.currentCoordinate === 2 && this.currentId && this.close();
2433
2474
  }
@@ -2450,21 +2491,21 @@ class Pe extends W {
2450
2491
  this.currentId = void 0, this.direction = void 0, this.currentCoordinate = 0, this.state === "drawing" && this.setStarted();
2451
2492
  }
2452
2493
  styleFeature(t) {
2453
- const e = x({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
2494
+ const e = M({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
2454
2495
  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;
2455
2496
  }
2456
2497
  validateFeature(t) {
2457
- return !!super.validateFeature(t) && t.properties.mode === this.mode && R(t, this.coordinatePrecision);
2498
+ return this.validateModeFeature(t, (e) => ot(e, this.coordinatePrecision));
2458
2499
  }
2459
2500
  }
2460
2501
  class xe extends W {
2461
2502
  constructor(t) {
2462
2503
  super(t), this.mode = "sensor", this.currentCoordinate = 0, this.currentId = void 0, this.currentInitialArcId = void 0, this.currentStartingPointId = void 0, this.keyEvents = void 0, this.direction = void 0, this.arcPoints = void 0, this.cursors = void 0, this.mouseMove = !1;
2463
2504
  const e = { start: "crosshair", close: "pointer" };
2464
- if (this.cursors = t && t.cursors ? x({}, e, t.cursors) : e, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
2505
+ if (this.cursors = t && t.cursors ? M({}, e, t.cursors) : e, (t == null ? void 0 : t.keyEvents) === null) this.keyEvents = { cancel: null, finish: null };
2465
2506
  else {
2466
2507
  const i = { cancel: "Escape", finish: "Enter" };
2467
- this.keyEvents = t && t.keyEvents ? x({}, i, t.keyEvents) : i;
2508
+ this.keyEvents = t && t.keyEvents ? M({}, i, t.keyEvents) : i;
2468
2509
  }
2469
2510
  this.arcPoints = (t == null ? void 0 : t.arcPoints) || 64;
2470
2511
  }
@@ -2482,28 +2523,28 @@ class xe extends W {
2482
2523
  onMouseMove(t) {
2483
2524
  if (this.mouseMove = !0, this.setCursor(this.cursors.start), this.currentInitialArcId !== void 0 && this.currentStartingPointId !== void 0 && this.currentCoordinate !== 0) {
2484
2525
  if (this.currentCoordinate === 2) {
2485
- const e = this.store.getGeometryCopy(this.currentInitialArcId).coordinates, i = this.store.getGeometryCopy(this.currentStartingPointId).coordinates, o = e[0], r = [t.lng, t.lat], n = M(o[0], o[1]), a = M(r[0], r[1]), l = M(i[0], i[1]), c = F(l, n);
2526
+ const e = this.store.getGeometryCopy(this.currentInitialArcId).coordinates, i = this.store.getGeometryCopy(this.currentStartingPointId).coordinates, o = e[0], r = [t.lng, t.lat], n = x(o[0], o[1]), a = x(r[0], r[1]), l = x(i[0], i[1]), d = I(l, n);
2486
2527
  if (this.direction === void 0) {
2487
- const v = ve(l, n, a);
2488
- this.direction = v ? "clockwise" : "anticlockwise";
2528
+ const C = Ce(l, n, a);
2529
+ this.direction = C ? "clockwise" : "anticlockwise";
2489
2530
  }
2490
- const h = j(l, n), d = j(l, a), u = this.arcPoints, g = [o], p = V(h), y = V(d);
2531
+ const c = j(l, n), h = j(l, a), u = this.arcPoints, g = [o], p = V(c), y = V(h);
2491
2532
  let m;
2492
2533
  this.direction === "anticlockwise" ? (m = y - p, m < 0 && (m += 360)) : (m = p - y, m < 0 && (m += 360));
2493
2534
  const f = (this.direction === "anticlockwise" ? 1 : -1) * m / u;
2494
- for (let v = 0; v <= u; v++) {
2495
- const C = ot(l, c, p + v * f), { lng: S, lat: P } = L(C.x, C.y), w = [E(S, this.coordinatePrecision), E(P, this.coordinatePrecision)];
2535
+ for (let C = 0; C <= u; C++) {
2536
+ const v = it(l, d, p + C * f), { lng: P, lat: S } = O(v.x, v.y), w = [F(P, this.coordinatePrecision), F(S, this.coordinatePrecision)];
2496
2537
  w[0] !== g[g.length - 1][0] && w[1] !== g[g.length - 1][1] && g.push(w);
2497
2538
  }
2498
2539
  this.updateLineStringGeometry(this.currentInitialArcId, g, b.Provisional);
2499
2540
  } else if (this.currentCoordinate === 3) {
2500
2541
  const e = this.store.getGeometryCopy(this.currentInitialArcId).coordinates;
2501
2542
  if (e.length < 2 || !this.direction) return;
2502
- const i = this.store.getGeometryCopy(this.currentStartingPointId).coordinates, o = e[0], r = e[e.length - 1], n = M(t.lng, t.lat), a = M(o[0], o[1]), l = M(r[0], r[1]), c = M(i[0], i[1]), h = F(c, a), d = F(c, n) < h ? a : n, u = j(c, n), g = j(c, a), p = j(c, l), y = V(g), m = V(p), f = V(u);
2543
+ const i = this.store.getGeometryCopy(this.currentStartingPointId).coordinates, o = e[0], r = e[e.length - 1], n = x(t.lng, t.lat), a = x(o[0], o[1]), l = x(r[0], r[1]), d = x(i[0], i[1]), c = I(d, a), h = I(d, n) < c ? a : n, u = j(d, n), g = j(d, a), p = j(d, l), y = V(g), m = V(p), f = V(u);
2503
2544
  if (this.notInSector({ normalizedCursor: f, normalizedStart: y, normalizedEnd: m, direction: this.direction })) return;
2504
- const v = this.getDeltaBearing(this.direction, y, m), C = this.arcPoints, S = (this.direction === "anticlockwise" ? 1 : -1) * v / C, P = F(c, d), w = [];
2505
- for (let I = 0; I <= C; I++) {
2506
- const B = ot(c, P, y + I * S), { lng: T, lat: X } = L(B.x, B.y), N = [E(T, this.coordinatePrecision), E(X, this.coordinatePrecision)];
2545
+ const C = this.getDeltaBearing(this.direction, y, m), v = this.arcPoints, P = (this.direction === "anticlockwise" ? 1 : -1) * C / v, S = I(d, h), w = [];
2546
+ for (let E = 0; E <= v; E++) {
2547
+ const B = it(d, S, y + E * P), { lng: T, lat: R } = O(B.x, B.y), N = [F(T, this.coordinatePrecision), F(R, this.coordinatePrecision)];
2507
2548
  N[0] !== e[e.length - 1][0] && N[1] !== e[e.length - 1][1] && w.unshift(N);
2508
2549
  }
2509
2550
  e.push(...w), e.push(e[0]), this.currentId ? this.updatePolygonGeometry(this.currentId, e, b.Provisional) : [this.currentId] = this.store.create([{ geometry: { type: "Polygon", coordinates: [e] }, properties: { mode: this.mode } }]);
@@ -2512,11 +2553,11 @@ class xe extends W {
2512
2553
  }
2513
2554
  updateLineStringGeometry(t, e, i) {
2514
2555
  const o = { type: "LineString", coordinates: e };
2515
- 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));
2556
+ return !(this.validate && !this.validate({ type: "Feature", geometry: o }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: i }).valid || (this.store.updateGeometry([{ id: t, geometry: o }]), 0));
2516
2557
  }
2517
2558
  updatePolygonGeometry(t, e, i) {
2518
2559
  const o = { type: "Polygon", coordinates: [e] };
2519
- 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));
2560
+ return !(this.validate && !this.validate({ type: "Feature", geometry: o }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: i }).valid || (this.store.updateGeometry([{ id: t, geometry: o }]), 0));
2520
2561
  }
2521
2562
  onClick(t) {
2522
2563
  if (this.currentCoordinate > 0 && !this.mouseMove && this.onMouseMove(t), this.mouseMove = !1, this.currentCoordinate === 0) {
@@ -2546,11 +2587,11 @@ class xe extends W {
2546
2587
  this.currentStartingPointId = void 0, this.direction = void 0, this.currentId = void 0, this.currentCoordinate = 0, this.state === "drawing" && this.setStarted();
2547
2588
  }
2548
2589
  styleFeature(t) {
2549
- const e = x({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
2590
+ const e = M({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
2550
2591
  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) : t.geometry.type === "LineString" ? (e.lineStringColor = this.getHexColorStylingValue(this.styles.outlineColor, e.polygonOutlineColor, t), e.lineStringWidth = this.getNumericStylingValue(this.styles.outlineWidth, e.polygonOutlineWidth, t), e.zIndex = 10) : t.geometry.type === "Point" && (e.pointColor = this.getHexColorStylingValue(this.styles.centerPointColor, e.pointColor, t), e.pointWidth = this.getNumericStylingValue(this.styles.centerPointWidth, e.pointWidth, t), e.pointOutlineColor = this.getHexColorStylingValue(this.styles.centerPointOutlineColor, e.pointOutlineColor, t), e.pointOutlineWidth = this.getNumericStylingValue(this.styles.centerPointOutlineWidth, e.pointOutlineWidth, t), e.zIndex = 20)), e;
2551
2592
  }
2552
2593
  validateFeature(t) {
2553
- return !!super.validateFeature(t) && t.properties.mode === this.mode && R(t, this.coordinatePrecision);
2594
+ return this.validateModeFeature(t, (e) => ot(e, this.coordinatePrecision));
2554
2595
  }
2555
2596
  getDeltaBearing(t, e, i) {
2556
2597
  let o;
@@ -2560,51 +2601,51 @@ class xe extends W {
2560
2601
  return o === "clockwise" ? e <= i ? t >= e && t <= i : t >= e || t <= i : e >= i ? t <= e && t >= i : t <= e || t >= i;
2561
2602
  }
2562
2603
  }
2563
- class ii {
2604
+ class gi {
2564
2605
  constructor(t) {
2565
- 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 He();
2566
- const e = /* @__PURE__ */ new Set(), i = t.modes.reduce((h, d) => {
2567
- if (e.has(d.mode)) throw new Error(`There is already a ${d.mode} mode provided`);
2568
- return e.add(d.mode), h[d.mode] = d, h;
2606
+ 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 ii();
2607
+ const e = /* @__PURE__ */ new Set(), i = t.modes.reduce((c, h) => {
2608
+ if (e.has(h.mode)) throw new Error(`There is already a ${h.mode} mode provided`);
2609
+ return e.add(h.mode), c[h.mode] = h, c;
2569
2610
  }, {}), o = Object.keys(i);
2570
2611
  if (o.length === 0) throw new Error("No modes provided");
2571
- o.forEach((h) => {
2572
- if (i[h].type === U.Select) {
2612
+ o.forEach((c) => {
2613
+ if (i[c].type === U.Select) {
2573
2614
  if (this._instanceSelectMode) throw new Error("only one type of select mode can be provided");
2574
- this._instanceSelectMode = h;
2615
+ this._instanceSelectMode = c;
2575
2616
  }
2576
- }), this._modes = x({}, i, { static: this._mode }), this._eventListeners = { change: [], select: [], deselect: [], finish: [], ready: [] }, this._store = new ei({ tracked: !!t.tracked, idStrategy: t.idStrategy ? t.idStrategy : void 0 });
2577
- const r = (h) => {
2578
- const d = [], u = this._store.copyAll().filter((g) => !h.includes(g.id) || (d.push(g), !1));
2579
- return { changed: d, unchanged: u };
2580
- }, n = (h, d) => {
2617
+ }), this._modes = M({}, i, { static: this._mode }), this._eventListeners = { change: [], select: [], deselect: [], finish: [], ready: [] }, this._store = new di({ tracked: !!t.tracked, idStrategy: t.idStrategy ? t.idStrategy : void 0 });
2618
+ const r = (c) => {
2619
+ const h = [], u = this._store.copyAll().filter((g) => !c.includes(g.id) || (h.push(g), !1));
2620
+ return { changed: h, unchanged: u };
2621
+ }, n = (c, h) => {
2581
2622
  this._enabled && this._eventListeners.finish.forEach((u) => {
2582
- u(h, d);
2623
+ u(c, h);
2583
2624
  });
2584
- }, a = (h, d) => {
2625
+ }, a = (c, h) => {
2585
2626
  if (!this._enabled) return;
2586
2627
  this._eventListeners.change.forEach((p) => {
2587
- p(h, d);
2628
+ p(c, h);
2588
2629
  });
2589
- const { changed: u, unchanged: g } = r(h);
2590
- d === "create" ? this._adapter.render({ created: u, deletedIds: [], unchanged: g, updated: [] }, this.getModeStyles()) : d === "update" ? this._adapter.render({ created: [], deletedIds: [], unchanged: g, updated: u }, this.getModeStyles()) : d === "delete" ? this._adapter.render({ created: [], deletedIds: h, unchanged: g, updated: [] }, this.getModeStyles()) : d === "styling" && this._adapter.render({ created: [], deletedIds: [], unchanged: g, updated: [] }, this.getModeStyles());
2591
- }, l = (h) => {
2630
+ const { changed: u, unchanged: g } = r(c);
2631
+ h === "create" ? this._adapter.render({ created: u, deletedIds: [], unchanged: g, updated: [] }, this.getModeStyles()) : h === "update" ? this._adapter.render({ created: [], deletedIds: [], unchanged: g, updated: u }, this.getModeStyles()) : h === "delete" ? this._adapter.render({ created: [], deletedIds: c, unchanged: g, updated: [] }, this.getModeStyles()) : h === "styling" && this._adapter.render({ created: [], deletedIds: [], unchanged: g, updated: [] }, this.getModeStyles());
2632
+ }, l = (c) => {
2592
2633
  if (!this._enabled) return;
2593
2634
  this._eventListeners.select.forEach((g) => {
2594
- g(h);
2635
+ g(c);
2595
2636
  });
2596
- const { changed: d, unchanged: u } = r([h]);
2597
- this._adapter.render({ created: [], deletedIds: [], unchanged: u, updated: d }, this.getModeStyles());
2598
- }, c = (h) => {
2637
+ const { changed: h, unchanged: u } = r([c]);
2638
+ this._adapter.render({ created: [], deletedIds: [], unchanged: u, updated: h }, this.getModeStyles());
2639
+ }, d = (c) => {
2599
2640
  if (!this._enabled) return;
2600
2641
  this._eventListeners.deselect.forEach((g) => {
2601
2642
  g();
2602
2643
  });
2603
- const { changed: d, unchanged: u } = r([h]);
2604
- d && this._adapter.render({ created: [], deletedIds: [], unchanged: u, updated: d }, this.getModeStyles());
2644
+ const { changed: h, unchanged: u } = r([c]);
2645
+ h && this._adapter.render({ created: [], deletedIds: [], unchanged: u, updated: h }, this.getModeStyles());
2605
2646
  };
2606
- Object.keys(this._modes).forEach((h) => {
2607
- 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: c, onFinish: n, coordinatePrecision: this._adapter.getCoordinatePrecision() });
2647
+ Object.keys(this._modes).forEach((c) => {
2648
+ this._modes[c].register({ mode: c, 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: n, coordinatePrecision: this._adapter.getCoordinatePrecision() });
2608
2649
  });
2609
2650
  }
2610
2651
  checkEnabled() {
@@ -2613,26 +2654,26 @@ class ii {
2613
2654
  getModeStyles() {
2614
2655
  const t = {};
2615
2656
  return Object.keys(this._modes).forEach((e) => {
2616
- t[e] = (i) => this._instanceSelectMode && i.properties[bt] ? this._modes[this._instanceSelectMode].styleFeature.bind(this._modes[this._instanceSelectMode])(i) : this._modes[e].styleFeature.bind(this._modes[e])(i);
2657
+ t[e] = (i) => this._instanceSelectMode && i.properties[wt] ? this._modes[this._instanceSelectMode].styleFeature.bind(this._modes[this._instanceSelectMode])(i) : this._modes[e].styleFeature.bind(this._modes[e])(i);
2617
2658
  }), t;
2618
2659
  }
2619
2660
  featuresAtLocation({ lng: t, lat: e }, i) {
2620
- const o = i && i.pointerDistance !== void 0 ? i.pointerDistance : 30, r = !i || i.ignoreSelectFeatures === void 0 || i.ignoreSelectFeatures, n = this._adapter.unproject.bind(this._adapter), a = this._adapter.project.bind(this._adapter), l = a(t, e), c = ne({ unproject: n, point: l, pointerDistance: o });
2621
- return this._store.search(c).filter((h) => {
2622
- if (r && (h.properties[et] || h.properties.selectionPoint)) return !1;
2623
- if (h.geometry.type === "Point") {
2624
- const d = h.geometry.coordinates, u = a(d[0], d[1]);
2625
- return F(l, u) < o;
2661
+ const o = i && i.pointerDistance !== void 0 ? i.pointerDistance : 30, r = !i || i.ignoreSelectFeatures === void 0 || i.ignoreSelectFeatures, n = this._adapter.unproject.bind(this._adapter), a = this._adapter.project.bind(this._adapter), l = a(t, e), d = ne({ unproject: n, point: l, pointerDistance: o });
2662
+ return this._store.search(d).filter((c) => {
2663
+ if (r && (c.properties[tt] || c.properties.selectionPoint)) return !1;
2664
+ if (c.geometry.type === "Point") {
2665
+ const h = c.geometry.coordinates, u = a(h[0], h[1]);
2666
+ return I(l, u) < o;
2626
2667
  }
2627
- if (h.geometry.type === "LineString") {
2628
- const d = h.geometry.coordinates;
2629
- for (let u = 0; u < d.length - 1; u++) {
2630
- const g = d[u], p = d[u + 1];
2631
- if (pe(l, a(g[0], g[1]), a(p[0], p[1])) < o) return !0;
2668
+ if (c.geometry.type === "LineString") {
2669
+ const h = c.geometry.coordinates;
2670
+ for (let u = 0; u < h.length - 1; u++) {
2671
+ const g = h[u], p = h[u + 1];
2672
+ if (ye(l, a(g[0], g[1]), a(p[0], p[1])) < o) return !0;
2632
2673
  }
2633
2674
  return !1;
2634
2675
  }
2635
- return !!ge([t, e], h.geometry.coordinates) || void 0;
2676
+ return !!pe([t, e], c.geometry.coordinates) || void 0;
2636
2677
  });
2637
2678
  }
2638
2679
  getSelectMode() {
@@ -2678,12 +2719,16 @@ class ii {
2678
2719
  return this._store.has(t);
2679
2720
  }
2680
2721
  addFeatures(t) {
2681
- this.checkEnabled(), t.length !== 0 && this._store.load(t, (e) => {
2682
- if (e && typeof e == "object" && "properties" in e && typeof e.properties == "object" && e.properties !== null && "mode" in e.properties) {
2683
- const i = this._modes[e.properties.mode];
2684
- return !!i && i.validateFeature.bind(i)(e);
2722
+ return this.checkEnabled(), t.length === 0 ? [] : this._store.load(t, (e) => {
2723
+ if (function(i) {
2724
+ return !!(i && typeof i == "object" && "properties" in i && typeof i.properties == "object" && i.properties !== null && "mode" in i.properties);
2725
+ }(e)) {
2726
+ const i = e.properties.mode, o = this._modes[i];
2727
+ if (!o) return { id: e.id, valid: !1, reason: `${i} mode is not in the list of instantiated modes` };
2728
+ const r = o.validateFeature.bind(o)(e);
2729
+ return { id: e.id, valid: r.valid, reason: r.reason ? r.reason : r.valid ? void 0 : "Feature is invalid" };
2685
2730
  }
2686
- return !1;
2731
+ return { id: e.id, valid: !1, reason: "Mode property does not exist" };
2687
2732
  });
2688
2733
  }
2689
2734
  start() {
@@ -2729,7 +2774,7 @@ class ii {
2729
2774
  i.includes(e) && i.splice(i.indexOf(e), 1);
2730
2775
  }
2731
2776
  }
2732
- const vi = [
2777
+ const Di = [
2733
2778
  "render",
2734
2779
  "point",
2735
2780
  "linestring",
@@ -2743,7 +2788,7 @@ const vi = [
2743
2788
  "select",
2744
2789
  "delete-selection",
2745
2790
  "delete"
2746
- ], Pi = [
2791
+ ], Oi = [
2747
2792
  "render",
2748
2793
  "linestring",
2749
2794
  "polygon",
@@ -2756,7 +2801,7 @@ const vi = [
2756
2801
  "select",
2757
2802
  "delete-selection",
2758
2803
  "delete"
2759
- ], oi = {
2804
+ ], pi = {
2760
2805
  modes: [
2761
2806
  "render",
2762
2807
  "point",
@@ -2773,7 +2818,7 @@ const vi = [
2773
2818
  "delete"
2774
2819
  ],
2775
2820
  open: !1
2776
- }, ri = {
2821
+ }, yi = {
2777
2822
  modes: [
2778
2823
  "render",
2779
2824
  "linestring",
@@ -2784,12 +2829,14 @@ const vi = [
2784
2829
  "sector",
2785
2830
  "circle",
2786
2831
  "freehand",
2832
+ "select",
2833
+ "delete-selection",
2787
2834
  "delete"
2788
2835
  ],
2789
2836
  open: !1,
2790
2837
  // see styling parameters of Terra Draw at https://github.com/JamesLMilner/terra-draw/blob/main/guides/5.STYLING.md
2791
2838
  modeOptions: {
2792
- linestring: new le({
2839
+ linestring: new de({
2793
2840
  styles: {
2794
2841
  lineStringColor: "#000000",
2795
2842
  lineStringWidth: 2,
@@ -2809,15 +2856,9 @@ const vi = [
2809
2856
  closingPointWidth: 5,
2810
2857
  closingPointOutlineColor: "#000000",
2811
2858
  closingPointOutlineWidth: 1
2812
- },
2813
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2814
- // @ts-ignore
2815
- validation: (s, t) => {
2816
- const e = t.updateType;
2817
- return e === "finish" || e === "commit" ? me(s) : !0;
2818
2859
  }
2819
2860
  }),
2820
- rectangle: new de({
2861
+ rectangle: new ue({
2821
2862
  styles: {
2822
2863
  fillColor: "#FFFFFF",
2823
2864
  fillOpacity: 0.7,
@@ -2825,7 +2866,7 @@ const vi = [
2825
2866
  outlineWidth: 2
2826
2867
  }
2827
2868
  }),
2828
- "angled-rectangle": new Ce({
2869
+ "angled-rectangle": new ve({
2829
2870
  styles: {
2830
2871
  fillColor: "#FFFFFF",
2831
2872
  fillOpacity: 0.7,
@@ -2934,28 +2975,28 @@ const vi = [
2934
2975
  "text-color": "#000000"
2935
2976
  }
2936
2977
  }
2937
- }, si = () => ({
2938
- render: new dt({
2978
+ }, fi = () => ({
2979
+ render: new ht({
2939
2980
  modeName: "render",
2940
2981
  styles: {}
2941
2982
  }),
2942
- point: new Be(),
2943
- linestring: new le(),
2983
+ point: new Xe(),
2984
+ linestring: new de(),
2944
2985
  polygon: new he({
2945
2986
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2946
2987
  // @ts-ignore
2947
2988
  validation: (t, e) => {
2948
2989
  const i = e.updateType;
2949
- return i === "finish" || i === "commit" ? me(t) : !0;
2990
+ return i === "finish" || i === "commit" ? ui(t) : { valid: !0 };
2950
2991
  }
2951
2992
  }),
2952
- rectangle: new de(),
2953
- "angled-rectangle": new Ce(),
2993
+ rectangle: new ue(),
2994
+ "angled-rectangle": new ve(),
2954
2995
  circle: new re(),
2955
2996
  freehand: new se(),
2956
2997
  sensor: new xe(),
2957
2998
  sector: new Pe(),
2958
- select: new Ye({
2999
+ select: new ei({
2959
3000
  flags: {
2960
3001
  point: {
2961
3002
  feature: {
@@ -3056,29 +3097,29 @@ const vi = [
3056
3097
  }
3057
3098
  }
3058
3099
  }),
3059
- delete: new dt({
3100
+ delete: new ht({
3060
3101
  modeName: "delete",
3061
3102
  styles: {}
3062
3103
  }),
3063
- "delete-selection": new dt({
3104
+ "delete-selection": new ht({
3064
3105
  modeName: "delete-selection",
3065
3106
  styles: {}
3066
3107
  })
3067
3108
  });
3068
- class ni {
3109
+ class mi {
3069
3110
  /**
3070
3111
  * Constructor
3071
3112
  * @param options Plugin control options
3072
3113
  */
3073
3114
  constructor(t) {
3074
- k(this, "controlContainer");
3075
- k(this, "map");
3076
- k(this, "modeButtons", {});
3077
- k(this, "isExpanded", !1);
3078
- k(this, "terradraw");
3079
- k(this, "options", oi);
3080
- k(this, "events", {});
3081
- k(this, "defaultMode", "render");
3115
+ L(this, "controlContainer");
3116
+ L(this, "map");
3117
+ L(this, "modeButtons", {});
3118
+ L(this, "isExpanded", !1);
3119
+ L(this, "terradraw");
3120
+ L(this, "options", pi);
3121
+ L(this, "events", {});
3122
+ L(this, "defaultMode", "render");
3082
3123
  this.modeButtons = {}, t && (this.options = Object.assign(this.options, t));
3083
3124
  }
3084
3125
  /**
@@ -3098,36 +3139,36 @@ class ni {
3098
3139
  if (this.options && this.options.modes && this.options.modes.length === 0)
3099
3140
  throw new Error("At least a mode must be enabled.");
3100
3141
  this.map = t;
3101
- const e = si(), i = [];
3142
+ const e = fi(), i = [];
3102
3143
  return (r = (o = this.options) == null ? void 0 : o.modes) == null || r.forEach((l) => {
3103
3144
  if (this.options.modeOptions && this.options.modeOptions[l]) {
3104
- const c = this.options.modeOptions[l];
3145
+ const d = this.options.modeOptions[l];
3105
3146
  if (l === "select") {
3106
- const h = e[l];
3107
- if (h) {
3108
- const d = h.flags;
3109
- Object.keys(d).forEach((u) => {
3110
- c.flags[u] || (c.flags[u] = d[u]);
3147
+ const c = e[l];
3148
+ if (c) {
3149
+ const h = c.flags;
3150
+ Object.keys(h).forEach((u) => {
3151
+ d.flags[u] || (d.flags[u] = h[u]);
3111
3152
  });
3112
3153
  }
3113
3154
  }
3114
- i.push(c);
3155
+ i.push(d);
3115
3156
  } else e[l] && i.push(e[l]);
3116
3157
  }), i.forEach((l) => {
3117
3158
  l.state !== "unregistered" && (l._state = "unregistered");
3118
3159
  }), (a = (n = this.options) == null ? void 0 : n.modes) != null && a.includes("render") || (i.push(
3119
- new dt({
3160
+ new ht({
3120
3161
  modeName: "default",
3121
3162
  styles: {}
3122
3163
  })
3123
- ), this.defaultMode = "default"), this.isExpanded = this.options.open === !0, this.terradraw = new ii({
3124
- adapter: new Ee({ map: t }),
3164
+ ), this.defaultMode = "default"), this.isExpanded = this.options.open === !0, this.terradraw = new gi({
3165
+ adapter: new Fe({ map: t }),
3125
3166
  modes: i
3126
3167
  }), this.terradraw.start(), this.controlContainer = document.createElement("div"), this.controlContainer.classList.add("maplibregl-ctrl"), this.controlContainer.classList.add("maplibregl-ctrl-group"), i.forEach((l) => {
3127
3168
  l.mode !== "default" && this.addTerradrawButton(l.mode);
3128
3169
  }), Object.values(this.modeButtons).forEach((l) => {
3129
- var c;
3130
- (c = this.controlContainer) == null || c.appendChild(l);
3170
+ var d;
3171
+ (d = this.controlContainer) == null || d.appendChild(l);
3131
3172
  }), this.controlContainer;
3132
3173
  }
3133
3174
  /**
@@ -3260,7 +3301,7 @@ class ni {
3260
3301
  return t.charAt(0).toUpperCase() + t.slice(1);
3261
3302
  }
3262
3303
  }
3263
- var D = 63710088e-1, ai = {
3304
+ var D = 63710088e-1, vi = {
3264
3305
  centimeters: D * 100,
3265
3306
  centimetres: D * 100,
3266
3307
  degrees: 360 / (2 * Math.PI),
@@ -3277,37 +3318,37 @@ var D = 63710088e-1, ai = {
3277
3318
  radians: 1,
3278
3319
  yards: D * 1.0936
3279
3320
  };
3280
- function li(s, t, e = {}) {
3321
+ function Ci(s, t, e = {}) {
3281
3322
  const i = { type: "Feature" };
3282
3323
  return (e.id === 0 || e.id) && (i.id = e.id), e.bbox && (i.bbox = e.bbox), i.properties = t || {}, i.geometry = s, i;
3283
3324
  }
3284
- function ci(s, t, e = {}) {
3325
+ function Pi(s, t, e = {}) {
3285
3326
  if (!s)
3286
3327
  throw new Error("coordinates is required");
3287
3328
  if (!Array.isArray(s))
3288
3329
  throw new Error("coordinates must be an Array");
3289
3330
  if (s.length < 2)
3290
3331
  throw new Error("coordinates must be at least 2 numbers long");
3291
- if (!Jt(s[0]) || !Jt(s[1]))
3332
+ if (!$t(s[0]) || !$t(s[1]))
3292
3333
  throw new Error("coordinates must contain numbers");
3293
- return li({
3334
+ return Ci({
3294
3335
  type: "Point",
3295
3336
  coordinates: s
3296
3337
  }, t, e);
3297
3338
  }
3298
- function hi(s, t = "kilometers") {
3299
- const e = ai[t];
3339
+ function xi(s, t = "kilometers") {
3340
+ const e = vi[t];
3300
3341
  if (!e)
3301
3342
  throw new Error(t + " units is invalid");
3302
3343
  return s * e;
3303
3344
  }
3304
- function ht(s) {
3345
+ function ct(s) {
3305
3346
  return s % 360 * Math.PI / 180;
3306
3347
  }
3307
- function Jt(s) {
3348
+ function $t(s) {
3308
3349
  return !isNaN(s) && s !== null && !Array.isArray(s);
3309
3350
  }
3310
- function $t(s) {
3351
+ function qt(s) {
3311
3352
  if (!s)
3312
3353
  throw new Error("coord is required");
3313
3354
  if (!Array.isArray(s)) {
@@ -3320,86 +3361,86 @@ function $t(s) {
3320
3361
  return [...s];
3321
3362
  throw new Error("coord must be GeoJSON Point or an Array of numbers");
3322
3363
  }
3323
- function di(s, t, e = {}) {
3324
- var i = $t(s), o = $t(t), r = ht(o[1] - i[1]), n = ht(o[0] - i[0]), a = ht(i[1]), l = ht(o[1]), c = Math.pow(Math.sin(r / 2), 2) + Math.pow(Math.sin(n / 2), 2) * Math.cos(a) * Math.cos(l);
3325
- return hi(
3326
- 2 * Math.atan2(Math.sqrt(c), Math.sqrt(1 - c)),
3364
+ function Si(s, t, e = {}) {
3365
+ var i = qt(s), o = qt(t), r = ct(o[1] - i[1]), n = ct(o[0] - i[0]), a = ct(i[1]), l = ct(o[1]), d = Math.pow(Math.sin(r / 2), 2) + Math.pow(Math.sin(n / 2), 2) * Math.cos(a) * Math.cos(l);
3366
+ return xi(
3367
+ 2 * Math.atan2(Math.sqrt(d), Math.sqrt(1 - d)),
3327
3368
  e.units
3328
3369
  );
3329
3370
  }
3330
3371
  function Se(s, t, e) {
3331
3372
  if (s !== null)
3332
- for (var i, o, r, n, a, l, c, h = 0, d = 0, u, g = s.type, p = g === "FeatureCollection", y = g === "Feature", m = p ? s.features.length : 1, f = 0; f < m; f++) {
3333
- c = p ? s.features[f].geometry : y ? s.geometry : s, u = c ? c.type === "GeometryCollection" : !1, a = u ? c.geometries.length : 1;
3334
- for (var v = 0; v < a; v++) {
3335
- var C = 0, S = 0;
3336
- if (n = u ? c.geometries[v] : c, n !== null) {
3373
+ for (var i, o, r, n, a, l, d, c = 0, h = 0, u, g = s.type, p = g === "FeatureCollection", y = g === "Feature", m = p ? s.features.length : 1, f = 0; f < m; f++) {
3374
+ d = p ? s.features[f].geometry : y ? s.geometry : s, u = d ? d.type === "GeometryCollection" : !1, a = u ? d.geometries.length : 1;
3375
+ for (var C = 0; C < a; C++) {
3376
+ var v = 0, P = 0;
3377
+ if (n = u ? d.geometries[C] : d, n !== null) {
3337
3378
  l = n.coordinates;
3338
- var P = n.type;
3339
- switch (h = P === "Polygon" || P === "MultiPolygon" ? 1 : 0, P) {
3379
+ var S = n.type;
3380
+ switch (c = S === "Polygon" || S === "MultiPolygon" ? 1 : 0, S) {
3340
3381
  case null:
3341
3382
  break;
3342
3383
  case "Point":
3343
3384
  if (t(
3344
3385
  l,
3345
- d,
3386
+ h,
3346
3387
  f,
3347
- C,
3348
- S
3388
+ v,
3389
+ P
3349
3390
  ) === !1)
3350
3391
  return !1;
3351
- d++, C++;
3392
+ h++, v++;
3352
3393
  break;
3353
3394
  case "LineString":
3354
3395
  case "MultiPoint":
3355
3396
  for (i = 0; i < l.length; i++) {
3356
3397
  if (t(
3357
3398
  l[i],
3358
- d,
3399
+ h,
3359
3400
  f,
3360
- C,
3361
- S
3401
+ v,
3402
+ P
3362
3403
  ) === !1)
3363
3404
  return !1;
3364
- d++, P === "MultiPoint" && C++;
3405
+ h++, S === "MultiPoint" && v++;
3365
3406
  }
3366
- P === "LineString" && C++;
3407
+ S === "LineString" && v++;
3367
3408
  break;
3368
3409
  case "Polygon":
3369
3410
  case "MultiLineString":
3370
3411
  for (i = 0; i < l.length; i++) {
3371
- for (o = 0; o < l[i].length - h; o++) {
3412
+ for (o = 0; o < l[i].length - c; o++) {
3372
3413
  if (t(
3373
3414
  l[i][o],
3374
- d,
3415
+ h,
3375
3416
  f,
3376
- C,
3377
- S
3417
+ v,
3418
+ P
3378
3419
  ) === !1)
3379
3420
  return !1;
3380
- d++;
3421
+ h++;
3381
3422
  }
3382
- P === "MultiLineString" && C++, P === "Polygon" && S++;
3423
+ S === "MultiLineString" && v++, S === "Polygon" && P++;
3383
3424
  }
3384
- P === "Polygon" && C++;
3425
+ S === "Polygon" && v++;
3385
3426
  break;
3386
3427
  case "MultiPolygon":
3387
3428
  for (i = 0; i < l.length; i++) {
3388
- for (S = 0, o = 0; o < l[i].length; o++) {
3389
- for (r = 0; r < l[i][o].length - h; r++) {
3429
+ for (P = 0, o = 0; o < l[i].length; o++) {
3430
+ for (r = 0; r < l[i][o].length - c; r++) {
3390
3431
  if (t(
3391
3432
  l[i][o][r],
3392
- d,
3433
+ h,
3393
3434
  f,
3394
- C,
3395
- S
3435
+ v,
3436
+ P
3396
3437
  ) === !1)
3397
3438
  return !1;
3398
- d++;
3439
+ h++;
3399
3440
  }
3400
- S++;
3441
+ P++;
3401
3442
  }
3402
- C++;
3443
+ v++;
3403
3444
  }
3404
3445
  break;
3405
3446
  case "GeometryCollection":
@@ -3414,17 +3455,17 @@ function Se(s, t, e) {
3414
3455
  }
3415
3456
  }
3416
3457
  }
3417
- function ui(s, t) {
3418
- var e, i, o, r, n, a, l, c, h, d, u = 0, g = s.type === "FeatureCollection", p = s.type === "Feature", y = g ? s.features.length : 1;
3458
+ function Mi(s, t) {
3459
+ var e, i, o, r, n, a, l, d, c, h, u = 0, g = s.type === "FeatureCollection", p = s.type === "Feature", y = g ? s.features.length : 1;
3419
3460
  for (e = 0; e < y; e++) {
3420
- for (a = g ? s.features[e].geometry : p ? s.geometry : s, c = g ? s.features[e].properties : p ? s.properties : {}, h = g ? s.features[e].bbox : p ? s.bbox : void 0, d = g ? s.features[e].id : p ? s.id : void 0, l = a ? a.type === "GeometryCollection" : !1, n = l ? a.geometries.length : 1, o = 0; o < n; o++) {
3461
+ for (a = g ? s.features[e].geometry : p ? s.geometry : s, d = g ? s.features[e].properties : p ? s.properties : {}, c = g ? s.features[e].bbox : p ? s.bbox : void 0, h = g ? s.features[e].id : p ? s.id : void 0, l = a ? a.type === "GeometryCollection" : !1, n = l ? a.geometries.length : 1, o = 0; o < n; o++) {
3421
3462
  if (r = l ? a.geometries[o] : a, r === null) {
3422
3463
  if (t(
3423
3464
  null,
3424
3465
  u,
3466
+ d,
3425
3467
  c,
3426
- h,
3427
- d
3468
+ h
3428
3469
  ) === !1)
3429
3470
  return !1;
3430
3471
  continue;
@@ -3439,9 +3480,9 @@ function ui(s, t) {
3439
3480
  if (t(
3440
3481
  r,
3441
3482
  u,
3483
+ d,
3442
3484
  c,
3443
- h,
3444
- d
3485
+ h
3445
3486
  ) === !1)
3446
3487
  return !1;
3447
3488
  break;
@@ -3451,9 +3492,9 @@ function ui(s, t) {
3451
3492
  if (t(
3452
3493
  r.geometries[i],
3453
3494
  u,
3495
+ d,
3454
3496
  c,
3455
- h,
3456
- d
3497
+ h
3457
3498
  ) === !1)
3458
3499
  return !1;
3459
3500
  break;
@@ -3465,9 +3506,9 @@ function ui(s, t) {
3465
3506
  u++;
3466
3507
  }
3467
3508
  }
3468
- function gi(s, t, e) {
3509
+ function bi(s, t, e) {
3469
3510
  var i = e;
3470
- return ui(
3511
+ return Mi(
3471
3512
  s,
3472
3513
  function(o, r, n, a, l) {
3473
3514
  r === 0 && e === void 0 ? i = o : i = t(
@@ -3481,21 +3522,21 @@ function gi(s, t, e) {
3481
3522
  }
3482
3523
  ), i;
3483
3524
  }
3484
- function pi(s) {
3485
- return gi(
3525
+ function wi(s) {
3526
+ return bi(
3486
3527
  s,
3487
- (t, e) => t + yi(e),
3528
+ (t, e) => t + Fi(e),
3488
3529
  0
3489
3530
  );
3490
3531
  }
3491
- function yi(s) {
3532
+ function Fi(s) {
3492
3533
  let t = 0, e;
3493
3534
  switch (s.type) {
3494
3535
  case "Polygon":
3495
- return qt(s.coordinates);
3536
+ return Zt(s.coordinates);
3496
3537
  case "MultiPolygon":
3497
3538
  for (e = 0; e < s.coordinates.length; e++)
3498
- t += qt(s.coordinates[e]);
3539
+ t += Zt(s.coordinates[e]);
3499
3540
  return t;
3500
3541
  case "Point":
3501
3542
  case "MultiPoint":
@@ -3505,52 +3546,52 @@ function yi(s) {
3505
3546
  }
3506
3547
  return 0;
3507
3548
  }
3508
- function qt(s) {
3549
+ function Zt(s) {
3509
3550
  let t = 0;
3510
3551
  if (s && s.length > 0) {
3511
- t += Math.abs(Zt(s[0]));
3552
+ t += Math.abs(Qt(s[0]));
3512
3553
  for (let e = 1; e < s.length; e++)
3513
- t -= Math.abs(Zt(s[e]));
3554
+ t -= Math.abs(Qt(s[e]));
3514
3555
  }
3515
3556
  return t;
3516
3557
  }
3517
- var fi = D * D / 2, Mt = Math.PI / 180;
3518
- function Zt(s) {
3558
+ var Ei = D * D / 2, bt = Math.PI / 180;
3559
+ function Qt(s) {
3519
3560
  const t = s.length - 1;
3520
3561
  if (t <= 2)
3521
3562
  return 0;
3522
3563
  let e = 0, i = 0;
3523
3564
  for (; i < t; ) {
3524
- const o = s[i], r = s[i + 1 === t ? 0 : i + 1], n = s[i + 2 >= t ? (i + 2) % t : i + 2], a = o[0] * Mt, l = r[1] * Mt, c = n[0] * Mt;
3525
- e += (c - a) * Math.sin(l), i++;
3565
+ const o = s[i], r = s[i + 1 === t ? 0 : i + 1], n = s[i + 2 >= t ? (i + 2) % t : i + 2], a = o[0] * bt, l = r[1] * bt, d = n[0] * bt;
3566
+ e += (d - a) * Math.sin(l), i++;
3526
3567
  }
3527
- return e * fi;
3568
+ return e * Ei;
3528
3569
  }
3529
- function mi(s, t = {}) {
3570
+ function Ii(s, t = {}) {
3530
3571
  let e = 0, i = 0, o = 0;
3531
3572
  return Se(
3532
3573
  s,
3533
3574
  function(r) {
3534
3575
  e += r[0], i += r[1], o++;
3535
3576
  }
3536
- ), ci([e / o, i / o], t.properties);
3577
+ ), Pi([e / o, i / o], t.properties);
3537
3578
  }
3538
- class xi extends ni {
3579
+ class ki extends mi {
3539
3580
  /**
3540
3581
  * Constructor
3541
3582
  * @param options Plugin control options
3542
3583
  */
3543
3584
  constructor(e) {
3544
- let i = ri;
3585
+ let i = yi;
3545
3586
  e && (i = Object.assign(i, e));
3546
3587
  super({
3547
3588
  modes: i.modes,
3548
3589
  open: i.open,
3549
3590
  modeOptions: i.modeOptions
3550
3591
  });
3551
- k(this, "lineLayerLabelSpec");
3552
- k(this, "lineLayerNodeSpec");
3553
- k(this, "polygonLayerSpec");
3592
+ L(this, "lineLayerLabelSpec");
3593
+ L(this, "lineLayerNodeSpec");
3594
+ L(this, "polygonLayerSpec");
3554
3595
  this.lineLayerLabelSpec = i.lineLayerLabelSpec, this.lineLayerNodeSpec = i.lineLayerNodeSpec, this.polygonLayerSpec = i.polygonLayerSpec;
3555
3596
  }
3556
3597
  /**
@@ -3599,12 +3640,14 @@ class xi extends ni {
3599
3640
  if (!this.map) return;
3600
3641
  const l = this.getTerraDrawInstance();
3601
3642
  if (!l) return;
3602
- const c = l.getSnapshot();
3603
- for (const h of a) {
3604
- const d = c == null ? void 0 : c.find((p) => p.id === h);
3605
- if (!d) continue;
3606
- const u = d.geometry.type, g = d.properties.mode;
3607
- g === "linestring" && u === "LineString" ? this.measureLine(h) : !["point", "linestring", "select", "render"].includes(g) && u === "Polygon" && this.measurePolygon(h);
3643
+ const d = l.getSnapshot();
3644
+ for (const c of a) {
3645
+ const h = d == null ? void 0 : d.find((u) => u.id === c);
3646
+ if (h) {
3647
+ const u = h.geometry.type, g = h.properties.mode;
3648
+ g === "linestring" && u === "LineString" ? this.measureLine(c) : !["point", "linestring", "select", "render"].includes(g) && u === "Polygon" && this.measurePolygon(c);
3649
+ } else
3650
+ this.clearMeasureFeatures(c, this.lineLayerNodeSpec.source), this.clearMeasureFeatures(c, this.lineLayerLabelSpec.source), this.clearMeasureFeatures(c, this.polygonLayerSpec.source);
3608
3651
  }
3609
3652
  }), this.on("feature-deleted", this.onFeatureDeleted.bind(this)));
3610
3653
  }
@@ -3615,6 +3658,23 @@ class xi extends ni {
3615
3658
  unregisterMesureControl() {
3616
3659
  this.off("feature-deleted", this.onFeatureDeleted.bind(this)), this.map && (this.map.getLayer(this.lineLayerLabelSpec.id) && this.map.removeLayer(this.lineLayerLabelSpec.id), this.map.getLayer(this.lineLayerNodeSpec.id) && this.map.removeLayer(this.lineLayerNodeSpec.id), this.map.getLayer(this.polygonLayerSpec.id) && this.map.removeLayer(this.polygonLayerSpec.id), this.map.getSource(this.lineLayerLabelSpec.source) && this.map.removeSource(this.lineLayerLabelSpec.source), this.map.getSource(this.polygonLayerSpec.source) && this.map.removeSource(this.polygonLayerSpec.source));
3617
3660
  }
3661
+ /**
3662
+ * Clear GeoJSON feature related to measure control by TerraDraw feature ID
3663
+ * @param id feature ID
3664
+ * @param sourceId source ID to delete
3665
+ * @returns void
3666
+ */
3667
+ clearMeasureFeatures(e, i) {
3668
+ var r;
3669
+ if (!this.map) return;
3670
+ const o = this.map.getStyle().sources[i];
3671
+ o && typeof o.data != "string" && o.data.type === "FeatureCollection" && (o.data.features = o.data.features.filter(
3672
+ (n) => {
3673
+ var a;
3674
+ return ((a = n.properties) == null ? void 0 : a.originalId) !== e;
3675
+ }
3676
+ ), (r = this.map.getSource(i)) == null || r.setData(o.data));
3677
+ }
3618
3678
  /**
3619
3679
  * measure polygon area for given feature ID
3620
3680
  * @param id terradraw feature id
@@ -3634,10 +3694,10 @@ class xi extends ni {
3634
3694
  return ((g = u.properties) == null ? void 0 : g.originalId) !== e;
3635
3695
  }
3636
3696
  ));
3637
- const l = pi(r.geometry), c = JSON.parse(JSON.stringify(r));
3638
- c.id = c.id + "-area-label", c.geometry = mi(r.geometry).geometry, c.properties.originalId = r.id;
3639
- let h = l, d = "m2";
3640
- l > 1e4 ? (h = l / 1e4, d = "ha") : l > 1e3 && (h = l / 1e3, d = "km2"), c.properties.area = h.toFixed(2), c.properties.unit = d, typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(c), (n = this.map.getSource(this.polygonLayerSpec.source)) == null || n.setData(
3697
+ const l = wi(r.geometry), d = JSON.parse(JSON.stringify(r));
3698
+ d.id = d.id + "-area-label", d.geometry = Ii(r.geometry).geometry, d.properties.originalId = r.id;
3699
+ let c = l, h = "m2";
3700
+ l > 1e4 ? (c = l / 1e4, h = "ha") : l > 1e3 && (c = l / 1e3, h = "km2"), d.properties.area = c.toFixed(2), d.properties.unit = h, typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(d), (n = this.map.getSource(this.polygonLayerSpec.source)) == null || n.setData(
3641
3701
  a.data
3642
3702
  ), this.map.moveLayer(this.polygonLayerSpec.id);
3643
3703
  }
@@ -3658,28 +3718,28 @@ class xi extends ni {
3658
3718
  if (a) {
3659
3719
  const l = r.geometry.coordinates;
3660
3720
  typeof a.data != "string" && a.data.type === "FeatureCollection" && (a.data.features = a.data.features.filter(
3661
- (h) => {
3662
- var d;
3663
- return ((d = h.properties) == null ? void 0 : d.originalId) !== e;
3721
+ (c) => {
3722
+ var h;
3723
+ return ((h = c.properties) == null ? void 0 : h.originalId) !== e;
3664
3724
  }
3665
3725
  ));
3666
- let c = 0;
3667
- for (let h = 0; h < l.length - 1; h++) {
3668
- const d = l[h], u = l[h + 1], g = di(d, u, { units: "kilometers" });
3669
- c += g;
3726
+ let d = 0;
3727
+ for (let c = 0; c < l.length - 1; c++) {
3728
+ const h = l[c], u = l[c + 1], g = Si(h, u, { units: "kilometers" });
3729
+ d += g;
3670
3730
  const p = JSON.parse(JSON.stringify(r));
3671
- if (p.id = `${p.id}-${h}`, p.geometry.coordinates = [d, u], p.properties.originalId = r.id, p.properties.distance = g.toFixed(2), p.properties.total = c.toFixed(2), p.properties.unit = "km", typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(p), h === 0) {
3731
+ if (p.id = `${p.id}-${c}`, p.geometry.coordinates = [h, u], p.properties.originalId = r.id, p.properties.distance = g.toFixed(2), p.properties.total = d.toFixed(2), p.properties.unit = "km", typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(p), c === 0) {
3672
3732
  const m = JSON.parse(JSON.stringify(r));
3673
- m.id = `${p.id}-node-${h}`, m.geometry = {
3733
+ m.id = `${p.id}-node-${c}`, m.geometry = {
3674
3734
  type: "Point",
3675
- coordinates: d
3735
+ coordinates: h
3676
3736
  }, m.properties.originalId = r.id, m.properties.distance = 0, m.properties.total = 0, m.properties.unit = "km", typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(m);
3677
3737
  }
3678
3738
  const y = JSON.parse(JSON.stringify(r));
3679
- y.id = `${p.id}-node-${h + 1}`, y.geometry = {
3739
+ y.id = `${p.id}-node-${c + 1}`, y.geometry = {
3680
3740
  type: "Point",
3681
3741
  coordinates: u
3682
- }, y.properties.originalId = r.id, y.properties.distance = g.toFixed(2), y.properties.total = c.toFixed(2), y.properties.unit = "km", typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(y);
3742
+ }, y.properties.originalId = r.id, y.properties.distance = g.toFixed(2), y.properties.total = d.toFixed(2), y.properties.unit = "km", typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(y);
3683
3743
  }
3684
3744
  (n = this.map.getSource(this.lineLayerLabelSpec.source)) == null || n.setData(
3685
3745
  a.data
@@ -3699,13 +3759,13 @@ class xi extends ni {
3699
3759
  for (const n of r) {
3700
3760
  const a = this.map.getStyle().sources[n];
3701
3761
  if (a) {
3702
- const l = e.getSnapshot(), h = (l == null ? void 0 : l.filter(
3703
- (d) => ["LineString", "Polygon"].includes(d.geometry.type)
3704
- )).map((d) => d.id);
3762
+ const l = e.getSnapshot(), c = (l == null ? void 0 : l.filter(
3763
+ (h) => ["LineString", "Polygon"].includes(h.geometry.type)
3764
+ )).map((h) => h.id);
3705
3765
  typeof a.data != "string" && a.data.type === "FeatureCollection" && (a.data.features = a.data.features.filter(
3706
- (d) => {
3766
+ (h) => {
3707
3767
  var u;
3708
- return h.includes((u = d.properties) == null ? void 0 : u.originalId);
3768
+ return c.includes((u = h.properties) == null ? void 0 : u.originalId);
3709
3769
  }
3710
3770
  )), n === this.lineLayerLabelSpec.source ? ((i = this.map.getSource(this.lineLayerLabelSpec.source)) == null || i.setData(
3711
3771
  a.data
@@ -3718,12 +3778,12 @@ class xi extends ni {
3718
3778
  }
3719
3779
  }
3720
3780
  export {
3721
- Pi as AvailableMeasureModes,
3722
- vi as AvailableModes,
3723
- xi as MaplibreMeasureControl,
3724
- ni as MaplibreTerradrawControl,
3725
- oi as defaultControlOptions,
3726
- ri as defaultMeasureControlOptions,
3727
- si as getDefaultModeOptions
3781
+ Oi as AvailableMeasureModes,
3782
+ Di as AvailableModes,
3783
+ ki as MaplibreMeasureControl,
3784
+ mi as MaplibreTerradrawControl,
3785
+ pi as defaultControlOptions,
3786
+ yi as defaultMeasureControlOptions,
3787
+ fi as getDefaultModeOptions
3728
3788
  };
3729
3789
  //# sourceMappingURL=maplibre-gl-terradraw.es.js.map