@watergis/maplibre-gl-terradraw 0.0.5 → 0.1.0

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.
@@ -515,7 +515,7 @@ var Qt = class {
515
515
  return this.getPointResolutionFunc_;
516
516
  }
517
517
  };
518
- const J = 6378137, T = Math.PI * J, Pe = [-T, -T, T, T], Me = [-180, -85, 180, 85], it = J * Math.log(Math.tan(Math.PI / 2));
518
+ const J = 6378137, X = Math.PI * J, Pe = [-X, -X, X, X], Me = [-180, -85, 180, 85], it = J * Math.log(Math.tan(Math.PI / 2));
519
519
  class V extends Qt {
520
520
  constructor(t) {
521
521
  super({ code: t, units: "m", extent: Pe, global: !0, worldExtent: Me, getPointResolution: function(e, i) {
@@ -557,7 +557,7 @@ jt(Ft), jt(Ot), Lt = Ft, Wt = function(s, t, e) {
557
557
  const i = s.length;
558
558
  e = e > 1 ? e : 2, t === void 0 && (t = e > 2 ? s.slice() : new Array(i));
559
559
  for (let o = 0; o < i; o += e) {
560
- t[o] = T * s[o] / 180;
560
+ t[o] = X * s[o] / 180;
561
561
  let n = J * Math.log(Math.tan(Math.PI * (+s[o + 1] + 90) / 360));
562
562
  n > it ? n = it : n < -it && (n = -it), t[o + 1] = n;
563
563
  }
@@ -565,7 +565,7 @@ jt(Ft), jt(Ot), Lt = Ft, Wt = function(s, t, e) {
565
565
  }, Bt = function(s, t, e) {
566
566
  const i = s.length;
567
567
  e = e > 1 ? e : 2, t === void 0 && (t = e > 2 ? s.slice() : new Array(i));
568
- for (let o = 0; o < i; o += e) t[o] = 180 * s[o] / T, t[o + 1] = 360 * Math.atan(Math.exp(s[o + 1] / J)) / Math.PI - 90;
568
+ for (let o = 0; o < i; o += e) t[o] = 180 * s[o] / X, t[o + 1] = 360 * Math.atan(Math.exp(s[o + 1] / J)) / Math.PI - 90;
569
569
  return t;
570
570
  }, Ot.forEach(function(s) {
571
571
  Lt.forEach(function(t) {
@@ -689,13 +689,13 @@ function w(s) {
689
689
  function ee(s) {
690
690
  return s / (Mt / 1e3);
691
691
  }
692
- function X(s) {
692
+ function T(s) {
693
693
  return s % (2 * Math.PI) * 180 / Math.PI;
694
694
  }
695
695
  const At = 57.29577951308232, Vt = 0.017453292519943295, lt = 6378137, P = (s, t) => ({ x: s === 0 ? 0 : s * Vt * lt, y: t === 0 ? 0 : Math.log(Math.tan(Math.PI / 4 + t * Vt / 2)) * lt }), j = (s, t) => ({ lng: s === 0 ? 0 : At * (s / lt), lat: t === 0 ? 0 : (2 * Math.atan(Math.exp(t / lt)) - Math.PI / 2) * At });
696
696
  function Se(s, t, e) {
697
697
  const i = w(s[0]), o = w(s[1]), n = w(e), r = ee(t), a = Math.asin(Math.sin(o) * Math.cos(r) + Math.cos(o) * Math.sin(r) * Math.cos(n));
698
- return [X(i + Math.atan2(Math.sin(n) * Math.sin(r) * Math.cos(o), Math.cos(r) - Math.sin(o) * Math.sin(a))), X(a)];
698
+ return [T(i + Math.atan2(Math.sin(n) * Math.sin(r) * Math.cos(o), Math.cos(r) - Math.sin(o) * Math.sin(a))), T(a)];
699
699
  }
700
700
  function Rt(s) {
701
701
  const { center: t, radiusKilometers: e, coordinatePrecision: i } = s, o = s.steps ? s.steps : 64, n = [];
@@ -958,17 +958,17 @@ class se extends D {
958
958
  }), n.coord;
959
959
  }
960
960
  }
961
- function Tt(s, t, e) {
961
+ function Xt(s, t, e) {
962
962
  const i = w(s[0]), o = w(s[1]), n = w(e), r = ee(t), a = Math.asin(Math.sin(o) * Math.cos(r) + Math.cos(o) * Math.sin(r) * Math.cos(n));
963
- return [X(i + Math.atan2(Math.sin(n) * Math.sin(r) * Math.cos(o), Math.cos(r) - Math.sin(o) * Math.sin(a))), X(a)];
963
+ return [T(i + Math.atan2(Math.sin(n) * Math.sin(r) * Math.cos(o), Math.cos(r) - Math.sin(o) * Math.sin(a))), T(a)];
964
964
  }
965
- function Xt({ x: s, y: t }, e, i) {
965
+ function Tt({ x: s, y: t }, e, i) {
966
966
  const o = w(i);
967
967
  return { x: s + e * Math.cos(o), y: t + e * Math.sin(o) };
968
968
  }
969
969
  function Kt(s, t) {
970
970
  const e = w(s[0]), i = w(t[0]), o = w(s[1]), n = w(t[1]), r = Math.sin(i - e) * Math.cos(n), a = Math.cos(o) * Math.sin(n) - Math.sin(o) * Math.cos(n) * Math.cos(i - e);
971
- return X(Math.atan2(r, a));
971
+ return T(Math.atan2(r, a));
972
972
  }
973
973
  function ht({ x: s, y: t }, { x: e, y: i }) {
974
974
  let o = Math.atan2(i - t, e - s);
@@ -980,9 +980,9 @@ function De(s, t, e) {
980
980
  for (let h = 0; h < s.length && !(t >= l && h === s.length - 1); h++) {
981
981
  if (l > t && i.length === 0) {
982
982
  if (n = t - l, !n) return i.push(s[h]), i;
983
- r = Kt(s[h], s[h - 1]) - 180, a = Tt(s[h], n, r), i.push(a);
983
+ r = Kt(s[h], s[h - 1]) - 180, a = Xt(s[h], n, r), i.push(a);
984
984
  }
985
- if (l >= e) return n = e - l, n ? (r = Kt(s[h], s[h - 1]) - 180, a = Tt(s[h], n, r), i.push(a), i) : (i.push(s[h]), i);
985
+ if (l >= e) return n = e - l, n ? (r = Kt(s[h], s[h - 1]) - 180, a = Xt(s[h], n, r), i.push(a), i) : (i.push(s[h]), i);
986
986
  if (l >= t && i.push(s[h]), h === s.length - 1) return i;
987
987
  l += W(s[h], s[h + 1]);
988
988
  }
@@ -1431,7 +1431,7 @@ function dt(s, t) {
1431
1431
  const e = s, i = t, o = w(e[1]), n = w(i[1]);
1432
1432
  let r = w(i[0] - e[0]);
1433
1433
  r > Math.PI && (r -= 2 * Math.PI), r < -Math.PI && (r += 2 * Math.PI);
1434
- const a = Math.log(Math.tan(n / 2 + Math.PI / 4) / Math.tan(o / 2 + Math.PI / 4)), l = (X(Math.atan2(r, a)) + 360) % 360;
1434
+ const a = Math.log(Math.tan(n / 2 + Math.PI / 4) / Math.tan(o / 2 + Math.PI / 4)), l = (T(Math.atan2(r, a)) + 360) % 360;
1435
1435
  return l > 180 ? -(360 - l) : l;
1436
1436
  }
1437
1437
  function Et(s, t, e) {
@@ -1675,7 +1675,7 @@ function ut(s) {
1675
1675
  return { x: o / i, y: n / i };
1676
1676
  }(t);
1677
1677
  }
1678
- class Te extends D {
1678
+ class Xe extends D {
1679
1679
  constructor(t, e, i) {
1680
1680
  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;
1681
1681
  }
@@ -1718,7 +1718,7 @@ class Te extends D {
1718
1718
  this.store.updateGeometry([{ id: e, geometry: o }, ...h, ...d]), this.projection === "web-mercator" ? this.lastBearing = r : this.projection === "globe" && (this.lastBearing = r + 180);
1719
1719
  }
1720
1720
  }
1721
- class Xe extends D {
1721
+ class Te extends D {
1722
1722
  constructor(t, e, i) {
1723
1723
  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;
1724
1724
  }
@@ -1947,7 +1947,7 @@ class Ye extends Ee {
1947
1947
  this._state = "selecting";
1948
1948
  }
1949
1949
  registerBehaviors(t) {
1950
- this.pixelDistance = new pt(t), this.clickBoundingBox = new bt(t), this.featuresAtMouseEvent = new Ve(t, this.clickBoundingBox, this.pixelDistance), this.selectionPoints = new Ae(t), this.midPoints = new Ge(t, this.selectionPoints), this.rotateFeature = new Te(t, this.selectionPoints, this.midPoints), this.scaleFeature = new Xe(t, this.selectionPoints, this.midPoints), this.dragFeature = new Re(t, this.featuresAtMouseEvent, this.selectionPoints, this.midPoints), this.dragCoordinate = new Ue(t, this.pixelDistance, this.selectionPoints, this.midPoints), this.dragCoordinateResizeFeature = new Ke(t, this.pixelDistance, this.selectionPoints, this.midPoints);
1950
+ this.pixelDistance = new pt(t), this.clickBoundingBox = new bt(t), this.featuresAtMouseEvent = new Ve(t, this.clickBoundingBox, this.pixelDistance), this.selectionPoints = new Ae(t), this.midPoints = new Ge(t, this.selectionPoints), this.rotateFeature = new Xe(t, this.selectionPoints, this.midPoints), this.scaleFeature = new Te(t, this.selectionPoints, this.midPoints), this.dragFeature = new Re(t, this.featuresAtMouseEvent, this.selectionPoints, this.midPoints), this.dragCoordinate = new Ue(t, this.pixelDistance, this.selectionPoints, this.midPoints), this.dragCoordinateResizeFeature = new Ke(t, this.pixelDistance, this.selectionPoints, this.midPoints);
1951
1951
  }
1952
1952
  deselectFeature() {
1953
1953
  this.deselect();
@@ -2525,7 +2525,7 @@ class ii extends O {
2525
2525
  const o = e[0], n = e[1], r = re(o, n, this.coordinatePrecision, this.project, this.unproject), a = P(o[0], o[1]), l = P(r[0], r[1]), d = P(n[0], n[1]), h = P(t.lng, t.lat), c = I(h, a) < I(h, d), u = $t(a, l, h), g = c ? 90 - u : $t(a, l, h) - 90, p = I(l, h), y = Math.cos(w(g)) * p, v = ht(a, d) + (function(_, S, F) {
2526
2526
  const B = (F.x - S.x) * (_.y - S.y) - (F.y - S.y) * (_.x - S.x);
2527
2527
  return B > 1e-10 ? "left" : B < -1e-10 ? "right" : "left";
2528
- }(a, d, h) === "right" ? -90 : 90), m = Xt(a, y, v), x = Xt(d, y, v), M = j(m.x, m.y), E = j(x.x, x.y);
2528
+ }(a, d, h) === "right" ? -90 : 90), m = Tt(a, y, v), x = Tt(d, y, v), M = j(m.x, m.y), E = j(x.x, x.y);
2529
2529
  i = [e[0], e[1], [E.lng, E.lat], [M.lng, M.lat], e[0]];
2530
2530
  }
2531
2531
  i && this.updatePolygonGeometry(this.currentId, i, C.Provisional);
@@ -2740,115 +2740,120 @@ class oi {
2740
2740
  }
2741
2741
  }
2742
2742
  const si = {
2743
- point: !0,
2744
- line: !0,
2745
- polygon: !0,
2746
- rectangle: !0,
2747
- circle: !0,
2748
- freehand: !0,
2749
- angledRectangle: !0,
2750
- select: !0,
2743
+ modes: [
2744
+ "point",
2745
+ "linestring",
2746
+ "polygon",
2747
+ "rectangle",
2748
+ "angled-rectangle",
2749
+ "circle",
2750
+ "freehand",
2751
+ "select"
2752
+ ],
2751
2753
  open: !1
2752
- }, ni = (s) => {
2753
- const t = [];
2754
- return t.push(
2755
- new Be({
2756
- modeName: "render",
2757
- styles: {}
2758
- })
2759
- ), s.point === !0 && t.push(new Oe()), s.line === !0 && t.push(new ke()), s.polygon === !0 && t.push(
2760
- new Le({
2761
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2762
- // @ts-ignore
2763
- validation: (e, i) => {
2764
- const o = i.updateType;
2765
- return o === "finish" || o === "commit" ? ei(e) : !0;
2766
- }
2767
- })
2768
- ), s.rectangle === !0 && t.push(new We()), s.angledRectangle === !0 && t.push(new ii()), s.circle === !0 && t.push(new we()), s.freehand === !0 && t.push(new Ie()), s.select === !0 && t.push(
2769
- new Ye({
2770
- flags: {
2771
- point: {
2772
- feature: {
2773
- draggable: !0
2774
- }
2775
- },
2776
- polygon: {
2777
- feature: {
2754
+ }, ni = () => ({
2755
+ render: new Be({
2756
+ modeName: "render",
2757
+ styles: {}
2758
+ }),
2759
+ point: new Oe(),
2760
+ linestring: new ke(),
2761
+ polygon: new Le({
2762
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2763
+ // @ts-ignore
2764
+ validation: (t, e) => {
2765
+ const i = e.updateType;
2766
+ return i === "finish" || i === "commit" ? ei(t) : !0;
2767
+ }
2768
+ }),
2769
+ rectangle: new We(),
2770
+ "angled-rectangle": new ii(),
2771
+ circle: new we(),
2772
+ freehand: new Ie(),
2773
+ select: new Ye({
2774
+ flags: {
2775
+ point: {
2776
+ feature: {
2777
+ draggable: !0
2778
+ }
2779
+ },
2780
+ polygon: {
2781
+ feature: {
2782
+ draggable: !0,
2783
+ rotateable: !0,
2784
+ scaleable: !0,
2785
+ coordinates: {
2786
+ midpoints: !0,
2778
2787
  draggable: !0,
2779
- rotateable: !0,
2780
- scaleable: !0,
2781
- coordinates: {
2782
- midpoints: !0,
2783
- draggable: !0,
2784
- deletable: !0
2785
- }
2788
+ deletable: !0
2786
2789
  }
2787
- },
2788
- linestring: {
2789
- feature: {
2790
+ }
2791
+ },
2792
+ linestring: {
2793
+ feature: {
2794
+ draggable: !0,
2795
+ coordinates: {
2796
+ midpoints: !0,
2790
2797
  draggable: !0,
2791
- coordinates: {
2792
- midpoints: !0,
2793
- draggable: !0,
2794
- deletable: !0
2795
- }
2798
+ deletable: !0
2796
2799
  }
2797
- },
2798
- freehand: {
2799
- feature: {
2800
+ }
2801
+ },
2802
+ freehand: {
2803
+ feature: {
2804
+ draggable: !0,
2805
+ coordinates: {
2806
+ midpoints: !0,
2800
2807
  draggable: !0,
2801
- coordinates: {
2802
- midpoints: !0,
2803
- draggable: !0,
2804
- deletable: !0
2805
- }
2808
+ deletable: !0
2806
2809
  }
2807
- },
2808
- circle: {
2809
- feature: {
2810
+ }
2811
+ },
2812
+ circle: {
2813
+ feature: {
2814
+ draggable: !0,
2815
+ coordinates: {
2816
+ midpoints: !0,
2810
2817
  draggable: !0,
2811
- coordinates: {
2812
- midpoints: !0,
2813
- draggable: !0,
2814
- deletable: !0
2815
- }
2818
+ deletable: !0
2816
2819
  }
2817
- },
2818
- rectangle: {
2819
- feature: {
2820
+ }
2821
+ },
2822
+ rectangle: {
2823
+ feature: {
2824
+ draggable: !0,
2825
+ rotateable: !0,
2826
+ scaleable: !0,
2827
+ coordinates: {
2828
+ midpoints: !0,
2820
2829
  draggable: !0,
2821
- rotateable: !0,
2822
- scaleable: !0,
2823
- coordinates: {
2824
- midpoints: !0,
2825
- draggable: !0,
2826
- deletable: !0
2827
- }
2830
+ deletable: !0
2828
2831
  }
2829
- },
2830
- "angled-rectangle": {
2831
- feature: {
2832
+ }
2833
+ },
2834
+ "angled-rectangle": {
2835
+ feature: {
2836
+ draggable: !0,
2837
+ rotateable: !0,
2838
+ scaleable: !0,
2839
+ coordinates: {
2840
+ midpoints: !0,
2832
2841
  draggable: !0,
2833
- rotateable: !0,
2834
- scaleable: !0,
2835
- coordinates: {
2836
- midpoints: !0,
2837
- draggable: !0,
2838
- deletable: !0
2839
- }
2842
+ deletable: !0
2840
2843
  }
2841
2844
  }
2842
2845
  }
2843
- })
2844
- ), t;
2845
- };
2846
+ }
2847
+ })
2848
+ });
2846
2849
  class ai {
2847
2850
  /**
2848
2851
  * Constructor
2849
2852
  * @param options Plugin control options
2853
+ * @param modeOptions Overwrite Terra Draw mode options if you specified.
2854
+ *
2850
2855
  */
2851
- constructor(t) {
2856
+ constructor(t, e) {
2852
2857
  k(this, "controlContainer");
2853
2858
  k(this, "map");
2854
2859
  k(this, "addButton");
@@ -2858,26 +2863,30 @@ class ai {
2858
2863
  k(this, "activeMode");
2859
2864
  k(this, "terradraw");
2860
2865
  k(this, "options", si);
2861
- this.modeButtons = {}, this.activeMode = "render", t && (this.options = Object.assign(this.options, t));
2866
+ k(this, "modeOptions");
2867
+ this.modeButtons = {}, this.activeMode = "render", t && (this.options = Object.assign(this.options, t)), this.modeOptions = e;
2862
2868
  }
2863
2869
  getDefaultPosition() {
2864
2870
  return "top-right";
2865
2871
  }
2866
2872
  onAdd(t) {
2867
- this.map = t;
2868
- const e = ni(this.options);
2869
- if (e.length === 0)
2873
+ var o, n;
2874
+ if (this.options && this.options.modes && this.options.modes.length === 0)
2870
2875
  throw new Error("At least a mode must be enabled.");
2871
- return this.isExpanded = this.options.open === !0, this.terradraw = new oi({
2876
+ this.map = t;
2877
+ const e = ni(), i = [e.render];
2878
+ return (n = (o = this.options) == null ? void 0 : o.modes) == null || n.forEach((r) => {
2879
+ this.modeOptions && this.modeOptions[r] ? i.push(this.modeOptions[r]) : e[r] && i.push(e[r]);
2880
+ }), this.isExpanded = this.options.open === !0, this.terradraw = new oi({
2872
2881
  adapter: new pe({ map: t }),
2873
- modes: e
2874
- }), this.terradraw.start(), this.controlContainer = document.createElement("div"), this.controlContainer.classList.add("maplibregl-ctrl"), this.controlContainer.classList.add("maplibregl-ctrl-group"), this.addButton = document.createElement("button"), this.addButton.classList.add("maplibregl-terradraw-add-button"), this.isExpanded && this.addButton.classList.add("enabled"), this.addButton.type = "button", this.addButton.addEventListener("click", this.toggleEditor.bind(this)), e.forEach((i) => {
2875
- i.mode !== "render" && this.addTerradrawButton(i.mode);
2882
+ modes: i
2883
+ }), this.terradraw.start(), this.controlContainer = document.createElement("div"), this.controlContainer.classList.add("maplibregl-ctrl"), this.controlContainer.classList.add("maplibregl-ctrl-group"), this.addButton = document.createElement("button"), this.addButton.classList.add("maplibregl-terradraw-add-button"), this.isExpanded && this.addButton.classList.add("enabled"), this.addButton.type = "button", this.addButton.addEventListener("click", this.toggleEditor.bind(this)), i.forEach((r) => {
2884
+ r.mode !== "render" && this.addTerradrawButton(r.mode);
2876
2885
  }), this.deleteButton = document.createElement("button"), this.deleteButton.classList.add("maplibregl-terradraw-add-control"), this.deleteButton.classList.add("maplibregl-terradraw-delete-button"), this.isExpanded || this.deleteButton.classList.add("hidden"), this.deleteButton.type = "button", this.deleteButton.addEventListener("click", () => {
2877
2886
  this.terradraw && this.terradraw.enabled && (this.terradraw.clear(), this.deactivate());
2878
- }), this.controlContainer.appendChild(this.addButton), Object.values(this.modeButtons).forEach((i) => {
2879
- var o;
2880
- (o = this.controlContainer) == null || o.appendChild(i);
2887
+ }), this.controlContainer.appendChild(this.addButton), Object.values(this.modeButtons).forEach((r) => {
2888
+ var a;
2889
+ (a = this.controlContainer) == null || a.appendChild(r);
2881
2890
  }), this.controlContainer.appendChild(this.deleteButton), this.controlContainer;
2882
2891
  }
2883
2892
  onRemove() {