@loaders.gl/json 3.1.0-beta.3 → 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.
Files changed (47) hide show
  1. package/dist/bundle.js +885 -181
  2. package/dist/es5/bundle.js +1 -1
  3. package/dist/es5/bundle.js.map +1 -1
  4. package/dist/es5/geojson-loader.js +143 -29
  5. package/dist/es5/geojson-loader.js.map +1 -1
  6. package/dist/es5/index.js +14 -6
  7. package/dist/es5/index.js.map +1 -1
  8. package/dist/es5/json-loader.js +44 -18
  9. package/dist/es5/json-loader.js.map +1 -1
  10. package/dist/es5/lib/clarinet/clarinet.js +359 -335
  11. package/dist/es5/lib/clarinet/clarinet.js.map +1 -1
  12. package/dist/es5/lib/jsonpath/jsonpath.js +101 -54
  13. package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -1
  14. package/dist/es5/lib/parse-json-in-batches.js +251 -72
  15. package/dist/es5/lib/parse-json-in-batches.js.map +1 -1
  16. package/dist/es5/lib/parse-json.js +9 -4
  17. package/dist/es5/lib/parse-json.js.map +1 -1
  18. package/dist/es5/lib/parse-ndjson-in-batches.js +143 -31
  19. package/dist/es5/lib/parse-ndjson-in-batches.js.map +1 -1
  20. package/dist/es5/lib/parse-ndjson.js +2 -2
  21. package/dist/es5/lib/parse-ndjson.js.map +1 -1
  22. package/dist/es5/lib/parser/json-parser.js +117 -95
  23. package/dist/es5/lib/parser/json-parser.js.map +1 -1
  24. package/dist/es5/lib/parser/streaming-json-parser.js +115 -59
  25. package/dist/es5/lib/parser/streaming-json-parser.js.map +1 -1
  26. package/dist/es5/ndjson-loader.js +30 -8
  27. package/dist/es5/ndjson-loader.js.map +1 -1
  28. package/dist/esm/geojson-loader.js +1 -1
  29. package/dist/esm/geojson-loader.js.map +1 -1
  30. package/dist/esm/index.js +1 -0
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/json-loader.js +1 -1
  33. package/dist/esm/json-loader.js.map +1 -1
  34. package/dist/esm/lib/parse-json-in-batches.js +18 -1
  35. package/dist/esm/lib/parse-json-in-batches.js.map +1 -1
  36. package/dist/esm/ndjson-loader.js +1 -1
  37. package/dist/esm/ndjson-loader.js.map +1 -1
  38. package/dist/geojson-worker.js +781 -180
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +3 -1
  42. package/dist/lib/parse-json-in-batches.d.ts +1 -0
  43. package/dist/lib/parse-json-in-batches.d.ts.map +1 -1
  44. package/dist/lib/parse-json-in-batches.js +20 -0
  45. package/package.json +5 -5
  46. package/src/index.ts +2 -0
  47. package/src/lib/parse-json-in-batches.ts +23 -1
package/dist/bundle.js CHANGED
@@ -439,6 +439,17 @@
439
439
  }
440
440
  });
441
441
 
442
+ // ../loader-utils/src/lib/env-utils/assert.ts
443
+ function assert(condition, message) {
444
+ if (!condition) {
445
+ throw new Error(message || "loader assertion failed.");
446
+ }
447
+ }
448
+ var init_assert = __esm({
449
+ "../loader-utils/src/lib/env-utils/assert.ts"() {
450
+ }
451
+ });
452
+
442
453
  // ../loader-utils/src/lib/iterators/text-iterators.ts
443
454
  async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
444
455
  const textDecoder = new TextDecoder(void 0, options);
@@ -476,6 +487,7 @@
476
487
  // ../loader-utils/src/index.ts
477
488
  var init_src2 = __esm({
478
489
  "../loader-utils/src/index.ts"() {
490
+ init_assert();
479
491
  init_text_iterators();
480
492
  }
481
493
  });
