@sindicum/libre-draw 0.1.0 → 0.1.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 +1 -0
- package/dist/LibreDraw.d.ts +19 -1
- package/dist/core/FeatureStore.d.ts +1 -8
- package/dist/index.d.ts +1 -1
- package/dist/libre-draw.cjs +1 -1
- package/dist/libre-draw.cjs.map +1 -1
- package/dist/libre-draw.js +43 -23
- package/dist/libre-draw.js.map +1 -1
- package/dist/types/features.d.ts +7 -0
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/libre-draw.js
CHANGED
|
@@ -278,7 +278,7 @@ function j(r, e, t) {
|
|
|
278
278
|
function X(r, e) {
|
|
279
279
|
return Math.abs(r[0] - e[0]) < 1e-10 && Math.abs(r[1] - e[1]) < 1e-10;
|
|
280
280
|
}
|
|
281
|
-
function
|
|
281
|
+
function J(r, e, t, s) {
|
|
282
282
|
if (X(r, t) || X(r, s) || X(e, t) || X(e, s))
|
|
283
283
|
return !1;
|
|
284
284
|
const i = z(r, e, t), n = z(r, e, s), o = z(t, s, r), l = z(t, s, e);
|
|
@@ -289,7 +289,7 @@ function ae(r) {
|
|
|
289
289
|
if (e < 3) return !1;
|
|
290
290
|
for (let t = 0; t < e; t++)
|
|
291
291
|
for (let s = t + 2; s < e; s++)
|
|
292
|
-
if (!(t === 0 && s === e - 1) &&
|
|
292
|
+
if (!(t === 0 && s === e - 1) && J(r[t], r[t + 1], r[s], r[s + 1]))
|
|
293
293
|
return !0;
|
|
294
294
|
return !1;
|
|
295
295
|
}
|
|
@@ -297,15 +297,15 @@ function ye(r, e) {
|
|
|
297
297
|
if (r.length < 2) return !1;
|
|
298
298
|
const t = r[r.length - 1];
|
|
299
299
|
for (let s = 0; s < r.length - 2; s++)
|
|
300
|
-
if (
|
|
300
|
+
if (J(t, e, r[s], r[s + 1]))
|
|
301
301
|
return !0;
|
|
302
302
|
return !1;
|
|
303
303
|
}
|
|
304
|
-
function
|
|
304
|
+
function q(r) {
|
|
305
305
|
if (r.length < 3) return !1;
|
|
306
306
|
const e = r[0], t = r[r.length - 1];
|
|
307
307
|
for (let s = 1; s < r.length - 2; s++)
|
|
308
|
-
if (
|
|
308
|
+
if (J(t, e, r[s], r[s + 1]))
|
|
309
309
|
return !0;
|
|
310
310
|
return !1;
|
|
311
311
|
}
|
|
@@ -441,7 +441,7 @@ class Se {
|
|
|
441
441
|
lat: s[1]
|
|
442
442
|
}), n = e.point.x - i.x, o = e.point.y - i.y;
|
|
443
443
|
if (Math.sqrt(n * n + o * o) <= we) {
|
|
444
|
-
if (
|
|
444
|
+
if (q(this.vertices)) return;
|
|
445
445
|
this.finalizePolygon();
|
|
446
446
|
return;
|
|
447
447
|
}
|
|
@@ -454,7 +454,7 @@ class Se {
|
|
|
454
454
|
onPointerUp(e) {
|
|
455
455
|
}
|
|
456
456
|
onDoubleClick(e) {
|
|
457
|
-
this.isActive && (this.vertices.length > W && this.vertices.pop(), this.vertices.length >= W && (
|
|
457
|
+
this.isActive && (this.vertices.length > W && this.vertices.pop(), this.vertices.length >= W && (q(this.vertices) || this.finalizePolygon()), e.originalEvent.preventDefault(), e.originalEvent.stopPropagation());
|
|
458
458
|
}
|
|
459
459
|
onLongPress(e) {
|
|
460
460
|
this.isActive && this.vertices.length > 0 && (this.vertices.pop(), this.vertices.length === 0 ? this.callbacks.clearPreview() : this.callbacks.renderPreview(this.buildPreviewCoordinates()));
|
|
@@ -525,24 +525,24 @@ function Me(r, e) {
|
|
|
525
525
|
function H(r) {
|
|
526
526
|
return new Float64Array(r);
|
|
527
527
|
}
|
|
528
|
-
const Pe = (3 + 16 * N) * N, ke = (2 + 12 * N) * N, Fe = (9 + 64 * N) * N * N, O = H(4), Q = H(8), Z = H(12), ee = H(16),
|
|
529
|
-
function
|
|
530
|
-
let l, h, d, u, a, c, g, y, p, m, f, b, T, I, M, P,
|
|
528
|
+
const Pe = (3 + 16 * N) * N, ke = (2 + 12 * N) * N, Fe = (9 + 64 * N) * N * N, O = H(4), Q = H(8), Z = H(12), ee = H(16), D = H(4);
|
|
529
|
+
function De(r, e, t, s, i, n, o) {
|
|
530
|
+
let l, h, d, u, a, c, g, y, p, m, f, b, T, I, M, P, C, k;
|
|
531
531
|
const L = r - i, x = t - i, V = e - n, A = s - n;
|
|
532
|
-
I = L * A, c = F * L, g = c - (c - L), y = L - g, c = F * A, p = c - (c - A), m = A - p, M = y * m - (I - g * p - y * p - g * m), P = V * x, c = F * V, g = c - (c - V), y = V - g, c = F * x, p = c - (c - x), m = x - p,
|
|
532
|
+
I = L * A, c = F * L, g = c - (c - L), y = L - g, c = F * A, p = c - (c - A), m = A - p, M = y * m - (I - g * p - y * p - g * m), P = V * x, c = F * V, g = c - (c - V), y = V - g, c = F * x, p = c - (c - x), m = x - p, C = y * m - (P - g * p - y * p - g * m), f = M - C, a = M - f, O[0] = M - (f + a) + (a - C), b = I + f, a = b - I, T = I - (b - a) + (f - a), f = T - P, a = T - f, O[1] = T - (f + a) + (a - P), k = b + f, a = k - b, O[2] = b - (k - a) + (f - a), O[3] = k;
|
|
533
533
|
let _ = Me(4, O), U = ke * o;
|
|
534
534
|
if (_ >= U || -_ >= U || (a = r - L, l = r - (L + a) + (a - i), a = t - x, d = t - (x + a) + (a - i), a = e - V, h = e - (V + a) + (a - n), a = s - A, u = s - (A + a) + (a - n), l === 0 && h === 0 && d === 0 && u === 0) || (U = Fe * o + Te * Math.abs(_), _ += L * u + A * l - (V * d + x * h), _ >= U || -_ >= U)) return _;
|
|
535
|
-
I = l * A, c = F * l, g = c - (c - l), y = l - g, c = F * A, p = c - (c - A), m = A - p, M = y * m - (I - g * p - y * p - g * m), P = h * x, c = F * h, g = c - (c - h), y = h - g, c = F * x, p = c - (c - x), m = x - p,
|
|
536
|
-
const ce = Y(4, O, 4,
|
|
537
|
-
I = L * u, c = F * L, g = c - (c - L), y = L - g, c = F * u, p = c - (c - u), m = u - p, M = y * m - (I - g * p - y * p - g * m), P = V * d, c = F * V, g = c - (c - V), y = V - g, c = F * d, p = c - (c - d), m = d - p,
|
|
538
|
-
const he = Y(ce, Q, 4,
|
|
539
|
-
I = l * u, c = F * l, g = c - (c - l), y = l - g, c = F * u, p = c - (c - u), m = u - p, M = y * m - (I - g * p - y * p - g * m), P = h * d, c = F * h, g = c - (c - h), y = h - g, c = F * d, p = c - (c - d), m = d - p,
|
|
540
|
-
const de = Y(he, Z, 4,
|
|
535
|
+
I = l * A, c = F * l, g = c - (c - l), y = l - g, c = F * A, p = c - (c - A), m = A - p, M = y * m - (I - g * p - y * p - g * m), P = h * x, c = F * h, g = c - (c - h), y = h - g, c = F * x, p = c - (c - x), m = x - p, C = y * m - (P - g * p - y * p - g * m), f = M - C, a = M - f, D[0] = M - (f + a) + (a - C), b = I + f, a = b - I, T = I - (b - a) + (f - a), f = T - P, a = T - f, D[1] = T - (f + a) + (a - P), k = b + f, a = k - b, D[2] = b - (k - a) + (f - a), D[3] = k;
|
|
536
|
+
const ce = Y(4, O, 4, D, Q);
|
|
537
|
+
I = L * u, c = F * L, g = c - (c - L), y = L - g, c = F * u, p = c - (c - u), m = u - p, M = y * m - (I - g * p - y * p - g * m), P = V * d, c = F * V, g = c - (c - V), y = V - g, c = F * d, p = c - (c - d), m = d - p, C = y * m - (P - g * p - y * p - g * m), f = M - C, a = M - f, D[0] = M - (f + a) + (a - C), b = I + f, a = b - I, T = I - (b - a) + (f - a), f = T - P, a = T - f, D[1] = T - (f + a) + (a - P), k = b + f, a = k - b, D[2] = b - (k - a) + (f - a), D[3] = k;
|
|
538
|
+
const he = Y(ce, Q, 4, D, Z);
|
|
539
|
+
I = l * u, c = F * l, g = c - (c - l), y = l - g, c = F * u, p = c - (c - u), m = u - p, M = y * m - (I - g * p - y * p - g * m), P = h * d, c = F * h, g = c - (c - h), y = h - g, c = F * d, p = c - (c - d), m = d - p, C = y * m - (P - g * p - y * p - g * m), f = M - C, a = M - f, D[0] = M - (f + a) + (a - C), b = I + f, a = b - I, T = I - (b - a) + (f - a), f = T - P, a = T - f, D[1] = T - (f + a) + (a - P), k = b + f, a = k - b, D[2] = b - (k - a) + (f - a), D[3] = k;
|
|
540
|
+
const de = Y(he, Z, 4, D, ee);
|
|
541
541
|
return ee[de - 1];
|
|
542
542
|
}
|
|
543
|
-
function
|
|
543
|
+
function Ce(r, e, t, s, i, n) {
|
|
544
544
|
const o = (e - n) * (t - i), l = (r - i) * (s - n), h = o - l, d = Math.abs(o + l);
|
|
545
|
-
return Math.abs(h) >= Pe * d ? h : -
|
|
545
|
+
return Math.abs(h) >= Pe * d ? h : -De(r, e, t, s, i, n, d);
|
|
546
546
|
}
|
|
547
547
|
function Le(r, e) {
|
|
548
548
|
var t, s, i = 0, n, o, l, h, d, u, a, c = r[0], g = r[1], y = e.length;
|
|
@@ -556,7 +556,7 @@ function Le(r, e) {
|
|
|
556
556
|
if (h <= 0 && o >= 0 || o <= 0 && h >= 0)
|
|
557
557
|
return 0;
|
|
558
558
|
} else if (d >= 0 && l <= 0 || d <= 0 && l >= 0) {
|
|
559
|
-
if (n =
|
|
559
|
+
if (n = Ce(o, h, l, d, 0, 0), n === 0)
|
|
560
560
|
return 0;
|
|
561
561
|
(n > 0 && d > 0 && l <= 0 || n < 0 && d <= 0 && l > 0) && i++;
|
|
562
562
|
}
|
|
@@ -1550,7 +1550,7 @@ class $e {
|
|
|
1550
1550
|
e.display = "flex", e.alignItems = "center", e.justifyContent = "center", e.width = "44px", e.height = "44px", e.padding = "0", e.margin = "0", e.border = "1px solid #ddd", e.borderRadius = "4px", e.backgroundColor = "#ffffff", e.color = "#333333", e.cursor = "pointer", e.outline = "none", e.transition = "background-color 0.15s, color 0.15s", e.boxSizing = "border-box";
|
|
1551
1551
|
}
|
|
1552
1552
|
}
|
|
1553
|
-
const Ye = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2l8.5 6.2-3.2 9.8H6.7L3.5 8.2z"/></svg>', Ge = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/><path d="M13 13l6 6"/></svg>',
|
|
1553
|
+
const Ye = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2l8.5 6.2-3.2 9.8H6.7L3.5 8.2z"/></svg>', Ge = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/><path d="M13 13l6 6"/></svg>', Je = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>', qe = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 14 4 9 9 4"/><path d="M20 20v-7a4 4 0 00-4-4H4"/></svg>', Qe = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 14 20 9 15 4"/><path d="M4 20v-7a4 4 0 014-4h12"/></svg>', Ze = {
|
|
1554
1554
|
draw: !0,
|
|
1555
1555
|
select: !0,
|
|
1556
1556
|
delete: !0,
|
|
@@ -1598,9 +1598,9 @@ class et {
|
|
|
1598
1598
|
this.callbacks.onDrawClick();
|
|
1599
1599
|
}, !0), e.select && this.addButton("select", Ge, "Select feature", () => {
|
|
1600
1600
|
this.callbacks.onSelectClick();
|
|
1601
|
-
}, !0), e.delete && this.addButton("delete",
|
|
1601
|
+
}, !0), e.delete && this.addButton("delete", Je, "Delete selected", () => {
|
|
1602
1602
|
this.callbacks.onDeleteClick();
|
|
1603
|
-
}), e.undo && this.addButton("undo",
|
|
1603
|
+
}), e.undo && this.addButton("undo", qe, "Undo", () => {
|
|
1604
1604
|
this.callbacks.onUndoClick();
|
|
1605
1605
|
}), e.redo && this.addButton("redo", Qe, "Redo", () => {
|
|
1606
1606
|
this.callbacks.onRedoClick();
|
|
@@ -1762,6 +1762,26 @@ class tt {
|
|
|
1762
1762
|
getFeatures() {
|
|
1763
1763
|
return this.assertNotDestroyed(), this.featureStore.getAll();
|
|
1764
1764
|
}
|
|
1765
|
+
/**
|
|
1766
|
+
* Export all features as a GeoJSON FeatureCollection.
|
|
1767
|
+
*
|
|
1768
|
+
* Returns a standard GeoJSON FeatureCollection containing all polygon
|
|
1769
|
+
* features currently in the store.
|
|
1770
|
+
*
|
|
1771
|
+
* @returns A GeoJSON {@link FeatureCollection}.
|
|
1772
|
+
*
|
|
1773
|
+
* @throws {LibreDrawError} If this instance has been destroyed.
|
|
1774
|
+
*
|
|
1775
|
+
* @example
|
|
1776
|
+
* ```ts
|
|
1777
|
+
* const geojson = draw.toGeoJSON();
|
|
1778
|
+
* console.log(JSON.stringify(geojson));
|
|
1779
|
+
* // { "type": "FeatureCollection", "features": [...] }
|
|
1780
|
+
* ```
|
|
1781
|
+
*/
|
|
1782
|
+
toGeoJSON() {
|
|
1783
|
+
return this.assertNotDestroyed(), this.featureStore.toGeoJSON();
|
|
1784
|
+
}
|
|
1765
1785
|
/**
|
|
1766
1786
|
* Replace all features in the store with the given GeoJSON FeatureCollection.
|
|
1767
1787
|
*
|