@watergis/maplibre-gl-terradraw 1.3.9 → 1.3.10

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.
@@ -15,7 +15,7 @@ var M;
15
15
  (function(s) {
16
16
  s.Commit = "commit", s.Provisional = "provisional", s.Finish = "finish";
17
17
  })(M || (M = {}));
18
- const T = { SELECTED: "selected", MID_POINT: "midPoint", SELECTION_POINT: "selectionPoint" }, V = "edited", st = "closingPoint", Lt = "snappingPoint", kt = "coordinatePoint", rt = "coordinatePointIds";
18
+ const T = { SELECTED: "selected", MID_POINT: "midPoint", SELECTION_POINT: "selectionPoint" }, V = "edited", st = "closingPoint", _t = "snappingPoint", kt = "coordinatePoint", rt = "coordinatePointIds";
19
19
  function wt(s) {
20
20
  return !!(s && typeof s == "object" && s !== null && !Array.isArray(s));
21
21
  }
@@ -182,8 +182,8 @@ function Bt(s) {
182
182
  function o(r, n, a, l) {
183
183
  const d = t[r][n], h = t[r][n + 1], c = t[a][l], u = t[a][l + 1], p = function(m, v, f, C) {
184
184
  if (ct(m, f) || ct(m, C) || ct(v, f) || ct(C, f)) return null;
185
- const P = m[0], S = m[1], b = v[0], w = v[1], D = f[0], G = f[1], _ = C[0], j = C[1], z = (P - b) * (G - j) - (S - w) * (D - _);
186
- return z === 0 ? null : [((P * w - S * b) * (D - _) - (P - b) * (D * j - G * _)) / z, ((P * w - S * b) * (G - j) - (S - w) * (D * j - G * _)) / z];
185
+ const P = m[0], S = m[1], b = v[0], w = v[1], D = f[0], G = f[1], L = C[0], j = C[1], z = (P - b) * (G - j) - (S - w) * (D - L);
186
+ return z === 0 ? null : [((P * w - S * b) * (D - L) - (P - b) * (D * j - G * L)) / z, ((P * w - S * b) * (G - j) - (S - w) * (D * j - G * L)) / z];
187
187
  }(d, h, c, u);
188
188
  if (p === null) return;
189
189
  let g, y;
@@ -562,8 +562,8 @@ function ni(s, t, e) {
562
562
  const [Gt, At, Tt] = j, [Ut, Vt, Rt] = z;
563
563
  return [At * Rt - Tt * Vt, Tt * Ut - Gt * Rt, Gt * Vt - At * Ut];
564
564
  }(i, o), u = h * l - c * a, p = c * n - d * l, g = d * a - h * n, y = g * h - p * c, m = u * c - g * d, v = p * d - u * h, f = 1 / Math.sqrt(Math.pow(y, 2) + Math.pow(m, 2) + Math.pow(v, 2)), C = [y * f, m * f, v * f], P = [-1 * y * f, -1 * m * f, -1 * v * f], S = X(i, o), b = X(i, C), w = X(o, C), D = X(i, P), G = X(o, P);
565
- let _;
566
- return _ = b < D && b < G || w < D && w < G ? C : P, X(i, _) > S || X(o, _) > S ? U(K(_), K(i)) <= U(K(_), K(o)) ? [K(i), !0, !1] : [K(o), !1, !0] : [K(_), !1, !1];
565
+ let L;
566
+ return L = b < D && b < G || w < D && w < G ? C : P, X(i, L) > S || X(o, L) > S ? U(K(L), K(i)) <= U(K(L), K(o)) ? [K(i), !0, !1] : [K(o), !1, !0] : [K(L), !1, !1];
567
567
  }
568
568
  function ai(s, t, e) {
569
569
  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)));
