@watergis/maplibre-gl-terradraw 0.6.0 → 0.6.1

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.
package/README.md CHANGED
@@ -18,6 +18,10 @@ npm i -D @watergis/maplibre-gl-terradraw
18
18
 
19
19
  See the [documentation](https://terradraw.water-gis.com/).
20
20
 
21
+ ## Plugin API
22
+
23
+ See the [API documentation](https://watergis.github.io/maplibre-gl-terradraw/).
24
+
21
25
  ## Contribution
22
26
 
23
27
  See [CONTRIBUTING](./CONTRIBUTING.md)
@@ -3447,22 +3447,37 @@ class vi extends ni {
3447
3447
  * Register measure control related maplibre sources and layers
3448
3448
  */
3449
3449
  registerMesureControl() {
3450
+ var o, r;
3450
3451
  if (!this.map) return;
3451
- this.map.getSource(this.linelayerSpec.source) || this.map.addSource(this.linelayerSpec.source, {
3452
+ const e = (o = this.options.modes) == null ? void 0 : o.filter((n) => ["linestring"].includes(n));
3453
+ e && e.length > 0 && (this.map.getSource(this.linelayerSpec.source) || this.map.addSource(this.linelayerSpec.source, {
3452
3454
  type: "geojson",
3453
3455
  data: { type: "FeatureCollection", features: [] }
3454
- }), this.map.getLayer(this.linelayerSpec.id) || this.map.addLayer(this.linelayerSpec), this.map.getSource(this.polygonLayerSpec.source) || this.map.addSource(this.polygonLayerSpec.source, {
3456
+ }), this.map.getLayer(this.linelayerSpec.id) || this.map.addLayer(this.linelayerSpec));
3457
+ const i = (r = this.options.modes) == null ? void 0 : r.filter(
3458
+ (n) => [
3459
+ "polygon",
3460
+ "rectangle",
3461
+ "angled-rectangle",
3462
+ "circle",
3463
+ "sector",
3464
+ "sensor",
3465
+ "freehand"
3466
+ ].includes(n)
3467
+ );
3468
+ if (i && i.length > 0 && (this.map.getSource(this.polygonLayerSpec.source) || this.map.addSource(this.polygonLayerSpec.source, {
3455
3469
  type: "geojson",
3456
3470
  data: { type: "FeatureCollection", features: [] }
3457
- }), this.map.getLayer(this.polygonLayerSpec.id) || this.map.addLayer(this.polygonLayerSpec);
3458
- const e = this.getTerraDrawInstance();
3459
- e && (e.on("finish", (i) => {
3460
- if (!this.map) return;
3461
- const o = this.getTerraDrawInstance();
3462
- if (!o) return;
3463
- const r = o.getSnapshot(), a = (r == null ? void 0 : r.find((l) => l.id === i)).geometry.type;
3464
- a === "LineString" ? this.measureLine(i) : a === "Polygon" && this.measurePolygon(i);
3465
- }), this.on("feature-deleted", this.onFeatureDeleted.bind(this)));
3471
+ }), this.map.getLayer(this.polygonLayerSpec.id) || this.map.addLayer(this.polygonLayerSpec)), e && e.length > 0 || i && i.length > 0) {
3472
+ const n = this.getTerraDrawInstance();
3473
+ n && (n.on("finish", (a) => {
3474
+ if (!this.map) return;
3475
+ const l = this.getTerraDrawInstance();
3476
+ if (!l) return;
3477
+ const h = l.getSnapshot(), d = (h == null ? void 0 : h.find((u) => u.id === a)).geometry.type;
3478
+ d === "LineString" ? this.measureLine(a) : d === "Polygon" && this.measurePolygon(a);
3479
+ }), this.on("feature-deleted", this.onFeatureDeleted.bind(this)));
3480
+ }
3466
3481
  }
3467
3482
  /**
3468
3483
  * Unregister measure control related maplibre sources and layers
@@ -3538,21 +3553,24 @@ class vi extends ni {
3538
3553
  if (!this.map) return;
3539
3554
  const e = this.getTerraDrawInstance();
3540
3555
  if (e) {
3541
- const r = this.map.getStyle().sources[this.linelayerSpec.source, this.polygonLayerSpec.source];
3542
- if (r) {
3543
- const n = e.getSnapshot(), l = (n == null ? void 0 : n.filter(
3544
- (h) => ["LineString", "Polygon"].includes(h.geometry.type)
3545
- )).map((h) => h.id);
3546
- typeof r.data != "string" && r.data.type === "FeatureCollection" && (r.data.features = r.data.features.filter(
3547
- (h) => {
3548
- var c;
3549
- return l.includes((c = h.properties) == null ? void 0 : c.originalId);
3550
- }
3551
- )), (i = this.map.getSource(this.linelayerSpec.source)) == null || i.setData(
3552
- r.data
3553
- ), (o = this.map.getSource(this.polygonLayerSpec.source)) == null || o.setData(
3554
- r.data
3555
- ), this.map.moveLayer(this.linelayerSpec.id), this.map.moveLayer(this.polygonLayerSpec.id);
3556
+ const r = [this.linelayerSpec.source, this.polygonLayerSpec.source];
3557
+ for (const n of r) {
3558
+ const a = this.map.getStyle().sources[n];
3559
+ if (a) {
3560
+ const l = e.getSnapshot(), c = (l == null ? void 0 : l.filter(
3561
+ (d) => ["LineString", "Polygon"].includes(d.geometry.type)
3562
+ )).map((d) => d.id);
3563
+ typeof a.data != "string" && a.data.type === "FeatureCollection" && (a.data.features = a.data.features.filter(
3564
+ (d) => {
3565
+ var u;
3566
+ return c.includes((u = d.properties) == null ? void 0 : u.originalId);
3567
+ }
3568
+ )), n === this.linelayerSpec.source ? ((i = this.map.getSource(this.linelayerSpec.source)) == null || i.setData(
3569
+ a.data
3570
+ ), this.map.getLayer(this.linelayerSpec.id) && this.map.moveLayer(this.linelayerSpec.id)) : n === this.polygonLayerSpec.source && ((o = this.map.getSource(this.polygonLayerSpec.source)) == null || o.setData(
3571
+ a.data
3572
+ ), this.map.getLayer(this.polygonLayerSpec.id) && this.map.moveLayer(this.polygonLayerSpec.id));
3573
+ }
3556
3574
  }
3557
3575
  }
3558
3576
  }