@watergis/maplibre-gl-terradraw 1.3.3 → 1.3.5

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,6 +1,6 @@
1
- var Ue = Object.defineProperty;
2
- var ze = (s, t, e) => t in s ? Ue(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var k = (s, t, e) => ze(s, typeof t != "symbol" ? t + "" : t, e);
1
+ var Te = Object.defineProperty;
2
+ var Ae = (s, t, e) => t in s ? Te(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var k = (s, t, e) => Ae(s, typeof t != "symbol" ? t + "" : t, e);
4
4
  import "maplibre-gl";
5
5
  function b() {
6
6
  return b = Object.assign ? Object.assign.bind() : function(s) {
@@ -15,7 +15,7 @@ var I;
15
15
  (function(s) {
16
16
  s.Commit = "commit", s.Provisional = "provisional", s.Finish = "finish";
17
17
  })(I || (I = {}));
18
- const U = { SELECTED: "selected", MID_POINT: "midPoint", SELECTION_POINT: "selectionPoint" }, V = "edited", st = "closingPoint", Dt = "snappingPoint";
18
+ const U = { SELECTED: "selected", MID_POINT: "midPoint", SELECTION_POINT: "selectionPoint" }, V = "edited", st = "closingPoint", Ot = "snappingPoint";
19
19
  function bt(s) {
20
20
  return !!(s && typeof s == "object" && s !== null && !Array.isArray(s));
21
21
  }
@@ -24,7 +24,7 @@ function Vt(s) {
24
24
  return typeof t == "number" && !isNaN(new Date(t).valueOf());
25
25
  }(s);
26
26
  }
27
- const Re = "Feature mode property does not match the mode being added to";
27
+ const Ve = "Feature mode property does not match the mode being added to";
28
28
  var $;
29
29
  (function(s) {
30
30
  s.Drawing = "drawing", s.Select = "select", s.Static = "static", s.Render = "render";
@@ -94,7 +94,7 @@ class N {
94
94
  }
95
95
  validateModeFeature(t, e) {
96
96
  const i = this.performFeatureValidation(t);
97
- return i.valid ? t.properties.mode !== this.mode ? { valid: !1, reason: Re } : e(t) : { valid: !1, reason: i.reason };
97
+ return i.valid ? t.properties.mode !== this.mode ? { valid: !1, reason: Ve } : e(t) : { valid: !1, reason: i.reason };
98
98
  }
99
99
  onFinish(t, e) {
100
100
  }
@@ -126,7 +126,7 @@ class N {
126
126
  return t === void 0 ? e : typeof t == "function" ? t(i) : t;
127
127
  }
128
128
  }
129
- class Xe extends N {
129
+ class Ue extends N {
130
130
  constructor(...t) {
131
131
  super(...t), this.type = $.Select;
132
132
  }
@@ -135,30 +135,30 @@ function A(s, t) {
135
135
  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);
136
136
  return 2 * Math.atan2(Math.sqrt(l), Math.sqrt(1 - l)) * 6371e3 / 1e3;
137
137
  }
138
- const ye = 63710088e-1;
139
- function E(s) {
138
+ const ue = 63710088e-1;
139
+ function O(s) {
140
140
  return s % 360 * Math.PI / 180;
141
141
  }
142
- function fe(s) {
142
+ function pe(s) {
143
143
  return s / 6371.0088;
144
144
  }
145
- function z(s) {
145
+ function R(s) {
146
146
  return s % (2 * Math.PI) * 180 / Math.PI;
147
147
  }
148
- function F(s, t = 9) {
148
+ function w(s, t = 9) {
149
149
  const e = Math.pow(10, t);
150
150
  return Math.round(s * e) / e;
151
151
  }
152
- const Ut = 57.29577951308232, zt = 0.017453292519943295, ft = 6378137, x = (s, t) => ({ x: s === 0 ? 0 : s * zt * ft, y: t === 0 ? 0 : Math.log(Math.tan(Math.PI / 4 + t * zt / 2)) * ft }), W = (s, t) => ({ lng: s === 0 ? 0 : Ut * (s / ft), lat: t === 0 ? 0 : (2 * Math.atan(Math.exp(t / ft)) - Math.PI / 2) * Ut });
153
- function Ke(s, t, e) {
154
- const i = E(s[0]), o = E(s[1]), r = E(e), n = fe(t), a = Math.asin(Math.sin(o) * Math.cos(n) + Math.cos(o) * Math.sin(n) * Math.cos(r));
155
- return [z(i + Math.atan2(Math.sin(r) * Math.sin(n) * Math.cos(o), Math.cos(n) - Math.sin(o) * Math.sin(a))), z(a)];
152
+ const Ut = 57.29577951308232, Rt = 0.017453292519943295, ft = 6378137, x = (s, t) => ({ x: s === 0 ? 0 : s * Rt * ft, y: t === 0 ? 0 : Math.log(Math.tan(Math.PI / 4 + t * Rt / 2)) * ft }), j = (s, t) => ({ lng: s === 0 ? 0 : Ut * (s / ft), lat: t === 0 ? 0 : (2 * Math.atan(Math.exp(t / ft)) - Math.PI / 2) * Ut });
153
+ function Re(s, t, e) {
154
+ const i = O(s[0]), o = O(s[1]), r = O(e), n = pe(t), a = Math.asin(Math.sin(o) * Math.cos(n) + Math.cos(o) * Math.sin(n) * Math.cos(r));
155
+ return [R(i + Math.atan2(Math.sin(r) * Math.sin(n) * Math.cos(o), Math.cos(n) - Math.sin(o) * Math.sin(a))), R(a)];
156
156
  }
157
- function Rt(s) {
157
+ function zt(s) {
158
158
  const { center: t, radiusKilometers: e, coordinatePrecision: i } = s, o = s.steps ? s.steps : 64, r = [];
159
159
  for (let n = 0; n < o; n++) {
160
- const a = Ke(t, e, -360 * n / o);
161
- r.push([F(a[0], i), F(a[1], i)]);
160
+ const a = Re(t, e, -360 * n / o);
161
+ r.push([w(a[0], i), w(a[1], i)]);
162
162
  }
163
163
  return r.push(r[0]), { type: "Feature", geometry: { type: "Polygon", coordinates: [r] }, properties: {} };
164
164
  }
@@ -178,39 +178,49 @@ function _t(s) {
178
178
  function o(r, n, a, l) {
179
179
  const d = t[r][n], h = t[r][n + 1], c = t[a][l], u = t[a][l + 1], p = function(v, f, m, C) {
180
180
  if (ht(v, m) || ht(v, C) || ht(f, m) || ht(C, m)) return null;
181
- const P = v[0], S = v[1], M = f[0], w = f[1], D = m[0], G = m[1], L = C[0], B = C[1], R = (P - M) * (G - B) - (S - w) * (D - L);
182
- return R === 0 ? null : [((P * w - S * M) * (D - L) - (P - M) * (D * B - G * L)) / R, ((P * w - S * M) * (G - B) - (S - w) * (D * B - G * L)) / R];
181
+ const P = v[0], S = v[1], M = f[0], F = f[1], D = m[0], G = m[1], _ = C[0], B = C[1], z = (P - M) * (G - B) - (S - F) * (D - _);
182
+ return z === 0 ? null : [((P * F - S * M) * (D - _) - (P - M) * (D * B - G * _)) / z, ((P * F - S * M) * (G - B) - (S - F) * (D * B - G * _)) / z];
183
183
  }(d, h, c, u);
184
184
  if (p === null) return;
185
- let g, y;
186
- g = h[0] !== d[0] ? (p[0] - d[0]) / (h[0] - d[0]) : (p[1] - d[1]) / (h[1] - d[1]), y = u[0] !== c[0] ? (p[0] - c[0]) / (u[0] - c[0]) : (p[1] - c[1]) / (u[1] - c[1]), i(g) || i(y) || (p.toString(), e.push(p));
185
+ let y, g;
186
+ y = h[0] !== d[0] ? (p[0] - d[0]) / (h[0] - d[0]) : (p[1] - d[1]) / (h[1] - d[1]), g = u[0] !== c[0] ? (p[0] - c[0]) / (u[0] - c[0]) : (p[1] - c[1]) / (u[1] - c[1]), i(y) || i(g) || (p.toString(), e.push(p));
187
187
  }
188
188
  }
189
189
  function ht(s, t) {
190
190
  return s[0] === t[0] && s[1] === t[1];
191
191
  }
192
192
  function St(s, t) {
193
- return s.length === 2 && typeof s[0] == "number" && typeof s[1] == "number" && s[0] !== 1 / 0 && s[1] !== 1 / 0 && (i = s[0]) >= -180 && i <= 180 && (e = s[1]) >= -90 && e <= 90 && Xt(s[0]) <= t && Xt(s[1]) <= t;
194
- var e, i;
193
+ return Xt(s[0]) <= t && Xt(s[1]) <= t;
194
+ }
195
+ function Lt(s) {
196
+ return s.length === 2 && typeof s[0] == "number" && typeof s[1] == "number" && s[0] !== 1 / 0 && s[1] !== 1 / 0 && (e = s[0]) >= -180 && e <= 180 && (t = s[1]) >= -90 && t <= 90;
197
+ var t, e;
195
198
  }
196
199
  function Xt(s) {
197
200
  let t = 1, e = 0;
198
201
  for (; Math.round(s * t) / t !== s; ) t *= 10, e++;
199
202
  return e;
200
203
  }
201
- const Ye = "Feature has holes", $e = "Feature has less than 4 coordinates", He = "Feature has invalid coordinates", qe = "Feature coordinates are not closed";
204
+ const ze = "Feature has holes", Xe = "Feature has less than 4 coordinates", Ke = "Feature has invalid coordinates", Ye = "Feature coordinates are not closed";
202
205
  function xt(s, t) {
203
- return s.geometry.type !== "Polygon" ? { valid: !1, reason: "Feature is not a Polygon" } : s.geometry.coordinates.length !== 1 ? { valid: !1, reason: Ye } : s.geometry.coordinates[0].length < 4 ? { valid: !1, reason: $e } : s.geometry.coordinates[0].every((o) => St(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: qe } : { valid: !0 } : { valid: !1, reason: He };
206
+ if (s.geometry.type !== "Polygon") return { valid: !1, reason: "Feature is not a Polygon" };
207
+ if (s.geometry.coordinates.length !== 1) return { valid: !1, reason: ze };
208
+ if (s.geometry.coordinates[0].length < 4) return { valid: !1, reason: Xe };
209
+ for (let o = 0; o < s.geometry.coordinates[0].length; o++) {
210
+ if (!Lt(s.geometry.coordinates[0][o])) return { valid: !1, reason: Ke };
211
+ if (!St(s.geometry.coordinates[0][o], t)) return { valid: !1, reason: "Feature has coordinates with excessive precision" };
212
+ }
213
+ return (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: Ye } : { valid: !0 };
204
214
  var e, i;
205
215
  }
206
216
  function lt(s, t) {
207
217
  const e = xt(s, t);
208
218
  return e.valid ? _t(s) ? { valid: !1, reason: "Feature intersects itself" } : { valid: !0 } : e;
209
219
  }
210
- const Je = { cancel: "Escape", finish: "Enter" }, Ze = { start: "crosshair" };
211
- let me = class extends N {
220
+ const $e = { cancel: "Escape", finish: "Enter" }, He = { start: "crosshair" };
221
+ let ge = class extends N {
212
222
  constructor(t) {
213
- super(t, !0), this.mode = "circle", this.center = void 0, this.clickCount = 0, this.currentCircleId = void 0, this.keyEvents = Je, this.cursors = Ze, this.startingRadiusKilometers = 1e-5, this.cursorMovedAfterInitialCursorDown = !1, this.updateOptions(t);
223
+ super(t, !0), this.mode = "circle", this.center = void 0, this.clickCount = 0, this.currentCircleId = void 0, this.keyEvents = $e, this.cursors = He, this.startingRadiusKilometers = 1e-5, this.cursorMovedAfterInitialCursorDown = !1, this.updateOptions(t);
214
224
  }
215
225
  updateOptions(t) {
216
226
  super.updateOptions(t), t != null && t.cursors && (this.cursors = b({}, this.cursors, t.cursors)), (t == null ? void 0 : t.keyEvents) === null ? this.keyEvents = { cancel: null, finish: null } : t != null && t.keyEvents && (this.keyEvents = b({}, this.keyEvents, t.keyEvents)), t != null && t.startingRadiusKilometers && (this.startingRadiusKilometers = t.startingRadiusKilometers);
@@ -233,7 +243,7 @@ let me = class extends N {
233
243
  onClick(t) {
234
244
  if (this.clickCount === 0) {
235
245
  this.center = [t.lng, t.lat];
236
- const e = Rt({ center: this.center, radiusKilometers: this.startingRadiusKilometers, coordinatePrecision: this.coordinatePrecision }), [i] = this.store.create([{ geometry: e.geometry, properties: { mode: this.mode, radiusKilometers: this.startingRadiusKilometers } }]);
246
+ const e = zt({ center: this.center, radiusKilometers: this.startingRadiusKilometers, coordinatePrecision: this.coordinatePrecision }), [i] = this.store.create([{ geometry: e.geometry, properties: { mode: this.mode, radiusKilometers: this.startingRadiusKilometers } }]);
237
247
  this.currentCircleId = i, this.clickCount++, this.cursorMovedAfterInitialCursorDown = !1, this.setDrawing();
238
248
  } else this.clickCount === 1 && this.center && this.currentCircleId !== void 0 && this.cursorMovedAfterInitialCursorDown && this.updateCircle(t), this.close();
239
249
  }
@@ -278,23 +288,23 @@ let me = class extends N {
278
288
  return Math.sqrt(Math.pow(h - l, 2) + Math.pow(c - d, 2)) / a;
279
289
  }(this.center, [t.lng, t.lat]);
280
290
  i = function(r) {
281
- const { center: n, radiusKilometers: a, coordinatePrecision: l } = r, d = r.steps ? r.steps : 64, h = 1e3 * a, [c, u] = n, { x: p, y: g } = x(c, u), y = [];
291
+ const { center: n, radiusKilometers: a, coordinatePrecision: l } = r, d = r.steps ? r.steps : 64, h = 1e3 * a, [c, u] = n, { x: p, y } = x(c, u), g = [];
282
292
  for (let v = 0; v < d; v++) {
283
- const f = 360 * v / d * Math.PI / 180, m = h * Math.cos(f), C = h * Math.sin(f), [P, S] = [p + m, g + C], { lng: M, lat: w } = W(P, S);
284
- y.push([F(M, l), F(w, l)]);
293
+ const f = 360 * v / d * Math.PI / 180, m = h * Math.cos(f), C = h * Math.sin(f), [P, S] = [p + m, y + C], { lng: M, lat: F } = j(P, S);
294
+ g.push([w(M, l), w(F, l)]);
285
295
  }
286
- return y.push(y[0]), { type: "Feature", geometry: { type: "Polygon", coordinates: [y] }, properties: {} };
296
+ return g.push(g[0]), { type: "Feature", geometry: { type: "Polygon", coordinates: [g] }, properties: {} };
287
297
  }({ center: this.center, radiusKilometers: e * o, coordinatePrecision: this.coordinatePrecision });
288
298
  } else {
289
299
  if (this.projection !== "globe") throw new Error("Invalid projection");
290
- i = Rt({ center: this.center, radiusKilometers: e, coordinatePrecision: this.coordinatePrecision });
300
+ i = zt({ center: this.center, radiusKilometers: e, coordinatePrecision: this.coordinatePrecision });
291
301
  }
292
302
  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: I.Provisional }).valid) return;
293
303
  this.store.updateGeometry([{ id: this.currentCircleId, geometry: i.geometry }]), this.store.updateProperty([{ id: this.currentCircleId, property: "radiusKilometers", value: e }]);
294
304
  }
295
305
  }
296
306
  };
297
- const O = (s, t) => {
307
+ const E = (s, t) => {
298
308
  const { x: e, y: i } = s, { x: o, y: r } = t, n = o - e, a = r - i;
299
309
  return Math.sqrt(a * a + n * n);
300
310
  };
@@ -309,10 +319,10 @@ function dt(s) {
309
319
  return o < 0;
310
320
  }(s)) return { type: "Polygon", coordinates: [s.coordinates[0].reverse()] };
311
321
  }
312
- const Qe = { cancel: "Escape", finish: "Enter" }, ti = { start: "crosshair", close: "pointer" };
313
- let ve = class extends N {
322
+ const qe = { cancel: "Escape", finish: "Enter" }, Je = { start: "crosshair", close: "pointer" };
323
+ class ye extends N {
314
324
  constructor(t) {
315
- super(t, !0), this.mode = "freehand", this.startingClick = !1, this.currentId = void 0, this.closingPointId = void 0, this.minDistance = 20, this.keyEvents = Qe, this.cursors = ti, this.preventPointsNearClose = !0, this.autoClose = !1, this.autoCloseTimeout = 500, this.hasLeftStartingPoint = !1, this.preventNewFeature = !1, this.updateOptions(t);
325
+ super(t, !0), this.mode = "freehand", this.startingClick = !1, this.currentId = void 0, this.closingPointId = void 0, this.minDistance = 20, this.keyEvents = qe, this.cursors = Je, this.preventPointsNearClose = !0, this.autoClose = !1, this.autoCloseTimeout = 500, this.hasLeftStartingPoint = !1, this.preventNewFeature = !1, this.updateOptions(t);
316
326
  }
317
327
  updateOptions(t) {
318
328
  super.updateOptions(t), t != null && t.minDistance && (this.minDistance = t.minDistance), (t == null ? void 0 : t.preventPointsNearClose) !== void 0 && (this.preventPointsNearClose = t.preventPointsNearClose), (t == null ? void 0 : t.autoClose) !== void 0 && (this.autoClose = t.autoClose), t != null && t.autoCloseTimeout && (this.autoCloseTimeout = t.autoCloseTimeout), (t == null ? void 0 : t.keyEvents) === null ? this.keyEvents = { cancel: null, finish: null } : t != null && t.keyEvents && (this.keyEvents = b({}, this.keyEvents, t.keyEvents)), t != null && t.cursors && (this.cursors = b({}, this.cursors, t.cursors));
@@ -338,8 +348,8 @@ let ve = class extends N {
338
348
  }
339
349
  onMouseMove(t) {
340
350
  if (this.currentId === void 0 || this.startingClick === !1) return;
341
- 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 = O({ x: n, y: a }, { x: t.containerX, y: t.containerY }), [d, h] = e.coordinates[0][0], { x: c, y: u } = this.project(d, h);
342
- if (O({ x: c, y: u }, { x: t.containerX, y: t.containerY }) < this.pointerDistance) {
351
+ 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 = E({ x: n, y: a }, { x: t.containerX, y: t.containerY }), [d, h] = e.coordinates[0][0], { x: c, y: u } = this.project(d, h);
352
+ if (E({ x: c, y: u }, { x: t.containerX, y: t.containerY }) < this.pointerDistance) {
343
353
  if (this.autoClose && this.hasLeftStartingPoint && (this.preventNewFeature = !0, setTimeout(() => {
344
354
  this.preventNewFeature = !1;
345
355
  }, this.autoCloseTimeout), this.close()), this.setCursor(this.cursors.close), this.preventPointsNearClose) return;
@@ -384,35 +394,35 @@ let ve = class extends N {
384
394
  validateFeature(t) {
385
395
  return this.validateModeFeature(t, (e) => xt(e, this.coordinatePrecision));
386
396
  }
387
- };
388
- class j {
397
+ }
398
+ class W {
389
399
  constructor({ store: t, mode: e, project: i, unproject: o, pointerDistance: r, coordinatePrecision: n, projection: a }) {
390
400
  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;
391
401
  }
392
402
  }
393
- function Ce({ unproject: s, point: t, pointerDistance: e }) {
403
+ function fe({ unproject: s, point: t, pointerDistance: e }) {
394
404
  const i = e / 2, { x: o, y: r } = t;
395
405
  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])] } };
396
406
  }
397
- let rt = class extends j {
407
+ class rt extends W {
398
408
  constructor(t) {
399
409
  super(t);
400
410
  }
401
411
  create(t) {
402
412
  const { containerX: e, containerY: i } = t;
403
- return Ce({ unproject: this.unproject, point: { x: e, y: i }, pointerDistance: this.pointerDistance });
413
+ return fe({ unproject: this.unproject, point: { x: e, y: i }, pointerDistance: this.pointerDistance });
404
414
  }
405
- };
406
- class nt extends j {
415
+ }
416
+ class nt extends W {
407
417
  constructor(t) {
408
418
  super(t);
409
419
  }
410
420
  measure(t, e) {
411
421
  const { x: i, y: o } = this.project(e[0], e[1]);
412
- return O({ x: i, y: o }, { x: t.containerX, y: t.containerY });
422
+ return E({ x: i, y: o }, { x: t.containerX, y: t.containerY });
413
423
  }
414
424
  }
415
- class Lt extends j {
425
+ let Dt = class extends W {
416
426
  constructor(t, e, i) {
417
427
  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)).coordinate, this.getSnappableCoordinate = (o, r) => this.getSnappable(o, (n) => !!(n.properties && n.properties.mode === this.mode && n.id !== r)).coordinate, this.config = t, this.pixelDistance = e, this.clickBoundingBox = i;
418
428
  }
@@ -431,18 +441,18 @@ class Lt extends j {
431
441
  });
432
442
  }), r;
433
443
  }
434
- }
444
+ };
435
445
  function Kt(s, t, e) {
436
- const i = E(s[0]), o = E(s[1]), r = E(e), n = fe(t), a = Math.asin(Math.sin(o) * Math.cos(n) + Math.cos(o) * Math.sin(n) * Math.cos(r));
437
- return [z(i + Math.atan2(Math.sin(r) * Math.sin(n) * Math.cos(o), Math.cos(n) - Math.sin(o) * Math.sin(a))), z(a)];
446
+ const i = O(s[0]), o = O(s[1]), r = O(e), n = pe(t), a = Math.asin(Math.sin(o) * Math.cos(n) + Math.cos(o) * Math.sin(n) * Math.cos(r));
447
+ return [R(i + Math.atan2(Math.sin(r) * Math.sin(n) * Math.cos(o), Math.cos(n) - Math.sin(o) * Math.sin(a))), R(a)];
438
448
  }
439
449
  function at({ x: s, y: t }, e, i) {
440
- const o = E(i);
450
+ const o = O(i);
441
451
  return { x: s + e * Math.cos(o), y: t + e * Math.sin(o) };
442
452
  }
443
453
  function Yt(s, t) {
444
- const e = E(s[0]), i = E(t[0]), o = E(s[1]), r = E(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);
445
- return z(Math.atan2(n, a));
454
+ const e = O(s[0]), i = O(t[0]), o = O(s[1]), r = O(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);
455
+ return R(Math.atan2(n, a));
446
456
  }
447
457
  function T({ x: s, y: t }, { x: e, y: i }) {
448
458
  let o = Math.atan2(i - t, e - s);
@@ -451,7 +461,7 @@ function T({ x: s, y: t }, { x: e, y: i }) {
451
461
  function Y(s) {
452
462
  return (s + 360) % 360;
453
463
  }
454
- function ei(s, t, e) {
464
+ function Ze(s, t, e) {
455
465
  const i = [], o = s.length;
456
466
  let r, n, a, l = 0;
457
467
  for (let h = 0; h < s.length && !(t >= l && h === s.length - 1); h++) {
@@ -473,7 +483,7 @@ function ct(s) {
473
483
  function $t(s) {
474
484
  return s * (180 / Math.PI);
475
485
  }
476
- class ii extends j {
486
+ class Qe extends W {
477
487
  constructor(t) {
478
488
  super(t), this.config = void 0, this.config = t;
479
489
  }
@@ -486,7 +496,7 @@ class ii extends j {
486
496
  Number.isInteger(n) || (n = Math.floor(n) + 1);
487
497
  const a = [];
488
498
  for (let d = 0; d < n; d++) {
489
- const h = ei(o, i * d, i * (d + 1));
499
+ const h = Ze(o, i * d, i * (d + 1));
490
500
  a.push(h);
491
501
  }
492
502
  const l = [];
@@ -497,27 +507,33 @@ class ii extends j {
497
507
  const o = A(t, e), r = function(n, a, l) {
498
508
  const d = [], h = ct(n[1]), c = ct(n[0]), u = ct(a[1]), p = ct(a[0]);
499
509
  l += 1;
500
- const g = 2 * Math.asin(Math.sqrt(Math.sin((u - h) / 2) ** 2 + Math.cos(h) * Math.cos(u) * Math.sin((p - c) / 2) ** 2));
501
- if (g === 0 || isNaN(g)) return d;
502
- for (let y = 0; y <= l; y++) {
503
- const v = y / l, f = Math.sin((1 - v) * g) / Math.sin(g), m = Math.sin(v * g) / Math.sin(g), C = f * Math.cos(h) * Math.cos(c) + m * Math.cos(u) * Math.cos(p), P = f * Math.cos(h) * Math.sin(c) + m * Math.cos(u) * Math.sin(p), S = f * Math.sin(h) + m * Math.sin(u);
510
+ const y = 2 * Math.asin(Math.sqrt(Math.sin((u - h) / 2) ** 2 + Math.cos(h) * Math.cos(u) * Math.sin((p - c) / 2) ** 2));
511
+ if (y === 0 || isNaN(y)) return d;
512
+ for (let g = 0; g <= l; g++) {
513
+ const v = g / l, f = Math.sin((1 - v) * y) / Math.sin(y), m = Math.sin(v * y) / Math.sin(y), C = f * Math.cos(h) * Math.cos(c) + m * Math.cos(u) * Math.cos(p), P = f * Math.cos(h) * Math.sin(c) + m * Math.cos(u) * Math.sin(p), S = f * Math.sin(h) + m * Math.sin(u);
504
514
  if (isNaN(C) || isNaN(P) || isNaN(S)) continue;
505
- const M = Math.atan2(S, Math.sqrt(C ** 2 + P ** 2)), w = Math.atan2(P, C);
506
- isNaN(M) || isNaN(w) || d.push([$t(w), $t(M)]);
515
+ const M = Math.atan2(S, Math.sqrt(C ** 2 + P ** 2)), F = Math.atan2(P, C);
516
+ isNaN(M) || isNaN(F) || d.push([$t(F), $t(M)]);
507
517
  }
508
518
  return d.slice(1, -1);
509
519
  }(t, e, Math.floor(o / i));
510
520
  return this.limitCoordinates(r);
511
521
  }
512
522
  limitCoordinates(t) {
513
- return t.map((e) => [F(e[0], this.config.coordinatePrecision), F(e[1], this.config.coordinatePrecision)]);
523
+ return t.map((e) => [w(e[0], this.config.coordinatePrecision), w(e[1], this.config.coordinatePrecision)]);
514
524
  }
515
525
  }
516
526
  function Z(s, t) {
517
527
  return s[0] === t[0] && s[1] === t[1];
518
528
  }
519
- function Pe(s, t) {
520
- 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) => St(e, t)) ? { valid: !0 } : { valid: !1, reason: "Feature has invalid coordinates" };
529
+ function me(s, t) {
530
+ if (s.geometry.type !== "LineString") return { valid: !1, reason: "Feature is not a LineString" };
531
+ if (s.geometry.coordinates.length < 2) return { valid: !1, reason: "Feature has less than 2 coordinates" };
532
+ for (let e = 0; e < s.geometry.coordinates.length; e++) {
533
+ if (!Lt(s.geometry.coordinates[e])) return { valid: !1, reason: "Feature has invalid coordinates" };
534
+ if (!St(s.geometry.coordinates[e], t)) return { valid: !1, reason: "Feature has coordinates with excessive precision" };
535
+ }
536
+ return { valid: !0 };
521
537
  }
522
538
  function Ht(s) {
523
539
  return Math.sqrt(Math.pow(s[0], 2) + Math.pow(s[1], 2) + Math.pow(s[2], 2));
@@ -530,26 +546,26 @@ function X(s, t) {
530
546
  return Math.acos(Math.min(Math.max(e, -1), 1));
531
547
  }
532
548
  function Mt(s) {
533
- const t = E(s[1]), e = E(s[0]);
549
+ const t = O(s[1]), e = O(s[0]);
534
550
  return [Math.cos(t) * Math.cos(e), Math.cos(t) * Math.sin(e), Math.sin(t)];
535
551
  }
536
552
  function K(s) {
537
- const [t, e, i] = s, o = z(Math.asin(i));
538
- return [z(Math.atan2(e, t)), o];
539
- }
540
- function oi(s, t, e) {
541
- const i = Mt(s), o = Mt(t), r = Mt(e), [n, a, l] = r, [d, h, c] = function(B, R) {
542
- const [jt, Bt, Nt] = B, [Gt, Tt, At] = R;
543
- return [Bt * At - Nt * Tt, Nt * Gt - jt * At, jt * Tt - Bt * Gt];
544
- }(i, o), u = h * l - c * a, p = c * n - d * l, g = d * a - h * n, y = g * h - p * c, v = u * c - g * d, f = p * d - u * h, m = 1 / Math.sqrt(Math.pow(y, 2) + Math.pow(v, 2) + Math.pow(f, 2)), C = [y * m, v * m, f * m], P = [-1 * y * m, -1 * v * m, -1 * f * m], S = X(i, o), M = X(i, C), w = X(o, C), D = X(i, P), G = X(o, P);
545
- let L;
546
- return L = M < D && M < G || w < D && w < G ? C : P, X(i, L) > S || X(o, L) > S ? A(K(L), K(i)) <= A(K(L), K(o)) ? [K(i), !0, !1] : [K(o), !1, !0] : [K(L), !1, !1];
547
- }
548
- function si(s, t, e) {
553
+ const [t, e, i] = s, o = R(Math.asin(i));
554
+ return [R(Math.atan2(e, t)), o];
555
+ }
556
+ function ti(s, t, e) {
557
+ const i = Mt(s), o = Mt(t), r = Mt(e), [n, a, l] = r, [d, h, c] = function(B, z) {
558
+ const [Wt, Bt, Nt] = B, [Gt, Tt, At] = z;
559
+ return [Bt * At - Nt * Tt, Nt * Gt - Wt * At, Wt * Tt - Bt * Gt];
560
+ }(i, o), u = h * l - c * a, p = c * n - d * l, y = d * a - h * n, g = y * h - p * c, v = u * c - y * d, f = p * d - u * h, m = 1 / Math.sqrt(Math.pow(g, 2) + Math.pow(v, 2) + Math.pow(f, 2)), C = [g * m, v * m, f * m], P = [-1 * g * m, -1 * v * m, -1 * f * m], S = X(i, o), M = X(i, C), F = X(o, C), D = X(i, P), G = X(o, P);
561
+ let _;
562
+ return _ = M < D && M < G || F < D && F < G ? C : P, X(i, _) > S || X(o, _) > S ? A(K(_), K(i)) <= A(K(_), K(o)) ? [K(i), !0, !1] : [K(o), !1, !0] : [K(_), !1, !1];
563
+ }
564
+ function ei(s, t, e) {
549
565
  const i = t.x - s.x, o = t.y - s.y, r = Math.max(0, Math.min(1, ((e.x - s.x) * i + (e.y - s.y) * o) / (i * i + o * o)));
550
566
  return { x: s.x + r * i, y: s.y + r * o };
551
567
  }
552
- class Se extends j {
568
+ class ve extends W {
553
569
  constructor(t, e, i) {
554
570
  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)).coordinate, this.getSnappableCoordinate = (o, r) => this.getSnappable(o, (n) => !!(n.properties && n.properties.mode === this.mode && n.id !== r)).coordinate, this.config = t, this.pixelDistance = e, this.clickBoundingBox = i;
555
571
  }
@@ -567,38 +583,38 @@ class Se extends j {
567
583
  let d;
568
584
  const h = [t.lng, t.lat];
569
585
  if (this.config.projection === "web-mercator" ? d = function(u, p) {
570
- let g = [1 / 0, 1 / 0], y = 1 / 0, v = 0;
586
+ let y = [1 / 0, 1 / 0], g = 1 / 0, v = 0;
571
587
  for (let f of p) {
572
588
  const m = f[0], C = f[1];
573
589
  let P, S = 1 / 0;
574
- const M = x(m[0], m[1]), w = x(C[0], C[1]), D = x(u[0], u[1]);
590
+ const M = x(m[0], m[1]), F = x(C[0], C[1]), D = x(u[0], u[1]);
575
591
  if (m[0] === u[0] && m[1] === u[1]) P = m;
576
592
  else if (C[0] === u[0] && C[1] === u[1]) P = C;
577
593
  else {
578
- const { x: G, y: L } = si(M, w, D), { lng: B, lat: R } = W(G, L);
579
- P = [B, R];
594
+ const { x: G, y: _ } = ei(M, F, D), { lng: B, lat: z } = j(G, _);
595
+ P = [B, z];
580
596
  }
581
- P && (S = O(D, x(P[0], P[1])), S < y && (g = P, y = S, v = p.indexOf(f)));
597
+ P && (S = E(D, x(P[0], P[1])), S < g && (y = P, g = S, v = p.indexOf(f)));
582
598
  }
583
- return y === 1 / 0 ? void 0 : { coordinate: g, lineIndex: v, distance: y };
599
+ return g === 1 / 0 ? void 0 : { coordinate: y, lineIndex: v, distance: g };
584
600
  }(h, l) : this.config.projection === "globe" && (d = function(u, p) {
585
- let g = [1 / 0, 1 / 0], y = 1 / 0, v = 0;
601
+ let y = [1 / 0, 1 / 0], g = 1 / 0, v = 0;
586
602
  for (let f of p) {
587
603
  const m = f[0], C = f[1];
588
604
  let P, S = 1 / 0;
589
- m[0] === u[0] && m[1] === u[1] ? P = m : C[0] === u[0] && C[1] === u[1] ? P = C : [P] = oi(m, C, u), P && (S = A(u, P), S < y && (g = P, y = S, v = p.indexOf(f)));
605
+ m[0] === u[0] && m[1] === u[1] ? P = m : C[0] === u[0] && C[1] === u[1] ? P = C : [P] = ti(m, C, u), P && (S = A(u, P), S < g && (y = P, g = S, v = p.indexOf(f)));
590
606
  }
591
- return y === 1 / 0 ? void 0 : { coordinate: g, distance: y, lineIndex: v };
607
+ return g === 1 / 0 ? void 0 : { coordinate: y, distance: g, lineIndex: v };
592
608
  }(h, l)), !d) return;
593
609
  const c = this.pixelDistance.measure(t, d.coordinate);
594
610
  c < r.minDistance && c < this.pointerDistance && (r.featureId = n.id, r.coordinate = d.coordinate, r.featureCoordinateIndex = d.lineIndex, r.minDistance = c);
595
611
  }), r;
596
612
  }
597
613
  }
598
- const ri = { cancel: "Escape", finish: "Enter" }, ni = { start: "crosshair", close: "pointer", dragStart: "grabbing", dragEnd: "crosshair" };
599
- class xe extends N {
614
+ const ii = { cancel: "Escape", finish: "Enter" }, oi = { start: "crosshair", close: "pointer", dragStart: "grabbing", dragEnd: "crosshair" };
615
+ class Ce extends N {
600
616
  constructor(t) {
601
- super(t, !0), this.mode = "linestring", this.currentCoordinate = 0, this.currentId = void 0, this.closingPointId = void 0, this.keyEvents = ri, this.snapping = void 0, this.cursors = ni, this.mouseMove = !1, this.insertCoordinates = void 0, this.lastCommitedCoordinates = void 0, this.snappedPointId = void 0, this.editable = !1, this.editedFeatureId = void 0, this.editedFeatureCoordinateIndex = void 0, this.editedSnapType = void 0, this.editedInsertIndex = void 0, this.editedPointId = void 0, this.coordinateSnapping = void 0, this.insertPoint = void 0, this.lineSnapping = void 0, this.pixelDistance = void 0, this.clickBoundingBox = void 0, this.updateOptions(t);
617
+ super(t, !0), this.mode = "linestring", this.currentCoordinate = 0, this.currentId = void 0, this.closingPointId = void 0, this.keyEvents = ii, this.snapping = void 0, this.cursors = oi, this.mouseMove = !1, this.insertCoordinates = void 0, this.lastCommitedCoordinates = void 0, this.snappedPointId = void 0, this.editable = !1, this.editedFeatureId = void 0, this.editedFeatureCoordinateIndex = void 0, this.editedSnapType = void 0, this.editedInsertIndex = void 0, this.editedPointId = void 0, this.coordinateSnapping = void 0, this.insertPoint = void 0, this.lineSnapping = void 0, this.pixelDistance = void 0, this.clickBoundingBox = void 0, this.updateOptions(t);
602
618
  }
603
619
  updateOptions(t) {
604
620
  super.updateOptions(t), t != null && t.cursors && (this.cursors = b({}, this.cursors, t.cursors)), t != null && t.snapping && (this.snapping = t.snapping), (t == null ? void 0 : t.keyEvents) === null ? this.keyEvents = { cancel: null, finish: null } : t != null && t.keyEvents && (this.keyEvents = b({}, this.keyEvents, t.keyEvents)), t != null && t.insertCoordinates && (this.insertCoordinates = t.insertCoordinates), t && t.editable && (this.editable = t.editable);
@@ -638,13 +654,13 @@ class xe extends N {
638
654
  updateToLine(t, e) {
639
655
  if (!this.currentId) return;
640
656
  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);
641
- if (O({ x: n, y: a }, { x: e.x, y: e.y }) < this.pointerDistance) return void this.close();
657
+ if (E({ x: n, y: a }, { x: e.x, y: e.y }) < this.pointerDistance) return void this.close();
642
658
  this.setCursor(this.cursors.close);
643
659
  const l = [...i, t];
644
660
  this.updateGeometries(l, i[i.length - 1], I.Commit), this.currentCoordinate++;
645
661
  }
646
662
  registerBehaviors(t) {
647
- this.coordinateSnapping = new Lt(t, new nt(t), new rt(t)), this.insertPoint = new ii(t), this.clickBoundingBox = new rt(t), this.pixelDistance = new nt(t), this.lineSnapping = new Se(t, this.pixelDistance, this.clickBoundingBox), this.coordinateSnapping = new Lt(t, this.pixelDistance, this.clickBoundingBox);
663
+ this.coordinateSnapping = new Dt(t, new nt(t), new rt(t)), this.insertPoint = new Qe(t), this.clickBoundingBox = new rt(t), this.pixelDistance = new nt(t), this.lineSnapping = new ve(t, this.pixelDistance, this.clickBoundingBox), this.coordinateSnapping = new Dt(t, this.pixelDistance, this.clickBoundingBox);
648
664
  }
649
665
  start() {
650
666
  this.setStarted(), this.setCursor(this.cursors.start);
@@ -658,7 +674,7 @@ class xe extends N {
658
674
  if (e) {
659
675
  if (this.snappedPointId) this.store.updateGeometry([{ id: this.snappedPointId, geometry: { type: "Point", coordinates: e } }]);
660
676
  else {
661
- const [n] = this.store.create([{ geometry: { type: "Point", coordinates: e }, properties: { mode: this.mode, [Dt]: !0 } }]);
677
+ const [n] = this.store.create([{ geometry: { type: "Point", coordinates: e }, properties: { mode: this.mode, [Ot]: !0 } }]);
662
678
  this.snappedPointId = n;
663
679
  }
664
680
  t.lng = e[0], t.lat = e[1];
@@ -668,7 +684,7 @@ class xe extends N {
668
684
  const o = this.store.getGeometryCopy(this.currentId).coordinates;
669
685
  if (o.pop(), this.closingPointId) {
670
686
  const [n, a] = o[o.length - 1], { x: l, y: d } = this.project(n, a);
671
- O({ x: l, y: d }, { x: t.containerX, y: t.containerY }) < this.pointerDistance && this.setCursor(this.cursors.close);
687
+ E({ x: l, y: d }, { x: t.containerX, y: t.containerY }) < this.pointerDistance && this.setCursor(this.cursors.close);
672
688
  }
673
689
  let r = [...o, i];
674
690
  if (this.insertCoordinates && this.currentId && this.lastCommitedCoordinates) {
@@ -682,13 +698,13 @@ class xe extends N {
682
698
  }
683
699
  onRightClick(t) {
684
700
  if (!this.editable || this.state !== "started") return;
685
- const { featureId: e, featureCoordinateIndex: i } = this.coordinateSnapping.getSnappable(t, (n) => n.geometry.type === "LineString");
701
+ const { featureId: e, featureCoordinateIndex: i } = this.coordinateSnapping.getSnappable(t, (n) => this.lineStringFilter(n));
686
702
  if (!e || i === void 0) return;
687
703
  const o = this.store.getGeometryCopy(e);
688
704
  let r;
689
705
  if (o.type === "LineString" && (r = o.coordinates, !(r.length <= 2))) {
690
706
  if (r.splice(i, 1), this.validate && !this.validate({ id: e, type: "Feature", geometry: o, properties: {} }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: I.Commit }).valid) return;
691
- this.snappedPointId && (this.store.delete([this.snappedPointId]), this.snappedPointId = void 0), this.store.updateGeometry([{ id: e, geometry: o }]);
707
+ this.snappedPointId && (this.store.delete([this.snappedPointId]), this.snappedPointId = void 0), this.store.updateGeometry([{ id: e, geometry: o }]), this.onFinish(e, { mode: this.mode, action: "edit" });
692
708
  }
693
709
  }
694
710
  onLeftClick(t) {
@@ -708,9 +724,9 @@ class xe extends N {
708
724
  if (!this.editable) return;
709
725
  let i;
710
726
  if (this.state === "started") {
711
- const o = this.lineSnapping.getSnappable(t);
727
+ const o = this.lineSnapping.getSnappable(t, (n) => this.lineStringFilter(n));
712
728
  o.coordinate && (this.editedSnapType = "line", this.editedFeatureCoordinateIndex = o.featureCoordinateIndex, this.editedFeatureId = o.featureId, i = o.coordinate);
713
- const r = this.coordinateSnapping.getSnappable(t);
729
+ const r = this.coordinateSnapping.getSnappable(t, (n) => this.lineStringFilter(n));
714
730
  r.coordinate && (this.editedSnapType = "coordinate", this.editedFeatureCoordinateIndex = r.featureCoordinateIndex, this.editedFeatureId = r.featureId, i = r.coordinate);
715
731
  }
716
732
  if (this.editedFeatureId && i) {
@@ -729,7 +745,7 @@ class xe extends N {
729
745
  this.validate && !this.validate({ type: "Feature", geometry: o, properties: this.store.getPropertiesCopy(this.editedFeatureId) }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: I.Provisional }).valid || (this.snapping && this.snappedPointId && (this.store.delete([this.snappedPointId]), this.snappedPointId = void 0), this.store.updateGeometry([{ id: this.editedFeatureId, geometry: o }]), this.editedPointId && this.store.updateGeometry([{ id: this.editedPointId, geometry: { type: "Point", coordinates: [t.lng, t.lat] } }]), this.store.updateProperty([{ id: this.editedFeatureId, property: V, value: !0 }]), e(!0));
730
746
  }
731
747
  onDragEnd(t, e) {
732
- this.editedFeatureId !== void 0 && (this.setCursor(this.cursors.dragEnd), this.editedPointId && (this.store.delete([this.editedPointId]), this.editedPointId = void 0), this.store.updateProperty([{ id: this.editedFeatureId, property: V, value: !1 }]), this.editedFeatureId = void 0, this.editedFeatureCoordinateIndex = void 0, this.editedInsertIndex = void 0, this.editedSnapType = void 0, e(!0));
748
+ this.editedFeatureId !== void 0 && (this.setCursor(this.cursors.dragEnd), this.editedPointId && (this.store.delete([this.editedPointId]), this.editedPointId = void 0), this.store.updateProperty([{ id: this.editedFeatureId, property: V, value: !1 }]), this.onFinish(this.editedFeatureId, { mode: this.mode, action: "edit" }), this.editedFeatureId = void 0, this.editedFeatureCoordinateIndex = void 0, this.editedInsertIndex = void 0, this.editedSnapType = void 0, e(!0));
733
749
  }
734
750
  cleanUp() {
735
751
  const t = this.currentId, e = this.closingPointId, i = this.snappedPointId;
@@ -749,7 +765,10 @@ class xe extends N {
749
765
  return e;
750
766
  }
751
767
  validateFeature(t) {
752
- return this.validateModeFeature(t, (e) => Pe(e, this.coordinatePrecision));
768
+ return this.validateModeFeature(t, (e) => me(e, this.coordinatePrecision));
769
+ }
770
+ lineStringFilter(t) {
771
+ return !!(t.geometry.type === "LineString" && t.properties && t.properties.mode === this.mode);
753
772
  }
754
773
  snapCoordinate(t) {
755
774
  var e, i;
@@ -757,14 +776,14 @@ class xe extends N {
757
776
  return (e = this.snapping) != null && e.toCoordinate && (o = this.currentId ? this.coordinateSnapping.getSnappableCoordinate(t, this.currentId) : this.coordinateSnapping.getSnappableCoordinateFirstClick(t)), (i = this.snapping) != null && i.toCustom && (o = this.snapping.toCustom(t)), o;
758
777
  }
759
778
  }
760
- const ai = "Feature is not a Point", li = "Feature has invalid coordinates";
761
- function Ie(s, t) {
762
- return s.geometry.type !== "Point" ? { valid: !1, reason: ai } : St(s.geometry.coordinates, t) ? { valid: !0 } : { valid: !1, reason: li };
779
+ const si = "Feature is not a Point", ri = "Feature has invalid coordinates", ni = "Feature has coordinates with excessive precision";
780
+ function Pe(s, t) {
781
+ return s.geometry.type !== "Point" ? { valid: !1, reason: si } : Lt(s.geometry.coordinates) ? St(s.geometry.coordinates, t) ? { valid: !0 } : { valid: !1, reason: ni } : { valid: !1, reason: ri };
763
782
  }
764
- const di = { create: "crosshair", dragStart: "grabbing", dragEnd: "crosshair" };
765
- class be extends N {
783
+ const ai = { create: "crosshair", dragStart: "grabbing", dragEnd: "crosshair" };
784
+ class Se extends N {
766
785
  constructor(t) {
767
- super(t, !0), this.mode = "point", this.cursors = di, this.editable = !1, this.editedFeatureId = void 0, this.pixelDistance = void 0, this.clickBoundingBox = void 0, this.updateOptions(t);
786
+ super(t, !0), this.mode = "point", this.cursors = ai, this.editable = !1, this.editedFeatureId = void 0, this.pixelDistance = void 0, this.clickBoundingBox = void 0, this.updateOptions(t);
768
787
  }
769
788
  updateOptions(t) {
770
789
  super.updateOptions(t), t != null && t.cursors && (this.cursors = b({}, this.cursors, t.cursors)), t != null && t.editable && (this.editable = t.editable);
@@ -813,7 +832,7 @@ class be extends N {
813
832
  return e;
814
833
  }
815
834
  validateFeature(t) {
816
- return this.validateModeFeature(t, (e) => Ie(e, this.coordinatePrecision));
835
+ return this.validateModeFeature(t, (e) => Pe(e, this.coordinatePrecision));
817
836
  }
818
837
  onLeftClick(t) {
819
838
  const e = { type: "Point", coordinates: [t.lng, t.lat] }, i = { mode: this.mode };
@@ -838,7 +857,7 @@ class be extends N {
838
857
  return o;
839
858
  }
840
859
  }
841
- class hi extends j {
860
+ class li extends W {
842
861
  constructor(t, e) {
843
862
  super(t), this.config = void 0, this.pixelDistance = void 0, this._startEndPoints = [], this.config = t, this.pixelDistance = e;
844
863
  }
@@ -864,10 +883,10 @@ class hi extends j {
864
883
  return { isClosing: o < this.pointerDistance, isPreviousClosing: r < this.pointerDistance };
865
884
  }
866
885
  }
867
- const ci = { cancel: "Escape", finish: "Enter" }, ui = { start: "crosshair", close: "pointer", dragStart: "grabbing", dragEnd: "crosshair" };
868
- class Me extends N {
886
+ const di = { cancel: "Escape", finish: "Enter" }, hi = { start: "crosshair", close: "pointer", dragStart: "grabbing", dragEnd: "crosshair" };
887
+ class xe extends N {
869
888
  constructor(t) {
870
- super(t, !0), this.mode = "polygon", this.currentCoordinate = 0, this.currentId = void 0, this.keyEvents = ci, this.cursors = ui, this.mouseMove = !1, this.snapping = void 0, this.snappedPointId = void 0, this.editable = !1, this.editedFeatureId = void 0, this.editedFeatureCoordinateIndex = void 0, this.editedSnapType = void 0, this.editedInsertIndex = void 0, this.editedPointId = void 0, this.lineSnapping = void 0, this.coordinateSnapping = void 0, this.pixelDistance = void 0, this.closingPoints = void 0, this.clickBoundingBox = void 0, this.updateOptions(t);
889
+ super(t, !0), this.mode = "polygon", this.currentCoordinate = 0, this.currentId = void 0, this.keyEvents = di, this.cursors = hi, this.mouseMove = !1, this.snapping = void 0, this.snappedPointId = void 0, this.editable = !1, this.editedFeatureId = void 0, this.editedFeatureCoordinateIndex = void 0, this.editedSnapType = void 0, this.editedInsertIndex = void 0, this.editedPointId = void 0, this.lineSnapping = void 0, this.coordinateSnapping = void 0, this.pixelDistance = void 0, this.closingPoints = void 0, this.clickBoundingBox = void 0, this.updateOptions(t);
871
890
  }
872
891
  updateOptions(t) {
873
892
  super.updateOptions(t), t != null && t.cursors && (this.cursors = b({}, this.cursors, t.cursors)), (t == null ? void 0 : t.keyEvents) === null ? this.keyEvents = { cancel: null, finish: null } : t != null && t.keyEvents && (this.keyEvents = b({}, this.keyEvents, t.keyEvents)), t != null && t.snapping && (this.snapping = t.snapping), t != null && t.editable && (this.editable = t.editable);
@@ -884,7 +903,7 @@ class Me extends N {
884
903
  this.snappedPointId && this.store.delete([this.snappedPointId]), this.currentCoordinate = 0, this.currentId = void 0, this.snappedPointId = void 0, this.closingPoints.delete(), this.state === "drawing" && this.setStarted(), this.onFinish(e, { mode: this.mode, action: "draw" });
885
904
  }
886
905
  registerBehaviors(t) {
887
- this.clickBoundingBox = new rt(t), this.pixelDistance = new nt(t), this.lineSnapping = new Se(t, this.pixelDistance, this.clickBoundingBox), this.coordinateSnapping = new Lt(t, this.pixelDistance, this.clickBoundingBox), this.closingPoints = new hi(t, this.pixelDistance);
906
+ this.clickBoundingBox = new rt(t), this.pixelDistance = new nt(t), this.lineSnapping = new ve(t, this.pixelDistance, this.clickBoundingBox), this.coordinateSnapping = new Dt(t, this.pixelDistance, this.clickBoundingBox), this.closingPoints = new li(t, this.pixelDistance);
888
907
  }
889
908
  start() {
890
909
  this.setStarted(), this.setCursor(this.cursors.start);
@@ -898,7 +917,7 @@ class Me extends N {
898
917
  if (e) {
899
918
  if (this.snappedPointId) this.store.updateGeometry([{ id: this.snappedPointId, geometry: { type: "Point", coordinates: e } }]);
900
919
  else {
901
- const [r] = this.store.create([{ geometry: { type: "Point", coordinates: e }, properties: { mode: this.mode, [Dt]: !0 } }]);
920
+ const [r] = this.store.create([{ geometry: { type: "Point", coordinates: e }, properties: { mode: this.mode, [Ot]: !0 } }]);
902
921
  this.snappedPointId = r;
903
922
  }
904
923
  t.lng = e[0], t.lat = e[1];
@@ -932,15 +951,18 @@ class Me extends N {
932
951
  let n;
933
952
  n = this.currentId ? this.coordinateSnapping.getSnappableCoordinate(t, this.currentId) : this.coordinateSnapping.getSnappableCoordinateFirstClick(t), n && (r = n);
934
953
  }
935
- return (o = this.snapping) != null && o.toCustom && (r = this.snapping.toCustom(t)), r;
954
+ return (o = this.snapping) != null && o.toCustom && (r = this.snapping.toCustom(t, { currentCoordinate: this.currentCoordinate, currentId: this.currentId, getCurrentGeometrySnapshot: this.currentId ? () => this.store.getGeometryCopy(this.currentId) : () => null, project: this.project, unproject: this.unproject })), r;
955
+ }
956
+ polygonFilter(t) {
957
+ return !!(t.geometry.type === "Polygon" && t.properties && t.properties.mode === this.mode);
936
958
  }
937
959
  onRightClick(t) {
938
960
  if (!this.editable) return;
939
- const { featureId: e, featureCoordinateIndex: i } = this.coordinateSnapping.getSnappable(t, (n) => n.geometry.type === "Polygon");
961
+ const { featureId: e, featureCoordinateIndex: i } = this.coordinateSnapping.getSnappable(t, (n) => this.polygonFilter(n));
940
962
  if (!e || i === void 0) return;
941
963
  const o = this.store.getGeometryCopy(e);
942
964
  let r;
943
- o.type === "Polygon" && (r = o.coordinates[0], r.length <= 4 || (o.type !== "Polygon" || i !== 0 && i !== r.length - 1 ? r.splice(i, 1) : (r.shift(), r.pop(), r.push([r[0][0], r[0][1]])), (!this.validate || this.validate({ id: e, type: "Feature", geometry: o, properties: {} }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: I.Commit }).valid) && (this.snappedPointId && (this.store.delete([this.snappedPointId]), this.snappedPointId = void 0), this.store.updateGeometry([{ id: e, geometry: o }]))));
965
+ o.type === "Polygon" && (r = o.coordinates[0], r.length <= 4 || (o.type !== "Polygon" || i !== 0 && i !== r.length - 1 ? r.splice(i, 1) : (r.shift(), r.pop(), r.push([r[0][0], r[0][1]])), (!this.validate || this.validate({ id: e, type: "Feature", geometry: o, properties: {} }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: I.Commit }).valid) && (this.snappedPointId && (this.store.delete([this.snappedPointId]), this.snappedPointId = void 0), this.store.updateGeometry([{ id: e, geometry: o }]), this.onFinish(e, { mode: this.mode, action: "edit" }))));
944
966
  }
945
967
  onLeftClick(t) {
946
968
  if (this.snappedPointId && (this.store.delete([this.snappedPointId]), this.snappedPointId = void 0), this.currentCoordinate === 0) {
@@ -986,9 +1008,9 @@ class Me extends N {
986
1008
  if (!this.editable) return;
987
1009
  let i;
988
1010
  if (this.state === "started") {
989
- const o = this.lineSnapping.getSnappable(t);
1011
+ const o = this.lineSnapping.getSnappable(t, (n) => this.polygonFilter(n));
990
1012
  o.coordinate && (this.editedSnapType = "line", this.editedFeatureCoordinateIndex = o.featureCoordinateIndex, this.editedFeatureId = o.featureId, i = o.coordinate);
991
- const r = this.coordinateSnapping.getSnappable(t);
1013
+ const r = this.coordinateSnapping.getSnappable(t, (n) => this.polygonFilter(n));
992
1014
  r.coordinate && (this.editedSnapType = "coordinate", this.editedFeatureCoordinateIndex = r.featureCoordinateIndex, this.editedFeatureId = r.featureId, i = r.coordinate);
993
1015
  }
994
1016
  if (this.editedFeatureId && i) {
@@ -1007,7 +1029,7 @@ class Me extends N {
1007
1029
  this.validate && !this.validate({ type: "Feature", geometry: r, properties: this.store.getPropertiesCopy(this.editedFeatureId) }, { project: this.project, unproject: this.unproject, coordinatePrecision: this.coordinatePrecision, updateType: I.Provisional }).valid || (this.snapping && this.snappedPointId && (this.store.delete([this.snappedPointId]), this.snappedPointId = void 0), this.store.updateGeometry([{ id: this.editedFeatureId, geometry: r }]), this.editedPointId && this.store.updateGeometry([{ id: this.editedPointId, geometry: { type: "Point", coordinates: [t.lng, t.lat] } }]), this.store.updateProperty([{ id: this.editedFeatureId, property: V, value: !0 }]), e(!0));
1008
1030
  }
1009
1031
  onDragEnd(t, e) {
1010
- this.editedFeatureId !== void 0 && (this.setCursor(this.cursors.dragEnd), this.editedPointId && (this.store.delete([this.editedPointId]), this.editedPointId = void 0), this.store.updateProperty([{ id: this.editedFeatureId, property: V, value: !1 }]), this.editedFeatureId = void 0, this.editedFeatureCoordinateIndex = void 0, this.editedInsertIndex = void 0, this.editedSnapType = void 0, e(!0));
1032
+ this.editedFeatureId !== void 0 && (this.setCursor(this.cursors.dragEnd), this.editedPointId && (this.store.delete([this.editedPointId]), this.editedPointId = void 0), this.store.updateProperty([{ id: this.editedFeatureId, property: V, value: !1 }]), this.onFinish(this.editedFeatureId, { mode: this.mode, action: "edit" }), this.editedFeatureId = void 0, this.editedFeatureCoordinateIndex = void 0, this.editedInsertIndex = void 0, this.editedSnapType = void 0, e(!0));
1011
1033
  }
1012
1034
  cleanUp() {
1013
1035
  const t = this.currentId, e = this.snappedPointId, i = this.editedPointId;
@@ -1022,7 +1044,7 @@ class Me extends N {
1022
1044
  if (t.properties.mode === this.mode) {
1023
1045
  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;
1024
1046
  if (t.geometry.type === "Point") {
1025
- const i = t.properties[V], o = i ? "editedPoint" : t.properties[st] ? "closingPoint" : t.properties[Dt] ? "snappingPoint" : void 0;
1047
+ const i = t.properties[V], o = i ? "editedPoint" : t.properties[st] ? "closingPoint" : t.properties[Ot] ? "snappingPoint" : void 0;
1026
1048
  if (!o) return e;
1027
1049
  const r = { editedPoint: { width: this.styles.editedPointOutlineWidth, color: this.styles.editedPointColor, outlineColor: this.styles.editedPointOutlineColor, outlineWidth: this.styles.editedPointOutlineWidth }, closingPoint: { width: this.styles.closingPointWidth, color: this.styles.closingPointColor, outlineColor: this.styles.closingPointOutlineColor, outlineWidth: this.styles.closingPointOutlineWidth }, snappingPoint: { width: this.styles.snappingPointWidth, color: this.styles.snappingPointColor, outlineColor: this.styles.snappingPointOutlineColor, outlineWidth: this.styles.snappingPointOutlineWidth } };
1028
1050
  return e.pointWidth = this.getNumericStylingValue(r[o].width, e.pointWidth, t), e.pointColor = this.getHexColorStylingValue(r[o].color, e.pointColor, t), e.pointOutlineColor = this.getHexColorStylingValue(r[o].outlineColor, e.pointOutlineColor, t), e.pointOutlineWidth = this.getNumericStylingValue(r[o].outlineWidth, 2, t), e.zIndex = i ? 35 : 30, e;
@@ -1034,10 +1056,10 @@ class Me extends N {
1034
1056
  return this.validateModeFeature(t, (e) => xt(e, this.coordinatePrecision));
1035
1057
  }
1036
1058
  }
1037
- const pi = { cancel: "Escape", finish: "Enter" }, gi = { start: "crosshair" };
1038
- class we extends N {
1059
+ const ci = { cancel: "Escape", finish: "Enter" }, ui = { start: "crosshair" };
1060
+ class Ie extends N {
1039
1061
  constructor(t) {
1040
- super(t, !0), this.mode = "rectangle", this.center = void 0, this.clickCount = 0, this.currentRectangleId = void 0, this.keyEvents = pi, this.cursors = gi, this.updateOptions(t);
1062
+ super(t, !0), this.mode = "rectangle", this.center = void 0, this.clickCount = 0, this.currentRectangleId = void 0, this.keyEvents = ci, this.cursors = ui, this.updateOptions(t);
1041
1063
  }
1042
1064
  updateOptions(t) {
1043
1065
  super.updateOptions(t), t != null && t.cursors && (this.cursors = b({}, this.cursors, t.cursors)), (t == null ? void 0 : t.keyEvents) === null ? this.keyEvents = { cancel: null, finish: null } : t != null && t.keyEvents && (this.keyEvents = b({}, this.keyEvents, t.keyEvents));
@@ -1135,50 +1157,50 @@ class et extends N {
1135
1157
  validateFeature(t) {
1136
1158
  const e = super.validateFeature(t);
1137
1159
  if (e.valid) {
1138
- const i = t, o = Ie(i, this.coordinatePrecision).valid || xt(i, this.coordinatePrecision).valid || Pe(i, this.coordinatePrecision).valid;
1160
+ const i = t, o = Pe(i, this.coordinatePrecision).valid || xt(i, this.coordinatePrecision).valid || me(i, this.coordinatePrecision).valid;
1139
1161
  return o ? { valid: !0 } : { valid: o, reason: "Feature is not a valid Point, Polygon or LineString feature" };
1140
1162
  }
1141
1163
  return e;
1142
1164
  }
1143
1165
  }
1144
1166
  function mt(s, t) {
1145
- const e = s, i = t, o = E(e[1]), r = E(i[1]);
1146
- let n = E(i[0] - e[0]);
1167
+ const e = s, i = t, o = O(e[1]), r = O(i[1]);
1168
+ let n = O(i[0] - e[0]);
1147
1169
  n > Math.PI && (n -= 2 * Math.PI), n < -Math.PI && (n += 2 * Math.PI);
1148
- const a = Math.log(Math.tan(r / 2 + Math.PI / 4) / Math.tan(o / 2 + Math.PI / 4)), l = (z(Math.atan2(n, a)) + 360) % 360;
1170
+ const a = Math.log(Math.tan(r / 2 + Math.PI / 4) / Math.tan(o / 2 + Math.PI / 4)), l = (R(Math.atan2(n, a)) + 360) % 360;
1149
1171
  return l > 180 ? -(360 - l) : l;
1150
1172
  }
1151
1173
  function kt(s, t, e) {
1152
1174
  let i = t;
1153
1175
  t < 0 && (i = -Math.abs(i));
1154
- const o = i / ye, r = s[0] * Math.PI / 180, n = E(s[1]), a = E(e), l = o * Math.cos(a);
1176
+ const o = i / ue, r = s[0] * Math.PI / 180, n = O(s[1]), a = O(e), l = o * Math.cos(a);
1155
1177
  let d = n + l;
1156
1178
  Math.abs(d) > Math.PI / 2 && (d = d > 0 ? Math.PI - d : -Math.PI - d);
1157
1179
  const h = Math.log(Math.tan(d / 2 + Math.PI / 4) / Math.tan(n / 2 + Math.PI / 4)), c = Math.abs(h) > 1e-11 ? l / h : Math.cos(n), u = [(180 * (r + o * Math.sin(a) / c) / Math.PI + 540) % 360 - 180, 180 * d / Math.PI];
1158
1180
  return u[0] += u[0] - s[0] > 180 ? -360 : s[0] - u[0] > 180 ? 360 : 0, u;
1159
1181
  }
1160
- function Fe(s, t, e, i, o) {
1182
+ function be(s, t, e, i, o) {
1161
1183
  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);
1162
- return [F(a, e), F(l, e)];
1184
+ return [w(a, e), w(l, e)];
1163
1185
  }
1164
- function yi(s, t, e) {
1186
+ function pi(s, t, e) {
1165
1187
  const i = kt(s, 1e3 * A(s, t) / 2, mt(s, t));
1166
- return [F(i[0], e), F(i[1], e)];
1188
+ return [w(i[0], e), w(i[1], e)];
1167
1189
  }
1168
1190
  function qt({ featureCoords: s, precision: t, unproject: e, project: i, projection: o }) {
1169
1191
  const r = [];
1170
1192
  for (let n = 0; n < s.length - 1; n++) {
1171
1193
  let a;
1172
- if (o === "web-mercator") a = Fe(s[n], s[n + 1], t, i, e);
1194
+ if (o === "web-mercator") a = be(s[n], s[n + 1], t, i, e);
1173
1195
  else {
1174
1196
  if (o !== "globe") throw new Error("Invalid projection");
1175
- a = yi(s[n], s[n + 1], t);
1197
+ a = pi(s[n], s[n + 1], t);
1176
1198
  }
1177
1199
  r.push(a);
1178
1200
  }
1179
1201
  return r;
1180
1202
  }
1181
- class fi extends j {
1203
+ class gi extends W {
1182
1204
  constructor(t, e) {
1183
1205
  super(t), this.config = void 0, this.selectionPointBehavior = void 0, this._midPoints = [], this.config = t, this.selectionPointBehavior = e;
1184
1206
  }
@@ -1204,7 +1226,7 @@ class fi extends j {
1204
1226
  if (this._midPoints.length !== 0) return qt({ 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 } }));
1205
1227
  }
1206
1228
  }
1207
- class mi extends j {
1229
+ class yi extends W {
1208
1230
  constructor(t) {
1209
1231
  super(t), this._selectionPoints = [];
1210
1232
  }
@@ -1230,7 +1252,7 @@ class mi extends j {
1230
1252
  if (this._selectionPoints[t] !== void 0) return { id: this._selectionPoints[t], geometry: { type: "Point", coordinates: e } };
1231
1253
  }
1232
1254
  }
1233
- function Ee(s, t) {
1255
+ function Me(s, t) {
1234
1256
  let e = !1;
1235
1257
  for (let n = 0, a = t.length; n < a; n++) {
1236
1258
  const l = t[n];
@@ -1239,7 +1261,7 @@ function Ee(s, t) {
1239
1261
  var i, o, r;
1240
1262
  return e;
1241
1263
  }
1242
- const Oe = (s, t, e) => {
1264
+ const we = (s, t, e) => {
1243
1265
  const i = (r) => r * r, o = (r, n) => i(r.x - n.x) + i(r.y - n.y);
1244
1266
  return Math.sqrt(((r, n, a) => {
1245
1267
  const l = o(n, a);
@@ -1248,7 +1270,7 @@ const Oe = (s, t, e) => {
1248
1270
  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) });
1249
1271
  })(s, t, e));
1250
1272
  };
1251
- class vi extends j {
1273
+ class fi extends W {
1252
1274
  constructor(t, e, i) {
1253
1275
  super(t), this.config = void 0, this.createClickBoundingBox = void 0, this.pixelDistance = void 0, this.config = t, this.createClickBoundingBox = e, this.pixelDistance = i;
1254
1276
  }
@@ -1256,26 +1278,26 @@ class vi extends j {
1256
1278
  let i, o, r, n, a = 1 / 0, l = 1 / 0, d = 1 / 0;
1257
1279
  const h = this.createClickBoundingBox.create(t), c = this.store.search(h);
1258
1280
  for (let u = 0; u < c.length; u++) {
1259
- const p = c[u], g = p.geometry;
1260
- if (g.type === "Point") {
1281
+ const p = c[u], y = p.geometry;
1282
+ if (y.type === "Point") {
1261
1283
  if (p.properties.selectionPoint || !e && p.properties[U.MID_POINT]) continue;
1262
- const y = this.pixelDistance.measure(t, g.coordinates);
1263
- p.properties[U.MID_POINT] && y < this.pointerDistance && y < d ? (d = y, r = p) : !p.properties[U.MID_POINT] && y < this.pointerDistance && y < a && (a = y, i = p);
1264
- } else if (g.type === "LineString") {
1284
+ const g = this.pixelDistance.measure(t, y.coordinates);
1285
+ p.properties[U.MID_POINT] && g < this.pointerDistance && g < d ? (d = g, r = p) : !p.properties[U.MID_POINT] && g < this.pointerDistance && g < a && (a = g, i = p);
1286
+ } else if (y.type === "LineString") {
1265
1287
  if (i) continue;
1266
- for (let y = 0; y < g.coordinates.length - 1; y++) {
1267
- const v = g.coordinates[y], f = g.coordinates[y + 1], m = Oe({ x: t.containerX, y: t.containerY }, this.project(v[0], v[1]), this.project(f[0], f[1]));
1288
+ for (let g = 0; g < y.coordinates.length - 1; g++) {
1289
+ const v = y.coordinates[g], f = y.coordinates[g + 1], m = we({ x: t.containerX, y: t.containerY }, this.project(v[0], v[1]), this.project(f[0], f[1]));
1268
1290
  m < this.pointerDistance && m < l && (l = m, o = p);
1269
1291
  }
1270
- } else if (g.type === "Polygon") {
1292
+ } else if (y.type === "Polygon") {
1271
1293
  if (i || o) continue;
1272
- Ee([t.lng, t.lat], g.coordinates) && (n = p);
1294
+ Me([t.lng, t.lat], y.coordinates) && (n = p);
1273
1295
  }
1274
1296
  }
1275
1297
  return { clickedFeature: i || o || n, clickedMidPoint: r };
1276
1298
  }
1277
1299
  }
1278
- class Ci extends j {
1300
+ class mi extends W {
1279
1301
  constructor(t, e, i, o) {
1280
1302
  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;
1281
1303
  }
@@ -1302,13 +1324,13 @@ class Ci extends j {
1302
1324
  const h = r[d];
1303
1325
  let c, u;
1304
1326
  if (this.config.projection === "web-mercator") {
1305
- const p = x(this.dragPosition[0], this.dragPosition[1]), g = x(o[0], o[1]), y = x(h[0], h[1]), v = { x: p.x - g.x, y: p.y - g.y }, f = y.x - v.x, m = y.y - v.y, { lng: C, lat: P } = W(f, m);
1327
+ const p = x(this.dragPosition[0], this.dragPosition[1]), y = x(o[0], o[1]), g = x(h[0], h[1]), v = { x: p.x - y.x, y: p.y - y.y }, f = g.x - v.x, m = g.y - v.y, { lng: C, lat: P } = j(f, m);
1306
1328
  c = C, u = P;
1307
1329
  } else {
1308
1330
  const p = [this.dragPosition[0] - o[0], this.dragPosition[1] - o[1]];
1309
1331
  c = h[0] - p[0], u = h[1] - p[1];
1310
1332
  }
1311
- if (c = F(c, this.config.coordinatePrecision), u = F(u, this.config.coordinatePrecision), c > 180 || c < -180 || u > 90 || u < -90) return !1;
1333
+ if (c = w(c, this.config.coordinatePrecision), u = w(u, this.config.coordinatePrecision), c > 180 || c < -180 || u > 90 || u < -90) return !1;
1312
1334
  r[d] = [c, u];
1313
1335
  }
1314
1336
  i.type === "Polygon" && (r[r.length - 1] = [r[0][0], r[0][1]]);
@@ -1318,7 +1340,7 @@ class Ci extends j {
1318
1340
  } else i.type === "Point" && (this.store.updateGeometry([{ id: this.draggedFeatureId, geometry: { type: "Point", coordinates: o } }]), this.dragPosition = [t.lng, t.lat]);
1319
1341
  }
1320
1342
  }
1321
- class Pi extends j {
1343
+ class vi extends W {
1322
1344
  constructor(t, e, i, o) {
1323
1345
  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;
1324
1346
  }
@@ -1371,9 +1393,9 @@ function vt(s) {
1371
1393
  t += o[0], e += o[1], i++;
1372
1394
  }, !0), [t / i, e / i];
1373
1395
  }
1374
- function De(s, t) {
1396
+ function Fe(s, t) {
1375
1397
  s[0] += s[0] - t[0] > 180 ? -360 : t[0] - s[0] > 180 ? 360 : 0;
1376
- const e = ye, i = t[1] * Math.PI / 180, o = s[1] * Math.PI / 180, r = o - i;
1398
+ const e = ue, i = t[1] * Math.PI / 180, o = s[1] * Math.PI / 180, r = o - i;
1377
1399
  let n = Math.abs(s[0] - t[0]) * Math.PI / 180;
1378
1400
  n > Math.PI && (n -= 2 * Math.PI);
1379
1401
  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);
@@ -1402,7 +1424,7 @@ function Ct(s) {
1402
1424
  return { x: o / i, y: r / i };
1403
1425
  }(t);
1404
1426
  }
1405
- class Si extends j {
1427
+ class Ci extends W {
1406
1428
  constructor(t, e, i) {
1407
1429
  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;
1408
1430
  }
@@ -1419,9 +1441,9 @@ class Si extends j {
1419
1441
  if (n = T(Ct(a), x(t.lng, t.lat)), !this.lastBearing) return void (this.lastBearing = n);
1420
1442
  ((c, u) => {
1421
1443
  if (u === 0 || u === 360 || u === -360) return c;
1422
- const p = 0.017453292519943295 * u, g = (c.geometry.type === "Polygon" ? c.geometry.coordinates[0] : c.geometry.coordinates).map(([f, m]) => x(f, m)), y = g.reduce((f, m) => ({ x: f.x + m.x, y: f.y + m.y }), { x: 0, y: 0 });
1423
- y.x /= g.length, y.y /= g.length;
1424
- const v = g.map((f) => ({ x: y.x + (f.x - y.x) * Math.cos(p) - (f.y - y.y) * Math.sin(p), y: y.y + (f.x - y.x) * Math.sin(p) + (f.y - y.y) * Math.cos(p) })).map(({ x: f, y: m }) => [W(f, m).lng, W(f, m).lat]);
1444
+ const p = 0.017453292519943295 * u, y = (c.geometry.type === "Polygon" ? c.geometry.coordinates[0] : c.geometry.coordinates).map(([f, m]) => x(f, m)), g = y.reduce((f, m) => ({ x: f.x + m.x, y: f.y + m.y }), { x: 0, y: 0 });
1445
+ g.x /= y.length, g.y /= y.length;
1446
+ const v = y.map((f) => ({ x: g.x + (f.x - g.x) * Math.cos(p) - (f.y - g.y) * Math.sin(p), y: g.y + (f.x - g.x) * Math.sin(p) + (f.y - g.y) * Math.cos(p) })).map(({ x: f, y: m }) => [j(f, m).lng, j(f, m).lat]);
1425
1447
  c.geometry.type === "Polygon" ? c.geometry.coordinates[0] = v : c.geometry.coordinates = v;
1426
1448
  })(a, -(this.lastBearing - n));
1427
1449
  } else {
@@ -1430,22 +1452,22 @@ class Si extends j {
1430
1452
  (function(c, u) {
1431
1453
  if (u === 0 || u === 360 || u === -360) return c;
1432
1454
  const p = vt(c);
1433
- (c.geometry.type === "Polygon" ? c.geometry.coordinates[0] : c.geometry.coordinates).forEach((g) => {
1434
- const y = mt(p, g) + u, v = De(p, g), f = kt(p, v, y);
1435
- g[0] = f[0], g[1] = f[1];
1455
+ (c.geometry.type === "Polygon" ? c.geometry.coordinates[0] : c.geometry.coordinates).forEach((y) => {
1456
+ const g = mt(p, y) + u, v = Fe(p, y), f = kt(p, v, g);
1457
+ y[0] = f[0], y[1] = f[1];
1436
1458
  });
1437
1459
  })(a, -(this.lastBearing - (n + 180)));
1438
1460
  }
1439
1461
  const l = o.type === "Polygon" ? o.coordinates[0] : o.coordinates;
1440
1462
  l.forEach((c) => {
1441
- c[0] = F(c[0], this.coordinatePrecision), c[1] = F(c[1], this.coordinatePrecision);
1463
+ c[0] = w(c[0], this.coordinatePrecision), c[1] = w(c[1], this.coordinatePrecision);
1442
1464
  });
1443
1465
  const d = this.midPoints.getUpdated(l) || [], h = this.selectionPoints.getUpdated(l) || [];
1444
1466
  if (i && !i({ id: e, type: "Feature", geometry: o, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: I.Provisional })) return !1;
1445
1467
  this.store.updateGeometry([{ id: e, geometry: o }, ...h, ...d]), this.projection === "web-mercator" ? this.lastBearing = n : this.projection === "globe" && (this.lastBearing = n + 180);
1446
1468
  }
1447
1469
  }
1448
- class xi extends j {
1470
+ class Pi extends W {
1449
1471
  constructor(t, e, i) {
1450
1472
  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;
1451
1473
  }
@@ -1460,7 +1482,7 @@ class xi extends j {
1460
1482
  const l = Ct(n);
1461
1483
  if (this.config.projection === "web-mercator") {
1462
1484
  const p = x(t.lng, t.lat);
1463
- a = O(l, p);
1485
+ a = E(l, p);
1464
1486
  } else {
1465
1487
  if (this.config.projection !== "globe") throw new Error("Invalid projection");
1466
1488
  a = A(vt({ geometry: o }), r);
@@ -1468,28 +1490,28 @@ class xi extends j {
1468
1490
  if (!this.lastDistance) return void (this.lastDistance = a);
1469
1491
  const d = 1 - (this.lastDistance - a) / a;
1470
1492
  if (this.config.projection === "web-mercator") {
1471
- const { lng: p, lat: g } = W(l.x, l.y);
1472
- (function(y, v, f) {
1473
- if (v === 1) return y;
1474
- const m = (y.geometry.type === "Polygon" ? y.geometry.coordinates[0] : y.geometry.coordinates).map(([S, M]) => x(S, M)), C = x(f[0], f[1]), P = m.map((S) => ({ x: C.x + (S.x - C.x) * v, y: C.y + (S.y - C.y) * v })).map(({ x: S, y: M }) => [W(S, M).lng, W(S, M).lat]);
1475
- y.geometry.type === "Polygon" ? y.geometry.coordinates[0] = P : y.geometry.coordinates = P;
1476
- })(n, d, [p, g]);
1477
- } else this.config.projection === "globe" && function(p, g, y, v = "xy") {
1478
- g === 1 || (p.geometry.type === "Polygon" ? p.geometry.coordinates[0] : p.geometry.coordinates).forEach((f) => {
1479
- const m = De(y, f), C = mt(y, f), P = kt(y, m * g, C);
1493
+ const { lng: p, lat: y } = j(l.x, l.y);
1494
+ (function(g, v, f) {
1495
+ if (v === 1) return g;
1496
+ const m = (g.geometry.type === "Polygon" ? g.geometry.coordinates[0] : g.geometry.coordinates).map(([S, M]) => x(S, M)), C = x(f[0], f[1]), P = m.map((S) => ({ x: C.x + (S.x - C.x) * v, y: C.y + (S.y - C.y) * v })).map(({ x: S, y: M }) => [j(S, M).lng, j(S, M).lat]);
1497
+ g.geometry.type === "Polygon" ? g.geometry.coordinates[0] = P : g.geometry.coordinates = P;
1498
+ })(n, d, [p, y]);
1499
+ } else this.config.projection === "globe" && function(p, y, g, v = "xy") {
1500
+ y === 1 || (p.geometry.type === "Polygon" ? p.geometry.coordinates[0] : p.geometry.coordinates).forEach((f) => {
1501
+ const m = Fe(g, f), C = mt(g, f), P = kt(g, m * y, C);
1480
1502
  v !== "x" && v !== "xy" || (f[0] = P[0]), v !== "y" && v !== "xy" || (f[1] = P[1]);
1481
1503
  });
1482
1504
  }(n, d, vt(n));
1483
1505
  const h = o.type === "Polygon" ? o.coordinates[0] : o.coordinates;
1484
1506
  h.forEach((p) => {
1485
- p[0] = F(p[0], this.coordinatePrecision), p[1] = F(p[1], this.coordinatePrecision);
1507
+ p[0] = w(p[0], this.coordinatePrecision), p[1] = w(p[1], this.coordinatePrecision);
1486
1508
  });
1487
1509
  const c = this.midPoints.getUpdated(h) || [], u = this.selectionPoints.getUpdated(h) || [];
1488
1510
  if (i && !i({ id: e, type: "Feature", geometry: o, properties: {} }, { project: this.config.project, unproject: this.config.unproject, coordinatePrecision: this.config.coordinatePrecision, updateType: I.Provisional })) return !1;
1489
1511
  this.store.updateGeometry([{ id: e, geometry: o }, ...u, ...c]), this.lastDistance = a;
1490
1512
  }
1491
1513
  }
1492
- class Ii extends j {
1514
+ class Si extends W {
1493
1515
  constructor(t, e, i, o) {
1494
1516
  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;
1495
1517
  }
@@ -1563,7 +1585,7 @@ class Ii extends j {
1563
1585
  }
1564
1586
  scaleFixedWebMercator({ closestBBoxIndex: t, webMercatorOrigin: e, webMercatorSelected: i, webMercatorCursor: o, updatedCoords: r }) {
1565
1587
  if (!this.isValidDragWebMercator(t, e.x - o.x, e.y - o.y)) return null;
1566
- let n = O(e, o) / O(e, i);
1588
+ let n = E(e, o) / E(e, i);
1567
1589
  return n < 0 && (n = this.minimumScale), this.performWebMercatorScale(r, e.x, e.y, n, n), r;
1568
1590
  }
1569
1591
  oppositeFixedWebMercatorDrag(t) {
@@ -1600,7 +1622,7 @@ class Ii extends j {
1600
1622
  }
1601
1623
  performWebMercatorScale(t, e, i, o, r) {
1602
1624
  t.forEach((n) => {
1603
- const { x: a, y: l } = x(n[0], n[1]), d = e + (a - e) * o, h = i + (l - i) * r, { lng: c, lat: u } = W(d, h);
1625
+ const { x: a, y: l } = x(n[0], n[1]), d = e + (a - e) * o, h = i + (l - i) * r, { lng: c, lat: u } = j(d, h);
1604
1626
  n[0] = c, n[1] = u;
1605
1627
  });
1606
1628
  }
@@ -1618,7 +1640,7 @@ class Ii extends j {
1618
1640
  getIndexesWebMercator(t, e) {
1619
1641
  let i, o = 1 / 0;
1620
1642
  for (let r = 0; r < t.length; r++) {
1621
- const n = O({ x: e.x, y: e.y }, { x: t[r][0], y: t[r][1] });
1643
+ const n = E({ x: e.x, y: e.y }, { x: t[r][0], y: t[r][1] });
1622
1644
  n < o && (i = r, o = n);
1623
1645
  }
1624
1646
  if (i === void 0) throw new Error("No closest coordinate found");
@@ -1645,16 +1667,16 @@ class Ii extends j {
1645
1667
  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;
1646
1668
  for (let d = 0; d < r.length; d++) {
1647
1669
  const h = r[d];
1648
- if (h[0] = F(h[0], this.coordinatePrecision), h[1] = F(h[1], this.coordinatePrecision), !St(h, this.coordinatePrecision)) return !1;
1670
+ if (h[0] = w(h[0], this.coordinatePrecision), h[1] = w(h[1], this.coordinatePrecision), !St(h, this.coordinatePrecision)) return !1;
1649
1671
  }
1650
1672
  const n = this.midPoints.getUpdated(r) || [], a = this.selectionPoints.getUpdated(r) || [], l = { type: o.geometry.type, coordinates: o.geometry.type === "Polygon" ? [r] : r };
1651
1673
  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: I.Provisional }).valid || (this.store.updateGeometry([{ id: this.draggedCoordinate.id, geometry: l }, ...a, ...n]), 0));
1652
1674
  }
1653
1675
  }
1654
- const bi = { deselect: "Escape", delete: "Delete", rotate: ["Control", "r"], scale: ["Control", "s"] }, Jt = { pointerOver: "move", dragStart: "move", dragEnd: "move", insertMidpoint: "crosshair" };
1655
- class Le extends Xe {
1676
+ const xi = { deselect: "Escape", delete: "Delete", rotate: ["Control", "r"], scale: ["Control", "s"] }, Jt = { pointerOver: "move", dragStart: "move", dragEnd: "move", insertMidpoint: "crosshair" };
1677
+ class Ee extends Ue {
1656
1678
  constructor(t) {
1657
- super(t, !0), this.mode = "select", this.allowManualDeselection = !0, this.dragEventThrottle = 5, this.dragEventCount = 0, this.selected = [], this.flags = {}, this.keyEvents = bi, this.cursors = Jt, this.validations = {}, 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.updateOptions(t);
1679
+ super(t, !0), this.mode = "select", this.allowManualDeselection = !0, this.dragEventThrottle = 5, this.dragEventCount = 0, this.selected = [], this.flags = {}, this.keyEvents = xi, this.cursors = Jt, this.validations = {}, 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.updateOptions(t);
1658
1680
  }
1659
1681
  updateOptions(t) {
1660
1682
  if (super.updateOptions(t), this.cursors = t && t.cursors ? b({}, this.cursors, t.cursors) : Jt, (t == null ? void 0 : t.keyEvents) === null ? this.keyEvents = { deselect: null, delete: null, rotate: null, scale: null } : t != null && t.keyEvents && (this.keyEvents = b({}, this.keyEvents, t.keyEvents)), (t == null ? void 0 : t.dragEventThrottle) !== void 0 && (this.dragEventThrottle = t.dragEventThrottle), (t == null ? void 0 : t.allowManualDeselection) !== void 0 && (this.allowManualDeselection = t.allowManualDeselection), t != null && t.flags) {
@@ -1673,7 +1695,7 @@ class Le extends Xe {
1673
1695
  this._state = "selecting";
1674
1696
  }
1675
1697
  registerBehaviors(t) {
1676
- this.pixelDistance = new nt(t), this.clickBoundingBox = new rt(t), this.featuresAtMouseEvent = new vi(t, this.clickBoundingBox, this.pixelDistance), this.selectionPoints = new mi(t), this.midPoints = new fi(t, this.selectionPoints), this.rotateFeature = new Si(t, this.selectionPoints, this.midPoints), this.scaleFeature = new xi(t, this.selectionPoints, this.midPoints), this.dragFeature = new Ci(t, this.featuresAtMouseEvent, this.selectionPoints, this.midPoints), this.dragCoordinate = new Pi(t, this.pixelDistance, this.selectionPoints, this.midPoints), this.dragCoordinateResizeFeature = new Ii(t, this.pixelDistance, this.selectionPoints, this.midPoints);
1698
+ this.pixelDistance = new nt(t), this.clickBoundingBox = new rt(t), this.featuresAtMouseEvent = new fi(t, this.clickBoundingBox, this.pixelDistance), this.selectionPoints = new yi(t), this.midPoints = new gi(t, this.selectionPoints), this.rotateFeature = new Ci(t, this.selectionPoints, this.midPoints), this.scaleFeature = new Pi(t, this.selectionPoints, this.midPoints), this.dragFeature = new mi(t, this.featuresAtMouseEvent, this.selectionPoints, this.midPoints), this.dragCoordinate = new vi(t, this.pixelDistance, this.selectionPoints, this.midPoints), this.dragCoordinateResizeFeature = new Si(t, this.pixelDistance, this.selectionPoints, this.midPoints);
1677
1699
  }
1678
1700
  deselectFeature() {
1679
1701
  this.deselect();
@@ -1756,10 +1778,19 @@ class Le extends Xe {
1756
1778
  onDragStart(t, e) {
1757
1779
  if (!this.selected.length) return;
1758
1780
  const i = this.store.getPropertiesCopy(this.selected[0]), o = this.flags[i.mode];
1759
- if (!(o && o.feature && (o.feature.draggable || o.feature.coordinates && o.feature.coordinates.draggable || o.feature.coordinates && o.feature.coordinates.resizable))) return;
1781
+ if (!(o && o.feature && (o.feature.draggable || o.feature.coordinates && o.feature.coordinates.draggable || o.feature.coordinates && o.feature.coordinates.resizable || o.feature.coordinates && typeof o.feature.coordinates.midpoints == "object" && o.feature.coordinates.midpoints.draggable))) return;
1760
1782
  this.dragEventCount = 0;
1761
1783
  const r = this.selected[0], n = this.dragCoordinate.getDraggableIndex(t, r);
1762
- return o && o.feature && o.feature.coordinates && (o.feature.coordinates.draggable || o.feature.coordinates.resizable) && n !== -1 ? (this.setCursor(this.cursors.dragStart), o.feature.coordinates.resizable ? this.dragCoordinateResizeFeature.startDragging(r, n) : this.dragCoordinate.startDragging(r, n), void e(!1)) : o && o.feature && o.feature.draggable && this.dragFeature.canDrag(t, r) ? (this.setCursor(this.cursors.dragStart), this.dragFeature.startDragging(t, r), void e(!1)) : void 0;
1784
+ if (o && o.feature && o.feature.coordinates && (o.feature.coordinates.draggable || o.feature.coordinates.resizable) && n !== -1) return this.setCursor(this.cursors.dragStart), o.feature.coordinates.resizable ? this.dragCoordinateResizeFeature.startDragging(r, n) : this.dragCoordinate.startDragging(r, n), void e(!1);
1785
+ if (o && o.feature && o.feature.coordinates && typeof o.feature.coordinates.midpoints == "object" && o.feature.coordinates.midpoints.draggable) {
1786
+ const { clickedMidPoint: a } = this.featuresAtMouseEvent.find(t, this.selected.length > 0);
1787
+ if (this.selected.length && a) {
1788
+ this.midPoints.insert(a.id, this.coordinatePrecision);
1789
+ const l = this.dragCoordinate.getDraggableIndex(t, r);
1790
+ return this.dragCoordinate.startDragging(r, l), void e(!1);
1791
+ }
1792
+ }
1793
+ return o && o.feature && o.feature.draggable && this.dragFeature.canDrag(t, r) ? (this.setCursor(this.cursors.dragStart), this.dragFeature.startDragging(t, r), void e(!1)) : void 0;
1763
1794
  }
1764
1795
  onDrag(t, e) {
1765
1796
  const i = this.selected[0];
@@ -1808,7 +1839,7 @@ class Le extends Xe {
1808
1839
  return e;
1809
1840
  }
1810
1841
  }
1811
- class Mi extends N {
1842
+ class Ii extends N {
1812
1843
  constructor(...t) {
1813
1844
  super(...t), this.type = $.Static, this.mode = "static";
1814
1845
  }
@@ -1836,11 +1867,11 @@ class Mi extends N {
1836
1867
  return b({}, { polygonFillColor: "#3f97e0", polygonOutlineColor: "#3f97e0", polygonOutlineWidth: 4, polygonFillOpacity: 0.3, pointColor: "#3f97e0", pointOutlineColor: "#ffffff", pointOutlineWidth: 0, pointWidth: 6, lineStringColor: "#3f97e0", lineStringWidth: 4, zIndex: 0 });
1837
1868
  }
1838
1869
  }
1839
- function _e(s, t, e, i, o) {
1870
+ function Oe(s, t, e, i, o) {
1840
1871
  for (; i > e; ) {
1841
1872
  if (i - e > 600) {
1842
1873
  const l = i - e + 1, d = t - e + 1, h = Math.log(l), c = 0.5 * Math.exp(2 * h / 3), u = 0.5 * Math.sqrt(h * c * (l - c) / l) * (d - l / 2 < 0 ? -1 : 1);
1843
- _e(s, t, Math.max(e, Math.floor(t - d * c / l + u)), Math.min(i, Math.floor(t + (l - d) * c / l + u)), o);
1874
+ Oe(s, t, Math.max(e, Math.floor(t - d * c / l + u)), Math.min(i, Math.floor(t + (l - d) * c / l + u)), o);
1844
1875
  }
1845
1876
  const r = s[t];
1846
1877
  let n = e, a = i;
@@ -1869,10 +1900,10 @@ function it(s, t, e, i, o) {
1869
1900
  function ot(s, t) {
1870
1901
  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;
1871
1902
  }
1872
- function wi(s, t) {
1903
+ function bi(s, t) {
1873
1904
  return s.minX - t.minX;
1874
1905
  }
1875
- function Fi(s, t) {
1906
+ function Mi(s, t) {
1876
1907
  return s.minY - t.minY;
1877
1908
  }
1878
1909
  function wt(s) {
@@ -1881,7 +1912,7 @@ function wt(s) {
1881
1912
  function ut(s) {
1882
1913
  return s.maxX - s.minX + (s.maxY - s.minY);
1883
1914
  }
1884
- function Ei(s, t) {
1915
+ function wi(s, t) {
1885
1916
  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);
1886
1917
  return Math.max(0, o - e) * Math.max(0, r - i);
1887
1918
  }
@@ -1899,10 +1930,10 @@ function Zt(s, t, e, i, o) {
1899
1930
  for (; r.length; ) {
1900
1931
  if ((e = r.pop()) - (t = r.pop()) <= i) continue;
1901
1932
  const n = t + Math.ceil((e - t) / i / 2) * i;
1902
- _e(s, n, t, e, o), r.push(t, n, n, e);
1933
+ Oe(s, n, t, e, o), r.push(t, n, n, e);
1903
1934
  }
1904
1935
  }
1905
- class Oi {
1936
+ class Fi {
1906
1937
  constructor(t) {
1907
1938
  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();
1908
1939
  }
@@ -2031,13 +2062,13 @@ class Oi {
2031
2062
  _chooseSplitIndex(t, e, i) {
2032
2063
  let o, r = 1 / 0, n = 1 / 0;
2033
2064
  for (let a = e; a <= i - e; a++) {
2034
- const l = it(t, 0, a, this.toBBox), d = it(t, a, i, this.toBBox), h = Ei(l, d), c = wt(l) + wt(d);
2065
+ const l = it(t, 0, a, this.toBBox), d = it(t, a, i, this.toBBox), h = wi(l, d), c = wt(l) + wt(d);
2035
2066
  h < r ? (r = h, o = a, n = c < n ? c : n) : h === r && c < n && (n = c, o = a);
2036
2067
  }
2037
2068
  return o || i - e;
2038
2069
  }
2039
2070
  _chooseSplitAxis(t, e, i) {
2040
- const o = t.leaf ? this.compareMinX : wi, r = t.leaf ? this.compareMinY : Fi;
2071
+ const o = t.leaf ? this.compareMinX : bi, r = t.leaf ? this.compareMinY : Mi;
2041
2072
  this._allDistMargin(t, e, i, o) < this._allDistMargin(t, e, i, r) && t.children.sort(o);
2042
2073
  }
2043
2074
  _allDistMargin(t, e, i, o) {
@@ -2061,9 +2092,9 @@ class Oi {
2061
2092
  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() : H(t[i], this.toBBox);
2062
2093
  }
2063
2094
  }
2064
- class Di {
2095
+ class Ei {
2065
2096
  constructor(t) {
2066
- this.tree = void 0, this.idToNode = void 0, this.nodeToId = void 0, this.tree = new Oi(t && t.maxEntries ? t.maxEntries : 9), this.idToNode = /* @__PURE__ */ new Map(), this.nodeToId = /* @__PURE__ */ new Map();
2097
+ this.tree = void 0, this.idToNode = void 0, this.nodeToId = void 0, this.tree = new Fi(t && t.maxEntries ? t.maxEntries : 9), this.idToNode = /* @__PURE__ */ new Map(), this.nodeToId = /* @__PURE__ */ new Map();
2067
2098
  }
2068
2099
  setMaps(t, e) {
2069
2100
  this.idToNode.set(t.id, e), this.nodeToId.set(e, t.id);
@@ -2114,14 +2145,14 @@ class Di {
2114
2145
  return this.tree.collides(this.toBBox(t));
2115
2146
  }
2116
2147
  }
2117
- const Li = { getId: () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(s) {
2148
+ const Oi = { getId: () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(s) {
2118
2149
  const t = 16 * Math.random() | 0;
2119
2150
  return (s == "x" ? t : 3 & t | 8).toString(16);
2120
2151
  }), isValidId: (s) => typeof s == "string" && s.length === 36 };
2121
- class _i {
2152
+ class Di {
2122
2153
  constructor(t) {
2123
2154
  this.idStrategy = void 0, this.tracked = void 0, this.spatialIndex = void 0, this.store = void 0, this._onChange = () => {
2124
- }, this.store = {}, this.spatialIndex = new Di(), this.tracked = !t || t.tracked !== !1, this.idStrategy = t && t.idStrategy ? t.idStrategy : Li;
2155
+ }, this.store = {}, this.spatialIndex = new Ei(), this.tracked = !t || t.tracked !== !1, this.idStrategy = t && t.idStrategy ? t.idStrategy : Oi;
2125
2156
  }
2126
2157
  clone(t) {
2127
2158
  return JSON.parse(JSON.stringify(t));
@@ -2218,16 +2249,16 @@ class _i {
2218
2249
  return Object.keys(this.store).length;
2219
2250
  }
2220
2251
  }
2221
- const ki = "Feature is not a Polygon or LineString", Wi = "Feature intersects itself", ji = (s) => s.geometry.type !== "Polygon" && s.geometry.type !== "LineString" ? { valid: !1, reason: ki } : _t(s) ? { valid: !1, reason: Wi } : { valid: !0 };
2252
+ const _i = "Feature is not a Polygon or LineString", Li = "Feature intersects itself", ki = (s) => s.geometry.type !== "Polygon" && s.geometry.type !== "LineString" ? { valid: !1, reason: _i } : _t(s) ? { valid: !1, reason: Li } : { valid: !0 };
2222
2253
  function Qt(s, t, e) {
2223
2254
  const i = T(s, t);
2224
2255
  let o = T(t, e) - i;
2225
2256
  return o < 0 && (o += 360), 180 - Math.abs(o - 90 - 90);
2226
2257
  }
2227
- const Bi = { cancel: "Escape", finish: "Enter" }, Ni = { start: "crosshair", close: "pointer" };
2228
- class ke extends N {
2258
+ const ji = { cancel: "Escape", finish: "Enter" }, Wi = { start: "crosshair", close: "pointer" };
2259
+ class De extends N {
2229
2260
  constructor(t) {
2230
- super(t, !0), this.mode = "angled-rectangle", this.currentCoordinate = 0, this.currentId = void 0, this.keyEvents = Bi, this.cursors = Ni, this.mouseMove = !1, this.updateOptions(t);
2261
+ super(t, !0), this.mode = "angled-rectangle", this.currentCoordinate = 0, this.currentId = void 0, this.keyEvents = ji, this.cursors = Wi, this.mouseMove = !1, this.updateOptions(t);
2231
2262
  }
2232
2263
  updateOptions(t) {
2233
2264
  super.updateOptions(t), t != null && t.cursors && (this.cursors = b({}, this.cursors, t.cursors)), (t == null ? void 0 : t.keyEvents) === null ? this.keyEvents = { cancel: null, finish: null } : t != null && t.keyEvents && (this.keyEvents = b({}, this.keyEvents, t.keyEvents));
@@ -2251,10 +2282,10 @@ class ke extends N {
2251
2282
  const o = 1 / Math.pow(10, this.coordinatePrecision - 1), r = Math.max(1e-6, o);
2252
2283
  i = [e[0], [t.lng, t.lat], [t.lng, t.lat - r], e[0]];
2253
2284
  } else if (this.currentCoordinate === 2) {
2254
- const o = e[0], r = e[1], n = Fe(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]), h = x(t.lng, t.lat), c = O(h, a) < O(h, d), u = Qt(a, l, h), p = c ? 90 - u : Qt(a, l, h) - 90, g = O(l, h), y = Math.cos(E(p)) * g, v = T(a, d) + (function(S, M, w) {
2255
- const D = (w.x - M.x) * (S.y - M.y) - (w.y - M.y) * (S.x - M.x);
2285
+ const o = e[0], r = e[1], n = be(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]), h = x(t.lng, t.lat), c = E(h, a) < E(h, d), u = Qt(a, l, h), p = c ? 90 - u : Qt(a, l, h) - 90, y = E(l, h), g = Math.cos(O(p)) * y, v = T(a, d) + (function(S, M, F) {
2286
+ const D = (F.x - M.x) * (S.y - M.y) - (F.y - M.y) * (S.x - M.x);
2256
2287
  return D > 1e-10 ? "left" : D < -1e-10 ? "right" : "left";
2257
- }(a, d, h) === "right" ? -90 : 90), f = at(a, y, v), m = at(d, y, v), C = W(f.x, f.y), P = W(m.x, m.y);
2288
+ }(a, d, h) === "right" ? -90 : 90), f = at(a, g, v), m = at(d, g, v), C = j(f.x, f.y), P = j(m.x, m.y);
2258
2289
  i = [e[0], e[1], [P.lng, P.lat], [C.lng, C.lat], e[0]];
2259
2290
  }
2260
2291
  i && this.updatePolygonGeometry(this.currentId, i, I.Provisional);
@@ -2303,13 +2334,13 @@ class ke extends N {
2303
2334
  return this.validateModeFeature(t, (e) => lt(e, this.coordinatePrecision));
2304
2335
  }
2305
2336
  }
2306
- function We(s, t, e) {
2337
+ function _e(s, t, e) {
2307
2338
  return (t.x - s.x) * (e.y - s.y) - (t.y - s.y) * (e.x - s.x) <= 0;
2308
2339
  }
2309
- const Gi = { cancel: "Escape", finish: "Enter" }, Ti = { start: "crosshair", close: "pointer" };
2310
- class je extends N {
2340
+ const Bi = { cancel: "Escape", finish: "Enter" }, Ni = { start: "crosshair", close: "pointer" };
2341
+ class Le extends N {
2311
2342
  constructor(t) {
2312
- super(t, !0), this.mode = "sector", this.currentCoordinate = 0, this.currentId = void 0, this.keyEvents = Gi, this.direction = void 0, this.arcPoints = 64, this.cursors = Ti, this.mouseMove = !1, this.updateOptions(t);
2343
+ super(t, !0), this.mode = "sector", this.currentCoordinate = 0, this.currentId = void 0, this.keyEvents = Bi, this.direction = void 0, this.arcPoints = 64, this.cursors = Ni, this.mouseMove = !1, this.updateOptions(t);
2313
2344
  }
2314
2345
  updateOptions(t) {
2315
2346
  super.updateOptions(t), t != null && t.cursors && (this.cursors = b({}, this.cursors, t.cursors)), (t == null ? void 0 : t.keyEvents) === null ? this.keyEvents = { cancel: null, finish: null } : t != null && t.keyEvents && (this.keyEvents = b({}, this.keyEvents, t.keyEvents)), t != null && t.arcPoints && (this.arcPoints = t.arcPoints);
@@ -2337,19 +2368,19 @@ class je extends N {
2337
2368
  } else if (this.currentCoordinate === 2) {
2338
2369
  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]);
2339
2370
  if (this.direction === void 0) {
2340
- const C = We(a, l, d);
2371
+ const C = _e(a, l, d);
2341
2372
  this.direction = C ? "clockwise" : "anticlockwise";
2342
2373
  }
2343
- const h = O(a, l), c = T(a, l), u = T(a, d), p = this.arcPoints, g = [o], y = Y(c), v = Y(u);
2374
+ const h = E(a, l), c = T(a, l), u = T(a, d), p = this.arcPoints, y = [o], g = Y(c), v = Y(u);
2344
2375
  let f;
2345
- this.direction === "anticlockwise" ? (f = v - y, f < 0 && (f += 360)) : (f = y - v, f < 0 && (f += 360));
2376
+ this.direction === "anticlockwise" ? (f = v - g, f < 0 && (f += 360)) : (f = g - v, f < 0 && (f += 360));
2346
2377
  const m = (this.direction === "anticlockwise" ? 1 : -1) * f / p;
2347
- g.push(r);
2378
+ y.push(r);
2348
2379
  for (let C = 0; C <= p; C++) {
2349
- const P = at(a, h, y + C * m), { lng: S, lat: M } = W(P.x, P.y), w = [F(S, this.coordinatePrecision), F(M, this.coordinatePrecision)];
2350
- w[0] !== g[g.length - 1][0] && w[1] !== g[g.length - 1][1] && g.push(w);
2380
+ const P = at(a, h, g + C * m), { lng: S, lat: M } = j(P.x, P.y), F = [w(S, this.coordinatePrecision), w(M, this.coordinatePrecision)];
2381
+ F[0] !== y[y.length - 1][0] && F[1] !== y[y.length - 1][1] && y.push(F);
2351
2382
  }
2352
- g.push(o), i = [...g];
2383
+ y.push(o), i = [...y];
2353
2384
  }
2354
2385
  i && this.updatePolygonGeometry(this.currentId, i, I.Provisional);
2355
2386
  }
@@ -2393,10 +2424,10 @@ class je extends N {
2393
2424
  return this.validateModeFeature(t, (e) => lt(e, this.coordinatePrecision));
2394
2425
  }
2395
2426
  }
2396
- const Ai = { cancel: "Escape", finish: "Enter" }, Vi = { start: "crosshair", close: "pointer" };
2397
- class Be extends N {
2427
+ const Gi = { cancel: "Escape", finish: "Enter" }, Ti = { start: "crosshair", close: "pointer" };
2428
+ class ke extends N {
2398
2429
  constructor(t) {
2399
- super(t, !0), this.mode = "sensor", this.currentCoordinate = 0, this.currentId = void 0, this.currentInitialArcId = void 0, this.currentStartingPointId = void 0, this.keyEvents = Ai, this.direction = void 0, this.arcPoints = 64, this.cursors = Vi, this.mouseMove = !1, this.updateOptions(t);
2430
+ super(t, !0), this.mode = "sensor", this.currentCoordinate = 0, this.currentId = void 0, this.currentInitialArcId = void 0, this.currentStartingPointId = void 0, this.keyEvents = Gi, this.direction = void 0, this.arcPoints = 64, this.cursors = Ti, this.mouseMove = !1, this.updateOptions(t);
2400
2431
  }
2401
2432
  updateOptions(t) {
2402
2433
  super.updateOptions(t), t != null && t.cursors && (this.cursors = b({}, this.cursors, t.cursors)), (t == null ? void 0 : t.keyEvents) === null ? this.keyEvents = { cancel: null, finish: null } : t != null && t.keyEvents && (this.keyEvents = b({}, this.keyEvents, t.keyEvents)), t != null && t.arcPoints && (this.arcPoints = t.arcPoints);
@@ -2419,28 +2450,28 @@ class Be extends N {
2419
2450
  onMouseMove(t) {
2420
2451
  if (this.mouseMove = !0, this.setCursor(this.cursors.start), this.currentInitialArcId !== void 0 && this.currentStartingPointId !== void 0 && this.currentCoordinate !== 0) {
2421
2452
  if (this.currentCoordinate === 2) {
2422
- 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 = O(l, n);
2453
+ 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 = E(l, n);
2423
2454
  if (this.direction === void 0) {
2424
- const m = We(l, n, a);
2455
+ const m = _e(l, n, a);
2425
2456
  this.direction = m ? "clockwise" : "anticlockwise";
2426
2457
  }
2427
- const h = T(l, n), c = T(l, a), u = this.arcPoints, p = [o], g = Y(h), y = Y(c);
2458
+ const h = T(l, n), c = T(l, a), u = this.arcPoints, p = [o], y = Y(h), g = Y(c);
2428
2459
  let v;
2429
- this.direction === "anticlockwise" ? (v = y - g, v < 0 && (v += 360)) : (v = g - y, v < 0 && (v += 360));
2460
+ this.direction === "anticlockwise" ? (v = g - y, v < 0 && (v += 360)) : (v = y - g, v < 0 && (v += 360));
2430
2461
  const f = (this.direction === "anticlockwise" ? 1 : -1) * v / u;
2431
2462
  for (let m = 0; m <= u; m++) {
2432
- const C = at(l, d, g + m * f), { lng: P, lat: S } = W(C.x, C.y), M = [F(P, this.coordinatePrecision), F(S, this.coordinatePrecision)];
2463
+ const C = at(l, d, y + m * f), { lng: P, lat: S } = j(C.x, C.y), M = [w(P, this.coordinatePrecision), w(S, this.coordinatePrecision)];
2433
2464
  M[0] !== p[p.length - 1][0] && M[1] !== p[p.length - 1][1] && p.push(M);
2434
2465
  }
2435
2466
  this.updateLineStringGeometry(this.currentInitialArcId, p, I.Provisional);
2436
2467
  } else if (this.currentCoordinate === 3) {
2437
2468
  const e = this.store.getGeometryCopy(this.currentInitialArcId).coordinates;
2438
2469
  if (e.length < 2 || !this.direction) return;
2439
- 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]), h = O(d, a), c = O(d, n) < h ? a : n, u = T(d, n), p = T(d, a), g = T(d, l), y = Y(p), v = Y(g), f = Y(u);
2440
- if (this.notInSector({ normalizedCursor: f, normalizedStart: y, normalizedEnd: v, direction: this.direction })) return;
2441
- const m = this.getDeltaBearing(this.direction, y, v), C = this.arcPoints, P = (this.direction === "anticlockwise" ? 1 : -1) * m / C, S = O(d, c), M = [];
2442
- for (let w = 0; w <= C; w++) {
2443
- const D = at(d, S, y + w * P), { lng: G, lat: L } = W(D.x, D.y), B = [F(G, this.coordinatePrecision), F(L, this.coordinatePrecision)];
2470
+ 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]), h = E(d, a), c = E(d, n) < h ? a : n, u = T(d, n), p = T(d, a), y = T(d, l), g = Y(p), v = Y(y), f = Y(u);
2471
+ if (this.notInSector({ normalizedCursor: f, normalizedStart: g, normalizedEnd: v, direction: this.direction })) return;
2472
+ const m = this.getDeltaBearing(this.direction, g, v), C = this.arcPoints, P = (this.direction === "anticlockwise" ? 1 : -1) * m / C, S = E(d, c), M = [];
2473
+ for (let F = 0; F <= C; F++) {
2474
+ const D = at(d, S, g + F * P), { lng: G, lat: _ } = j(D.x, D.y), B = [w(G, this.coordinatePrecision), w(_, this.coordinatePrecision)];
2444
2475
  B[0] !== e[e.length - 1][0] && B[1] !== e[e.length - 1][1] && M.unshift(B);
2445
2476
  }
2446
2477
  e.push(...M), e.push(e[0]), this.currentId ? this.updatePolygonGeometry(this.currentId, e, I.Provisional) : [this.currentId] = this.store.create([{ geometry: { type: "Polygon", coordinates: [e] }, properties: { mode: this.mode } }]);
@@ -2497,9 +2528,108 @@ class Be extends N {
2497
2528
  return o === "clockwise" ? e <= i ? t >= e && t <= i : t >= e || t <= i : e >= i ? t <= e && t >= i : t <= e || t >= i;
2498
2529
  }
2499
2530
  }
2500
- class Ui {
2531
+ class q {
2532
+ constructor({ name: t, callback: e, unregister: i, register: o }) {
2533
+ this.name = void 0, this.callback = void 0, this.registered = !1, this.register = void 0, this.unregister = void 0, this.name = t, this.register = () => {
2534
+ this.registered || (this.registered = !0, o(e));
2535
+ }, this.unregister = () => {
2536
+ this.register && (this.registered = !1, i(e));
2537
+ }, this.callback = e;
2538
+ }
2539
+ }
2540
+ var Ai = { __proto__: null, TerraDrawBaseAdapter: class {
2541
+ constructor(s) {
2542
+ 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 s.minPixelDragDistance == "number" ? s.minPixelDragDistance : 1, this._minPixelDragDistanceSelecting = typeof s.minPixelDragDistanceSelecting == "number" ? s.minPixelDragDistanceSelecting : 1, this._minPixelDragDistanceDrawing = typeof s.minPixelDragDistanceDrawing == "number" ? s.minPixelDragDistanceDrawing : 8, this._coordinatePrecision = typeof s.coordinatePrecision == "number" ? s.coordinatePrecision : 9;
2543
+ }
2544
+ getButton(s) {
2545
+ return s.button === -1 ? "neither" : s.button === 0 ? "left" : s.button === 1 ? "middle" : s.button === 2 ? "right" : "neither";
2546
+ }
2547
+ getMapElementXYPosition(s) {
2548
+ const t = this.getMapEventElement(), { left: e, top: i } = t.getBoundingClientRect();
2549
+ return { containerX: s.clientX - e, containerY: s.clientY - i };
2550
+ }
2551
+ getDrawEventFromEvent(s) {
2552
+ const t = this.getLngLatFromEvent(s);
2553
+ if (!t) return null;
2554
+ const { lng: e, lat: i } = t, { containerX: o, containerY: r } = this.getMapElementXYPosition(s), n = this.getButton(s), a = Array.from(this._heldKeys);
2555
+ return { lng: w(e, this._coordinatePrecision), lat: w(i, this._coordinatePrecision), containerX: o, containerY: r, button: n, heldKeys: a };
2556
+ }
2557
+ register(s) {
2558
+ this._currentModeCallbacks = s, this._listeners = this.getAdapterListeners(), this._listeners.forEach((t) => {
2559
+ t.register();
2560
+ });
2561
+ }
2562
+ getCoordinatePrecision() {
2563
+ return this._coordinatePrecision;
2564
+ }
2565
+ getAdapterListeners() {
2566
+ return [new q({ name: "pointerdown", callback: (s) => {
2567
+ if (!this._currentModeCallbacks || !s.isPrimary) return;
2568
+ const t = this.getDrawEventFromEvent(s);
2569
+ t && (this._dragState = "pre-dragging", this._lastDrawEvent = t);
2570
+ }, register: (s) => {
2571
+ this.getMapEventElement().addEventListener("pointerdown", s);
2572
+ }, unregister: (s) => {
2573
+ this.getMapEventElement().removeEventListener("pointerdown", s);
2574
+ } }), new q({ name: "pointermove", callback: (s) => {
2575
+ if (!this._currentModeCallbacks || !s.isPrimary) return;
2576
+ s.preventDefault();
2577
+ const t = this.getDrawEventFromEvent(s);
2578
+ if (t) if (this._dragState === "not-dragging") this._currentModeCallbacks.onMouseMove(t), this._lastDrawEvent = t;
2579
+ else if (this._dragState === "pre-dragging") {
2580
+ if (!this._lastDrawEvent) return;
2581
+ const e = { x: this._lastDrawEvent.containerX, y: this._lastDrawEvent.containerY }, i = { x: t.containerX, y: t.containerY }, o = this._currentModeCallbacks.getState(), r = E(e, i);
2582
+ let n = !1;
2583
+ if (n = o === "drawing" ? r < this._minPixelDragDistanceDrawing : o === "selecting" ? r < this._minPixelDragDistanceSelecting : r < this._minPixelDragDistance, n) return;
2584
+ this._dragState = "dragging", this._currentModeCallbacks.onDragStart(t, (a) => {
2585
+ this.setDraggability.bind(this)(a);
2586
+ });
2587
+ } else this._dragState === "dragging" && this._currentModeCallbacks.onDrag(t, (e) => {
2588
+ this.setDraggability.bind(this)(e);
2589
+ });
2590
+ }, register: (s) => {
2591
+ this.getMapEventElement().addEventListener("pointermove", s);
2592
+ }, unregister: (s) => {
2593
+ this.getMapEventElement().removeEventListener("pointermove", s);
2594
+ } }), new q({ name: "contextmenu", callback: (s) => {
2595
+ this._currentModeCallbacks && s.preventDefault();
2596
+ }, register: (s) => {
2597
+ this.getMapEventElement().addEventListener("contextmenu", s);
2598
+ }, unregister: (s) => {
2599
+ this.getMapEventElement().removeEventListener("contextmenu", s);
2600
+ } }), new q({ name: "pointerup", callback: (s) => {
2601
+ if (!this._currentModeCallbacks || s.target !== this.getMapEventElement() || !s.isPrimary) return;
2602
+ const t = this.getDrawEventFromEvent(s);
2603
+ t && (this._dragState === "dragging" ? this._currentModeCallbacks.onDragEnd(t, (e) => {
2604
+ this.setDraggability.bind(this)(e);
2605
+ }) : this._dragState !== "not-dragging" && this._dragState !== "pre-dragging" || this._currentModeCallbacks.onClick(t), this._dragState = "not-dragging", this.setDraggability(!0));
2606
+ }, register: (s) => {
2607
+ this.getMapEventElement().addEventListener("pointerup", s);
2608
+ }, unregister: (s) => {
2609
+ this.getMapEventElement().removeEventListener("pointerup", s);
2610
+ } }), new q({ name: "keyup", callback: (s) => {
2611
+ this._currentModeCallbacks && (this._heldKeys.delete(s.key), this._currentModeCallbacks.onKeyUp({ key: s.key, heldKeys: Array.from(this._heldKeys), preventDefault: () => s.preventDefault() }));
2612
+ }, register: (s) => {
2613
+ this.getMapEventElement().addEventListener("keyup", s);
2614
+ }, unregister: (s) => {
2615
+ this.getMapEventElement().removeEventListener("keyup", s);
2616
+ } }), new q({ name: "keydown", callback: (s) => {
2617
+ this._currentModeCallbacks && (this._heldKeys.add(s.key), this._currentModeCallbacks.onKeyDown({ key: s.key, heldKeys: Array.from(this._heldKeys), preventDefault: () => s.preventDefault() }));
2618
+ }, register: (s) => {
2619
+ this.getMapEventElement().addEventListener("keydown", s);
2620
+ }, unregister: (s) => {
2621
+ this.getMapEventElement().removeEventListener("keydown", s);
2622
+ } })];
2623
+ }
2624
+ unregister() {
2625
+ this._listeners.forEach((s) => {
2626
+ s.unregister();
2627
+ }), this.clear();
2628
+ }
2629
+ } };
2630
+ class Vi {
2501
2631
  constructor(t) {
2502
- 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 Mi();
2632
+ 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();
2503
2633
  const e = /* @__PURE__ */ new Set(), i = t.modes.reduce((h, c) => {
2504
2634
  if (e.has(c.mode)) throw new Error(`There is already a ${c.mode} mode provided`);
2505
2635
  return e.add(c.mode), h[c.mode] = c, h;
@@ -2510,7 +2640,7 @@ class Ui {
2510
2640
  if (this._instanceSelectMode) throw new Error("only one type of select mode can be provided");
2511
2641
  this._instanceSelectMode = h;
2512
2642
  }
2513
- }), this._modes = b({}, i, { static: this._mode }), this._eventListeners = { change: [], select: [], deselect: [], finish: [], ready: [] }, this._store = new _i({ tracked: !!t.tracked, idStrategy: t.idStrategy ? t.idStrategy : void 0 });
2643
+ }), this._modes = b({}, 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 });
2514
2644
  const r = (h) => {
2515
2645
  const c = [], u = this._store.copyAll().filter((p) => !h.includes(p.id) || (c.push(p), !1));
2516
2646
  return { changed: c, unchanged: u };
@@ -2520,8 +2650,8 @@ class Ui {
2520
2650
  });
2521
2651
  }, a = (h, c) => {
2522
2652
  if (!this._enabled) return;
2523
- this._eventListeners.change.forEach((g) => {
2524
- g(h, c);
2653
+ this._eventListeners.change.forEach((y) => {
2654
+ y(h, c);
2525
2655
  });
2526
2656
  const { changed: u, unchanged: p } = r(h);
2527
2657
  c === "create" ? this._adapter.render({ created: u, deletedIds: [], unchanged: p, updated: [] }, this.getModeStyles()) : c === "update" ? this._adapter.render({ created: [], deletedIds: [], unchanged: p, updated: u }, this.getModeStyles()) : c === "delete" ? this._adapter.render({ created: [], deletedIds: h, unchanged: p, updated: [] }, this.getModeStyles()) : c === "styling" && this._adapter.render({ created: [], deletedIds: [], unchanged: p, updated: [] }, this.getModeStyles());
@@ -2554,22 +2684,22 @@ class Ui {
2554
2684
  }), t;
2555
2685
  }
2556
2686
  featuresAtLocation({ lng: t, lat: e }, i) {
2557
- 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 = Ce({ unproject: n, point: l, pointerDistance: o });
2687
+ 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 = fe({ unproject: n, point: l, pointerDistance: o });
2558
2688
  return this._store.search(d).filter((h) => {
2559
2689
  if (r && (h.properties[U.MID_POINT] || h.properties[U.SELECTION_POINT])) return !1;
2560
2690
  if (h.geometry.type === "Point") {
2561
2691
  const c = h.geometry.coordinates, u = a(c[0], c[1]);
2562
- return O(l, u) < o;
2692
+ return E(l, u) < o;
2563
2693
  }
2564
2694
  if (h.geometry.type === "LineString") {
2565
2695
  const c = h.geometry.coordinates;
2566
2696
  for (let u = 0; u < c.length - 1; u++) {
2567
- const p = c[u], g = c[u + 1];
2568
- if (Oe(l, a(p[0], p[1]), a(g[0], g[1])) < o) return !0;
2697
+ const p = c[u], y = c[u + 1];
2698
+ if (we(l, a(p[0], p[1]), a(y[0], y[1])) < o) return !0;
2569
2699
  }
2570
2700
  return !1;
2571
2701
  }
2572
- return !!Ee([t, e], h.geometry.coordinates) || void 0;
2702
+ return !!Me([t, e], h.geometry.coordinates) || void 0;
2573
2703
  });
2574
2704
  }
2575
2705
  getSelectMode() {
@@ -2677,119 +2807,9 @@ class Ui {
2677
2807
  i.includes(e) && i.splice(i.indexOf(e), 1);
2678
2808
  }
2679
2809
  }
2680
- var te, Et, ee;
2681
- function ie(s, t = 9) {
2682
- const e = Math.pow(10, t);
2683
- return Math.round(s * e) / e;
2684
- }
2685
- (Et = te || (te = {})).Commit = "commit", Et.Provisional = "provisional", Et.Finish = "finish", function(s) {
2686
- s.Drawing = "drawing", s.Select = "select", s.Static = "static", s.Render = "render";
2687
- }(ee || (ee = {}));
2688
- class q {
2689
- constructor({ name: t, callback: e, unregister: i, register: o }) {
2690
- this.name = void 0, this.callback = void 0, this.registered = !1, this.register = void 0, this.unregister = void 0, this.name = t, this.register = () => {
2691
- this.registered || (this.registered = !0, o(e));
2692
- }, this.unregister = () => {
2693
- this.register && (this.registered = !1, i(e));
2694
- }, this.callback = e;
2695
- }
2696
- }
2697
- var zi = class {
2698
- constructor(s) {
2699
- 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 s.minPixelDragDistance == "number" ? s.minPixelDragDistance : 1, this._minPixelDragDistanceSelecting = typeof s.minPixelDragDistanceSelecting == "number" ? s.minPixelDragDistanceSelecting : 1, this._minPixelDragDistanceDrawing = typeof s.minPixelDragDistanceDrawing == "number" ? s.minPixelDragDistanceDrawing : 8, this._coordinatePrecision = typeof s.coordinatePrecision == "number" ? s.coordinatePrecision : 9;
2700
- }
2701
- getButton(s) {
2702
- return s.button === -1 ? "neither" : s.button === 0 ? "left" : s.button === 1 ? "middle" : s.button === 2 ? "right" : "neither";
2703
- }
2704
- getMapElementXYPosition(s) {
2705
- const t = this.getMapEventElement(), { left: e, top: i } = t.getBoundingClientRect();
2706
- return { containerX: s.clientX - e, containerY: s.clientY - i };
2707
- }
2708
- getDrawEventFromEvent(s) {
2709
- const t = this.getLngLatFromEvent(s);
2710
- if (!t) return null;
2711
- const { lng: e, lat: i } = t, { containerX: o, containerY: r } = this.getMapElementXYPosition(s), n = this.getButton(s), a = Array.from(this._heldKeys);
2712
- return { lng: ie(e, this._coordinatePrecision), lat: ie(i, this._coordinatePrecision), containerX: o, containerY: r, button: n, heldKeys: a };
2713
- }
2714
- register(s) {
2715
- this._currentModeCallbacks = s, this._listeners = this.getAdapterListeners(), this._listeners.forEach((t) => {
2716
- t.register();
2717
- });
2718
- }
2719
- getCoordinatePrecision() {
2720
- return this._coordinatePrecision;
2721
- }
2722
- getAdapterListeners() {
2723
- return [new q({ name: "pointerdown", callback: (s) => {
2724
- if (!this._currentModeCallbacks || !s.isPrimary) return;
2725
- const t = this.getDrawEventFromEvent(s);
2726
- t && (this._dragState = "pre-dragging", this._lastDrawEvent = t);
2727
- }, register: (s) => {
2728
- this.getMapEventElement().addEventListener("pointerdown", s);
2729
- }, unregister: (s) => {
2730
- this.getMapEventElement().removeEventListener("pointerdown", s);
2731
- } }), new q({ name: "pointermove", callback: (s) => {
2732
- if (!this._currentModeCallbacks || !s.isPrimary) return;
2733
- s.preventDefault();
2734
- const t = this.getDrawEventFromEvent(s);
2735
- if (t) if (this._dragState === "not-dragging") this._currentModeCallbacks.onMouseMove(t), this._lastDrawEvent = t;
2736
- else if (this._dragState === "pre-dragging") {
2737
- if (!this._lastDrawEvent) return;
2738
- const e = { x: this._lastDrawEvent.containerX, y: this._lastDrawEvent.containerY }, i = { x: t.containerX, y: t.containerY }, o = this._currentModeCallbacks.getState(), r = ((a, l) => {
2739
- const { x: d, y: h } = a, { x: c, y: u } = l, p = c - d, g = u - h;
2740
- return Math.sqrt(g * g + p * p);
2741
- })(e, i);
2742
- let n = !1;
2743
- if (n = o === "drawing" ? r < this._minPixelDragDistanceDrawing : o === "selecting" ? r < this._minPixelDragDistanceSelecting : r < this._minPixelDragDistance, n) return;
2744
- this._dragState = "dragging", this._currentModeCallbacks.onDragStart(t, (a) => {
2745
- this.setDraggability.bind(this)(a);
2746
- });
2747
- } else this._dragState === "dragging" && this._currentModeCallbacks.onDrag(t, (e) => {
2748
- this.setDraggability.bind(this)(e);
2749
- });
2750
- }, register: (s) => {
2751
- this.getMapEventElement().addEventListener("pointermove", s);
2752
- }, unregister: (s) => {
2753
- this.getMapEventElement().removeEventListener("pointermove", s);
2754
- } }), new q({ name: "contextmenu", callback: (s) => {
2755
- this._currentModeCallbacks && s.preventDefault();
2756
- }, register: (s) => {
2757
- this.getMapEventElement().addEventListener("contextmenu", s);
2758
- }, unregister: (s) => {
2759
- this.getMapEventElement().removeEventListener("contextmenu", s);
2760
- } }), new q({ name: "pointerup", callback: (s) => {
2761
- if (!this._currentModeCallbacks || s.target !== this.getMapEventElement() || !s.isPrimary) return;
2762
- const t = this.getDrawEventFromEvent(s);
2763
- t && (this._dragState === "dragging" ? this._currentModeCallbacks.onDragEnd(t, (e) => {
2764
- this.setDraggability.bind(this)(e);
2765
- }) : this._dragState !== "not-dragging" && this._dragState !== "pre-dragging" || this._currentModeCallbacks.onClick(t), this._dragState = "not-dragging", this.setDraggability(!0));
2766
- }, register: (s) => {
2767
- this.getMapEventElement().addEventListener("pointerup", s);
2768
- }, unregister: (s) => {
2769
- this.getMapEventElement().removeEventListener("pointerup", s);
2770
- } }), new q({ name: "keyup", callback: (s) => {
2771
- this._currentModeCallbacks && (this._heldKeys.delete(s.key), this._currentModeCallbacks.onKeyUp({ key: s.key, heldKeys: Array.from(this._heldKeys), preventDefault: () => s.preventDefault() }));
2772
- }, register: (s) => {
2773
- this.getMapEventElement().addEventListener("keyup", s);
2774
- }, unregister: (s) => {
2775
- this.getMapEventElement().removeEventListener("keyup", s);
2776
- } }), new q({ name: "keydown", callback: (s) => {
2777
- this._currentModeCallbacks && (this._heldKeys.add(s.key), this._currentModeCallbacks.onKeyDown({ key: s.key, heldKeys: Array.from(this._heldKeys), preventDefault: () => s.preventDefault() }));
2778
- }, register: (s) => {
2779
- this.getMapEventElement().addEventListener("keydown", s);
2780
- }, unregister: (s) => {
2781
- this.getMapEventElement().removeEventListener("keydown", s);
2782
- } })];
2783
- }
2784
- unregister() {
2785
- this._listeners.forEach((s) => {
2786
- s.unregister();
2787
- }), this.clear();
2788
- }
2789
- };
2790
- class Ri extends zi {
2810
+ class Ui extends Ai.TerraDrawBaseAdapter {
2791
2811
  constructor(t) {
2792
- 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();
2812
+ super(t), this._initialDragPan = void 0, this._initialDragRotate = void 0, 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(), this._initialDragRotate = this._map.dragRotate.isEnabled(), this._initialDragPan = this._map.dragPan.isEnabled();
2793
2813
  }
2794
2814
  clearLayers() {
2795
2815
  this._rendered && (["point", "linestring", "polygon"].forEach((t) => {
@@ -2836,7 +2856,7 @@ class Ri extends zi {
2836
2856
  return this._map.getCanvas();
2837
2857
  }
2838
2858
  setDraggability(t) {
2839
- t ? (this._map.dragRotate.enable(), this._map.dragPan.enable()) : (this._map.dragRotate.disable(), this._map.dragPan.disable());
2859
+ t ? (this._initialDragRotate && this._map.dragRotate.enable(), this._initialDragPan && this._map.dragPan.enable()) : (this._initialDragRotate && this._map.dragRotate.disable(), this._initialDragPan && this._map.dragPan.disable());
2840
2860
  }
2841
2861
  project(t, e) {
2842
2862
  const { x: i, y: o } = this._map.project({ lng: t, lat: e });
@@ -2885,7 +2905,7 @@ class Ri extends zi {
2885
2905
  super.register(t), (e = this._currentModeCallbacks) != null && e.onReady && this._currentModeCallbacks.onReady();
2886
2906
  }
2887
2907
  }
2888
- const Lo = [
2908
+ const Eo = [
2889
2909
  "render",
2890
2910
  "point",
2891
2911
  "linestring",
@@ -2900,7 +2920,7 @@ const Lo = [
2900
2920
  "delete-selection",
2901
2921
  "delete",
2902
2922
  "download"
2903
- ], Xi = {
2923
+ ], Ri = {
2904
2924
  modes: [
2905
2925
  "render",
2906
2926
  "point",
@@ -2938,96 +2958,96 @@ const Lo = [
2938
2958
  open: !1,
2939
2959
  // see styling parameters of Terra Draw at https://github.com/JamesLMilner/terra-draw/blob/main/guides/5.STYLING.md
2940
2960
  modeOptions: {
2941
- point: new be({
2961
+ point: new Se({
2942
2962
  editable: !0,
2943
2963
  styles: {
2944
2964
  pointColor: "#FFFFFF",
2945
2965
  pointWidth: 5,
2946
- pointOutlineColor: "#232E3D",
2966
+ pointOutlineColor: "#666666",
2947
2967
  pointOutlineWidth: 1
2948
2968
  }
2949
2969
  }),
2950
- linestring: new xe({
2970
+ linestring: new Ce({
2951
2971
  editable: !0,
2952
2972
  styles: {
2953
- lineStringColor: "#232E3D",
2973
+ lineStringColor: "#666666",
2954
2974
  lineStringWidth: 2,
2955
2975
  closingPointColor: "#FFFFFF",
2956
2976
  closingPointWidth: 3,
2957
- closingPointOutlineColor: "#232E3D",
2977
+ closingPointOutlineColor: "#666666",
2958
2978
  closingPointOutlineWidth: 1
2959
2979
  }
2960
2980
  }),
2961
- polygon: new Me({
2981
+ polygon: new xe({
2962
2982
  editable: !0,
2963
2983
  styles: {
2964
2984
  fillColor: "#EDEFF0",
2965
2985
  fillOpacity: 0.7,
2966
- outlineColor: "#232E3D",
2986
+ outlineColor: "#666666",
2967
2987
  outlineWidth: 2,
2968
2988
  closingPointColor: "#FAFAFA",
2969
2989
  closingPointWidth: 3,
2970
- closingPointOutlineColor: "#232E3D",
2990
+ closingPointOutlineColor: "#666666",
2971
2991
  closingPointOutlineWidth: 1
2972
2992
  }
2973
2993
  }),
2974
- rectangle: new we({
2994
+ rectangle: new Ie({
2975
2995
  styles: {
2976
2996
  fillColor: "#EDEFF0",
2977
2997
  fillOpacity: 0.7,
2978
- outlineColor: "#232E3D",
2998
+ outlineColor: "#666666",
2979
2999
  outlineWidth: 2
2980
3000
  }
2981
3001
  }),
2982
- "angled-rectangle": new ke({
3002
+ "angled-rectangle": new De({
2983
3003
  styles: {
2984
3004
  fillColor: "#EDEFF0",
2985
3005
  fillOpacity: 0.7,
2986
- outlineColor: "#232E3D",
3006
+ outlineColor: "#666666",
2987
3007
  outlineWidth: 2
2988
3008
  }
2989
3009
  }),
2990
- circle: new me({
3010
+ circle: new ge({
2991
3011
  styles: {
2992
3012
  fillColor: "#EDEFF0",
2993
3013
  fillOpacity: 0.7,
2994
- outlineColor: "#232E3D",
3014
+ outlineColor: "#666666",
2995
3015
  outlineWidth: 2
2996
3016
  }
2997
3017
  }),
2998
- freehand: new ve({
3018
+ freehand: new ye({
2999
3019
  styles: {
3000
3020
  fillColor: "#EDEFF0",
3001
3021
  fillOpacity: 0.7,
3002
- outlineColor: "#232E3D",
3022
+ outlineColor: "#666666",
3003
3023
  outlineWidth: 2,
3004
3024
  closingPointColor: "#FAFAFA",
3005
3025
  closingPointWidth: 3,
3006
- closingPointOutlineColor: "#232E3D",
3026
+ closingPointOutlineColor: "#666666",
3007
3027
  closingPointOutlineWidth: 1
3008
3028
  }
3009
3029
  }),
3010
- sensor: new Be({
3030
+ sensor: new ke({
3011
3031
  styles: {
3012
3032
  fillColor: "#EDEFF0",
3013
3033
  fillOpacity: 0.7,
3014
- outlineColor: "#232E3D",
3034
+ outlineColor: "#666666",
3015
3035
  outlineWidth: 2,
3016
3036
  centerPointColor: "#FAFAFA",
3017
3037
  centerPointWidth: 3,
3018
- centerPointOutlineColor: "#232E3D",
3038
+ centerPointOutlineColor: "#666666",
3019
3039
  centerPointOutlineWidth: 1
3020
3040
  }
3021
3041
  }),
3022
- sector: new je({
3042
+ sector: new Le({
3023
3043
  styles: {
3024
3044
  fillColor: "#EDEFF0",
3025
3045
  fillOpacity: 0.7,
3026
- outlineColor: "#232E3D",
3046
+ outlineColor: "#666666",
3027
3047
  outlineWidth: 2
3028
3048
  }
3029
3049
  }),
3030
- select: new Le({
3050
+ select: new Ee({
3031
3051
  flags: {
3032
3052
  point: {
3033
3053
  feature: {
@@ -3281,33 +3301,33 @@ Alt. `, ["to-string", ["floor", ["get", "elevation"]]], " m"],
3281
3301
  distancePrecision: 2,
3282
3302
  areaUnit: "metric",
3283
3303
  areaPrecision: 2
3284
- }, Ki = () => ({
3304
+ }, zi = () => ({
3285
3305
  render: new et({
3286
3306
  modeName: "render",
3287
3307
  styles: {}
3288
3308
  }),
3289
- point: new be({
3309
+ point: new Se({
3290
3310
  editable: !0
3291
3311
  }),
3292
- linestring: new xe({
3312
+ linestring: new Ce({
3293
3313
  editable: !0
3294
3314
  }),
3295
- polygon: new Me({
3315
+ polygon: new xe({
3296
3316
  editable: !0,
3297
3317
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3298
3318
  // @ts-ignore
3299
3319
  validation: (t, e) => {
3300
3320
  const i = e.updateType;
3301
- return i === "finish" || i === "commit" ? ji(t) : { valid: !0 };
3321
+ return i === "finish" || i === "commit" ? ki(t) : { valid: !0 };
3302
3322
  }
3303
3323
  }),
3304
- rectangle: new we(),
3305
- "angled-rectangle": new ke(),
3306
- circle: new me(),
3307
- freehand: new ve(),
3308
- sensor: new Be(),
3309
- sector: new je(),
3310
- select: new Le({
3324
+ rectangle: new Ie(),
3325
+ "angled-rectangle": new De(),
3326
+ circle: new ge(),
3327
+ freehand: new ye(),
3328
+ sensor: new ke(),
3329
+ sector: new Le(),
3330
+ select: new Ee({
3311
3331
  flags: {
3312
3332
  point: {
3313
3333
  feature: {
@@ -3421,43 +3441,43 @@ Alt. `, ["to-string", ["floor", ["get", "elevation"]]], " m"],
3421
3441
  styles: {}
3422
3442
  })
3423
3443
  });
3424
- var _ = 63710088e-1, Yi = {
3425
- centimeters: _ * 100,
3426
- centimetres: _ * 100,
3444
+ var L = 63710088e-1, Xi = {
3445
+ centimeters: L * 100,
3446
+ centimetres: L * 100,
3427
3447
  degrees: 360 / (2 * Math.PI),
3428
- feet: _ * 3.28084,
3429
- inches: _ * 39.37,
3430
- kilometers: _ / 1e3,
3431
- kilometres: _ / 1e3,
3432
- meters: _,
3433
- metres: _,
3434
- miles: _ / 1609.344,
3435
- millimeters: _ * 1e3,
3436
- millimetres: _ * 1e3,
3437
- nauticalmiles: _ / 1852,
3448
+ feet: L * 3.28084,
3449
+ inches: L * 39.37,
3450
+ kilometers: L / 1e3,
3451
+ kilometres: L / 1e3,
3452
+ meters: L,
3453
+ metres: L,
3454
+ miles: L / 1609.344,
3455
+ millimeters: L * 1e3,
3456
+ millimetres: L * 1e3,
3457
+ nauticalmiles: L / 1852,
3438
3458
  radians: 1,
3439
- yards: _ * 1.0936
3459
+ yards: L * 1.0936
3440
3460
  };
3441
- function $i(s, t, e = {}) {
3461
+ function Ki(s, t, e = {}) {
3442
3462
  const i = { type: "Feature" };
3443
3463
  return (e.id === 0 || e.id) && (i.id = e.id), e.bbox && (i.bbox = e.bbox), i.properties = t || {}, i.geometry = s, i;
3444
3464
  }
3445
- function Hi(s, t, e = {}) {
3465
+ function Yi(s, t, e = {}) {
3446
3466
  if (!s)
3447
3467
  throw new Error("coordinates is required");
3448
3468
  if (!Array.isArray(s))
3449
3469
  throw new Error("coordinates must be an Array");
3450
3470
  if (s.length < 2)
3451
3471
  throw new Error("coordinates must be at least 2 numbers long");
3452
- if (!oe(s[0]) || !oe(s[1]))
3472
+ if (!te(s[0]) || !te(s[1]))
3453
3473
  throw new Error("coordinates must contain numbers");
3454
- return $i({
3474
+ return Ki({
3455
3475
  type: "Point",
3456
3476
  coordinates: s
3457
3477
  }, t, e);
3458
3478
  }
3459
- function qi(s, t = "kilometers") {
3460
- const e = Yi[t];
3479
+ function $i(s, t = "kilometers") {
3480
+ const e = Xi[t];
3461
3481
  if (!e)
3462
3482
  throw new Error(t + " units is invalid");
3463
3483
  return s * e;
@@ -3465,13 +3485,13 @@ function qi(s, t = "kilometers") {
3465
3485
  function gt(s) {
3466
3486
  return s % 360 * Math.PI / 180;
3467
3487
  }
3468
- function oe(s) {
3488
+ function te(s) {
3469
3489
  return !isNaN(s) && s !== null && !Array.isArray(s);
3470
3490
  }
3471
- function Ne(s, t, e) {
3491
+ function je(s, t, e) {
3472
3492
  if (s !== null)
3473
- for (var i, o, r, n, a, l, d, h = 0, c = 0, u, p = s.type, g = p === "FeatureCollection", y = p === "Feature", v = g ? s.features.length : 1, f = 0; f < v; f++) {
3474
- d = g ? s.features[f].geometry : y ? s.geometry : s, u = d ? d.type === "GeometryCollection" : !1, a = u ? d.geometries.length : 1;
3493
+ for (var i, o, r, n, a, l, d, h = 0, c = 0, u, p = s.type, y = p === "FeatureCollection", g = p === "Feature", v = y ? s.features.length : 1, f = 0; f < v; f++) {
3494
+ d = y ? s.features[f].geometry : g ? s.geometry : s, u = d ? d.type === "GeometryCollection" : !1, a = u ? d.geometries.length : 1;
3475
3495
  for (var m = 0; m < a; m++) {
3476
3496
  var C = 0, P = 0;
3477
3497
  if (n = u ? d.geometries[m] : d, n !== null) {
@@ -3545,7 +3565,7 @@ function Ne(s, t, e) {
3545
3565
  break;
3546
3566
  case "GeometryCollection":
3547
3567
  for (i = 0; i < n.geometries.length; i++)
3548
- if (Ne(n.geometries[i], t) === !1)
3568
+ if (je(n.geometries[i], t) === !1)
3549
3569
  return !1;
3550
3570
  break;
3551
3571
  default:
@@ -3555,10 +3575,10 @@ function Ne(s, t, e) {
3555
3575
  }
3556
3576
  }
3557
3577
  }
3558
- function Ji(s, t) {
3559
- var e, i, o, r, n, a, l, d, h, c, u = 0, p = s.type === "FeatureCollection", g = s.type === "Feature", y = p ? s.features.length : 1;
3560
- for (e = 0; e < y; e++) {
3561
- for (a = p ? s.features[e].geometry : g ? s.geometry : s, d = p ? s.features[e].properties : g ? s.properties : {}, h = p ? s.features[e].bbox : g ? s.bbox : void 0, c = p ? s.features[e].id : g ? s.id : void 0, l = a ? a.type === "GeometryCollection" : !1, n = l ? a.geometries.length : 1, o = 0; o < n; o++) {
3578
+ function Hi(s, t) {
3579
+ var e, i, o, r, n, a, l, d, h, c, u = 0, p = s.type === "FeatureCollection", y = s.type === "Feature", g = p ? s.features.length : 1;
3580
+ for (e = 0; e < g; e++) {
3581
+ for (a = p ? s.features[e].geometry : y ? s.geometry : s, d = p ? s.features[e].properties : y ? s.properties : {}, h = p ? s.features[e].bbox : y ? s.bbox : void 0, c = p ? s.features[e].id : y ? s.id : void 0, l = a ? a.type === "GeometryCollection" : !1, n = l ? a.geometries.length : 1, o = 0; o < n; o++) {
3562
3582
  if (r = l ? a.geometries[o] : a, r === null) {
3563
3583
  if (t(
3564
3584
  null,
@@ -3606,9 +3626,9 @@ function Ji(s, t) {
3606
3626
  u++;
3607
3627
  }
3608
3628
  }
3609
- function Zi(s, t, e) {
3629
+ function qi(s, t, e) {
3610
3630
  var i = e;
3611
- return Ji(
3631
+ return Hi(
3612
3632
  s,
3613
3633
  function(o, r, n, a, l) {
3614
3634
  r === 0 && e === void 0 ? i = o : i = t(
@@ -3622,21 +3642,21 @@ function Zi(s, t, e) {
3622
3642
  }
3623
3643
  ), i;
3624
3644
  }
3625
- function Qi(s) {
3626
- return Zi(
3645
+ function Ji(s) {
3646
+ return qi(
3627
3647
  s,
3628
- (t, e) => t + to(e),
3648
+ (t, e) => t + Zi(e),
3629
3649
  0
3630
3650
  );
3631
3651
  }
3632
- function to(s) {
3652
+ function Zi(s) {
3633
3653
  let t = 0, e;
3634
3654
  switch (s.type) {
3635
3655
  case "Polygon":
3636
- return se(s.coordinates);
3656
+ return ee(s.coordinates);
3637
3657
  case "MultiPolygon":
3638
3658
  for (e = 0; e < s.coordinates.length; e++)
3639
- t += se(s.coordinates[e]);
3659
+ t += ee(s.coordinates[e]);
3640
3660
  return t;
3641
3661
  case "Point":
3642
3662
  case "MultiPoint":
@@ -3646,36 +3666,36 @@ function to(s) {
3646
3666
  }
3647
3667
  return 0;
3648
3668
  }
3649
- function se(s) {
3669
+ function ee(s) {
3650
3670
  let t = 0;
3651
3671
  if (s && s.length > 0) {
3652
- t += Math.abs(re(s[0]));
3672
+ t += Math.abs(ie(s[0]));
3653
3673
  for (let e = 1; e < s.length; e++)
3654
- t -= Math.abs(re(s[e]));
3674
+ t -= Math.abs(ie(s[e]));
3655
3675
  }
3656
3676
  return t;
3657
3677
  }
3658
- var eo = _ * _ / 2, Ot = Math.PI / 180;
3659
- function re(s) {
3678
+ var Qi = L * L / 2, Et = Math.PI / 180;
3679
+ function ie(s) {
3660
3680
  const t = s.length - 1;
3661
3681
  if (t <= 2) return 0;
3662
3682
  let e = 0, i = 0;
3663
3683
  for (; i < t; ) {
3664
- 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] * Ot, l = r[1] * Ot, d = n[0] * Ot;
3684
+ 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] * Et, l = r[1] * Et, d = n[0] * Et;
3665
3685
  e += (d - a) * Math.sin(l), i++;
3666
3686
  }
3667
- return e * eo;
3687
+ return e * Qi;
3668
3688
  }
3669
- var io = Qi;
3670
- const oo = (s, t) => {
3689
+ var to = Ji;
3690
+ const eo = (s, t) => {
3671
3691
  let e = s, i = "m²";
3672
3692
  return t === "metric" ? s >= 1e6 ? (e = s / 1e6, i = "km²") : s >= 1e4 && (e = s / 1e4, i = "ha") : s >= 258998811e-2 ? (e = s / 258998811e-2, i = "mi²") : s >= 4046.856 ? (e = s / 4046.856, i = "acre") : s >= 0.83612736 && (e = s / 0.83612736, i = "yd²"), { area: e, unit: i };
3673
- }, ne = (s, t, e) => {
3693
+ }, oe = (s, t, e) => {
3674
3694
  if (s.geometry.type !== "Polygon") return s;
3675
- const i = io(s.geometry), o = oo(i, t);
3695
+ const i = to(s.geometry), o = eo(i, t);
3676
3696
  return o.area = parseFloat(o.area.toFixed(e)), s.properties.area = o.area, s.properties.unit = o.unit, s;
3677
3697
  };
3678
- function ae(s) {
3698
+ function se(s) {
3679
3699
  if (!s)
3680
3700
  throw new Error("coord is required");
3681
3701
  if (!Array.isArray(s)) {
@@ -3688,52 +3708,52 @@ function ae(s) {
3688
3708
  return [...s];
3689
3709
  throw new Error("coord must be GeoJSON Point or an Array of numbers");
3690
3710
  }
3691
- function so(s, t, e = {}) {
3692
- var i = ae(s), o = ae(t), r = gt(o[1] - i[1]), n = gt(o[0] - i[0]), a = gt(i[1]), l = gt(o[1]), d = Math.pow(Math.sin(r / 2), 2) + Math.pow(Math.sin(n / 2), 2) * Math.cos(a) * Math.cos(l);
3693
- return qi(
3711
+ function io(s, t, e = {}) {
3712
+ var i = se(s), o = se(t), r = gt(o[1] - i[1]), n = gt(o[0] - i[0]), a = gt(i[1]), l = gt(o[1]), d = Math.pow(Math.sin(r / 2), 2) + Math.pow(Math.sin(n / 2), 2) * Math.cos(a) * Math.cos(l);
3713
+ return $i(
3694
3714
  2 * Math.atan2(Math.sqrt(d), Math.sqrt(1 - d)),
3695
3715
  e.units
3696
3716
  );
3697
3717
  }
3698
- var ro = so;
3699
- const no = (s) => s === "degrees" ? "°" : s === "miles" ? "mi" : s === "radians" ? "rad" : "km", le = (s, t, e, i, o, r) => {
3718
+ var oo = io;
3719
+ const so = (s) => s === "degrees" ? "°" : s === "miles" ? "mi" : s === "radians" ? "rad" : "km", re = (s, t, e, i, o, r) => {
3700
3720
  if (s.geometry.type !== "LineString") return s;
3701
3721
  const n = s.geometry.coordinates;
3702
3722
  let a = 0;
3703
3723
  const l = [];
3704
3724
  for (let d = 0; d < n.length - 1; d++) {
3705
- const h = n[d], c = n[d + 1], u = ro(h, c, { units: t });
3725
+ const h = n[d], c = n[d + 1], u = oo(h, c, { units: t });
3706
3726
  a += u;
3707
3727
  const p = JSON.parse(JSON.stringify(s));
3708
- if (p.id = `${p.id}-${d}`, p.geometry.coordinates = [h, c], p.properties.originalId = s.id, p.properties.distance = parseFloat(u.toFixed(e)), p.properties.total = parseFloat(a.toFixed(e)), p.properties.unit = no(t), o === !0 && r === void 0) {
3709
- const g = i == null ? void 0 : i.queryTerrainElevation(h);
3710
- g && (p.properties.elevation_start = g);
3711
- const y = i == null ? void 0 : i.queryTerrainElevation(c);
3712
- y && (p.properties.elevation_end = y);
3728
+ if (p.id = `${p.id}-${d}`, p.geometry.coordinates = [h, c], p.properties.originalId = s.id, p.properties.distance = parseFloat(u.toFixed(e)), p.properties.total = parseFloat(a.toFixed(e)), p.properties.unit = so(t), o === !0 && r === void 0) {
3729
+ const y = i == null ? void 0 : i.queryTerrainElevation(h);
3730
+ y && (p.properties.elevation_start = y);
3731
+ const g = i == null ? void 0 : i.queryTerrainElevation(c);
3732
+ g && (p.properties.elevation_end = g);
3713
3733
  }
3714
3734
  l.push(p);
3715
3735
  }
3716
3736
  return s.properties.distance = l[l.length - 1].properties.total, s.properties.unit = l[l.length - 1].properties.unit, s.properties.segments = JSON.parse(JSON.stringify(l)), s;
3717
- }, de = (s) => s.charAt(0).toUpperCase() + s.slice(1), It = ["td-point", "td-linestring", "td-polygon"];
3718
- var ue, pe, ge;
3719
- const _o = [
3737
+ }, ne = (s) => s.charAt(0).toUpperCase() + s.slice(1), It = ["td-point", "td-linestring", "td-polygon"];
3738
+ var de, he, ce;
3739
+ const Oo = [
3720
3740
  ...It,
3721
- (ue = yt.polygonLayerSpec) == null ? void 0 : ue.source,
3722
- (pe = yt.lineLayerLabelSpec) == null ? void 0 : pe.source,
3723
- (ge = yt.pointLayerLabelSpec) == null ? void 0 : ge.source
3724
- ], Ge = (s, t, e = It) => {
3741
+ (de = yt.polygonLayerSpec) == null ? void 0 : de.source,
3742
+ (he = yt.lineLayerLabelSpec) == null ? void 0 : he.source,
3743
+ (ce = yt.pointLayerLabelSpec) == null ? void 0 : ce.source
3744
+ ], We = (s, t, e = It) => {
3725
3745
  const i = JSON.parse(JSON.stringify(s));
3726
3746
  return t && (t.onlyTerraDrawLayers === !0 ? (i.layers = i.layers.filter((o) => "source" in o && e.includes(o.source)), Object.keys(i.sources).forEach((o) => {
3727
3747
  e.includes(o) || delete i.sources[o];
3728
3748
  })) : t.excludeTerraDrawLayers === !0 && (i.layers = i.layers.filter((o) => "source" in o && !e.includes(o.source)), Object.keys(i.sources).forEach((o) => {
3729
3749
  e.includes(o) && delete i.sources[o];
3730
3750
  }))), i;
3731
- }, ao = (s, t = 250) => {
3751
+ }, ro = (s, t = 250) => {
3732
3752
  let e;
3733
3753
  return (...i) => {
3734
3754
  clearTimeout(e), e = setTimeout(() => s(...i), t);
3735
3755
  };
3736
- }, he = (s, t, e, i) => {
3756
+ }, ae = (s, t, e, i) => {
3737
3757
  if (s.geometry.type !== "Point") return s;
3738
3758
  const o = s.geometry.coordinates;
3739
3759
  if (e === !0 && i === void 0) {
@@ -3742,58 +3762,58 @@ const _o = [
3742
3762
  }
3743
3763
  return s;
3744
3764
  };
3745
- var lo = Object.defineProperty, ho = (s, t, e) => t in s ? lo(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e, tt = (s, t, e) => ho(s, typeof t != "symbol" ? t + "" : t, e), Pt = 2 * Math.PI * 6378137 / 2;
3746
- function co(s) {
3765
+ var no = Object.defineProperty, ao = (s, t, e) => t in s ? no(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e, tt = (s, t, e) => ao(s, typeof t != "symbol" ? t + "" : t, e), Pt = 2 * Math.PI * 6378137 / 2;
3766
+ function lo(s) {
3747
3767
  return s = s || 256, 2 * Math.PI * 6378137 / s;
3748
3768
  }
3749
- function uo(s, t, e = { enable: !0, decimal: 1 }) {
3750
- s = Wt(s);
3769
+ function ho(s, t, e = { enable: !0, decimal: 1 }) {
3770
+ s = jt(s);
3751
3771
  var i = s[0], o = s[1], r = i * Pt / 180, n = Math.log(Math.tan((90 + o) * Math.PI / 360)) / (Math.PI / 180);
3752
3772
  return n = n * Pt / 180, e.enable && (r = Number(r.toFixed(e.decimal)), n = Number(n.toFixed(e.decimal))), [r, n];
3753
3773
  }
3754
- function po(s, t, e) {
3755
- var i = s[0], o = s[1], r = Co(t, e), n = (i + Pt) / r, a = (o + Pt) / r;
3774
+ function co(s, t, e) {
3775
+ var i = s[0], o = s[1], r = mo(t, e), n = (i + Pt) / r, a = (o + Pt) / r;
3756
3776
  return [n, a, t];
3757
3777
  }
3758
- function Te(s, t, e) {
3759
- s = Wt(s);
3760
- var i = uo(s), o = po(i, t);
3761
- return yo(o);
3778
+ function Be(s, t, e) {
3779
+ s = jt(s);
3780
+ var i = ho(s), o = co(i, t);
3781
+ return po(o);
3762
3782
  }
3763
- function go(s, t, e) {
3764
- if (s = Wt(s), t === 0)
3783
+ function uo(s, t, e) {
3784
+ if (s = jt(s), t === 0)
3765
3785
  return [0, 0, 0];
3766
- var i = Te(s, t);
3767
- return fo(i);
3786
+ var i = Be(s, t);
3787
+ return go(i);
3768
3788
  }
3769
- function yo(s, t, e) {
3789
+ function po(s, t, e) {
3770
3790
  t = t || 256;
3771
3791
  var i = s[0], o = s[1], r = s[2];
3772
3792
  if (r === 0) return [0, 0, 0];
3773
- Ae(r);
3793
+ Ne(r);
3774
3794
  var n = Math.ceil(i / t) - 1, a = Math.ceil(o / t) - 1;
3775
3795
  return n < 0 && (n = 0), a < 0 && (a = 0), [n, a, r];
3776
3796
  }
3777
- function fo(s, t) {
3778
- mo(s);
3797
+ function go(s, t) {
3798
+ yo(s);
3779
3799
  var e = s[0], i = s[1], o = s[2];
3780
3800
  if (o === 0)
3781
3801
  return [0, 0, 0];
3782
3802
  var r = e, n = Math.pow(2, o) - 1 - i;
3783
3803
  return [r, n, o];
3784
3804
  }
3785
- function mo(s, t) {
3805
+ function yo(s, t) {
3786
3806
  var e = s[0], i = s[1], o = s[2];
3787
3807
  if (o == null) throw new Error("<zoom> is required");
3788
3808
  if (e == null) throw new Error("<x> is required");
3789
3809
  if (i == null) throw new Error("<y> is required");
3790
- return o = Ae(o), s = vo(s), s;
3810
+ return o = Ne(o), s = fo(s), s;
3791
3811
  }
3792
- function vo(s) {
3812
+ function fo(s) {
3793
3813
  var t = s[0], e = s[1], i = s[2], o = Math.pow(2, i);
3794
3814
  return t = t % o, t < 0 && (t = t + o), [t, e, i];
3795
3815
  }
3796
- function Ae(s) {
3816
+ function Ne(s) {
3797
3817
  if (s === !1) return s;
3798
3818
  if (s == null)
3799
3819
  throw new Error("<zoom> is required");
@@ -3803,22 +3823,22 @@ function Ae(s) {
3803
3823
  throw new Error("<zoom> cannot be greater than 32");
3804
3824
  return s;
3805
3825
  }
3806
- function Wt(s, t) {
3807
- var e = So(s[0]), i = Po(s[1]);
3826
+ function jt(s, t) {
3827
+ var e = Co(s[0]), i = vo(s[1]);
3808
3828
  return i > 85 && (i = 85), i < -85 && (i = -85), [e, i];
3809
3829
  }
3810
- function Co(s, t) {
3811
- return co(t) / Math.pow(2, s);
3830
+ function mo(s, t) {
3831
+ return lo(t) / Math.pow(2, s);
3812
3832
  }
3813
- function Po(s) {
3833
+ function vo(s) {
3814
3834
  if (s == null) throw new Error("lat is required");
3815
3835
  return (s > 90 || s < -90) && (s = s % 180, s > 90 && (s = -180 + s), s < -90 && (s = 180 + s), s === 0 && (s = 0)), s;
3816
3836
  }
3817
- function So(s) {
3837
+ function Co(s) {
3818
3838
  if (s == null) throw new Error("lng is required");
3819
3839
  return (s > 180 || s < -180) && (s = s % 360, s > 180 && (s = -360 + s), s < -180 && (s = 360 + s), s === 0 && (s = 0)), s;
3820
3840
  }
3821
- class Ve {
3841
+ class Ge {
3822
3842
  /**
3823
3843
  * Constructor
3824
3844
  * @param url URL for terrain RGB raster tilesets
@@ -3843,7 +3863,7 @@ class Ve {
3843
3863
  const r = t[0], n = t[1];
3844
3864
  let a = e;
3845
3865
  e > this.maxzoom ? a = this.maxzoom : e < this.minzoom && (a = this.minzoom);
3846
- const l = this.tms ? Te([r, n], a) : go([r, n], a), d = this.url.replace(/{x}/g, l[0].toString()).replace(/{y}/g, l[1].toString()).replace(/{z}/g, l[2].toString());
3866
+ const l = this.tms ? Be([r, n], a) : uo([r, n], a), d = this.url.replace(/{x}/g, l[0].toString()).replace(/{y}/g, l[1].toString()).replace(/{z}/g, l[2].toString());
3847
3867
  let h = this.getUrlExtension(d);
3848
3868
  switch (h || (h = "png"), h) {
3849
3869
  case "png":
@@ -3883,8 +3903,8 @@ class Ve {
3883
3903
  const c = h.getContext("2d");
3884
3904
  if (!c) return l(new Error("Failed to create canvas context"));
3885
3905
  c.drawImage(d, 0, 0);
3886
- const u = c.getImageData(0, 0, d.width, d.height).data, p = this.pixels2rgba(new Uint8Array(u), e, i, o), g = this.calc(p[0], p[1], p[2], p[3]);
3887
- a(g);
3906
+ const u = c.getImageData(0, 0, d.width, d.height).data, p = this.pixels2rgba(new Uint8Array(u), e, i, o), y = this.calc(p[0], p[1], p[2], p[3]);
3907
+ a(y);
3888
3908
  }, d.onerror = () => a(void 0), d.src = URL.createObjectURL(n);
3889
3909
  });
3890
3910
  }
@@ -3899,8 +3919,8 @@ class Ve {
3899
3919
  pixels2rgba(t, e, i, o) {
3900
3920
  const r = [];
3901
3921
  for (let d = 0; d < t.length; d += 4) {
3902
- const h = t[d], c = t[d + 1], u = t[d + 2], p = t[d + 3], g = [h, c, u, p];
3903
- r.push(g);
3922
+ const h = t[d], c = t[d + 1], u = t[d + 2], p = t[d + 3], y = [h, c, u, p];
3923
+ r.push(y);
3904
3924
  }
3905
3925
  const n = this.tileToBBOX(e), a = this.getPixelPosition(i, o, n), l = a[0] + a[1] * this.tileSize;
3906
3926
  return r[l];
@@ -3945,7 +3965,7 @@ class Ve {
3945
3965
  return i * Math.atan(0.5 * (Math.exp(o) - Math.exp(-o)));
3946
3966
  }
3947
3967
  }
3948
- class xo extends Ve {
3968
+ class Po extends Ge {
3949
3969
  /**
3950
3970
  * Constructor
3951
3971
  * @param url URL for terrain RGB raster tilesets
@@ -3977,7 +3997,7 @@ class xo extends Ve {
3977
3997
  return -1e4 + (t * 256 * 256 + e * 256 + i) * 0.1;
3978
3998
  }
3979
3999
  }
3980
- class Io extends Ve {
4000
+ class So extends Ge {
3981
4001
  /**
3982
4002
  * Constructor
3983
4003
  * @param url URL for terrarium raster tilesets
@@ -4011,14 +4031,14 @@ class Io extends Ve {
4011
4031
  return parseInt(o.toFixed(0));
4012
4032
  }
4013
4033
  }
4014
- const ce = async (s, t) => {
4034
+ const le = async (s, t) => {
4015
4035
  const e = [];
4016
4036
  for (const i of s)
4017
4037
  e.push(
4018
4038
  new Promise((o) => {
4019
4039
  if (i.geometry.type !== "Point" && o(i), t) {
4020
4040
  const r = t.url, n = t.encoding ?? "mapbox", a = t.tileSize ?? 512, l = t.minzoom ?? 5, d = t.maxzoom ?? 15, h = t.tms ?? !1;
4021
- (n === "mapbox" ? new xo(r, a, l, d, h) : new Io(r, a, l, d, h)).getElevation(i.geometry.coordinates, d).then((c) => {
4041
+ (n === "mapbox" ? new Po(r, a, l, d, h) : new So(r, a, l, d, h)).getElevation(i.geometry.coordinates, d).then((c) => {
4022
4042
  c && (i.properties.elevation = c), o(i);
4023
4043
  }).catch(() => o(i));
4024
4044
  } else
@@ -4026,8 +4046,42 @@ const ce = async (s, t) => {
4026
4046
  })
4027
4047
  );
4028
4048
  return await Promise.all(e);
4049
+ }, Do = (s, t = 9) => {
4050
+ function e(o) {
4051
+ return [Number(o[0].toFixed(t)), Number(o[1].toFixed(t))];
4052
+ }
4053
+ function i(o) {
4054
+ const r = o.type;
4055
+ let n = o.coordinates;
4056
+ switch (r) {
4057
+ case "Point":
4058
+ n = e(n);
4059
+ break;
4060
+ case "LineString":
4061
+ case "MultiPoint":
4062
+ n = n.map(e);
4063
+ break;
4064
+ case "Polygon":
4065
+ case "MultiLineString":
4066
+ n = n.map((a) => a.map(e));
4067
+ break;
4068
+ case "MultiPolygon":
4069
+ n = n.map(
4070
+ (a) => a.map((l) => l.map(e))
4071
+ );
4072
+ break;
4073
+ }
4074
+ return {
4075
+ ...o,
4076
+ coordinates: n
4077
+ };
4078
+ }
4079
+ return s.map((o) => ({
4080
+ ...o,
4081
+ geometry: i(o.geometry)
4082
+ }));
4029
4083
  };
4030
- class bo {
4084
+ class xo {
4031
4085
  /**
4032
4086
  * Constructor
4033
4087
  * @param options Plugin control options
@@ -4038,7 +4092,7 @@ class bo {
4038
4092
  k(this, "modeButtons", {});
4039
4093
  k(this, "_isExpanded", !1);
4040
4094
  k(this, "terradraw");
4041
- k(this, "options", Xi);
4095
+ k(this, "options", Ri);
4042
4096
  k(this, "events", {});
4043
4097
  k(this, "defaultMode", "render");
4044
4098
  this.modeButtons = {}, t && (this.options = Object.assign(this.options, t));
@@ -4082,7 +4136,7 @@ class bo {
4082
4136
  if (this.options && this.options.modes && this.options.modes.length === 0)
4083
4137
  throw new Error("At least a mode must be enabled.");
4084
4138
  this.map = t;
4085
- const e = Ki(), i = [];
4139
+ const e = zi(), i = [];
4086
4140
  return (r = (o = this.options) == null ? void 0 : o.modes) == null || r.forEach((d) => {
4087
4141
  if (this.options.modeOptions && this.options.modeOptions[d]) {
4088
4142
  const h = this.options.modeOptions[d];
@@ -4104,8 +4158,8 @@ class bo {
4104
4158
  modeName: "default",
4105
4159
  styles: {}
4106
4160
  })
4107
- ), this.defaultMode = "default"), this.isExpanded = this.options.open === !0, this.terradraw = new Ui({
4108
- adapter: new Ri({ map: t, ...this.options.adapterOptions }),
4161
+ ), this.defaultMode = "default"), this.isExpanded = this.options.open === !0, this.terradraw = new Vi({
4162
+ adapter: new Ui({ map: t, ...this.options.adapterOptions }),
4109
4163
  modes: i
4110
4164
  }), this.terradraw.start(), this.controlContainer = document.createElement("div"), this.controlContainer.classList.add("maplibregl-ctrl"), this.controlContainer.classList.add("maplibregl-ctrl-group"), i.forEach((d) => {
4111
4165
  d.mode !== "default" && this.addTerradrawButton(d.mode);
@@ -4202,7 +4256,7 @@ class bo {
4202
4256
  */
4203
4257
  addTerradrawButton(t) {
4204
4258
  const e = document.createElement("button");
4205
- e.type = "button", this.modeButtons[t] = e, t === "render" ? (e.classList.add(`maplibregl-terradraw-${t}-button`), this.isExpanded && e.classList.add("enabled"), e.type = "button", e.title = de("expand or collapse drawing tool"), e.addEventListener("click", this.toggleEditor.bind(this))) : (e.classList.add("maplibregl-terradraw-add-control"), this.isExpanded || e.classList.add("hidden"), e.title = de(t.replace(/-/g, " ")), t === "delete" ? (e.classList.add(`maplibregl-terradraw-${t}-button`), e.addEventListener("click", () => {
4259
+ e.type = "button", this.modeButtons[t] = e, t === "render" ? (e.classList.add(`maplibregl-terradraw-${t}-button`), this.isExpanded && e.classList.add("enabled"), e.type = "button", e.title = ne("expand or collapse drawing tool"), e.addEventListener("click", this.toggleEditor.bind(this))) : (e.classList.add("maplibregl-terradraw-add-control"), this.isExpanded || e.classList.add("hidden"), e.title = ne(t.replace(/-/g, " ")), t === "delete" ? (e.classList.add(`maplibregl-terradraw-${t}-button`), e.addEventListener("click", () => {
4206
4260
  this.terradraw && this.terradraw.enabled && (this.terradraw.clear(), this.deactivate(), this.toggleDeleteSelectionButton(), this.toggleButtonsWhenNoFeature(), this.dispatchEvent("feature-deleted"));
4207
4261
  })) : t === "delete-selection" ? (e.classList.add(`maplibregl-terradraw-${t}-button`), e.classList.add("hidden-delete-selection"), e.addEventListener("click", () => {
4208
4262
  var r;
@@ -4252,7 +4306,7 @@ class bo {
4252
4306
  * @returns
4253
4307
  */
4254
4308
  cleanStyle(t, e) {
4255
- return Ge(t, e, It);
4309
+ return We(t, e, It);
4256
4310
  }
4257
4311
  /**
4258
4312
  * Download button click event handler
@@ -4298,16 +4352,16 @@ class bo {
4298
4352
  }
4299
4353
  }
4300
4354
  }
4301
- function Mo(s, t = {}) {
4355
+ function Io(s, t = {}) {
4302
4356
  let e = 0, i = 0, o = 0;
4303
- return Ne(
4357
+ return je(
4304
4358
  s,
4305
4359
  function(r) {
4306
4360
  e += r[0], i += r[1], o++;
4307
4361
  }
4308
- ), Hi([e / o, i / o], t.properties);
4362
+ ), Yi([e / o, i / o], t.properties);
4309
4363
  }
4310
- class ko extends bo {
4364
+ class _o extends xo {
4311
4365
  /**
4312
4366
  * Constructor
4313
4367
  * @param options Plugin control options
@@ -4346,7 +4400,7 @@ class ko extends bo {
4346
4400
  * Handle finish event of terradraw. It will be called after finishing adding a feature
4347
4401
  * @param id Feature ID
4348
4402
  */
4349
- k(this, "handleTerradrawFeatureReady", ao((e) => {
4403
+ k(this, "handleTerradrawFeatureReady", ro((e) => {
4350
4404
  this.map && (this.computeElevationByLineFeatureID(e), this.computeElevationByPointFeatureID(e));
4351
4405
  }, 300));
4352
4406
  /**
@@ -4364,7 +4418,7 @@ class ko extends bo {
4364
4418
  }
4365
4419
  );
4366
4420
  if (o && o.length > 0) {
4367
- const r = await ce(
4421
+ const r = await le(
4368
4422
  o,
4369
4423
  this.measureOptions.terrainSource
4370
4424
  );
@@ -4392,7 +4446,7 @@ class ko extends bo {
4392
4446
  }
4393
4447
  );
4394
4448
  if (o && o.length > 0) {
4395
- const r = await ce(
4449
+ const r = await le(
4396
4450
  o,
4397
4451
  this.measureOptions.terrainSource
4398
4452
  );
@@ -4527,7 +4581,7 @@ class ko extends bo {
4527
4581
  const n = (d = this.measureOptions.lineLayerLabelSpec) == null ? void 0 : d.source;
4528
4582
  n && o.push(n);
4529
4583
  const a = (h = this.measureOptions.pointLayerLabelSpec) == null ? void 0 : h.source;
4530
- return a && o.push(a), Ge(e, i, o);
4584
+ return a && o.push(a), We(e, i, o);
4531
4585
  }
4532
4586
  /**
4533
4587
  * Register measure control related maplibre sources and layers
@@ -4700,7 +4754,7 @@ class ko extends bo {
4700
4754
  }
4701
4755
  ));
4702
4756
  const l = JSON.parse(JSON.stringify(r));
4703
- l.id = l.id + "-area-label", l.geometry = Mo(r.geometry).geometry, l.properties.originalId = r.id, r = ne(r, this.areaUnit, this.areaPrecision), l.properties.area = r.properties.area, l.properties.unit = r.properties.unit, typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(l), (n = this.map.getSource(
4757
+ l.id = l.id + "-area-label", l.geometry = Io(r.geometry).geometry, l.properties.originalId = r.id, r = oe(r, this.areaUnit, this.areaPrecision), l.properties.area = r.properties.area, l.properties.unit = r.properties.unit, typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(l), (n = this.map.getSource(
4704
4758
  this.measureOptions.polygonLayerSpec.source
4705
4759
  )) == null || n.setData(a.data), this.map.moveLayer(this.measureOptions.polygonLayerSpec.id), this.map.getLayer(this.measureOptions.lineLayerLabelSpec.id) && this.map.moveLayer(
4706
4760
  this.measureOptions.lineLayerLabelSpec.id
@@ -4733,7 +4787,7 @@ class ko extends bo {
4733
4787
  var h;
4734
4788
  return ((h = d.properties) == null ? void 0 : h.originalId) !== e;
4735
4789
  }
4736
- )), r = le(
4790
+ )), r = re(
4737
4791
  r,
4738
4792
  this.distanceUnit,
4739
4793
  this.distancePrecision,
@@ -4747,17 +4801,17 @@ class ko extends bo {
4747
4801
  typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(h);
4748
4802
  const c = h.geometry.coordinates, u = c[0], p = c[1];
4749
4803
  if (d === 0) {
4750
- const y = JSON.parse(JSON.stringify(h));
4751
- y.id = `${h.id}-node-${d}`, y.geometry = {
4804
+ const g = JSON.parse(JSON.stringify(h));
4805
+ g.id = `${h.id}-node-${d}`, g.geometry = {
4752
4806
  type: "Point",
4753
4807
  coordinates: u
4754
- }, y.properties.distance = 0, y.properties.total = 0, h.properties.elevation_start && (y.properties.elevation = h.properties.elevation_start), typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(y);
4808
+ }, g.properties.distance = 0, g.properties.total = 0, h.properties.elevation_start && (g.properties.elevation = h.properties.elevation_start), typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(g);
4755
4809
  }
4756
- const g = JSON.parse(JSON.stringify(h));
4757
- g.id = `${h.id}-node-${d + 1}`, g.geometry = {
4810
+ const y = JSON.parse(JSON.stringify(h));
4811
+ y.id = `${h.id}-node-${d + 1}`, y.geometry = {
4758
4812
  type: "Point",
4759
4813
  coordinates: p
4760
- }, h.properties.elevation_end && (g.properties.elevation = h.properties.elevation_end), typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(g);
4814
+ }, h.properties.elevation_end && (y.properties.elevation = h.properties.elevation_end), typeof a.data != "string" && a.data.type === "FeatureCollection" && a.data.features.push(y);
4761
4815
  }
4762
4816
  (n = this.map.getSource(
4763
4817
  this.measureOptions.lineLayerLabelSpec.source
@@ -4782,7 +4836,7 @@ class ko extends bo {
4782
4836
  let r = o == null ? void 0 : o.find((a) => a.id === e && a.geometry.type === "Point");
4783
4837
  if (r) {
4784
4838
  const a = this.map.getStyle().sources[this.measureOptions.pointLayerLabelSpec.source];
4785
- a && (typeof a.data != "string" && a.data.type === "FeatureCollection" && (a.data.features = a.data.features.filter((l) => l.id !== e)), r = he(
4839
+ a && (typeof a.data != "string" && a.data.type === "FeatureCollection" && (a.data.features = a.data.features.filter((l) => l.id !== e)), r = ae(
4786
4840
  r,
4787
4841
  this.map,
4788
4842
  this.computeElevation,
@@ -4827,14 +4881,14 @@ class ko extends bo {
4827
4881
  const r = i.features[o];
4828
4882
  if (!this.map || !this.map.loaded()) continue;
4829
4883
  const n = r.geometry.type;
4830
- n === "LineString" ? i.features[o] = le(
4884
+ n === "LineString" ? i.features[o] = re(
4831
4885
  r,
4832
4886
  this.distanceUnit,
4833
4887
  this.distancePrecision,
4834
4888
  this.map,
4835
4889
  this.computeElevation,
4836
4890
  this.measureOptions.terrainSource
4837
- ) : n === "Polygon" ? i.features[o] = ne(r, this.areaUnit, this.areaPrecision) : n === "Point" && (i.features[o] = he(
4891
+ ) : n === "Polygon" ? i.features[o] = oe(r, this.areaUnit, this.areaPrecision) : n === "Point" && (i.features[o] = ae(
4838
4892
  r,
4839
4893
  this.map,
4840
4894
  this.computeElevation,
@@ -4845,22 +4899,23 @@ class ko extends bo {
4845
4899
  }
4846
4900
  }
4847
4901
  export {
4848
- Lo as AvailableModes,
4849
- ko as MaplibreMeasureControl,
4850
- bo as MaplibreTerradrawControl,
4851
- _o as TERRADRAW_MEASURE_SOURCE_IDS,
4902
+ Eo as AvailableModes,
4903
+ _o as MaplibreMeasureControl,
4904
+ xo as MaplibreTerradrawControl,
4905
+ Oo as TERRADRAW_MEASURE_SOURCE_IDS,
4852
4906
  It as TERRADRAW_SOURCE_IDS,
4853
- ne as calcArea,
4854
- le as calcDistance,
4855
- de as capitalize,
4856
- Ge as cleanMaplibreStyle,
4857
- oo as convertAreaUnit,
4858
- ao as debounce,
4859
- Xi as defaultControlOptions,
4907
+ oe as calcArea,
4908
+ re as calcDistance,
4909
+ ne as capitalize,
4910
+ We as cleanMaplibreStyle,
4911
+ eo as convertAreaUnit,
4912
+ ro as debounce,
4913
+ Ri as defaultControlOptions,
4860
4914
  yt as defaultMeasureControlOptions,
4861
- Ki as getDefaultModeOptions,
4862
- no as getDistanceUnitName,
4863
- he as queryElevationByPoint,
4864
- ce as queryElevationFromRasterDEM
4915
+ zi as getDefaultModeOptions,
4916
+ so as getDistanceUnitName,
4917
+ ae as queryElevationByPoint,
4918
+ le as queryElevationFromRasterDEM,
4919
+ Do as roundFeatureCoordinates
4865
4920
  };
4866
4921
  //# sourceMappingURL=maplibre-gl-terradraw.es.js.map