@@ -1276,11 +1288,25 @@ Char: ${this.c}`;
1276
1288
  yield finalBatch;
1277
1289
  }
1278
1290
  }
1291
+ function rebuildJsonObject(batch, data) {
1292
+ assert(batch.batchType === "final-result");
1293
+ if (batch.jsonpath === "$") {
1294
+ return data;
1295
+ }
1296
+ if (batch.jsonpath && batch.jsonpath.length > 1) {
1297
+ const topLevelObject = batch.container;
1298
+ const streamingPath = new JSONPath(batch.jsonpath);
1299
+ streamingPath.setFieldAtPath(topLevelObject, data);
1300
+ return topLevelObject;
1301
+ }
1302
+ return batch.container;
1303
+ }
1279
1304
  var init_parse_json_in_batches = __esm({
1280
1305
  "src/lib/parse-json-in-batches.ts"() {
1281
1306
  init_src();
1282
1307
  init_src2();
1283
1308
  init_streaming_json_parser();
1309
+ init_jsonpath();
1284
1310
  }
1285
1311
  });
1286
1312
 
@@ -1411,105 +1437,577 @@ Char: ${this.c}`;
1411
1437
  }
1412
1438
  });
1413
1439
 
1414
- // ../gis/src/lib/geojson-to-binary.ts
1415
- function geojsonToBinary(features, options = {}) {
1416
- const firstPassData = firstPass(features);
1417
- return secondPass(features, firstPassData, {
1418
- coordLength: options.coordLength || firstPassData.coordLength,
1419
- numericPropKeys: options.numericPropKeys || firstPassData.numericPropKeys,
1420
- PositionDataType: options.PositionDataType || Float32Array
1421
- });
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;
1422
1453
  }
1423
- function firstPass(features) {
1424
- let pointPositionsCount = 0;
1425
- let pointFeaturesCount = 0;
1426
- let linePositionsCount = 0;
1427
- let linePathsCount = 0;
1428
- let lineFeaturesCount = 0;
1429
- let polygonPositionsCount = 0;
1430
- let polygonObjectsCount = 0;
1431
- let polygonRingsCount = 0;
1432
- let polygonFeaturesCount = 0;
1433
- const coordLengths = new Set();
1434
- const numericPropKeys = {};
1435
- for (const feature of features) {
1436
- const geometry = feature.geometry;
1437
- switch (geometry.type) {
1438
- case "Point":
1439
- pointFeaturesCount++;
1440
- pointPositionsCount++;
1441
- coordLengths.add(geometry.coordinates.length);
1442
- break;
1443
- case "MultiPoint":
1444
- pointFeaturesCount++;
1445
- pointPositionsCount += geometry.coordinates.length;
1446
- for (const point of geometry.coordinates) {
1447
- coordLengths.add(point.length);
1448
- }
1449
- break;
1450
- case "LineString":
1451
- lineFeaturesCount++;
1452
- linePositionsCount += geometry.coordinates.length;
1453
- linePathsCount++;
1454
- for (const coord of geometry.coordinates) {
1455
- coordLengths.add(coord.length);
1456
- }
1457
- break;
1458
- case "MultiLineString":
1459
- lineFeaturesCount++;
1460
- for (const line of geometry.coordinates) {
1461
- linePositionsCount += line.length;
1462
- linePathsCount++;
1463
- for (const coord of line) {
1464
- coordLengths.add(coord.length);
1465
- }
1466
- }
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)
1467
1541
  break;
1468
- case "Polygon":
1469
- polygonFeaturesCount++;
1470
- polygonObjectsCount++;
1471
- polygonRingsCount += geometry.coordinates.length;
1472
- polygonPositionsCount += flatten(geometry.coordinates).length;
1473
- for (const coord of flatten(geometry.coordinates)) {
1474
- coordLengths.add(coord.length);
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;
1475
1715
  }
1476
- break;
1477
- case "MultiPolygon":
1478
- polygonFeaturesCount++;
1479
- for (const polygon of geometry.coordinates) {
1480
- polygonObjectsCount++;
1481
- polygonRingsCount += polygon.length;
1482
- polygonPositionsCount += flatten(polygon).length;
1483
- for (const coord of flatten(polygon)) {
1484
- coordLengths.add(coord.length);
1485
- }
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--;
1486
1794
  }
1487
- break;
1488
- default:
1489
- throw new Error(`Unsupported geometry type: ${geometry.type}`);
1795
+ if (tail)
1796
+ tail.nextZ = e;
1797
+ else
1798
+ list = e;
1799
+ e.prevZ = tail;
1800
+ tail = e;
1801
+ }
1802
+ p = q;
1490
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) {
1491
2001
  if (feature.properties) {
1492
2002
  for (const key in feature.properties) {
1493
2003
  const val = feature.properties[key];
1494
- numericPropKeys[key] = numericPropKeys[key] || numericPropKeys[key] === void 0 ? isNumeric(val) : numericPropKeys[key];
2004
+ propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
1495
2005
  }
1496
2006
  }
1497
2007
  }
