@@ -128,7 +128,6 @@ export const useMapStore = defineStore('map', () => {
128128 const map = shallowRef < Map > ( ) ;
129129 const availableBasemaps = ref < Basemap [ ] > ( [ ] ) ;
130130 const currentBasemap = ref < Basemap > ( ) ;
131- const showMapBaseLayer = ref ( true ) ;
132131 const tooltipOverlay = ref < Popup > ( ) ;
133132 const clickedFeature = ref < ClickedFeatureData > ( ) ;
134133 const rasterTooltipDataCache = ref < Record < number , RasterDataValues | undefined > > ( { } ) ;
@@ -139,7 +138,10 @@ export const useMapStore = defineStore('map', () => {
139138 const appStore = useAppStore ( ) ;
140139
141140 async function fetchAvailableBasemaps ( ) {
142- availableBasemaps . value = await getBasemaps ( ) ;
141+ availableBasemaps . value = [
142+ { name : 'None' } ,
143+ ...await getBasemaps ( )
144+ ] ;
143145 setBasemapToDefault ( ) ;
144146 }
145147
@@ -151,6 +153,21 @@ export const useMapStore = defineStore('map', () => {
151153 }
152154 }
153155
156+ function setBasemapVisibility ( visible : boolean ) {
157+ const map = getMap ( ) ;
158+ const baseLayerSourceIds = getBaseLayerSourceIds ( ) ;
159+ map . getLayersOrder ( ) . forEach ( ( id ) => {
160+ const layer = map . getLayer ( id ) ;
161+ if ( layer && baseLayerSourceIds . includes ( layer . source ) ) {
162+ map . setLayoutProperty (
163+ id ,
164+ "visibility" ,
165+ visible ? "visible" : "none"
166+ ) ;
167+ }
168+ } ) ;
169+ }
170+
154171 function handleLayerClick ( e : MapLayerMouseEvent ) {
155172 const map = getMap ( ) ;
156173 const clickedFeatures = map . queryRenderedFeatures ( e . point ) . filter (
@@ -182,26 +199,6 @@ export const useMapStore = defineStore('map', () => {
182199 }
183200 }
184201
185- // Update the base layer visibility
186- watch ( showMapBaseLayer , ( ) => {
187- const map = getMap ( ) ;
188- const baseLayerSourceIds = getBaseLayerSourceIds ( ) ;
189- map . getLayersOrder ( ) . forEach ( ( id ) => {
190- const layer = map . getLayer ( id ) ;
191- if ( layer && baseLayerSourceIds . includes ( layer . source ) ) {
192- map . setLayoutProperty (
193- id ,
194- "visibility" ,
195- showMapBaseLayer . value ? "visible" : "none"
196- ) ;
197- }
198- } ) ;
199- } ) ;
200-
201- function toggleBaseLayer ( ) {
202- showMapBaseLayer . value = ! showMapBaseLayer . value ;
203- }
204-
205202 function getMap ( ) {
206203 if ( map . value === undefined ) {
207204 throw new Error ( "Map not yet initialized!" ) ;
@@ -509,16 +506,15 @@ export const useMapStore = defineStore('map', () => {
509506 map,
510507 availableBasemaps,
511508 currentBasemap,
512- showMapBaseLayer,
513509 tooltipOverlay,
514510 clickedFeature,
515511 rasterTooltipDataCache,
516512 rasterSourceTileURLs,
517513 // Functions
518514 fetchAvailableBasemaps,
519515 setBasemapToDefault,
516+ setBasemapVisibility,
520517 handleLayerClick,
521- toggleBaseLayer,
522518 getMap,
523519 getMapSources,
524520 getCurrentMapPosition,
0 commit comments