@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 +4 -0
- package/dist/maplibre-gl-terradraw.es.js +44 -26
- package/dist/maplibre-gl-terradraw.es.js.map +1 -1
- package/dist/maplibre-gl-terradraw.umd.js +2 -2
- package/dist/maplibre-gl-terradraw.umd.js.map +1 -1
- package/dist/types/MaplibreMeasureControl.d.ts.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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)
|
|
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
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
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 =
|
|
3542
|
-
|
|
3543
|
-
const
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
(
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
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
|
}
|