maplibre-gl-lidar 0.6.1 → 0.6.2

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.
@@ -34221,6 +34221,7 @@ class PointCloudLoader {
34221
34221
  };
34222
34222
  }
34223
34223
  }
34224
+ proj4.defs("EPSG:2180", "+proj=tmerc +lat_0=0 +lon_0=19 +k=0.9993 +x_0=500000 +y_0=-5300000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs");
34224
34225
  function createBufferGetter(buffer) {
34225
34226
  const uint8 = new Uint8Array(buffer);
34226
34227
  return async (begin, end) => {
@@ -34332,6 +34333,32 @@ function getVerticalUnitConversionFactor$1(wkt2) {
34332
34333
  }
34333
34334
  return 1;
34334
34335
  }
34336
+ function clampLatLng$1(lng, lat, context = "") {
34337
+ let clampedLng = lng;
34338
+ let clampedLat = lat;
34339
+ let wasClamped = false;
34340
+ if (lat > 90) {
34341
+ clampedLat = 90;
34342
+ wasClamped = true;
34343
+ } else if (lat < -90) {
34344
+ clampedLat = -90;
34345
+ wasClamped = true;
34346
+ }
34347
+ if (lng > 180) {
34348
+ clampedLng = 180;
34349
+ wasClamped = true;
34350
+ } else if (lng < -180) {
34351
+ clampedLng = -180;
34352
+ wasClamped = true;
34353
+ }
34354
+ if (wasClamped) {
34355
+ console.warn(
34356
+ `COPC: Clamped transformed coordinates to valid WGS84 range${context ? ` (${context})` : ""}:`,
34357
+ `[${lng.toFixed(6)}, ${lat.toFixed(6)}] -> [${clampedLng.toFixed(6)}, ${clampedLat.toFixed(6)}]`
34358
+ );
34359
+ }
34360
+ return [clampedLng, clampedLat];
34361
+ }
34335
34362
  const DEFAULT_OPTIONS$2 = {
34336
34363
  pointBudget: 5e6,
34337
34364
  maxConcurrentRequests: 4,
@@ -34439,10 +34466,30 @@ class CopcStreamingLoader {
34439
34466
  } catch (e) {
34440
34467
  console.warn("Failed to setup coordinate transformation:", e);
34441
34468
  }
34469
+ } else {
34470
+ const minX = header2.min[0];
34471
+ const minY = header2.min[1];
34472
+ const maxX = header2.max[0];
34473
+ const maxY = header2.max[1];
34474
+ let detectedEPSG = null;
34475
+ if (minX >= 1e5 && maxX <= 9e5 && minY >= 1e5 && maxY <= 8e5) {
34476
+ detectedEPSG = "EPSG:2180";
34477
+ }
34478
+ if (detectedEPSG) {
34479
+ try {
34480
+ const projConverter = proj4(detectedEPSG, "EPSG:4326");
34481
+ this._transformer = (coord) => projConverter.forward(coord);
34482
+ this._needsTransform = true;
34483
+ } catch (e) {
34484
+ console.warn(`Failed to setup coordinate transformation from ${detectedEPSG}:`, e);
34485
+ }
34486
+ }
34442
34487
  }
34443
34488
  if (this._needsTransform && this._transformer) {
34444
- const [minLng, minLat] = this._transformer([header2.min[0], header2.min[1]]);
34445
- const [maxLng, maxLat] = this._transformer([header2.max[0], header2.max[1]]);
34489
+ const [rawMinLng, rawMinLat] = this._transformer([header2.min[0], header2.min[1]]);
34490
+ const [rawMaxLng, rawMaxLat] = this._transformer([header2.max[0], header2.max[1]]);
34491
+ const [minLng, minLat] = clampLatLng$1(rawMinLng, rawMinLat, "header bounds min");
34492
+ const [maxLng, maxLat] = clampLatLng$1(rawMaxLng, rawMaxLat, "header bounds max");
34446
34493
  this._bounds = {
34447
34494
  minX: Math.min(minLng, maxLng),
34448
34495
  minY: Math.min(minLat, maxLat),
@@ -34532,8 +34579,10 @@ class CopcStreamingLoader {
34532
34579
  };
34533
34580
  let boundsWgs84 = bounds2;
34534
34581
  if (this._needsTransform && this._transformer) {
34535
- const [sw_lng, sw_lat] = this._transformer([minX, minY]);
34536
- const [ne_lng, ne_lat] = this._transformer([minX + nodeSize, minY + nodeSize]);
34582
+ const [rawSwLng, rawSwLat] = this._transformer([minX, minY]);
34583
+ const [rawNeLng, rawNeLat] = this._transformer([minX + nodeSize, minY + nodeSize]);
34584
+ const [sw_lng, sw_lat] = clampLatLng$1(rawSwLng, rawSwLat, "node bounds SW");
34585
+ const [ne_lng, ne_lat] = clampLatLng$1(rawNeLng, rawNeLat, "node bounds NE");
34537
34586
  boundsWgs84 = {
34538
34587
  minX: Math.min(sw_lng, ne_lng),
34539
34588
  minY: Math.min(sw_lat, ne_lat),
@@ -34765,7 +34814,8 @@ class CopcStreamingLoader {
34765
34814
  const y = yGetter(i);
34766
34815
  const z = zGetter(i);
34767
34816
  if (this._needsTransform && this._transformer) {
34768
- const [lng, lat] = this._transformer([x, y]);
34817
+ const [rawLng, rawLat] = this._transformer([x, y]);
34818
+ const [lng, lat] = clampLatLng$1(rawLng, rawLat, "");
34769
34819
  this._positions[pointIndex * 3] = lng - this._coordinateOrigin[0];
34770
34820
  this._positions[pointIndex * 3 + 1] = lat - this._coordinateOrigin[1];
34771
34821
  this._positions[pointIndex * 3 + 2] = z * this._verticalUnitFactor;
@@ -34986,6 +35036,32 @@ function createAttributeArray(type, length) {
34986
35036
  return new Float32Array(length);
34987
35037
  }
34988
35038
  }
35039
+ function clampLatLng(lng, lat, context = "") {
35040
+ let clampedLng = lng;
35041
+ let clampedLat = lat;
35042
+ let wasClamped = false;
35043
+ if (lat > 90) {
35044
+ clampedLat = 90;
35045
+ wasClamped = true;
35046
+ } else if (lat < -90) {
35047
+ clampedLat = -90;
35048
+ wasClamped = true;
35049
+ }
35050
+ if (lng > 180) {
35051
+ clampedLng = 180;
35052
+ wasClamped = true;
35053
+ } else if (lng < -180) {
35054
+ clampedLng = -180;
35055
+ wasClamped = true;
35056
+ }
35057
+ if (wasClamped && context) {
35058
+ console.warn(
35059
+ `EPT: Clamped transformed coordinates to valid WGS84 range${context ? ` (${context})` : ""}:`,
35060
+ `[${lng.toFixed(6)}, ${lat.toFixed(6)}] -> [${clampedLng.toFixed(6)}, ${clampedLat.toFixed(6)}]`
35061
+ );
35062
+ }
35063
+ return [clampedLng, clampedLat];
35064
+ }
34989
35065
  function extractProjcsFromWkt(wkt2) {
34990
35066
  if (wkt2.startsWith("COMPD_CS[")) {
34991
35067
  const projcsStart = wkt2.indexOf("PROJCS[");
@@ -35125,17 +35201,19 @@ class EptStreamingLoader {
35125
35201
  }
35126
35202
  const [minX, minY, minZ, maxX, maxY, maxZ] = this._metadata.boundsConforming;
35127
35203
  if (this._needsTransform && this._transformer) {
35128
- const [minLng, minLat] = this._transformer([minX, minY]);
35129
- const [maxLng, maxLat] = this._transformer([maxX, maxY]);
35130
- if (isNaN(minLng) || isNaN(minLat) || isNaN(maxLng) || isNaN(maxLat) || !isFinite(minLng) || !isFinite(minLat) || !isFinite(maxLng) || !isFinite(maxLat)) {
35204
+ const [rawMinLng, rawMinLat] = this._transformer([minX, minY]);
35205
+ const [rawMaxLng, rawMaxLat] = this._transformer([maxX, maxY]);
35206
+ if (isNaN(rawMinLng) || isNaN(rawMinLat) || isNaN(rawMaxLng) || isNaN(rawMaxLat) || !isFinite(rawMinLng) || !isFinite(rawMinLat) || !isFinite(rawMaxLng) || !isFinite(rawMaxLat)) {
35131
35207
  console.error("EPT coordinate transformation produced invalid bounds:", {
35132
35208
  input: { minX, minY, maxX, maxY },
35133
- output: { minLng, minLat, maxLng, maxLat }
35209
+ output: { rawMinLng, rawMinLat, rawMaxLng, rawMaxLat }
35134
35210
  });
35135
35211
  this._bounds = { minX, minY, minZ, maxX, maxY, maxZ };
35136
35212
  this._needsTransform = false;
35137
35213
  this._transformer = null;
35138
35214
  } else {
35215
+ const [minLng, minLat] = clampLatLng(rawMinLng, rawMinLat, "header bounds min");
35216
+ const [maxLng, maxLat] = clampLatLng(rawMaxLng, rawMaxLat, "header bounds max");
35139
35217
  this._bounds = {
35140
35218
  minX: Math.min(minLng, maxLng),
35141
35219
  minY: Math.min(minLat, maxLat),
@@ -35286,8 +35364,10 @@ class EptStreamingLoader {
35286
35364
  };
35287
35365
  let boundsWgs84 = bounds2;
35288
35366
  if (this._needsTransform && this._transformer) {
35289
- const [sw_lng, sw_lat] = this._transformer([minX, minY]);
35290
- const [ne_lng, ne_lat] = this._transformer([minX + nodeSize, minY + nodeSize]);
35367
+ const [rawSwLng, rawSwLat] = this._transformer([minX, minY]);
35368
+ const [rawNeLng, rawNeLat] = this._transformer([minX + nodeSize, minY + nodeSize]);
35369
+ const [sw_lng, sw_lat] = clampLatLng(rawSwLng, rawSwLat, "node bounds SW");
35370
+ const [ne_lng, ne_lat] = clampLatLng(rawNeLng, rawNeLat, "node bounds NE");
35291
35371
  boundsWgs84 = {
35292
35372
  minX: Math.min(sw_lng, ne_lng),
35293
35373
  minY: Math.min(sw_lat, ne_lat),
@@ -35571,7 +35651,8 @@ class EptStreamingLoader {
35571
35651
  const y = positions[i * 3 + 1];
35572
35652
  const z = positions[i * 3 + 2];
35573
35653
  if (this._needsTransform && this._transformer) {
35574
- const [lng, lat] = this._transformer([x, y]);
35654
+ const [rawLng, rawLat] = this._transformer([x, y]);
35655
+ const [lng, lat] = clampLatLng(rawLng, rawLat, "");
35575
35656
  this._positions[pointIndex * 3] = lng - this._coordinateOrigin[0];
35576
35657
  this._positions[pointIndex * 3 + 1] = lat - this._coordinateOrigin[1];
35577
35658
  this._positions[pointIndex * 3 + 2] = z * this._verticalUnitFactor;
@@ -35651,7 +35732,8 @@ class EptStreamingLoader {
35651
35732
  const y = yGetter(dataView, byteOffset);
35652
35733
  const z = zGetter(dataView, byteOffset);
35653
35734
  if (this._needsTransform && this._transformer) {
35654
- const [lng, lat] = this._transformer([x, y]);
35735
+ const [rawLng, rawLat] = this._transformer([x, y]);
35736
+ const [lng, lat] = clampLatLng(rawLng, rawLat, "");
35655
35737
  this._positions[pointIndex * 3] = lng - this._coordinateOrigin[0];
35656
35738
  this._positions[pointIndex * 3 + 1] = lat - this._coordinateOrigin[1];
35657
35739
  this._positions[pointIndex * 3 + 2] = z * this._verticalUnitFactor;
@@ -38431,10 +38513,14 @@ class LidarControl {
38431
38513
  });
38432
38514
  viewportManager.start();
38433
38515
  if (this._options.autoZoom) {
38516
+ const clampedMinY = Math.max(-90, Math.min(90, bounds2.minY));
38517
+ const clampedMaxY = Math.max(-90, Math.min(90, bounds2.maxY));
38518
+ const clampedMinX = Math.max(-180, Math.min(180, bounds2.minX));
38519
+ const clampedMaxX = Math.max(-180, Math.min(180, bounds2.maxX));
38434
38520
  (_c = this._map) == null ? void 0 : _c.fitBounds(
38435
38521
  [
38436
- [bounds2.minX, bounds2.minY],
38437
- [bounds2.maxX, bounds2.maxY]
38522
+ [clampedMinX, clampedMinY],
38523
+ [clampedMaxX, clampedMaxY]
38438
38524
  ],
38439
38525
  {
38440
38526
  padding: 50,
@@ -38591,10 +38677,14 @@ class LidarControl {
38591
38677
  });
38592
38678
  viewportManager.start();
38593
38679
  if (this._options.autoZoom) {
38680
+ const clampedMinY = Math.max(-90, Math.min(90, bounds2.minY));
38681
+ const clampedMaxY = Math.max(-90, Math.min(90, bounds2.maxY));
38682
+ const clampedMinX = Math.max(-180, Math.min(180, bounds2.minX));
38683
+ const clampedMaxX = Math.max(-180, Math.min(180, bounds2.maxX));
38594
38684
  (_d = this._map) == null ? void 0 : _d.fitBounds(
38595
38685
  [
38596
- [bounds2.minX, bounds2.minY],
38597
- [bounds2.maxX, bounds2.maxY]
38686
+ [clampedMinX, clampedMinY],
38687
+ [clampedMaxX, clampedMaxY]
38598
38688
  ],
38599
38689
  {
38600
38690
  padding: 50,
@@ -39704,4 +39794,4 @@ exports.generateId = generateId;
39704
39794
  exports.getClassificationName = getClassificationName;
39705
39795
  exports.getFilename = getFilename;
39706
39796
  exports.throttle = throttle;
39707
- //# sourceMappingURL=LidarLayerAdapter-BW2Hj7QW.cjs.map
39797
+ //# sourceMappingURL=LidarLayerAdapter-Sw_plY5a.cjs.map