11import { useEffect , useRef , ReactNode } from 'react' ;
2- import mapboxgl from 'mapbox -gl' ;
3- import 'mapbox -gl/dist/mapbox -gl.css' ;
2+ import maplibregl from 'maplibre -gl' ;
3+ import 'maplibre -gl/dist/maplibre -gl.css' ;
44import { useMapInternal } from '../context/MapContext' ;
55import { DrawProvider } from '../context/DrawContext' ;
66import { MapOptions , DEFAULT_MAP_OPTIONS , BASEMAP_STYLES , BasemapStyle } from '../types' ;
@@ -59,22 +59,12 @@ export function MapContainer({
5959 style,
6060} : MapContainerProps ) {
6161 const containerRef = useRef < HTMLDivElement > ( null ) ;
62- const mapRef = useRef < mapboxgl . Map | null > ( null ) ;
62+ const mapRef = useRef < maplibregl . Map | null > ( null ) ;
6363 const { setMap, setIsLoaded, setIsLoading, setError } = useMapInternal ( ) ;
6464
6565 useEffect ( ( ) => {
6666 if ( ! containerRef . current ) return ;
6767
68- // Get access token from environment
69- const accessToken = import . meta. env . VITE_MAPBOX_TOKEN ;
70- if ( ! accessToken ) {
71- setError ( new Error ( 'VITE_MAPBOX_TOKEN environment variable is not set' ) ) ;
72- setIsLoading ( false ) ;
73- return ;
74- }
75-
76- mapboxgl . accessToken = accessToken ;
77-
7868 // Merge options with defaults
7969 const mergedOptions = { ...DEFAULT_MAP_OPTIONS , ...options } ;
8070
@@ -107,15 +97,15 @@ export function MapContainer({
10797 setIsLoading ( true ) ;
10898 setError ( null ) ;
10999
110- const map = new mapboxgl . Map ( {
100+ const map = new maplibregl . Map ( {
111101 container : containerRef . current ,
112102 style : initialStyle ,
113103 center : initialCenter ,
114104 zoom : initialZoom ,
115105 pitch : initialPitch ,
116106 bearing : initialBearing ,
117- attributionControl : true ,
118- preserveDrawingBuffer : true , // Needed for export/screenshots
107+ attributionControl : { compact : true } ,
108+ canvasContextAttributes : { preserveDrawingBuffer : true } , // Required for useRasterHover (gl.readPixels)
119109 } ) ;
120110
121111 mapRef . current = map ;
@@ -125,23 +115,26 @@ export function MapContainer({
125115 setIsLoaded ( true ) ;
126116 setIsLoading ( false ) ;
127117
128- // Add terrain if enabled
129- if ( mergedOptions . terrain ) {
130- map . addSource ( 'mapbox-dem' , {
131- type : 'raster-dem' ,
132- url : 'mapbox://mapbox.mapbox-terrain-dem-v1' ,
133- tileSize : 512 ,
134- maxzoom : 14 ,
135- } ) ;
136- map . setTerrain ( {
137- source : 'mapbox-dem' ,
138- exaggeration : mergedOptions . terrainExaggeration ,
139- } ) ;
140- }
118+ // Terrain disabled - requires DEM source configuration
119+ // Mapbox DEM is not compatible with MapLibre
120+ // To enable, configure a compatible DEM source (e.g., MapTiler, self-hosted)
121+ // See useTerrain.ts for details
122+ // if (mergedOptions.terrain) {
123+ // map.addSource('terrain-dem', {
124+ // type: 'raster-dem',
125+ // url: 'YOUR_DEM_SOURCE_URL',
126+ // tileSize: 512,
127+ // maxzoom: 14,
128+ // });
129+ // map.setTerrain({
130+ // source: 'terrain-dem',
131+ // exaggeration: mergedOptions.terrainExaggeration,
132+ // });
133+ // }
141134
142135 // Add navigation controls
143- map . addControl ( new mapboxgl . NavigationControl ( ) , 'top-right' ) ;
144- map . addControl ( new mapboxgl . ScaleControl ( { unit : 'metric' } ) , 'bottom-left' ) ;
136+ map . addControl ( new maplibregl . NavigationControl ( ) , 'top-right' ) ;
137+ map . addControl ( new maplibregl . ScaleControl ( { unit : 'metric' } ) , 'bottom-left' ) ;
145138 } ) ;
146139
147140 // Save map view position on move end
0 commit comments