1498
- return {
1499
- coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
1500
- pointPositionsCount,
1501
- pointFeaturesCount,
1502
- linePositionsCount,
1503
- linePathsCount,
1504
- lineFeaturesCount,
1505
- polygonPositionsCount,
1506
- polygonObjectsCount,
1507
- polygonRingsCount,
1508
- polygonFeaturesCount,
1509
- numericPropKeys: Object.keys(numericPropKeys).filter((k) => numericPropKeys[k])
1510
- };
2008
+ return propArrayTypes;
1511
2009
  }
1512
- function secondPass(features, firstPassData, options) {
2010
+ function fillArrays(features, geometryInfo, options) {
1513
2011
  const {
1514
2012
  pointPositionsCount,
1515
2013
  pointFeaturesCount,
@@ -1519,40 +2017,48 @@ Char: ${this.c}`;
1519
2017
  polygonPositionsCount,
1520
2018
  polygonObjectsCount,
1521
2019
  polygonRingsCount,
1522
- polygonFeaturesCount
1523
- } = firstPassData;
1524
- const { coordLength, numericPropKeys, PositionDataType = Float32Array } = options;
2020
+ polygonFeaturesCount,
2021
+ propArrayTypes,
2022
+ coordLength
2023
+ } = geometryInfo;
2024
+ const { numericPropKeys = [], PositionDataType = Float32Array } = options;
2025
+ const hasGlobalId = features[0] && "id" in features[0];
1525
2026
  const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
1526
2027
  const points = {
2028
+ type: "Point",
1527
2029
  positions: new PositionDataType(pointPositionsCount * coordLength),
1528
2030
  globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
1529
2031
  featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
1530
2032
  numericProps: {},
1531
- properties: Array(),
1532
- fields: Array()
2033
+ properties: [],
2034
+ fields: []
1533
2035
  };
1534
2036
  const lines = {
1535
- positions: new PositionDataType(linePositionsCount * coordLength),
2037
+ type: "LineString",
1536
2038
  pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
2039
+ positions: new PositionDataType(linePositionsCount * coordLength),
1537
2040
  globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
1538
2041
  featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
1539
2042
  numericProps: {},
1540
- properties: Array(),
1541
- fields: Array()
2043
+ properties: [],
2044
+ fields: []
1542
2045
  };
1543
2046
  const polygons = {
1544
- positions: new PositionDataType(polygonPositionsCount * coordLength),
2047
+ type: "Polygon",
1545
2048
  polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
1546
2049
  primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
2050
+ positions: new PositionDataType(polygonPositionsCount * coordLength),
2051
+ triangles: [],
1547
2052
  globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
1548
2053
  featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
1549
2054
  numericProps: {},
1550
- properties: Array(),
1551
- fields: Array()
2055
+ properties: [],
2056
+ fields: []
1552
2057
  };
1553
2058
  for (const object of [points, lines, polygons]) {
1554
- for (const propName of numericPropKeys || []) {
1555
- object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
2059
+ for (const propName of numericPropKeys) {
2060
+ const T = propArrayTypes[propName];
2061
+ object.numericProps[propName] = new T(object.positions.length / coordLength);
1556
2062
  }
1557
2063
  }
1558
2064
  lines.pathIndices[linePathsCount] = linePositionsCount;
@@ -1575,33 +2081,27 @@ Char: ${this.c}`;
1575
2081
  const properties = feature.properties || {};
1576
2082
  switch (geometry.type) {
1577
2083
  case "Point":
1578
- handlePoint(geometry.coordinates, points, indexMap, coordLength, properties);
1579
- points.properties.push(keepStringProperties(properties, numericPropKeys));
1580
- indexMap.pointFeature++;
1581
- break;
1582
- case "MultiPoint":
1583
- handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties);
2084
+ handlePoint(geometry, points, indexMap, coordLength, properties);
1584
2085
  points.properties.push(keepStringProperties(properties, numericPropKeys));
2086
+ if (hasGlobalId) {
2087
+ points.fields.push({ id: feature.id });
2088
+ }
1585
2089
  indexMap.pointFeature++;
1586
2090
  break;
1587
2091
  case "LineString":
1588
- handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
1589
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
1590
- indexMap.lineFeature++;
1591
- break;
1592
- case "MultiLineString":
1593
- handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
2092
+ handleLineString(geometry, lines, indexMap, coordLength, properties);
1594
2093
  lines.properties.push(keepStringProperties(properties, numericPropKeys));
2094
+ if (hasGlobalId) {
2095
+ lines.fields.push({ id: feature.id });
2096
+ }
1595
2097
  indexMap.lineFeature++;
1596
2098
  break;
1597
2099
  case "Polygon":
1598
- handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
1599
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
1600
- indexMap.polygonFeature++;
1601
- break;
1602
- case "MultiPolygon":
1603
- handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
2100
+ handlePolygon(geometry, polygons, indexMap, coordLength, properties);
1604
2101
  polygons.properties.push(keepStringProperties(properties, numericPropKeys));
2102
+ if (hasGlobalId) {
2103
+ polygons.fields.push({ id: feature.id });
2104
+ }
1605
2105
  indexMap.polygonFeature++;
1606
2106
  break;
1607
2107
  default:
@@ -1611,93 +2111,105 @@ Char: ${this.c}`;
1611
2111
  }
1612
2112
  return makeAccessorObjects(points, lines, polygons, coordLength);
1613
2113
  }
1614
- function handlePoint(coords, points, indexMap, coordLength, properties) {
1615
- points.positions.set(coords, indexMap.pointPosition * coordLength);
1616
- points.globalFeatureIds[indexMap.pointPosition] = indexMap.feature;
1617
- points.featureIds[indexMap.pointPosition] = indexMap.pointFeature;
1618
- fillNumericProperties(points, properties, indexMap.pointPosition, 1);
1619
- indexMap.pointPosition++;
1620
- }
1621
- function handleMultiPoint(coords, points, indexMap, coordLength, properties) {
1622
- for (const point of coords) {
1623
- handlePoint(point, points, indexMap, coordLength, properties);
1624
- }
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;
1625
2121
  }
1626
- function handleLineString(coords, lines, indexMap, coordLength, properties) {
1627
- lines.pathIndices[indexMap.linePath] = indexMap.linePosition;
1628
- indexMap.linePath++;
1629
- fillCoords(lines.positions, coords, indexMap.linePosition, coordLength);
1630
- 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;
1631
2125
  fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
1632
- lines.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.linePosition);
1633
- lines.featureIds.set(new Uint32Array(nPositions).fill(indexMap.lineFeature), indexMap.linePosition);
1634
- indexMap.linePosition += nPositions;
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
+ }
1635
2134
  }
1636
- function handleMultiLineString(coords, lines, indexMap, coordLength, properties) {
1637
- for (const line of coords) {
1638
- handleLineString(line, lines, indexMap, coordLength, properties);
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 });
1639
2155
  }
1640
2156
  }
1641
- function handlePolygon(coords, polygons, indexMap, coordLength, properties) {
1642
- polygons.polygonIndices[indexMap.polygonObject] = indexMap.polygonPosition;
1643
- indexMap.polygonObject++;
1644
- for (const ring of coords) {
1645
- polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition;
1646
- indexMap.polygonRing++;
1647
- fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength);
1648
- const nPositions = ring.length;
1649
- fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
1650
- polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition);
1651
- polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition);
1652
- indexMap.polygonPosition += nPositions;
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]);
1653
2170
  }
1654
2171
  }
1655
- function handleMultiPolygon(coords, polygons, indexMap, coordLength, properties) {
1656
- for (const polygon of coords) {
1657
- handlePolygon(polygon, polygons, indexMap, coordLength, properties);
2172
+ function wrapProps(obj, size) {
2173
+ const returnObj = {};
2174
+ for (const key in obj) {
2175
+ returnObj[key] = { value: obj[key], size };
1658
2176
  }
2177
+ return returnObj;
1659
2178
  }
1660
2179
  function makeAccessorObjects(points, lines, polygons, coordLength) {
1661
- const returnObj = {
2180
+ return {
1662
2181
  points: {
1663
2182
  ...points,
1664
2183
  positions: { value: points.positions, size: coordLength },
1665
2184
  globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
1666
2185
  featureIds: { value: points.featureIds, size: 1 },
1667
- type: "Point"
2186
+ numericProps: wrapProps(points.numericProps, 1)
1668
2187
  },
1669
2188
  lines: {
1670
2189
  ...lines,
1671
- pathIndices: { value: lines.pathIndices, size: 1 },
1672
2190
  positions: { value: lines.positions, size: coordLength },
2191
+ pathIndices: { value: lines.pathIndices, size: 1 },
1673
2192
  globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
1674
2193
  featureIds: { value: lines.featureIds, size: 1 },
1675
- type: "LineString"
2194
+ numericProps: wrapProps(lines.numericProps, 1)
1676
2195
  },
1677
2196
  polygons: {
1678
2197
  ...polygons,
2198
+ positions: { value: polygons.positions, size: coordLength },
1679
2199
  polygonIndices: { value: polygons.polygonIndices, size: 1 },
1680
2200
  primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
1681
- positions: { value: polygons.positions, size: coordLength },
2201
+ triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
1682
2202
  globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
1683
2203
  featureIds: { value: polygons.featureIds, size: 1 },
1684
- type: "Polygon"
2204
+ numericProps: wrapProps(polygons.numericProps, 1)
1685
2205
  }
1686
2206
  };
1687
- for (const geomType in returnObj) {
1688
- for (const numericProp in returnObj[geomType].numericProps) {
1689
- returnObj[geomType].numericProps[numericProp] = {
1690
- value: returnObj[geomType].numericProps[numericProp],
1691
- size: 1
1692
- };
1693
- }
1694
- }
1695
- return returnObj;
1696
2207
  }
1697
2208
  function fillNumericProperties(object, properties, index, length) {
1698
2209
  for (const numericPropName in object.numericProps) {
1699
2210
  if (numericPropName in properties) {
1700
- object.numericProps[numericPropName].set(new Array(length).fill(properties[numericPropName]), index);
2211
+ const value = properties[numericPropName];
2212
+ object.numericProps[numericPropName].fill(value, index, index + length);
1701
2213
  }
1702
2214
  }
1703
2215
  }
@@ -1710,21 +2222,211 @@ Char: ${this.c}`;
1710
2222
  }
1711
2223
  return props;
1712
2224
  }
1713
- function fillCoords(array, coords, startVertex, coordLength) {
1714
- let index = startVertex * coordLength;
1715
- for (const coord of coords) {
1716
- array.set(coord, index);
1717
- index += coordLength;
2225
+ function deduceArrayType(x, constructor) {
2226
+ if (constructor === Array || !Number.isFinite(x)) {
2227
+ return Array;
2228
+ }
2229
+ return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
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);
1718
2335
  }
1719
2336
  }
1720
- function flatten(arrays) {
1721
- return [].concat(...arrays);
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
+ }
1722
2345
  }
1723
- function isNumeric(x) {
1724
- return Number.isFinite(x);
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
+ });
1725
2424
  }
1726
2425
  var init_geojson_to_binary = __esm({
1727
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();
1728
2430
  }
1729
2431
  });
1730
2432
 
@@ -1815,7 +2517,8 @@ Char: ${this.c}`;
1815
2517
  _ClarinetParser: () => ClarinetParser,
1816
2518
  _GeoJSONLoader: () => GeoJSONLoader,
1817
2519
  _GeoJSONWorkerLoader: () => GeoJSONWorkerLoader,
1818
- _JSONPath: () => JSONPath
2520
+ _JSONPath: () => JSONPath,
2521
+ _rebuildJsonObject: () => rebuildJsonObject
1819
2522
  });
1820
2523
  var init_src4 = __esm({
1821
2524
  "src/index.ts"() {
@@ -1824,6 +2527,7 @@ Char: ${this.c}`;
1824
2527
  init_geojson_loader();
1825
2528
  init_jsonpath();
1826
2529
  init_clarinet();
2530
+ init_parse_json_in_batches();
1827
2531
  }
1828
2532
  });
1829
2533