@watergis/maplibre-gl-terradraw 1.3.2 → 1.3.3

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.
@@ -4582,29 +4582,27 @@ class ko extends bo {
4582
4582
  * @param ids Feature IDs
4583
4583
  */
4584
4584
  handleTerradrawFeatureChanged(e, i) {
4585
- if (!this.map || i === "stylying") return;
4586
- const o = this.getTerraDrawInstance();
4587
- if (!o) return;
4588
- const r = o.getSnapshot();
4589
- for (const n of e) {
4590
- const a = r.find((l) => l.id === n);
4591
- if (a) {
4592
- const l = a.geometry.type, d = a.properties.mode;
4593
- d === "linestring" && l === "LineString" ? this.measureLine(n) : d === "point" && l === "Point" ? this.measurePoint(n) : !["point", "linestring", "select", "render"].includes(d) && l === "Polygon" && this.measurePolygon(n);
4585
+ if (!this.map || i === "styling") return;
4586
+ const r = [
4587
+ this.measureOptions.pointLayerLabelSpec,
4588
+ this.measureOptions.lineLayerLabelSpec,
4589
+ this.measureOptions.lineLayerNodeSpec,
4590
+ this.measureOptions.polygonLayerSpec
4591
+ ].map((l) => l.source);
4592
+ if (i === "delete") {
4593
+ this.clearMeasureFeatures(r, e);
4594
+ return;
4595
+ }
4596
+ const n = this.getTerraDrawInstance();
4597
+ if (!n) return;
4598
+ const a = n.getSnapshot();
4599
+ for (const l of e) {
4600
+ const d = a.find((h) => h.id === l);
4601
+ if (d) {
4602
+ const h = d.geometry.type, c = d.properties.mode;
4603
+ c === "linestring" && h === "LineString" ? this.measureLine(l) : c === "point" && h === "Point" ? this.measurePoint(l) : !["point", "linestring", "select", "render"].includes(c) && h === "Polygon" && this.measurePolygon(l);
4594
4604
  } else
4595
- this.clearMeasureFeatures(
4596
- n,
4597
- this.measureOptions.lineLayerNodeSpec.source
4598
- ), this.clearMeasureFeatures(
4599
- n,
4600
- this.measureOptions.lineLayerLabelSpec.source
4601
- ), this.clearMeasureFeatures(
4602
- n,
4603
- this.measureOptions.polygonLayerSpec.source
4604
- ), this.clearMeasureFeatures(
4605
- n,
4606
- this.measureOptions.pointLayerLabelSpec.source
4607
- );
4605
+ this.clearMeasureFeatures(r, [l]);
4608
4606
  }
4609
4607
  }
4610
4608
  /**
@@ -4627,20 +4625,20 @@ class ko extends bo {
4627
4625
  }
4628
4626
  /**
4629
4627
  * Clear GeoJSON feature related to measure control by TerraDraw feature ID
4630
- * @param id feature ID
4631
- * @param sourceId source ID to delete
4628
+ * @param sourceIds the array of source ID to delete
4629
+ * @param ids the array of feature ID. Optional, if undefined, delete all labels for source
4632
4630
  * @returns void
4633
4631
  */
4634
- clearMeasureFeatures(e, i) {
4635
- var r;
4636
- if (!this.map) return;
4637
- const o = this.map.getStyle().sources[i];
4638
- o && typeof o.data != "string" && o.data.type === "FeatureCollection" && (o.data.features = o.data.features.filter(
4639
- (n) => {
4640
- var a;
4641
- return ((a = n.properties) == null ? void 0 : a.originalId) !== e;
4632
+ clearMeasureFeatures(e, i = void 0) {
4633
+ var o;
4634
+ if (this.map)
4635
+ for (const r of e) {
4636
+ const n = this.map.getStyle().sources[r];
4637
+ n && typeof n.data != "string" && n.data.type === "FeatureCollection" && (i === void 0 ? n.data.features = [] : n.data.features = n.data.features.filter((a) => {
4638
+ var l;
4639
+ return (l = a.properties) != null && l.originalId ? !i.includes(a.properties.originalId) : !i.includes(a.id);
4640
+ }), (o = this.map.getSource(r)) == null || o.setData(n.data));
4642
4641
  }
4643
- ), (r = this.map.getSource(i)) == null || r.setData(o.data));
4644
4642
  }
4645
4643
  /**
4646
4644
  * Replace GeoJSON source with updated features for a given source ID
@@ -4649,32 +4647,35 @@ class ko extends bo {
4649
4647
  * @param type either 'linestring' or 'point'
4650
4648
  */
4651
4649
  replaceGeoJSONSource(e, i, o) {
4652
- var n;
4650
+ var n, a;
4653
4651
  if (!this.map) return;
4654
4652
  const r = this.map.getStyle().sources[i];
4655
4653
  if (r && typeof r.data != "string" && r.data.type === "FeatureCollection") {
4656
- const a = e.map((l) => l.id);
4654
+ const l = [];
4655
+ for (const h of e)
4656
+ (n = this.terradraw) != null && n.getSnapshotFeature(h.id) && l.push(h);
4657
+ const d = l.map((h) => h.id);
4657
4658
  if (typeof r.data != "string" && r.data.type === "FeatureCollection") {
4658
4659
  o === "linestring" ? r.data.features = [
4659
4660
  ...r.data.features = r.data.features.filter(
4660
- (d) => {
4661
- var h;
4662
- return !(a.includes((h = d.properties) == null ? void 0 : h.originalId) && d.geometry.type === "Point");
4661
+ (c) => {
4662
+ var u;
4663
+ return !(d.includes((u = c.properties) == null ? void 0 : u.originalId) && c.geometry.type === "Point");
4663
4664
  }
4664
4665
  ),
4665
- ...e
4666
+ ...l
4666
4667
  ] : o === "point" && (r.data.features = [
4667
4668
  ...r.data.features = r.data.features.filter(
4668
- (d) => !(a.includes(d.id) && d.geometry.type === "Point")
4669
+ (c) => !(d.includes(c.id) && c.geometry.type === "Point")
4669
4670
  ),
4670
- ...e
4671
+ ...l
4671
4672
  ]);
4672
- const l = {};
4673
- r.data.features.forEach((d) => {
4674
- var c;
4675
- const h = d.id;
4676
- l[h] ? !l[h].properties.elevation && ((c = d.properties) != null && c.elevation) && (l[h] = d) : l[h] = d;
4677
- }), r.data.features = Array.from(Object.values(l)), (n = this.map.getSource(i)) == null || n.setData(r.data);
4673
+ const h = {};
4674
+ r.data.features.forEach((c) => {
4675
+ var p;
4676
+ const u = c.id;
4677
+ h[u] ? !h[u].properties.elevation && ((p = c.properties) != null && p.elevation) && (h[u] = c) : h[u] = c;
4678
+ }), r.data.features = Array.from(Object.values(h)), (a = this.map.getSource(i)) == null || a.setData(r.data);
4678
4679
  }
4679
4680
  }
4680
4681
  }
@@ -4801,29 +4802,17 @@ class ko extends bo {
4801
4802
  * Event definition when feature is deleted by terradraw
4802
4803
  */
4803
4804
  onFeatureDeleted(e) {
4804
- var o, r;
4805
4805
  if (!this.map) return;
4806
4806
  if (this.getTerraDrawInstance()) {
4807
- let n = [];
4808
- typeof e == "object" && e !== null && "deletedIds" in e && (n = e.deletedIds);
4809
- const a = [
4807
+ let o = [];
4808
+ typeof e == "object" && e !== null && "deletedIds" in e && (o = e.deletedIds);
4809
+ const n = [
4810
4810
  this.measureOptions.pointLayerLabelSpec,
4811
4811
  this.measureOptions.lineLayerLabelSpec,
4812
+ this.measureOptions.lineLayerNodeSpec,
4812
4813
  this.measureOptions.polygonLayerSpec
4813
- ];
4814
- if (n && n.length > 0)
4815
- for (const l of a) {
4816
- const d = this.map.getStyle().sources[l.source];
4817
- d && (typeof d.data != "string" && d.data.type === "FeatureCollection" && (d.data.features = d.data.features.filter((h) => {
4818
- var c;
4819
- return (c = h.properties) != null && c.originalId ? !n.includes(h.properties.originalId) : !n.includes(h.id);
4820
- })), (o = this.map.getSource(l.source)) == null || o.setData(d.data));
4821
- }
4822
- else
4823
- for (const l of a) {
4824
- const d = this.map.getStyle().sources[l.source];
4825
- d && (typeof d.data != "string" && d.data.type === "FeatureCollection" && (d.data.features = []), (r = this.map.getSource(l.source)) == null || r.setData(d.data));
4826
- }
4814
+ ].map((a) => a.source);
4815
+ o && o.length > 0 ? this.clearMeasureFeatures(n, o) : this.clearMeasureFeatures(n, void 0);
4827
4816
  }
4828
4817
  }
4829
4818
  /**