11import { useLayoutEffect , useEffect , useCallback , useState , createRef } from 'react' ;
22import { useSelector } from 'react-redux' ;
3- import mapboxgl from 'mapbox -gl' ;
4- import 'mapbox -gl/dist/mapbox -gl.css' ;
3+ import maplibregl from 'maplibre -gl' ;
4+ import 'maplibre -gl/dist/maplibre -gl.css' ;
55import { featureCollection } from '@turf/helpers' ;
66import MapboxLanguage from '@mapbox/mapbox-gl-language' ;
7- import MapboxGeocoder from '@mapbox/mapbox -gl-geocoder' ;
8- import '@mapbox/mapbox -gl-geocoder/dist/mapbox -gl-geocoder.css' ;
7+ import MaplibreGeocoder from '@maplibre/maplibre -gl-geocoder' ;
8+ import '@maplibre/maplibre -gl-geocoder/dist/maplibre -gl-geocoder.css' ;
99import { useDropzone } from 'react-dropzone' ;
1010
11- import { mapboxLayerDefn } from '../projects/projectsMap' ;
11+ import { maplibreLayerDefn } from '../projects/projectsMap' ;
1212import useMapboxSupportedLanguage from '../../hooks/UseMapboxSupportedLanguage' ;
1313
14- import {
15- MAPBOX_TOKEN ,
16- MAP_STYLE ,
17- CHART_COLOURS ,
18- MAPBOX_RTL_PLUGIN_URL ,
19- TASK_COLOURS ,
20- } from '../../config' ;
14+ import { MAPBOX_TOKEN , MAP_STYLE , CHART_COLOURS , TASK_COLOURS } from '../../config' ;
2115import { fetchLocalJSONAPI } from '../../network/genericJSONRequest' ;
2216import { useDebouncedCallback } from '../../hooks/UseThrottle' ;
17+ import isWebglSupported from '../../utils/isWebglSupported' ;
18+ import useSetRTLTextPlugin from '../../utils/useSetRTLTextPlugin' ;
2319import { BasemapMenu } from '../basemapMenu' ;
2420import { ProjectsAOILayerCheckBox } from './projectsAOILayerCheckBox' ;
2521import WebglUnsupported from '../webglUnsupported' ;
2622
27- mapboxgl . accessToken = MAPBOX_TOKEN ;
28- try {
29- mapboxgl . setRTLTextPlugin ( MAPBOX_RTL_PLUGIN_URL ) ;
30- } catch {
31- console . log ( 'RTLTextPlugin is loaded' ) ;
32- }
23+ maplibregl . accessToken = MAPBOX_TOKEN ;
3324
3425const ProjectCreationMap = ( { mapObj, setMapObj, metadata, updateMetadata, step, uploadFile } ) => {
3526 const mapRef = createRef ( ) ;
@@ -47,6 +38,8 @@ const ProjectCreationMap = ({ mapObj, setMapObj, metadata, updateMetadata, step,
4738 } ) ;
4839 const minZoomLevelToAOIVisualization = 9 ;
4940
41+ useSetRTLTextPlugin ( ) ;
42+
5043 useEffect ( ( ) => {
5144 fetchLocalJSONAPI ( 'projects/' ) . then ( ( res ) => setExistingProjectsList ( res . mapResults ) ) ;
5245 } , [ ] ) ;
@@ -78,22 +71,22 @@ const ProjectCreationMap = ({ mapObj, setMapObj, metadata, updateMetadata, step,
7871 } , [ showProjectsAOILayer , debouncedGetProjectsAOI , clearProjectsAOI , step ] ) ;
7972
8073 useLayoutEffect ( ( ) => {
81- if ( ! mapboxgl . supported ( ) ) return ;
82- const map = new mapboxgl . Map ( {
74+ if ( ! isWebglSupported ( ) ) return ;
75+ const map = new maplibregl . Map ( {
8376 container : mapRef . current ,
8477 style : MAP_STYLE ,
8578 center : [ 0 , 0 ] ,
8679 zoom : 1.3 ,
8780 attributionControl : false ,
8881 } )
89- . addControl ( new mapboxgl . AttributionControl ( { compact : false } ) )
82+ . addControl ( new maplibregl . AttributionControl ( { compact : false } ) )
9083 . addControl ( new MapboxLanguage ( { defaultLanguage : mapboxSupportedLanguage } ) )
91- . addControl ( new mapboxgl . ScaleControl ( { unit : 'metric' } ) ) ;
84+ . addControl ( new maplibregl . ScaleControl ( { unit : 'metric' } ) ) ;
9285 if ( MAPBOX_TOKEN ) {
9386 map . addControl (
94- new MapboxGeocoder ( {
87+ new MaplibreGeocoder ( {
9588 accessToken : MAPBOX_TOKEN ,
96- mapboxgl : mapboxgl ,
89+ maplibregl ,
9790 marker : false ,
9891 collapsed : true ,
9992 language : mapboxSupportedLanguage ,
@@ -222,9 +215,9 @@ const ProjectCreationMap = ({ mapObj, setMapObj, metadata, updateMetadata, step,
222215
223216 /* set up style/sources for the map, either immediately or on base load */
224217 if ( mapReadyProjectsReady ) {
225- mapboxLayerDefn ( map , existingProjectsList , noop , true ) ;
218+ maplibreLayerDefn ( map , existingProjectsList , noop , true ) ;
226219 } else if ( projectsReadyMapLoading ) {
227- map . on ( 'load' , ( ) => mapboxLayerDefn ( map , existingProjectsList , noop , true ) ) ;
220+ map . on ( 'load' , ( ) => maplibreLayerDefn ( map , existingProjectsList , noop , true ) ) ;
228221 }
229222
230223 /* refill the source on existingProjectsList changes */
@@ -234,17 +227,17 @@ const ProjectCreationMap = ({ mapObj, setMapObj, metadata, updateMetadata, step,
234227 } , [ mapObj , existingProjectsList ] ) ;
235228
236229 useLayoutEffect ( ( ) => {
237- if ( mapObj . map !== null && mapboxgl . supported ( ) ) {
230+ if ( mapObj . map !== null && isWebglSupported ( ) ) {
238231 mapObj . map . on ( 'moveend' , ( event ) => {
239232 debouncedGetProjectsAOI ( ) ;
240233 } ) ;
241234 }
242235 } ) ;
243236
244237 useLayoutEffect ( ( ) => {
245- if ( mapObj . map !== null && mapboxgl . supported ( ) ) {
238+ if ( mapObj . map !== null && isWebglSupported ( ) ) {
246239 mapObj . map . on ( 'load' , ( ) => {
247- mapObj . map . addControl ( new mapboxgl . NavigationControl ( ) ) ;
240+ mapObj . map . addControl ( new maplibregl . NavigationControl ( ) ) ;
248241 mapObj . map . addControl ( mapObj . draw ) ;
249242 addMapLayers ( mapObj . map ) ;
250243 } ) ;
@@ -282,7 +275,7 @@ const ProjectCreationMap = ({ mapObj, setMapObj, metadata, updateMetadata, step,
282275 }
283276 } , [ mapObj , metadata , updateMetadata , step ] ) ;
284277
285- if ( ! mapboxgl . supported ( ) ) {
278+ if ( ! isWebglSupported ( ) ) {
286279 return < WebglUnsupported className = "vh-50 h-100-l w-100" /> ;
287280 } else {
288281 return (
0 commit comments