11import maplibregl from 'maplibre-gl' ;
2- import { LidarControl } from 'maplibre-gl-lidar' ;
2+ import { LidarControl , LidarLayerAdapter } from 'maplibre-gl-lidar' ;
33import { LayerControl } from 'maplibre-gl-layer-control' ;
44import 'maplibre-gl-lidar/style.css' ;
55import 'maplibre-gl/dist/maplibre-gl.css' ;
@@ -9,13 +9,11 @@ const urlFormContainer = document.getElementById('url-form-container') as HTMLDi
99const urlForm = document . getElementById ( 'url-form' ) as HTMLFormElement ;
1010const urlInput = document . getElementById ( 'url-input' ) as HTMLInputElement ;
1111const loadBtn = document . getElementById ( 'load-btn' ) as HTMLButtonElement ;
12- const infoBox = document . getElementById ( 'info-box' ) as HTMLDivElement ;
13- const urlDisplay = document . getElementById ( 'url-display' ) as HTMLDivElement ;
14- const loadAnotherBtn = document . getElementById ( 'load-another-btn' ) as HTMLButtonElement ;
1512const loadingIndicator = document . getElementById ( 'loading-indicator' ) as HTMLDivElement ;
1613
1714let map : maplibregl . Map | null = null ;
1815let lidarControl : LidarControl | null = null ;
16+ let layerControl : LayerControl | null = null ;
1917
2018/**
2119 * Initialize the MapLibre GL map instance.
@@ -42,13 +40,13 @@ function initMap(): maplibregl.Map {
4240 map . addControl ( new maplibregl . NavigationControl ( ) , 'top-right' ) ;
4341 map . addControl ( new maplibregl . FullscreenControl ( ) , 'top-right' ) ;
4442 map . addControl ( new maplibregl . GlobeControl ( ) , 'top-right' ) ;
45- map . addControl ( new maplibregl . ScaleControl ( ) , 'bottom-right ' ) ;
43+ map . addControl ( new maplibregl . ScaleControl ( ) , 'bottom-left ' ) ;
4644
4745 // Add layer control for basemap layers
48- const layerControl = new LayerControl ( {
46+ layerControl = new LayerControl ( {
4947 collapsed : true ,
5048 basemapStyleUrl : BASEMAP_STYLE ,
51- } ) ;
49+ } ) ;
5250 map . addControl ( layerControl , 'top-right' ) ;
5351
5452 return map ;
@@ -130,6 +128,12 @@ async function loadPointCloud(url: string): Promise<void> {
130128 const control = initLidarControl ( ) ;
131129 if ( ! mapInstance . hasControl ( control ) ) {
132130 mapInstance . addControl ( control , 'top-right' ) ;
131+
132+ // Register LidarLayerAdapter with LayerControl
133+ if ( layerControl ) {
134+ const lidarAdapter = new LidarLayerAdapter ( control ) ;
135+ layerControl . registerCustomAdapter ( lidarAdapter ) ;
136+ }
133137 }
134138
135139 // Clear existing point clouds
@@ -155,10 +159,8 @@ async function loadPointCloud(url: string): Promise<void> {
155159 const filename = url . split ( '/' ) . pop ( ) || 'Point Cloud' ;
156160 document . title = `${ filename } - LiDAR Viewer` ;
157161
158- // Show map, hide form
162+ // Hide form when point cloud is loaded
159163 urlFormContainer . style . display = 'none' ;
160- infoBox . style . display = 'block' ;
161- urlDisplay . textContent = url ;
162164 } catch ( err ) {
163165 console . error ( 'Failed to load point cloud:' , err ) ;
164166 const message = err instanceof Error ? err . message : 'Unknown error' ;
@@ -169,26 +171,6 @@ async function loadPointCloud(url: string): Promise<void> {
169171 }
170172}
171173
172- /**
173- * Show the URL input form and reset the UI to initial state.
174- *
175- * Hides the info box, displays the form, and removes the URL
176- * parameter from the browser address bar.
177- */
178- function showForm ( ) : void {
179- urlFormContainer . style . display = 'flex' ;
180- infoBox . style . display = 'none' ;
181- urlInput . focus ( ) ;
182-
183- // Update URL (remove query param)
184- const newUrl = new URL ( window . location . href ) ;
185- newUrl . searchParams . delete ( 'url' ) ;
186- window . history . pushState ( { } , '' , newUrl . toString ( ) ) ;
187-
188- // Reset title
189- document . title = 'LiDAR Point Cloud Viewer' ;
190- }
191-
192174// Event listeners
193175urlForm . addEventListener ( 'submit' , ( e ) => {
194176 e . preventDefault ( ) ;
@@ -209,9 +191,6 @@ document.querySelectorAll('.sample-urls button[data-url]').forEach((btn) => {
209191 } ) ;
210192} ) ;
211193
212- // Load another button
213- loadAnotherBtn . addEventListener ( 'click' , showForm ) ;
214-
215194// Check for URL parameter on page load
216195const params = new URLSearchParams ( window . location . search ) ;
217196const initialUrl = params . get ( 'url' ) ;
0 commit comments