@@ -595,7 +595,7 @@ class Ie extends k {
595
595
  if (f[0] === u[0] && f[1] === u[1]) P = f;
596
596
  else if (C[0] === u[0] && C[1] === u[1]) P = C;
597
597
  else {
598
- const { x: G, y: _ } = ai(b, w, D), { lng: j, lat: z } = W(G, _);
598
+ const { x: G, y: L } = ai(b, w, D), { lng: j, lat: z } = W(G, L);
599
599
  P = [j, z];
600
600
  }
601
601
  P && (S = E(D, x(P[0], P[1])), S < y && (g = P, y = S, m = p.indexOf(v)));
@@ -678,7 +678,7 @@ class be extends N {
678
678
  if (e) {
679
679
  if (this.snappedPointId) this.store.updateGeometry([{ id: this.snappedPointId, geometry: { type: "Point", coordinates: e } }]);
680
680
  else {
681
- const [n] = this.store.create([{ geometry: { type: "Point", coordinates: e }, properties: { mode: this.mode, [Lt]: !0 } }]);
681
+ const [n] = this.store.create([{ geometry: { type: "Point", coordinates: e }, properties: { mode: this.mode, [_t]: !0 } }]);
682
682
  this.snappedPointId = n;
683
683
  }
684
684
  t.lng = e[0], t.lat = e[1];
@@ -984,7 +984,7 @@ class Ee extends N {
984
984
  if (e) {
985
985
  if (this.snappedPointId) this.store.updateGeometry([{ id: this.snappedPointId, geometry: { type: "Point", coordinates: e } }]);
986
986
  else {
987
- const [r] = this.store.create([{ geometry: { type: "Point", coordinates: e }, properties: { mode: this.mode, [Lt]: !0 } }]);
987
+ const [r] = this.store.create([{ geometry: { type: "Point", coordinates: e }, properties: { mode: this.mode, [_t]: !0 } }]);
988
988
  this.snappedPointId = r;
989
989
  }
990
990
  t.lng = e[0], t.lat = e[1];
@@ -1111,7 +1111,7 @@ class Ee extends N {
1111
1111
  if (t.properties.mode === this.mode) {
1112
1112
  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;
1113
1113
  if (t.geometry.type === "Point") {
1114
- const i = t.properties[V], o = t.properties[kt], r = i ? "editedPoint" : t.properties[st] ? "closingPoint" : t.properties[Lt] ? "snappingPoint" : o ? "coordinatePoint" : void 0;
1114
+ const i = t.properties[V], o = t.properties[kt], r = i ? "editedPoint" : t.properties[st] ? "closingPoint" : t.properties[_t] ? "snappingPoint" : o ? "coordinatePoint" : void 0;
1115
1115
  if (!r) return e;
1116
1116
  const n = { 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 }, coordinatePoint: { width: this.styles.coordinatePointWidth, color: this.styles.coordinatePointColor, outlineColor: this.styles.coordinatePointOutlineColor, outlineWidth: this.styles.coordinatePointOutlineWidth } };
1117
1117
  return e.pointWidth = this.getNumericStylingValue(n[r].width, e.pointWidth, t), e.pointColor = this.getHexColorStylingValue(n[r].color, e.pointColor, t), e.pointOutlineColor = this.getHexColorStylingValue(n[r].outlineColor, e.pointOutlineColor, t), e.pointOutlineWidth = this.getNumericStylingValue(n[r].outlineWidth, 2, t), e.zIndex = i ? 35 : o ? 25 : 30, e;
@@ -1322,7 +1322,7 @@ class Si extends k {
1322
1322
  if (this._selectionPoints[t] !== void 0) return { id: this._selectionPoints[t], geometry: { type: "Point", coordinates: e } };
1323
1323
  }
1324
1324
  }
1325
- function _e(s, t) {
1325
+ function Le(s, t) {
1326
1326
  let e = !1;
1327
1327
  for (let n = 0, a = t.length; n < a; n++) {
1328
1328
  const l = t[n];
@@ -1331,7 +1331,7 @@ function _e(s, t) {
1331
1331
  var i, o, r;
1332
1332
  return e;
1333
1333
  }
1334
- const Le = (s, t, e) => {
1334
+ const _e = (s, t, e) => {
1335
1335
  const i = (r) => r * r, o = (r, n) => i(r.x - n.x) + i(r.y - n.y);
1336
1336
  return Math.sqrt(((r, n, a) => {
1337
1337
  const l = o(n, a);
@@ -1356,12 +1356,12 @@ class xi extends k {
1356
1356
  } else if (g.type === "LineString") {
1357
1357
  if (i) continue;
1358
1358
  for (let y = 0; y < g.coordinates.length - 1; y++) {
1359
- const m = g.coordinates[y], v = g.coordinates[y + 1], f = Le({ x: t.containerX, y: t.containerY }, this.project(m[0], m[1]), this.project(v[0], v[1]));
1359
+ const m = g.coordinates[y], v = g.coordinates[y + 1], f = _e({ x: t.containerX, y: t.containerY }, this.project(m[0], m[1]), this.project(v[0], v[1]));
1360
1360
  f < this.pointerDistance && f < l && (l = f, o = p);
1361
1361
  }
1362
1362
  } else if (g.type === "Polygon") {
1363
1363
  if (i || o) continue;
1364
- _e([t.lng, t.lat], g.coordinates) && (n = p);
1364
+ Le([t.lng, t.lat], g.coordinates) && (n = p);
1365
1365
  }
1366
1366
  }
1367
1367
  return { clickedFeature: i || o || n, clickedMidPoint: r };
@@ -1989,7 +1989,7 @@ function ot(s, t) {
1989
1989
  function Di(s, t) {
1990
1990
  return s.minX - t.minX;
1991
1991
  }
1992
- function _i(s, t) {
1992
+ function Li(s, t) {
1993
1993
  return s.minY - t.minY;
1994
1994
  }
1995
1995
  function Et(s) {
@@ -1998,7 +1998,7 @@ function Et(s) {
1998
1998
  function pt(s) {
1999
1999
  return s.maxX - s.minX + (s.maxY - s.minY);
2000
2000
  }
2001
- function Li(s, t) {
2001
+ function _i(s, t) {
2002
2002
  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);
2003
2003
  return Math.max(0, o - e) * Math.max(0, r - i);
2004
2004
  }
@@ -2148,13 +2148,13 @@ class ki {
2148
2148
  _chooseSplitIndex(t, e, i) {
2149
2149
  let o, r = 1 / 0, n = 1 / 0;
2150
2150
  for (let a = e; a <= i - e; a++) {
2151
- const l = it(t, 0, a, this.toBBox), d = it(t, a, i, this.toBBox), h = Li(l, d), c = Et(l) + Et(d);
2151
+ const l = it(t, 0, a, this.toBBox), d = it(t, a, i, this.toBBox), h = _i(l, d), c = Et(l) + Et(d);
2152
2152
  h < r ? (r = h, o = a, n = c < n ? c : n) : h === r && c < n && (n = c, o = a);
2153
2153
  }
2154
2154
  return o || i - e;
2155
2155
  }
2156
2156
  _chooseSplitAxis(t, e, i) {
2157
- const o = t.leaf ? this.compareMinX : Di, r = t.leaf ? this.compareMinY : _i;
2157
+ const o = t.leaf ? this.compareMinX : Di, r = t.leaf ? this.compareMinY : Li;
2158
2158
  this._allDistMargin(t, e, i, o) < this._allDistMargin(t, e, i, r) && t.children.sort(o);
2159
2159
  }
2160
2160
  _allDistMargin(t, e, i, o) {
@@ -2560,7 +2560,7 @@ class Ae extends N {
2560
2560
  if (this.notInSector({ normalizedCursor: v, normalizedStart: y, normalizedEnd: m, direction: this.direction })) return;
2561
2561
  const f = this.getDeltaBearing(this.direction, y, m), C = this.arcPoints, P = (this.direction === "anticlockwise" ? 1 : -1) * f / C, S = E(d, c), b = [];
2562
2562
  for (let w = 0; w <= C; w++) {
2563
- const D = lt(d, S, y + w * P), { lng: G, lat: _ } = W(D.x, D.y), j = [F(G, this.coordinatePrecision), F(_, this.coordinatePrecision)];
2563
+ const D = lt(d, S, y + w * P), { lng: G, lat: L } = W(D.x, D.y), j = [F(G, this.coordinatePrecision), F(L, this.coordinatePrecision)];
2564
2564
  j[0] !== e[e.length - 1][0] && j[1] !== e[e.length - 1][1] && b.unshift(j);
2565
2565
  }
2566
2566
  e.push(...b), e.push(e[0]), this.currentId ? this.updatePolygonGeometry(this.currentId, e, M.Provisional) : [this.currentId] = this.store.create([{ geometry: { type: "Polygon", coordinates: [e] }, properties: { mode: this.mode } }]);
@@ -2784,11 +2784,11 @@ class $i {
2784
2784
  const c = h.geometry.coordinates;
2785
2785
  for (let u = 0; u < c.length - 1; u++) {
2786
2786
  const p = c[u], g = c[u + 1];
2787
- if (Le(l, a(p[0], p[1]), a(g[0], g[1])) < o) return !0;
2787
+ if (_e(l, a(p[0], p[1]), a(g[0], g[1])) < o) return !0;
2788
2788
  }
2789
2789
  return !1;
2790
2790
  }
2791
- return !!_e([t, e], h.geometry.coordinates) || void 0;
2791
+ return !!Le([t, e], h.geometry.coordinates) || void 0;
2792
2792
  });
2793
2793
  }
2794
2794
  getSelectMode() {
@@ -3538,22 +3538,22 @@ Alt. `, ["to-string", ["floor", ["get", "elevation"]]], " m"],
3538
3538
  styles: {}
3539
3539
  })
3540
3540
  });
3541
- var L = 63710088e-1, qi = {
3542
- centimeters: L * 100,
3543
- centimetres: L * 100,
3541
+ var _ = 63710088e-1, qi = {
3542
+ centimeters: _ * 100,
3543
+ centimetres: _ * 100,
3544
3544
  degrees: 360 / (2 * Math.PI),
3545
- feet: L * 3.28084,
3546
- inches: L * 39.37,
3547
- kilometers: L / 1e3,
3548
- kilometres: L / 1e3,
3549
- meters: L,
3550
- metres: L,
3551
- miles: L / 1609.344,
3552
- millimeters: L * 1e3,
3553
- millimetres: L * 1e3,
3554
- nauticalmiles: L / 1852,
3545
+ feet: _ * 3.28084,
3546
+ inches: _ * 39.37,
3547
+ kilometers: _ / 1e3,
3548
+ kilometres: _ / 1e3,
3549
+ meters: _,
3550
+ metres: _,
3551
+ miles: _ / 1609.344,
3552
+ millimeters: _ * 1e3,
3553
+ millimetres: _ * 1e3,
3554
+ nauticalmiles: _ / 1852,
3555
3555
  radians: 1,
3556
- yards: L * 1.0936
3556
+ yards: _ * 1.0936
3557
3557
  };
3558
3558
  function Zi(s, t, e = {}) {
3559
3559
  const i = { type: "Feature" };
@@ -3772,7 +3772,7 @@ function re(s) {
3772
3772
  }
3773
3773
  return t;
3774
3774
  }
3775
- var ro = L * L / 2, Dt = Math.PI / 180;
3775
+ var ro = _ * _ / 2, Dt = Math.PI / 180;
3776
3776
  function ne(s) {
3777
3777
  const t = s.length - 1;
3778
3778
  if (t <= 2) return 0;
@@ -3813,7 +3813,7 @@ function lo(s, t, e = {}) {
3813
3813
  );
3814
3814
  }
3815
3815
  var ho = lo;
3816
- const de = (s) => s === "degrees" ? "°" : s === "miles" ? "mi" : s === "radians" ? "rad" : "km", _t = (s) => {
3816
+ const de = (s) => s === "degrees" ? "°" : s === "miles" ? "mi" : s === "radians" ? "rad" : "km", Lt = (s) => {
3817
3817
  if (s >= 1)
3818
3818
  return {
3819
3819
  distance: s,
@@ -3845,12 +3845,12 @@ const de = (s) => s === "degrees" ? "°" : s === "miles" ? "mi" : s === "radians
3845
3845
  l.push(p);
3846
3846
  }
3847
3847
  if (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)), t === "kilometers") {
3848
- const d = _t(s.properties.distance);
3848
+ const d = Lt(s.properties.distance);
3849
3849
  s.properties.distance = d.distance, s.properties.unit = d.unit, s.properties.segments.forEach(
3850
3850
  (h) => {
3851
- const c = _t(h.properties.distance);
3851
+ const c = Lt(h.properties.distance);
3852
3852
  h.properties.distance = c.distance, h.properties.unit = c.unit;
3853
- const u = _t(h.properties.total);
3853
+ const u = Lt(h.properties.total);
3854
3854
  h.properties.total = u.distance, h.properties.totalUnit = u.unit;
3855
3855
  }
3856
3856
  );
@@ -4502,7 +4502,7 @@ class jo extends Fo {
4502
4502
  * @param options Plugin control options
4503
4503
  */
4504
4504
  constructor(e) {
4505
- let i = ft;
4505
+ let i = structuredClone(ft);
4506
4506
  e && (i = Object.assign(i, e));
4507
4507
  super({
4508
4508
  modes: i.modes,
@@ -4649,6 +4649,41 @@ class jo extends Fo {
4649
4649
  const i = this.measureOptions.computeElevation === e;
4650
4650
  this.measureOptions.computeElevation = e, i || this.recalc();
4651
4651
  }
4652
+ /**
4653
+ * Get/Set font glyph for measure control layers
4654
+ *
4655
+ * As default, this maesure control uses maplibre's default font glyphs(`Open Sans Regular,Arial Unicode MS Regular`) described at https://maplibre.org/maplibre-style-spec/layers/#text-font
4656
+ *
4657
+ * If you are using your own maplibre style or different map privider, you probably need to set the font glyphs to match your maplibre style.
4658
+ *
4659
+ * Font glyph availability depends on what types of glyphs are supported by your maplibre style (e.g., Carto, Openmap tiles, Protomap, Maptiler, etc.)
4660
+ * Please make sure the font glyphs are available in your maplibre style.
4661
+ *
4662
+ * Usage:
4663
+ *
4664
+ * ```js
4665
+ * const drawControl = new MaplibreMeasureControl()
4666
+ * drawControl.fontGlyphs = ['Open Sans Italic']
4667
+ * map.addControl(drawControl)
4668
+ * ```
4669
+ */
4670
+ get fontGlyphs() {
4671
+ const i = [
4672
+ this.measureOptions.pointLayerLabelSpec,
4673
+ this.measureOptions.lineLayerLabelSpec,
4674
+ this.measureOptions.polygonLayerSpec
4675
+ ][0];
4676
+ return i && i.layout && i.layout["text-font"];
4677
+ }
4678
+ set fontGlyphs(e) {
4679
+ const i = [
4680
+ this.measureOptions.pointLayerLabelSpec,
4681
+ this.measureOptions.lineLayerLabelSpec,
4682
+ this.measureOptions.polygonLayerSpec
4683
+ ];
4684
+ for (const o of i)
4685
+ o && o.layout && (o.layout["text-font"] = e), this.map && o && this.map.getLayer(o.id) && this.map.setLayoutProperty(o.id, "text-font", e);
4686
+ }
4652
4687
  /**
4653
4688
  * add the plugin control to maplibre
4654
4689
  * @param map Maplibre Map object
@@ -5044,7 +5079,7 @@ export {
5044
5079
  ce as capitalize,
5045
5080
  Ue as cleanMaplibreStyle,
5046
5081
  ao as convertAreaUnit,
5047
- _t as convertMetricDistance,
5082
+ Lt as convertMetricDistance,
5048
5083
  co as debounce,
5049
5084
  Hi as defaultControlOptions,
5050
5085
  ft as defaultMeasureControlOptions,