maplibre-gl-lidar 0.8.2 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -501,7 +501,9 @@ console.log(`Loaded ${data.pointCount} points`);
501
501
 
502
502
  ### Next.js
503
503
 
504
- When using maplibre-gl-lidar with Next.js, you need to configure webpack to handle Node.js built-in modules that are referenced (but not executed) in browser code. Add the following to your `next.config.js`:
504
+ maplibre-gl-lidar works with Next.js out of the box, including Turbopack (the default bundler in Next.js 15+). The library bundles browser-safe shims for Node.js modules that are statically referenced but never executed in browsers.
505
+
506
+ **Note for older Next.js versions or custom webpack configs:** If you encounter "Can't resolve 'fs'" errors, add this to your `next.config.js`:
505
507
 
506
508
  ```javascript
507
509
  /** @type {import('next').NextConfig} */
@@ -521,8 +523,6 @@ const nextConfig = {
521
523
  module.exports = nextConfig;
522
524
  ```
523
525
 
524
- This configuration tells webpack not to bundle the `fs` and `path` modules for client-side code. These modules are only referenced in environment-guarded code paths that never execute in browsers.
525
-
526
526
  ## Coordinate Systems
527
527
 
528
528
  Point clouds are automatically transformed to WGS84 (EPSG:4326) for display on the map. The loader reads the WKT coordinate reference system from the file and uses proj4 to transform coordinates. Supported features:
