@loaders.gl/json 3.1.0 → 3.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/dist/bundle.js +852 -182
- package/dist/es5/geojson-loader.js +1 -1
- package/dist/es5/json-loader.js +1 -1
- package/dist/es5/ndjson-loader.js +1 -1
- package/dist/esm/geojson-loader.js +1 -1
- package/dist/esm/json-loader.js +1 -1
- package/dist/esm/ndjson-loader.js +1 -1
- package/dist/geojson-worker.js +777 -182
- package/package.json +5 -5
package/dist/bundle.js
CHANGED
|
@@ -1437,83 +1437,567 @@ Char: ${this.c}`;
|
|
|
1437
1437
|
}
|
|
1438
1438
|
});
|
|
1439
1439
|
|
|
1440
|
-
//
|
|
1441
|
-
function
|
|
1442
|
-
const
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1440
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
|
|
1441
|
+
function getPolygonSignedArea(points, options = {}) {
|
|
1442
|
+
const {
|
|
1443
|
+
start = 0,
|
|
1444
|
+
end = points.length
|
|
1445
|
+
} = options;
|
|
1446
|
+
const dim = options.size || 2;
|
|
1447
|
+
let area2 = 0;
|
|
1448
|
+
for (let i = start, j = end - dim; i < end; i += dim) {
|
|
1449
|
+
area2 += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);
|
|
1450
|
+
j = i;
|
|
1451
|
+
}
|
|
1452
|
+
return area2 / 2;
|
|
1448
1453
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1454
|
+
var init_polygon_utils = __esm({
|
|
1455
|
+
"../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js"() {
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
|
|
1459
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
|
|
1460
|
+
var init_polygon = __esm({
|
|
1461
|
+
"../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
|
|
1462
|
+
init_polygon_utils();
|
|
1463
|
+
}
|
|
1464
|
+
});
|
|
1465
|
+
|
|
1466
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
|
|
1467
|
+
function earcut(data, holeIndices, dim, areas) {
|
|
1468
|
+
dim = dim || 2;
|
|
1469
|
+
const hasHoles = holeIndices && holeIndices.length;
|
|
1470
|
+
const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
|
|
1471
|
+
let outerNode = linkedList(data, 0, outerLen, dim, true, areas && areas[0]);
|
|
1472
|
+
const triangles = [];
|
|
1473
|
+
if (!outerNode || outerNode.next === outerNode.prev)
|
|
1474
|
+
return triangles;
|
|
1475
|
+
let invSize;
|
|
1476
|
+
let maxX;
|
|
1477
|
+
let maxY;
|
|
1478
|
+
let minX;
|
|
1479
|
+
let minY;
|
|
1480
|
+
let x;
|
|
1481
|
+
let y;
|
|
1482
|
+
if (hasHoles)
|
|
1483
|
+
outerNode = eliminateHoles(data, holeIndices, outerNode, dim, areas);
|
|
1484
|
+
if (data.length > 80 * dim) {
|
|
1485
|
+
minX = maxX = data[0];
|
|
1486
|
+
minY = maxY = data[1];
|
|
1487
|
+
for (let i = dim; i < outerLen; i += dim) {
|
|
1488
|
+
x = data[i];
|
|
1489
|
+
y = data[i + 1];
|
|
1490
|
+
if (x < minX)
|
|
1491
|
+
minX = x;
|
|
1492
|
+
if (y < minY)
|
|
1493
|
+
minY = y;
|
|
1494
|
+
if (x > maxX)
|
|
1495
|
+
maxX = x;
|
|
1496
|
+
if (y > maxY)
|
|
1497
|
+
maxY = y;
|
|
1498
|
+
}
|
|
1499
|
+
invSize = Math.max(maxX - minX, maxY - minY);
|
|
1500
|
+
invSize = invSize !== 0 ? 1 / invSize : 0;
|
|
1501
|
+
}
|
|
1502
|
+
earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
|
|
1503
|
+
return triangles;
|
|
1504
|
+
}
|
|
1505
|
+
function linkedList(data, start, end, dim, clockwise, area2) {
|
|
1506
|
+
let i;
|
|
1507
|
+
let last;
|
|
1508
|
+
if (area2 === void 0) {
|
|
1509
|
+
area2 = getPolygonSignedArea(data, {
|
|
1510
|
+
start,
|
|
1511
|
+
end,
|
|
1512
|
+
size: dim
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
if (clockwise === area2 < 0) {
|
|
1516
|
+
for (i = start; i < end; i += dim)
|
|
1517
|
+
last = insertNode(i, data[i], data[i + 1], last);
|
|
1518
|
+
} else {
|
|
1519
|
+
for (i = end - dim; i >= start; i -= dim)
|
|
1520
|
+
last = insertNode(i, data[i], data[i + 1], last);
|
|
1521
|
+
}
|
|
1522
|
+
if (last && equals(last, last.next)) {
|
|
1523
|
+
removeNode(last);
|
|
1524
|
+
last = last.next;
|
|
1525
|
+
}
|
|
1526
|
+
return last;
|
|
1527
|
+
}
|
|
1528
|
+
function filterPoints(start, end) {
|
|
1529
|
+
if (!start)
|
|
1530
|
+
return start;
|
|
1531
|
+
if (!end)
|
|
1532
|
+
end = start;
|
|
1533
|
+
let p = start;
|
|
1534
|
+
let again;
|
|
1535
|
+
do {
|
|
1536
|
+
again = false;
|
|
1537
|
+
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
|
1538
|
+
removeNode(p);
|
|
1539
|
+
p = end = p.prev;
|
|
1540
|
+
if (p === p.next)
|
|
1493
1541
|
break;
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1542
|
+
again = true;
|
|
1543
|
+
} else {
|
|
1544
|
+
p = p.next;
|
|
1545
|
+
}
|
|
1546
|
+
} while (again || p !== end);
|
|
1547
|
+
return end;
|
|
1548
|
+
}
|
|
1549
|
+
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
1550
|
+
if (!ear)
|
|
1551
|
+
return;
|
|
1552
|
+
if (!pass && invSize)
|
|
1553
|
+
indexCurve(ear, minX, minY, invSize);
|
|
1554
|
+
let stop = ear;
|
|
1555
|
+
let prev;
|
|
1556
|
+
let next;
|
|
1557
|
+
while (ear.prev !== ear.next) {
|
|
1558
|
+
prev = ear.prev;
|
|
1559
|
+
next = ear.next;
|
|
1560
|
+
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
1561
|
+
triangles.push(prev.i / dim);
|
|
1562
|
+
triangles.push(ear.i / dim);
|
|
1563
|
+
triangles.push(next.i / dim);
|
|
1564
|
+
removeNode(ear);
|
|
1565
|
+
ear = next.next;
|
|
1566
|
+
stop = next.next;
|
|
1567
|
+
continue;
|
|
1568
|
+
}
|
|
1569
|
+
ear = next;
|
|
1570
|
+
if (ear === stop) {
|
|
1571
|
+
if (!pass) {
|
|
1572
|
+
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
|
1573
|
+
} else if (pass === 1) {
|
|
1574
|
+
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
|
|
1575
|
+
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
|
1576
|
+
} else if (pass === 2) {
|
|
1577
|
+
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
|
1578
|
+
}
|
|
1579
|
+
break;
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
function isEar(ear) {
|
|
1584
|
+
const a = ear.prev;
|
|
1585
|
+
const b = ear;
|
|
1586
|
+
const c = ear.next;
|
|
1587
|
+
if (area(a, b, c) >= 0)
|
|
1588
|
+
return false;
|
|
1589
|
+
let p = ear.next.next;
|
|
1590
|
+
while (p !== ear.prev) {
|
|
1591
|
+
if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
1592
|
+
return false;
|
|
1593
|
+
p = p.next;
|
|
1594
|
+
}
|
|
1595
|
+
return true;
|
|
1596
|
+
}
|
|
1597
|
+
function isEarHashed(ear, minX, minY, invSize) {
|
|
1598
|
+
const a = ear.prev;
|
|
1599
|
+
const b = ear;
|
|
1600
|
+
const c = ear.next;
|
|
1601
|
+
if (area(a, b, c) >= 0)
|
|
1602
|
+
return false;
|
|
1603
|
+
const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
|
|
1604
|
+
const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
|
|
1605
|
+
const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
|
|
1606
|
+
const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
|
|
1607
|
+
const minZ = zOrder(minTX, minTY, minX, minY, invSize);
|
|
1608
|
+
const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
|
|
1609
|
+
let p = ear.prevZ;
|
|
1610
|
+
let n = ear.nextZ;
|
|
1611
|
+
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
|
1612
|
+
if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
1613
|
+
return false;
|
|
1614
|
+
p = p.prevZ;
|
|
1615
|
+
if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
1616
|
+
return false;
|
|
1617
|
+
n = n.nextZ;
|
|
1618
|
+
}
|
|
1619
|
+
while (p && p.z >= minZ) {
|
|
1620
|
+
if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
1621
|
+
return false;
|
|
1622
|
+
p = p.prevZ;
|
|
1623
|
+
}
|
|
1624
|
+
while (n && n.z <= maxZ) {
|
|
1625
|
+
if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
1626
|
+
return false;
|
|
1627
|
+
n = n.nextZ;
|
|
1628
|
+
}
|
|
1629
|
+
return true;
|
|
1630
|
+
}
|
|
1631
|
+
function cureLocalIntersections(start, triangles, dim) {
|
|
1632
|
+
let p = start;
|
|
1633
|
+
do {
|
|
1634
|
+
const a = p.prev;
|
|
1635
|
+
const b = p.next.next;
|
|
1636
|
+
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
|
1637
|
+
triangles.push(a.i / dim);
|
|
1638
|
+
triangles.push(p.i / dim);
|
|
1639
|
+
triangles.push(b.i / dim);
|
|
1640
|
+
removeNode(p);
|
|
1641
|
+
removeNode(p.next);
|
|
1642
|
+
p = start = b;
|
|
1643
|
+
}
|
|
1644
|
+
p = p.next;
|
|
1645
|
+
} while (p !== start);
|
|
1646
|
+
return filterPoints(p);
|
|
1647
|
+
}
|
|
1648
|
+
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
1649
|
+
let a = start;
|
|
1650
|
+
do {
|
|
1651
|
+
let b = a.next.next;
|
|
1652
|
+
while (b !== a.prev) {
|
|
1653
|
+
if (a.i !== b.i && isValidDiagonal(a, b)) {
|
|
1654
|
+
let c = splitPolygon(a, b);
|
|
1655
|
+
a = filterPoints(a, a.next);
|
|
1656
|
+
c = filterPoints(c, c.next);
|
|
1657
|
+
earcutLinked(a, triangles, dim, minX, minY, invSize);
|
|
1658
|
+
earcutLinked(c, triangles, dim, minX, minY, invSize);
|
|
1659
|
+
return;
|
|
1660
|
+
}
|
|
1661
|
+
b = b.next;
|
|
1662
|
+
}
|
|
1663
|
+
a = a.next;
|
|
1664
|
+
} while (a !== start);
|
|
1665
|
+
}
|
|
1666
|
+
function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
|
|
1667
|
+
const queue = [];
|
|
1668
|
+
let i;
|
|
1669
|
+
let len;
|
|
1670
|
+
let start;
|
|
1671
|
+
let end;
|
|
1672
|
+
let list;
|
|
1673
|
+
for (i = 0, len = holeIndices.length; i < len; i++) {
|
|
1674
|
+
start = holeIndices[i] * dim;
|
|
1675
|
+
end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
|
1676
|
+
list = linkedList(data, start, end, dim, false, areas && areas[i + 1]);
|
|
1677
|
+
if (list === list.next)
|
|
1678
|
+
list.steiner = true;
|
|
1679
|
+
queue.push(getLeftmost(list));
|
|
1680
|
+
}
|
|
1681
|
+
queue.sort(compareX);
|
|
1682
|
+
for (i = 0; i < queue.length; i++) {
|
|
1683
|
+
eliminateHole(queue[i], outerNode);
|
|
1684
|
+
outerNode = filterPoints(outerNode, outerNode.next);
|
|
1685
|
+
}
|
|
1686
|
+
return outerNode;
|
|
1687
|
+
}
|
|
1688
|
+
function compareX(a, b) {
|
|
1689
|
+
return a.x - b.x;
|
|
1690
|
+
}
|
|
1691
|
+
function eliminateHole(hole, outerNode) {
|
|
1692
|
+
outerNode = findHoleBridge(hole, outerNode);
|
|
1693
|
+
if (outerNode) {
|
|
1694
|
+
const b = splitPolygon(outerNode, hole);
|
|
1695
|
+
filterPoints(outerNode, outerNode.next);
|
|
1696
|
+
filterPoints(b, b.next);
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
function findHoleBridge(hole, outerNode) {
|
|
1700
|
+
let p = outerNode;
|
|
1701
|
+
const hx = hole.x;
|
|
1702
|
+
const hy = hole.y;
|
|
1703
|
+
let qx = -Infinity;
|
|
1704
|
+
let m;
|
|
1705
|
+
do {
|
|
1706
|
+
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
|
1707
|
+
const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
|
|
1708
|
+
if (x <= hx && x > qx) {
|
|
1709
|
+
qx = x;
|
|
1710
|
+
if (x === hx) {
|
|
1711
|
+
if (hy === p.y)
|
|
1712
|
+
return p;
|
|
1713
|
+
if (hy === p.next.y)
|
|
1714
|
+
return p.next;
|
|
1501
1715
|
}
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1716
|
+
m = p.x < p.next.x ? p : p.next;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
p = p.next;
|
|
1720
|
+
} while (p !== outerNode);
|
|
1721
|
+
if (!m)
|
|
1722
|
+
return null;
|
|
1723
|
+
if (hx === qx)
|
|
1724
|
+
return m;
|
|
1725
|
+
const stop = m;
|
|
1726
|
+
const mx = m.x;
|
|
1727
|
+
const my = m.y;
|
|
1728
|
+
let tanMin = Infinity;
|
|
1729
|
+
let tan;
|
|
1730
|
+
p = m;
|
|
1731
|
+
do {
|
|
1732
|
+
if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
|
|
1733
|
+
tan = Math.abs(hy - p.y) / (hx - p.x);
|
|
1734
|
+
if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
|
|
1735
|
+
m = p;
|
|
1736
|
+
tanMin = tan;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
p = p.next;
|
|
1740
|
+
} while (p !== stop);
|
|
1741
|
+
return m;
|
|
1742
|
+
}
|
|
1743
|
+
function sectorContainsSector(m, p) {
|
|
1744
|
+
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
|
|
1745
|
+
}
|
|
1746
|
+
function indexCurve(start, minX, minY, invSize) {
|
|
1747
|
+
let p = start;
|
|
1748
|
+
do {
|
|
1749
|
+
if (p.z === null)
|
|
1750
|
+
p.z = zOrder(p.x, p.y, minX, minY, invSize);
|
|
1751
|
+
p.prevZ = p.prev;
|
|
1752
|
+
p.nextZ = p.next;
|
|
1753
|
+
p = p.next;
|
|
1754
|
+
} while (p !== start);
|
|
1755
|
+
p.prevZ.nextZ = null;
|
|
1756
|
+
p.prevZ = null;
|
|
1757
|
+
sortLinked(p);
|
|
1758
|
+
}
|
|
1759
|
+
function sortLinked(list) {
|
|
1760
|
+
let e;
|
|
1761
|
+
let i;
|
|
1762
|
+
let inSize = 1;
|
|
1763
|
+
let numMerges;
|
|
1764
|
+
let p;
|
|
1765
|
+
let pSize;
|
|
1766
|
+
let q;
|
|
1767
|
+
let qSize;
|
|
1768
|
+
let tail;
|
|
1769
|
+
do {
|
|
1770
|
+
p = list;
|
|
1771
|
+
list = null;
|
|
1772
|
+
tail = null;
|
|
1773
|
+
numMerges = 0;
|
|
1774
|
+
while (p) {
|
|
1775
|
+
numMerges++;
|
|
1776
|
+
q = p;
|
|
1777
|
+
pSize = 0;
|
|
1778
|
+
for (i = 0; i < inSize; i++) {
|
|
1779
|
+
pSize++;
|
|
1780
|
+
q = q.nextZ;
|
|
1781
|
+
if (!q)
|
|
1782
|
+
break;
|
|
1783
|
+
}
|
|
1784
|
+
qSize = inSize;
|
|
1785
|
+
while (pSize > 0 || qSize > 0 && q) {
|
|
1786
|
+
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
|
1787
|
+
e = p;
|
|
1788
|
+
p = p.nextZ;
|
|
1789
|
+
pSize--;
|
|
1790
|
+
} else {
|
|
1791
|
+
e = q;
|
|
1792
|
+
q = q.nextZ;
|
|
1793
|
+
qSize--;
|
|
1512
1794
|
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1795
|
+
if (tail)
|
|
1796
|
+
tail.nextZ = e;
|
|
1797
|
+
else
|
|
1798
|
+
list = e;
|
|
1799
|
+
e.prevZ = tail;
|
|
1800
|
+
tail = e;
|
|
1801
|
+
}
|
|
1802
|
+
p = q;
|
|
1516
1803
|
}
|
|
1804
|
+
tail.nextZ = null;
|
|
1805
|
+
inSize *= 2;
|
|
1806
|
+
} while (numMerges > 1);
|
|
1807
|
+
return list;
|
|
1808
|
+
}
|
|
1809
|
+
function zOrder(x, y, minX, minY, invSize) {
|
|
1810
|
+
x = 32767 * (x - minX) * invSize;
|
|
1811
|
+
y = 32767 * (y - minY) * invSize;
|
|
1812
|
+
x = (x | x << 8) & 16711935;
|
|
1813
|
+
x = (x | x << 4) & 252645135;
|
|
1814
|
+
x = (x | x << 2) & 858993459;
|
|
1815
|
+
x = (x | x << 1) & 1431655765;
|
|
1816
|
+
y = (y | y << 8) & 16711935;
|
|
1817
|
+
y = (y | y << 4) & 252645135;
|
|
1818
|
+
y = (y | y << 2) & 858993459;
|
|
1819
|
+
y = (y | y << 1) & 1431655765;
|
|
1820
|
+
return x | y << 1;
|
|
1821
|
+
}
|
|
1822
|
+
function getLeftmost(start) {
|
|
1823
|
+
let p = start;
|
|
1824
|
+
let leftmost = start;
|
|
1825
|
+
do {
|
|
1826
|
+
if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
|
|
1827
|
+
leftmost = p;
|
|
1828
|
+
p = p.next;
|
|
1829
|
+
} while (p !== start);
|
|
1830
|
+
return leftmost;
|
|
1831
|
+
}
|
|
1832
|
+
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
|
1833
|
+
return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
|
|
1834
|
+
}
|
|
1835
|
+
function isValidDiagonal(a, b) {
|
|
1836
|
+
return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
|
|
1837
|
+
}
|
|
1838
|
+
function area(p, q, r) {
|
|
1839
|
+
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
|
1840
|
+
}
|
|
1841
|
+
function equals(p1, p2) {
|
|
1842
|
+
return p1.x === p2.x && p1.y === p2.y;
|
|
1843
|
+
}
|
|
1844
|
+
function intersects(p1, q1, p2, q2) {
|
|
1845
|
+
const o1 = sign(area(p1, q1, p2));
|
|
1846
|
+
const o2 = sign(area(p1, q1, q2));
|
|
1847
|
+
const o3 = sign(area(p2, q2, p1));
|
|
1848
|
+
const o4 = sign(area(p2, q2, q1));
|
|
1849
|
+
if (o1 !== o2 && o3 !== o4)
|
|
1850
|
+
return true;
|
|
1851
|
+
if (o1 === 0 && onSegment(p1, p2, q1))
|
|
1852
|
+
return true;
|
|
1853
|
+
if (o2 === 0 && onSegment(p1, q2, q1))
|
|
1854
|
+
return true;
|
|
1855
|
+
if (o3 === 0 && onSegment(p2, p1, q2))
|
|
1856
|
+
return true;
|
|
1857
|
+
if (o4 === 0 && onSegment(p2, q1, q2))
|
|
1858
|
+
return true;
|
|
1859
|
+
return false;
|
|
1860
|
+
}
|
|
1861
|
+
function onSegment(p, q, r) {
|
|
1862
|
+
return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
|
|
1863
|
+
}
|
|
1864
|
+
function sign(num) {
|
|
1865
|
+
return num > 0 ? 1 : num < 0 ? -1 : 0;
|
|
1866
|
+
}
|
|
1867
|
+
function intersectsPolygon(a, b) {
|
|
1868
|
+
let p = a;
|
|
1869
|
+
do {
|
|
1870
|
+
if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
|
|
1871
|
+
return true;
|
|
1872
|
+
p = p.next;
|
|
1873
|
+
} while (p !== a);
|
|
1874
|
+
return false;
|
|
1875
|
+
}
|
|
1876
|
+
function locallyInside(a, b) {
|
|
1877
|
+
return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
|
|
1878
|
+
}
|
|
1879
|
+
function middleInside(a, b) {
|
|
1880
|
+
let p = a;
|
|
1881
|
+
let inside = false;
|
|
1882
|
+
const px = (a.x + b.x) / 2;
|
|
1883
|
+
const py = (a.y + b.y) / 2;
|
|
1884
|
+
do {
|
|
1885
|
+
if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)
|
|
1886
|
+
inside = !inside;
|
|
1887
|
+
p = p.next;
|
|
1888
|
+
} while (p !== a);
|
|
1889
|
+
return inside;
|
|
1890
|
+
}
|
|
1891
|
+
function splitPolygon(a, b) {
|
|
1892
|
+
const a2 = new Node(a.i, a.x, a.y);
|
|
1893
|
+
const b2 = new Node(b.i, b.x, b.y);
|
|
1894
|
+
const an = a.next;
|
|
1895
|
+
const bp = b.prev;
|
|
1896
|
+
a.next = b;
|
|
1897
|
+
b.prev = a;
|
|
1898
|
+
a2.next = an;
|
|
1899
|
+
an.prev = a2;
|
|
1900
|
+
b2.next = a2;
|
|
1901
|
+
a2.prev = b2;
|
|
1902
|
+
bp.next = b2;
|
|
1903
|
+
b2.prev = bp;
|
|
1904
|
+
return b2;
|
|
1905
|
+
}
|
|
1906
|
+
function insertNode(i, x, y, last) {
|
|
1907
|
+
const p = new Node(i, x, y);
|
|
1908
|
+
if (!last) {
|
|
1909
|
+
p.prev = p;
|
|
1910
|
+
p.next = p;
|
|
1911
|
+
} else {
|
|
1912
|
+
p.next = last.next;
|
|
1913
|
+
p.prev = last;
|
|
1914
|
+
last.next.prev = p;
|
|
1915
|
+
last.next = p;
|
|
1916
|
+
}
|
|
1917
|
+
return p;
|
|
1918
|
+
}
|
|
1919
|
+
function removeNode(p) {
|
|
1920
|
+
p.next.prev = p.prev;
|
|
1921
|
+
p.prev.next = p.next;
|
|
1922
|
+
if (p.prevZ)
|
|
1923
|
+
p.prevZ.nextZ = p.nextZ;
|
|
1924
|
+
if (p.nextZ)
|
|
1925
|
+
p.nextZ.prevZ = p.prevZ;
|
|
1926
|
+
}
|
|
1927
|
+
function Node(i, x, y) {
|
|
1928
|
+
this.i = i;
|
|
1929
|
+
this.x = x;
|
|
1930
|
+
this.y = y;
|
|
1931
|
+
this.prev = null;
|
|
1932
|
+
this.next = null;
|
|
1933
|
+
this.z = null;
|
|
1934
|
+
this.prevZ = null;
|
|
1935
|
+
this.nextZ = null;
|
|
1936
|
+
this.steiner = false;
|
|
1937
|
+
}
|
|
1938
|
+
var init_earcut = __esm({
|
|
1939
|
+
"../../node_modules/@math.gl/polygon/dist/esm/earcut.js"() {
|
|
1940
|
+
init_polygon_utils();
|
|
1941
|
+
}
|
|
1942
|
+
});
|
|
1943
|
+
|
|
1944
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/utils.js
|
|
1945
|
+
var init_utils = __esm({
|
|
1946
|
+
"../../node_modules/@math.gl/polygon/dist/esm/utils.js"() {
|
|
1947
|
+
}
|
|
1948
|
+
});
|
|
1949
|
+
|
|
1950
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/lineclip.js
|
|
1951
|
+
var init_lineclip = __esm({
|
|
1952
|
+
"../../node_modules/@math.gl/polygon/dist/esm/lineclip.js"() {
|
|
1953
|
+
init_utils();
|
|
1954
|
+
}
|
|
1955
|
+
});
|
|
1956
|
+
|
|
1957
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js
|
|
1958
|
+
var init_cut_by_grid = __esm({
|
|
1959
|
+
"../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js"() {
|
|
1960
|
+
init_lineclip();
|
|
1961
|
+
init_utils();
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
|
|
1965
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js
|
|
1966
|
+
var init_cut_by_mercator_bounds = __esm({
|
|
1967
|
+
"../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js"() {
|
|
1968
|
+
init_cut_by_grid();
|
|
1969
|
+
init_utils();
|
|
1970
|
+
}
|
|
1971
|
+
});
|
|
1972
|
+
|
|
1973
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/index.js
|
|
1974
|
+
var init_esm = __esm({
|
|
1975
|
+
"../../node_modules/@math.gl/polygon/dist/esm/index.js"() {
|
|
1976
|
+
init_polygon();
|
|
1977
|
+
init_polygon_utils();
|
|
1978
|
+
init_earcut();
|
|
1979
|
+
init_lineclip();
|
|
1980
|
+
init_cut_by_grid();
|
|
1981
|
+
init_cut_by_mercator_bounds();
|
|
1982
|
+
init_polygon();
|
|
1983
|
+
}
|
|
1984
|
+
});
|
|
1985
|
+
|
|
1986
|
+
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
1987
|
+
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
1988
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
1989
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1990
|
+
return fillArrays(features, {
|
|
1991
|
+
propArrayTypes,
|
|
1992
|
+
...geometryInfo
|
|
1993
|
+
}, {
|
|
1994
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
1995
|
+
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
1996
|
+
});
|
|
1997
|
+
}
|
|
1998
|
+
function extractNumericPropTypes(features) {
|
|
1999
|
+
const propArrayTypes = {};
|
|
2000
|
+
for (const feature of features) {
|
|
1517
2001
|
if (feature.properties) {
|
|
1518
2002
|
for (const key in feature.properties) {
|
|
1519
2003
|
const val = feature.properties[key];
|
|
@@ -1521,22 +2005,9 @@ Char: ${this.c}`;
|
|
|
1521
2005
|
}
|
|
1522
2006
|
}
|
|
1523
2007
|
}
|
|
1524
|
-
return
|
|
1525
|
-
coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
|
|
1526
|
-
pointPositionsCount,
|
|
1527
|
-
pointFeaturesCount,
|
|
1528
|
-
linePositionsCount,
|
|
1529
|
-
linePathsCount,
|
|
1530
|
-
lineFeaturesCount,
|
|
1531
|
-
polygonPositionsCount,
|
|
1532
|
-
polygonObjectsCount,
|
|
1533
|
-
polygonRingsCount,
|
|
1534
|
-
polygonFeaturesCount,
|
|
1535
|
-
numericPropKeys: Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array),
|
|
1536
|
-
propArrayTypes
|
|
1537
|
-
};
|
|
2008
|
+
return propArrayTypes;
|
|
1538
2009
|
}
|
|
1539
|
-
function
|
|
2010
|
+
function fillArrays(features, geometryInfo, options) {
|
|
1540
2011
|
const {
|
|
1541
2012
|
pointPositionsCount,
|
|
1542
2013
|
pointFeaturesCount,
|
|
@@ -1546,42 +2017,48 @@ Char: ${this.c}`;
|
|
|
1546
2017
|
polygonPositionsCount,
|
|
1547
2018
|
polygonObjectsCount,
|
|
1548
2019
|
polygonRingsCount,
|
|
2020
|
+
polygonFeaturesCount,
|
|
1549
2021
|
propArrayTypes,
|
|
1550
|
-
|
|
1551
|
-
} =
|
|
1552
|
-
const {
|
|
2022
|
+
coordLength
|
|
2023
|
+
} = geometryInfo;
|
|
2024
|
+
const { numericPropKeys = [], PositionDataType = Float32Array } = options;
|
|
2025
|
+
const hasGlobalId = features[0] && "id" in features[0];
|
|
1553
2026
|
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1554
2027
|
const points = {
|
|
2028
|
+
type: "Point",
|
|
1555
2029
|
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
1556
2030
|
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
1557
2031
|
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
1558
2032
|
numericProps: {},
|
|
1559
|
-
properties:
|
|
1560
|
-
fields:
|
|
2033
|
+
properties: [],
|
|
2034
|
+
fields: []
|
|
1561
2035
|
};
|
|
1562
2036
|
const lines = {
|
|
1563
|
-
|
|
2037
|
+
type: "LineString",
|
|
1564
2038
|
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
2039
|
+
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
1565
2040
|
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
1566
2041
|
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
1567
2042
|
numericProps: {},
|
|
1568
|
-
properties:
|
|
1569
|
-
fields:
|
|
2043
|
+
properties: [],
|
|
2044
|
+
fields: []
|
|
1570
2045
|
};
|
|
1571
2046
|
const polygons = {
|
|
1572
|
-
|
|
2047
|
+
type: "Polygon",
|
|
1573
2048
|
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
1574
2049
|
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
2050
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
2051
|
+
triangles: [],
|
|
1575
2052
|
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
1576
2053
|
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
1577
2054
|
numericProps: {},
|
|
1578
|
-
properties:
|
|
1579
|
-
fields:
|
|
2055
|
+
properties: [],
|
|
2056
|
+
fields: []
|
|
1580
2057
|
};
|
|
1581
2058
|
for (const object of [points, lines, polygons]) {
|
|
1582
|
-
for (const propName of numericPropKeys
|
|
1583
|
-
const
|
|
1584
|
-
object.numericProps[propName] = new
|
|
2059
|
+
for (const propName of numericPropKeys) {
|
|
2060
|
+
const T = propArrayTypes[propName];
|
|
2061
|
+
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
1585
2062
|
}
|
|
1586
2063
|
}
|
|
1587
2064
|
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
@@ -1604,33 +2081,27 @@ Char: ${this.c}`;
|
|
|
1604
2081
|
const properties = feature.properties || {};
|
|
1605
2082
|
switch (geometry.type) {
|
|
1606
2083
|
case "Point":
|
|
1607
|
-
handlePoint(geometry
|
|
1608
|
-
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1609
|
-
indexMap.pointFeature++;
|
|
1610
|
-
break;
|
|
1611
|
-
case "MultiPoint":
|
|
1612
|
-
handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties);
|
|
2084
|
+
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1613
2085
|
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
2086
|
+
if (hasGlobalId) {
|
|
2087
|
+
points.fields.push({ id: feature.id });
|
|
2088
|
+
}
|
|
1614
2089
|
indexMap.pointFeature++;
|
|
1615
2090
|
break;
|
|
1616
2091
|
case "LineString":
|
|
1617
|
-
handleLineString(geometry
|
|
1618
|
-
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1619
|
-
indexMap.lineFeature++;
|
|
1620
|
-
break;
|
|
1621
|
-
case "MultiLineString":
|
|
1622
|
-
handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
|
|
2092
|
+
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
1623
2093
|
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
2094
|
+
if (hasGlobalId) {
|
|
2095
|
+
lines.fields.push({ id: feature.id });
|
|
2096
|
+
}
|
|
1624
2097
|
indexMap.lineFeature++;
|
|
1625
2098
|
break;
|
|
1626
2099
|
case "Polygon":
|
|
1627
|
-
handlePolygon(geometry
|
|
1628
|
-
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1629
|
-
indexMap.polygonFeature++;
|
|
1630
|
-
break;
|
|
1631
|
-
case "MultiPolygon":
|
|
1632
|
-
handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
|
|
2100
|
+
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
1633
2101
|
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
2102
|
+
if (hasGlobalId) {
|
|
2103
|
+
polygons.fields.push({ id: feature.id });
|
|
2104
|
+
}
|
|
1634
2105
|
indexMap.polygonFeature++;
|
|
1635
2106
|
break;
|
|
1636
2107
|
default:
|
|
@@ -1640,93 +2111,105 @@ Char: ${this.c}`;
|
|
|
1640
2111
|
}
|
|
1641
2112
|
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
1642
2113
|
}
|
|
1643
|
-
function handlePoint(
|
|
1644
|
-
points.positions.set(
|
|
1645
|
-
|
|
1646
|
-
points
|
|
1647
|
-
|
|
1648
|
-
indexMap.pointPosition
|
|
1649
|
-
|
|
1650
|
-
function handleMultiPoint(coords, points, indexMap, coordLength, properties) {
|
|
1651
|
-
for (const point of coords) {
|
|
1652
|
-
handlePoint(point, points, indexMap, coordLength, properties);
|
|
1653
|
-
}
|
|
2114
|
+
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
2115
|
+
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
2116
|
+
const nPositions = geometry.data.length / coordLength;
|
|
2117
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
2118
|
+
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
2119
|
+
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
2120
|
+
indexMap.pointPosition += nPositions;
|
|
1654
2121
|
}
|
|
1655
|
-
function handleLineString(
|
|
1656
|
-
lines.
|
|
1657
|
-
|
|
1658
|
-
fillCoords(lines.positions, coords, indexMap.linePosition, coordLength);
|
|
1659
|
-
const nPositions = coords.length;
|
|
2122
|
+
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
2123
|
+
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
2124
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1660
2125
|
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1661
|
-
lines.globalFeatureIds.
|
|
1662
|
-
lines.featureIds.
|
|
1663
|
-
|
|
2126
|
+
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
2127
|
+
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
2128
|
+
for (let i = 0, il = geometry.indices.length; i < il; ++i) {
|
|
2129
|
+
const start = geometry.indices[i];
|
|
2130
|
+
const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
|
|
2131
|
+
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
2132
|
+
indexMap.linePosition += (end - start) / coordLength;
|
|
2133
|
+
}
|
|
1664
2134
|
}
|
|
1665
|
-
function
|
|
1666
|
-
|
|
1667
|
-
|
|
2135
|
+
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
2136
|
+
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
2137
|
+
const nPositions = geometry.data.length / coordLength;
|
|
2138
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
2139
|
+
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
2140
|
+
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
2141
|
+
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
2142
|
+
const startPosition = indexMap.polygonPosition;
|
|
2143
|
+
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
2144
|
+
const areas = geometry.areas[l];
|
|
2145
|
+
const indices = geometry.indices[l];
|
|
2146
|
+
const nextIndices = geometry.indices[l + 1];
|
|
2147
|
+
for (let i = 0, il = indices.length; i < il; ++i) {
|
|
2148
|
+
const start = indices[i];
|
|
2149
|
+
const end = i === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i + 1];
|
|
2150
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
2151
|
+
indexMap.polygonPosition += (end - start) / coordLength;
|
|
2152
|
+
}
|
|
2153
|
+
const endPosition = indexMap.polygonPosition;
|
|
2154
|
+
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
1668
2155
|
}
|
|
1669
2156
|
}
|
|
1670
|
-
function
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
2157
|
+
function triangulatePolygon(polygons, areas, indices, {
|
|
2158
|
+
startPosition,
|
|
2159
|
+
endPosition,
|
|
2160
|
+
coordLength
|
|
2161
|
+
}) {
|
|
2162
|
+
const start = startPosition * coordLength;
|
|
2163
|
+
const end = endPosition * coordLength;
|
|
2164
|
+
const polygonPositions = polygons.positions.subarray(start, end);
|
|
2165
|
+
const offset = indices[0];
|
|
2166
|
+
const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
|
|
2167
|
+
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
2168
|
+
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
2169
|
+
polygons.triangles.push(startPosition + triangles[t]);
|
|
1682
2170
|
}
|
|
1683
2171
|
}
|
|
1684
|
-
function
|
|
1685
|
-
|
|
1686
|
-
|
|
2172
|
+
function wrapProps(obj, size) {
|
|
2173
|
+
const returnObj = {};
|
|
2174
|
+
for (const key in obj) {
|
|
2175
|
+
returnObj[key] = { value: obj[key], size };
|
|
1687
2176
|
}
|
|
2177
|
+
return returnObj;
|
|
1688
2178
|
}
|
|
1689
2179
|
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
1690
|
-
|
|
2180
|
+
return {
|
|
1691
2181
|
points: {
|
|
1692
2182
|
...points,
|
|
1693
2183
|
positions: { value: points.positions, size: coordLength },
|
|
1694
2184
|
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
1695
2185
|
featureIds: { value: points.featureIds, size: 1 },
|
|
1696
|
-
|
|
2186
|
+
numericProps: wrapProps(points.numericProps, 1)
|
|
1697
2187
|
},
|
|
1698
2188
|
lines: {
|
|
1699
2189
|
...lines,
|
|
1700
|
-
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
1701
2190
|
positions: { value: lines.positions, size: coordLength },
|
|
2191
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
1702
2192
|
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
1703
2193
|
featureIds: { value: lines.featureIds, size: 1 },
|
|
1704
|
-
|
|
2194
|
+
numericProps: wrapProps(lines.numericProps, 1)
|
|
1705
2195
|
},
|
|
1706
2196
|
polygons: {
|
|
1707
2197
|
...polygons,
|
|
2198
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
1708
2199
|
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
1709
2200
|
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
1710
|
-
|
|
2201
|
+
triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
|
|
1711
2202
|
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
1712
2203
|
featureIds: { value: polygons.featureIds, size: 1 },
|
|
1713
|
-
|
|
2204
|
+
numericProps: wrapProps(polygons.numericProps, 1)
|
|
1714
2205
|
}
|
|
1715
2206
|
};
|
|
1716
|
-
for (const geomType in returnObj) {
|
|
1717
|
-
for (const numericProp in returnObj[geomType].numericProps) {
|
|
1718
|
-
returnObj[geomType].numericProps[numericProp] = {
|
|
1719
|
-
value: returnObj[geomType].numericProps[numericProp],
|
|
1720
|
-
size: 1
|
|
1721
|
-
};
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
return returnObj;
|
|
1725
2207
|
}
|
|
1726
2208
|
function fillNumericProperties(object, properties, index, length) {
|
|
1727
2209
|
for (const numericPropName in object.numericProps) {
|
|
1728
2210
|
if (numericPropName in properties) {
|
|
1729
|
-
|
|
2211
|
+
const value = properties[numericPropName];
|
|
2212
|
+
object.numericProps[numericPropName].fill(value, index, index + length);
|
|
1730
2213
|
}
|
|
1731
2214
|
}
|
|
1732
2215
|
}
|
|
@@ -1739,24 +2222,211 @@ Char: ${this.c}`;
|
|
|
1739
2222
|
}
|
|
1740
2223
|
return props;
|
|
1741
2224
|
}
|
|
1742
|
-
function fillCoords(array, coords, startVertex, coordLength) {
|
|
1743
|
-
let index = startVertex * coordLength;
|
|
1744
|
-
for (const coord of coords) {
|
|
1745
|
-
array.set(coord, index);
|
|
1746
|
-
index += coordLength;
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
function flatten(arrays) {
|
|
1750
|
-
return [].concat(...arrays);
|
|
1751
|
-
}
|
|
1752
2225
|
function deduceArrayType(x, constructor) {
|
|
1753
2226
|
if (constructor === Array || !Number.isFinite(x)) {
|
|
1754
2227
|
return Array;
|
|
1755
2228
|
}
|
|
1756
2229
|
return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
|
|
1757
2230
|
}
|
|
2231
|
+
var init_flat_geojson_to_binary = __esm({
|
|
2232
|
+
"../gis/src/lib/flat-geojson-to-binary.ts"() {
|
|
2233
|
+
init_esm();
|
|
2234
|
+
}
|
|
2235
|
+
});
|
|
2236
|
+
|
|
2237
|
+
// ../gis/src/lib/extract-geometry-info.ts
|
|
2238
|
+
function extractGeometryInfo(features) {
|
|
2239
|
+
let pointPositionsCount = 0;
|
|
2240
|
+
let pointFeaturesCount = 0;
|
|
2241
|
+
let linePositionsCount = 0;
|
|
2242
|
+
let linePathsCount = 0;
|
|
2243
|
+
let lineFeaturesCount = 0;
|
|
2244
|
+
let polygonPositionsCount = 0;
|
|
2245
|
+
let polygonObjectsCount = 0;
|
|
2246
|
+
let polygonRingsCount = 0;
|
|
2247
|
+
let polygonFeaturesCount = 0;
|
|
2248
|
+
const coordLengths = new Set();
|
|
2249
|
+
for (const feature of features) {
|
|
2250
|
+
const geometry = feature.geometry;
|
|
2251
|
+
switch (geometry.type) {
|
|
2252
|
+
case "Point":
|
|
2253
|
+
pointFeaturesCount++;
|
|
2254
|
+
pointPositionsCount++;
|
|
2255
|
+
coordLengths.add(geometry.coordinates.length);
|
|
2256
|
+
break;
|
|
2257
|
+
case "MultiPoint":
|
|
2258
|
+
pointFeaturesCount++;
|
|
2259
|
+
pointPositionsCount += geometry.coordinates.length;
|
|
2260
|
+
for (const point of geometry.coordinates) {
|
|
2261
|
+
coordLengths.add(point.length);
|
|
2262
|
+
}
|
|
2263
|
+
break;
|
|
2264
|
+
case "LineString":
|
|
2265
|
+
lineFeaturesCount++;
|
|
2266
|
+
linePositionsCount += geometry.coordinates.length;
|
|
2267
|
+
linePathsCount++;
|
|
2268
|
+
for (const coord of geometry.coordinates) {
|
|
2269
|
+
coordLengths.add(coord.length);
|
|
2270
|
+
}
|
|
2271
|
+
break;
|
|
2272
|
+
case "MultiLineString":
|
|
2273
|
+
lineFeaturesCount++;
|
|
2274
|
+
for (const line of geometry.coordinates) {
|
|
2275
|
+
linePositionsCount += line.length;
|
|
2276
|
+
linePathsCount++;
|
|
2277
|
+
for (const coord of line) {
|
|
2278
|
+
coordLengths.add(coord.length);
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
break;
|
|
2282
|
+
case "Polygon":
|
|
2283
|
+
polygonFeaturesCount++;
|
|
2284
|
+
polygonObjectsCount++;
|
|
2285
|
+
polygonRingsCount += geometry.coordinates.length;
|
|
2286
|
+
const flattened = geometry.coordinates.flat();
|
|
2287
|
+
polygonPositionsCount += flattened.length;
|
|
2288
|
+
for (const coord of flattened) {
|
|
2289
|
+
coordLengths.add(coord.length);
|
|
2290
|
+
}
|
|
2291
|
+
break;
|
|
2292
|
+
case "MultiPolygon":
|
|
2293
|
+
polygonFeaturesCount++;
|
|
2294
|
+
for (const polygon of geometry.coordinates) {
|
|
2295
|
+
polygonObjectsCount++;
|
|
2296
|
+
polygonRingsCount += polygon.length;
|
|
2297
|
+
const flattened2 = polygon.flat();
|
|
2298
|
+
polygonPositionsCount += flattened2.length;
|
|
2299
|
+
for (const coord of flattened2) {
|
|
2300
|
+
coordLengths.add(coord.length);
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
break;
|
|
2304
|
+
default:
|
|
2305
|
+
throw new Error(`Unsupported geometry type: ${geometry.type}`);
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
return {
|
|
2309
|
+
coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
|
|
2310
|
+
pointPositionsCount,
|
|
2311
|
+
pointFeaturesCount,
|
|
2312
|
+
linePositionsCount,
|
|
2313
|
+
linePathsCount,
|
|
2314
|
+
lineFeaturesCount,
|
|
2315
|
+
polygonPositionsCount,
|
|
2316
|
+
polygonObjectsCount,
|
|
2317
|
+
polygonRingsCount,
|
|
2318
|
+
polygonFeaturesCount
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
var init_extract_geometry_info = __esm({
|
|
2322
|
+
"../gis/src/lib/extract-geometry-info.ts"() {
|
|
2323
|
+
}
|
|
2324
|
+
});
|
|
2325
|
+
|
|
2326
|
+
// ../gis/src/lib/geojson-to-flat-geojson.ts
|
|
2327
|
+
function geojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
|
|
2328
|
+
return features.map((feature) => flattenFeature(feature, options));
|
|
2329
|
+
}
|
|
2330
|
+
function flattenPoint(coordinates, data, indices, options) {
|
|
2331
|
+
indices.push(data.length);
|
|
2332
|
+
data.push(...coordinates);
|
|
2333
|
+
for (let i = coordinates.length; i < options.coordLength; i++) {
|
|
2334
|
+
data.push(0);
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
function flattenLineString(coordinates, data, indices, options) {
|
|
2338
|
+
indices.push(data.length);
|
|
2339
|
+
for (const c of coordinates) {
|
|
2340
|
+
data.push(...c);
|
|
2341
|
+
for (let i = c.length; i < options.coordLength; i++) {
|
|
2342
|
+
data.push(0);
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
function flattenPolygon(coordinates, data, indices, areas, options) {
|
|
2347
|
+
let count = 0;
|
|
2348
|
+
const ringAreas = [];
|
|
2349
|
+
const polygons = [];
|
|
2350
|
+
for (const lineString of coordinates) {
|
|
2351
|
+
const lineString2d = lineString.map((p) => p.slice(0, 2));
|
|
2352
|
+
let area2 = getPolygonSignedArea(lineString2d.flat());
|
|
2353
|
+
const ccw = area2 < 0;
|
|
2354
|
+
if (options.fixRingWinding && (count === 0 && !ccw || count > 0 && ccw)) {
|
|
2355
|
+
lineString.reverse();
|
|
2356
|
+
area2 = -area2;
|
|
2357
|
+
}
|
|
2358
|
+
ringAreas.push(area2);
|
|
2359
|
+
flattenLineString(lineString, data, polygons, options);
|
|
2360
|
+
count++;
|
|
2361
|
+
}
|
|
2362
|
+
if (count > 0) {
|
|
2363
|
+
areas.push(ringAreas);
|
|
2364
|
+
indices.push(polygons);
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
function flattenFeature(feature, options) {
|
|
2368
|
+
const { geometry } = feature;
|
|
2369
|
+
if (geometry.type === "GeometryCollection") {
|
|
2370
|
+
throw new Error("GeometryCollection type not supported");
|
|
2371
|
+
}
|
|
2372
|
+
const data = [];
|
|
2373
|
+
const indices = [];
|
|
2374
|
+
let areas;
|
|
2375
|
+
let type;
|
|
2376
|
+
switch (geometry.type) {
|
|
2377
|
+
case "Point":
|
|
2378
|
+
type = "Point";
|
|
2379
|
+
flattenPoint(geometry.coordinates, data, indices, options);
|
|
2380
|
+
break;
|
|
2381
|
+
case "MultiPoint":
|
|
2382
|
+
type = "Point";
|
|
2383
|
+
geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));
|
|
2384
|
+
break;
|
|
2385
|
+
case "LineString":
|
|
2386
|
+
type = "LineString";
|
|
2387
|
+
flattenLineString(geometry.coordinates, data, indices, options);
|
|
2388
|
+
break;
|
|
2389
|
+
case "MultiLineString":
|
|
2390
|
+
type = "LineString";
|
|
2391
|
+
geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));
|
|
2392
|
+
break;
|
|
2393
|
+
case "Polygon":
|
|
2394
|
+
type = "Polygon";
|
|
2395
|
+
areas = [];
|
|
2396
|
+
flattenPolygon(geometry.coordinates, data, indices, areas, options);
|
|
2397
|
+
break;
|
|
2398
|
+
case "MultiPolygon":
|
|
2399
|
+
type = "Polygon";
|
|
2400
|
+
areas = [];
|
|
2401
|
+
geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));
|
|
2402
|
+
break;
|
|
2403
|
+
default:
|
|
2404
|
+
throw new Error(`Unknown type: ${type}`);
|
|
2405
|
+
}
|
|
2406
|
+
return { ...feature, geometry: { type, indices, data, areas } };
|
|
2407
|
+
}
|
|
2408
|
+
var init_geojson_to_flat_geojson = __esm({
|
|
2409
|
+
"../gis/src/lib/geojson-to-flat-geojson.ts"() {
|
|
2410
|
+
init_esm();
|
|
2411
|
+
}
|
|
2412
|
+
});
|
|
2413
|
+
|
|
2414
|
+
// ../gis/src/lib/geojson-to-binary.ts
|
|
2415
|
+
function geojsonToBinary(features, options = { fixRingWinding: true }) {
|
|
2416
|
+
const geometryInfo = extractGeometryInfo(features);
|
|
2417
|
+
const coordLength = geometryInfo.coordLength;
|
|
2418
|
+
const { fixRingWinding } = options;
|
|
2419
|
+
const flatFeatures = geojsonToFlatGeojson(features, { coordLength, fixRingWinding });
|
|
2420
|
+
return flatGeojsonToBinary(flatFeatures, geometryInfo, {
|
|
2421
|
+
numericPropKeys: options.numericPropKeys,
|
|
2422
|
+
PositionDataType: options.PositionDataType || Float32Array
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
1758
2425
|
var init_geojson_to_binary = __esm({
|
|
1759
2426
|
"../gis/src/lib/geojson-to-binary.ts"() {
|
|
2427
|
+
init_extract_geometry_info();
|
|
2428
|
+
init_geojson_to_flat_geojson();
|
|
2429
|
+
init_flat_geojson_to_binary();
|
|
1760
2430
|
}
|
|
1761
2431
|
});
|
|
1762
2432
|
|