@@ -6676,7 +6676,14 @@ function getModule() {
6676
6676
  var nodePath;
6677
6677
  if (ENVIRONMENT_IS_NODE) {
6678
6678
  if (ENVIRONMENT_IS_WORKER) {
6679
- scriptDirectory = require("path").dirname(scriptDirectory) + "/";
6679
+ scriptDirectory = {
6680
+ dirname: (p) => {
6681
+ const i = p.lastIndexOf("/");
6682
+ return i <= 0 ? i === 0 ? "/" : "." : p.substring(0, i);
6683
+ },
6684
+ normalize: (p) => p,
6685
+ join: (...a) => a.filter(Boolean).join("/").replace(/\/+/g, "/")
6686
+ }.dirname(scriptDirectory) + "/";
6680
6687
  } else {
6681
6688
  const dirname2 = typeof __dirname !== "undefined" ? __dirname : "";
6682
6689
  scriptDirectory = dirname2 + "/";
@@ -6687,9 +6694,16 @@ function getModule() {
6687
6694
  return binary2 ? ret : ret.toString();
6688
6695
  }
6689
6696
  if (!nodeFS)
6690
- nodeFS = require("fs");
6697
+ nodeFS = {};
6691
6698
  if (!nodePath)
6692
- nodePath = require("path");
6699
+ nodePath = {
6700
+ dirname: (p) => {
6701
+ const i = p.lastIndexOf("/");
6702
+ return i <= 0 ? i === 0 ? "/" : "." : p.substring(0, i);
6703
+ },
6704
+ normalize: (p) => p,
6705
+ join: (...a) => a.filter(Boolean).join("/").replace(/\/+/g, "/")
6706
+ };
6693
6707
  filename2 = nodePath["normalize"](filename2);
6694
6708
  return nodeFS["readFileSync"](filename2, binary2 ? null : "utf8");
6695
6709
  };
@@ -40930,6 +40944,8 @@ class LidarControl {
40930
40944
  __publicField(this, "_viewportManagers", /* @__PURE__ */ new Map());
40931
40945
  __publicField(this, "_eptViewportRequestIds", /* @__PURE__ */ new Map());
40932
40946
  __publicField(this, "_eptLastViewport", /* @__PURE__ */ new Map());
40947
+ // Track whether the user has explicitly set zOffset (to skip autoZOffset)
40948
+ __publicField(this, "_manualZOffset", false);
40933
40949
  // Metadata and cross-section components
40934
40950
  __publicField(this, "_metadataPanel");
40935
40951
  __publicField(this, "_fullMetadata", /* @__PURE__ */ new Map());
@@ -40968,6 +40984,9 @@ class LidarControl {
40968
40984
  terrainEnabled: this._options.terrainEnabled ?? false
40969
40985
  };
40970
40986
  this._loader = new PointCloudLoader();
40987
+ if ((options == null ? void 0 : options.zOffset) !== void 0 || (options == null ? void 0 : options.zOffsetEnabled) !== void 0) {
40988
+ this._manualZOffset = true;
40989
+ }
40971
40990
  }
40972
40991
  /**
40973
40992
  * Called when the control is added to the map.
@@ -41149,7 +41168,7 @@ class LidarControl {
41149
41168
  * @returns Promise resolving to the point cloud info
41150
41169
  */
41151
41170
  async loadPointCloud(source, options) {
41152
- var _a, _b, _c, _d;
41171
+ var _a, _b, _c, _d, _e;
41153
41172
  const isEptUrl = typeof source === "string" && (source.endsWith("/ept.json") || source.includes("/ept.json?"));
41154
41173
  if (isEptUrl) {
41155
41174
  return this.loadPointCloudEptStreaming(source);
@@ -41183,7 +41202,7 @@ class LidarControl {
41183
41202
  let zOffsetBase;
41184
41203
  let zOffset;
41185
41204
  let zOffsetEnabled = this._state.zOffsetEnabled;
41186
- if (this._options.autoZOffset && data.positions && data.pointCount > 0) {
41205
+ if (this._options.autoZOffset && !this._manualZOffset && data.positions && data.pointCount > 0) {
41187
41206
  const zValues = new Float32Array(data.pointCount);
41188
41207
  for (let i = 0; i < data.pointCount; i++) {
41189
41208
  zValues[i] = data.positions[i * 3 + 2] ?? 0;
@@ -41194,6 +41213,11 @@ class LidarControl {
41194
41213
  zOffsetEnabled = true;
41195
41214
  (_b = this._pointCloudManager) == null ? void 0 : _b.setZOffset(zOffset);
41196
41215
  console.log(`Auto Z offset applied: zOffsetBase=${zOffsetBase.toFixed(1)}, zOffset=${zOffset.toFixed(1)}, enabled=${zOffsetEnabled}`);
41216
+ } else if (this._manualZOffset) {
41217
+ (_c = this._pointCloudManager) == null ? void 0 : _c.setZOffset(this._state.zOffset);
41218
+ zOffset = this._state.zOffset;
41219
+ zOffsetEnabled = this._state.zOffsetEnabled;
41220
+ console.log(`Manual Z offset applied: zOffset=${zOffset}, enabled=${zOffsetEnabled}`);
41197
41221
  } else {
41198
41222
  console.log("Auto Z offset skipped - conditions not met");
41199
41223
  }
@@ -41225,7 +41249,7 @@ class LidarControl {
41225
41249
  zOffsetEnabled
41226
41250
  });
41227
41251
  this._updateComputedColorBounds();
41228
- (_c = this._panelBuilder) == null ? void 0 : _c.updateState(this._state);
41252
+ (_d = this._panelBuilder) == null ? void 0 : _d.updateState(this._state);
41229
41253
  this._emitWithData("load", { pointCloud: info2 });
41230
41254
  if (this._options.autoZoom) {
41231
41255
  this.flyToPointCloud(id);
@@ -41239,7 +41263,7 @@ class LidarControl {
41239
41263
  console.warn(
41240
41264
  `CORS error detected for ${source}. Falling back to download mode...`
41241
41265
  );
41242
- (_d = this._panelBuilder) == null ? void 0 : _d.updateLoadingProgress(5, "CORS blocked - downloading file...");
41266
+ (_e = this._panelBuilder) == null ? void 0 : _e.updateLoadingProgress(5, "CORS blocked - downloading file...");
41243
41267
  return this._loadPointCloudFullDownload(source);
41244
41268
  }
41245
41269
  this.setState({
@@ -41323,9 +41347,9 @@ class LidarControl {
41323
41347
  (_b = this._panelBuilder) == null ? void 0 : _b.updateLoadingProgress(20, "Setting up streaming...");
41324
41348
  let autoZOffsetApplied = false;
41325
41349
  streamingLoader.setOnPointsLoaded((data) => {
41326
- var _a2, _b2;
41350
+ var _a2, _b2, _c2;
41327
41351
  (_a2 = this._pointCloudManager) == null ? void 0 : _a2.updatePointCloud(id, data);
41328
- if (this._options.autoZOffset && !autoZOffsetApplied && data.bounds) {
41352
+ if (this._options.autoZOffset && !this._manualZOffset && !autoZOffsetApplied && data.bounds) {
41329
41353
  const zOffsetBase = data.bounds.minZ;
41330
41354
  const zOffset = -zOffsetBase;
41331
41355
  (_b2 = this._pointCloudManager) == null ? void 0 : _b2.setZOffset(zOffset);
@@ -41336,6 +41360,9 @@ class LidarControl {
41336
41360
  zOffsetEnabled: true
41337
41361
  });
41338
41362
  autoZOffsetApplied = true;
41363
+ } else if (this._manualZOffset && !autoZOffsetApplied) {
41364
+ (_c2 = this._pointCloudManager) == null ? void 0 : _c2.setZOffset(this._state.zOffset);
41365
+ autoZOffsetApplied = true;
41339
41366
  }
41340
41367
  const newClassifications = getAvailableClassifications(data);
41341
41368
  if (newClassifications.size > 0) {
@@ -41489,9 +41516,9 @@ class LidarControl {
41489
41516
  (_b = this._panelBuilder) == null ? void 0 : _b.updateLoadingProgress(20, "Setting up streaming...");
41490
41517
  let autoZOffsetApplied = false;
41491
41518
  eptLoader.setOnPointsLoaded((data) => {
41492
- var _a2, _b2;
41519
+ var _a2, _b2, _c2;
41493
41520
  (_a2 = this._pointCloudManager) == null ? void 0 : _a2.updatePointCloud(id, data);
41494
- if (this._options.autoZOffset && !autoZOffsetApplied && data.bounds) {
41521
+ if (this._options.autoZOffset && !this._manualZOffset && !autoZOffsetApplied && data.bounds) {
41495
41522
  const zOffsetBase = data.bounds.minZ;
41496
41523
  const zOffset = -zOffsetBase;
41497
41524
  (_b2 = this._pointCloudManager) == null ? void 0 : _b2.setZOffset(zOffset);
@@ -41502,6 +41529,9 @@ class LidarControl {
41502
41529
  zOffsetEnabled: true
41503
41530
  });
41504
41531
  autoZOffsetApplied = true;
41532
+ } else if (this._manualZOffset && !autoZOffsetApplied) {
41533
+ (_c2 = this._pointCloudManager) == null ? void 0 : _c2.setZOffset(this._state.zOffset);
41534
+ autoZOffsetApplied = true;
41505
41535
  }
41506
41536
  const newClassifications = getAvailableClassifications(data);
41507
41537
  if (newClassifications.size > 0) {
@@ -41702,7 +41732,7 @@ class LidarControl {
41702
41732
  * Used as fallback when streaming fails due to CORS.
41703
41733
  */
41704
41734
  async _loadPointCloudFullDownload(url) {
41705
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
41735
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
41706
41736
  const id = generateId("pc");
41707
41737
  const name = getFilename(url);
41708
41738
  try {
@@ -41750,7 +41780,7 @@ class LidarControl {
41750
41780
  let zOffsetBase;
41751
41781
  let zOffset;
41752
41782
  let zOffsetEnabled = this._state.zOffsetEnabled;
41753
- if (this._options.autoZOffset && data.positions && data.pointCount > 0) {
41783
+ if (this._options.autoZOffset && !this._manualZOffset && data.positions && data.pointCount > 0) {
41754
41784
  const zValues = new Float32Array(data.pointCount);
41755
41785
  for (let i = 0; i < data.pointCount; i++) {
41756
41786
  zValues[i] = data.positions[i * 3 + 2] ?? 0;
@@ -41761,8 +41791,12 @@ class LidarControl {
41761
41791
  zOffsetEnabled = true;
41762
41792
  (_g = this._pointCloudManager) == null ? void 0 : _g.setZOffset(zOffset);
41763
41793
  console.log(`Auto Z offset applied (download): ${zOffset.toFixed(1)}m (ground level: ${zOffsetBase.toFixed(1)}m)`);
41794
+ } else if (this._manualZOffset) {
41795
+ (_h = this._pointCloudManager) == null ? void 0 : _h.setZOffset(this._state.zOffset);
41796
+ zOffset = this._state.zOffset;
41797
+ zOffsetEnabled = this._state.zOffsetEnabled;
41764
41798
  }
41765
- (_h = this._panelBuilder) == null ? void 0 : _h.updateLoadingProgress(100, "Complete!");
41799
+ (_i = this._panelBuilder) == null ? void 0 : _i.updateLoadingProgress(100, "Complete!");
41766
41800
  const info2 = {
41767
41801
  id,
41768
41802
  name,
@@ -41790,7 +41824,7 @@ class LidarControl {
41790
41824
  zOffsetEnabled
41791
41825
  });
41792
41826
  this._updateComputedColorBounds();
41793
- (_i = this._panelBuilder) == null ? void 0 : _i.updateState(this._state);
41827
+ (_j = this._panelBuilder) == null ? void 0 : _j.updateState(this._state);
41794
41828
  this._emitWithData("load", { pointCloud: info2 });
41795
41829
  if (this._options.autoZoom) {
41796
41830
  this.flyToPointCloud(id);
@@ -42124,6 +42158,7 @@ class LidarControl {
42124
42158
  */
42125
42159
  setZOffset(offset) {
42126
42160
  var _a;
42161
+ this._manualZOffset = true;
42127
42162
  this._state.zOffset = offset;
42128
42163
  (_a = this._pointCloudManager) == null ? void 0 : _a.setZOffset(offset);
42129
42164
  this._emit("stylechange");
@@ -43103,4 +43138,4 @@ exports.getClassificationName = getClassificationName;
43103
43138
  exports.getColormap = getColormap;
43104
43139
  exports.getFilename = getFilename;
43105
43140
  exports.throttle = throttle;
43106
- //# sourceMappingURL=LidarLayerAdapter-BLZfG-we.cjs.map
43141
+ //# sourceMappingURL=LidarLayerAdapter-BhjrUBrW.cjs.map