forked from MapComplete/MapComplete
		
	Add enable/disable all button for layers, fix #1407
This commit is contained in:
		
							parent
							
								
									894c48520a
								
							
						
					
					
						commit
						5c11149085
					
				
					 3 changed files with 59 additions and 11 deletions
				
			
		|  | @ -223,6 +223,10 @@ | ||||||
|         "example": "Example", |         "example": "Example", | ||||||
|         "examples": "Examples", |         "examples": "Examples", | ||||||
|         "fewChangesBefore": "Please, answer a few questions of existing features before adding a new feature.", |         "fewChangesBefore": "Please, answer a few questions of existing features before adding a new feature.", | ||||||
|  |         "filterPanel": { | ||||||
|  |             "disableAll": "Disable all", | ||||||
|  |             "enableAll": "Enable all" | ||||||
|  |         }, | ||||||
|         "geopermissionDenied": "Using the geolocation was denied", |         "geopermissionDenied": "Using the geolocation was denied", | ||||||
|         "getStartedLogin": "Log in with OpenStreetMap to get started", |         "getStartedLogin": "Log in with OpenStreetMap to get started", | ||||||
|         "getStartedNewAccount": " or <a href='https://www.openstreetmap.org/user/new' target='_blank'>create a new account</a>", |         "getStartedNewAccount": " or <a href='https://www.openstreetmap.org/user/new' target='_blank'>create a new account</a>", | ||||||
|  |  | ||||||
|  | @ -8,6 +8,9 @@ | ||||||
|   let _c: boolean = selected.data ?? true |   let _c: boolean = selected.data ?? true | ||||||
|   let id = `checkbox-input-${Math.round(Math.random()*100000000)}` |   let id = `checkbox-input-${Math.round(Math.random()*100000000)}` | ||||||
|   $: selected.set(_c) |   $: selected.set(_c) | ||||||
|  |   selected.addCallbackD(s => { | ||||||
|  |       _c = s | ||||||
|  |   }) | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <label class="no-image-background flex items-center gap-1"> | <label class="no-image-background flex items-center gap-1"> | ||||||
|  |  | ||||||
|  | @ -12,6 +12,38 @@ | ||||||
| 
 | 
 | ||||||
|     export let state: ThemeViewState |     export let state: ThemeViewState | ||||||
|     let layout = state.layout |     let layout = state.layout | ||||||
|  |      | ||||||
|  |     let allEnabled : boolean | ||||||
|  |     let allDisabled: boolean | ||||||
|  |      | ||||||
|  |     function updateEnableState(){ | ||||||
|  |         allEnabled = true | ||||||
|  |         allDisabled = true | ||||||
|  |         state.layerState.filteredLayers.forEach((v) => { | ||||||
|  |             if(!v.layerDef.name){ | ||||||
|  |                 return | ||||||
|  |             } | ||||||
|  |             allEnabled &&= v.isDisplayed.data | ||||||
|  |             allDisabled &&= !v.isDisplayed.data | ||||||
|  |         }) | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     updateEnableState() | ||||||
|  |     state.layerState.filteredLayers.forEach((v) => { | ||||||
|  |         if(!v.layerDef.name){ | ||||||
|  |             return | ||||||
|  |         } | ||||||
|  |        v.isDisplayed.addCallbackD(_ => updateEnableState()) | ||||||
|  |     }) | ||||||
|  |     function enableAll(doEnable: boolean){ | ||||||
|  |         state.layerState.filteredLayers.forEach((v) => { | ||||||
|  |             if(!v.layerDef.name){ | ||||||
|  |                 return | ||||||
|  |             } | ||||||
|  |             v.isDisplayed.setData(doEnable) | ||||||
|  |         }) | ||||||
|  |     } | ||||||
|  |      | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <div class="m-2 flex flex-col"> | <div class="m-2 flex flex-col"> | ||||||
|  | @ -27,6 +59,15 @@ | ||||||
|       highlightedLayer={state.guistate.highlightedLayerInFilters} |       highlightedLayer={state.guistate.highlightedLayerInFilters} | ||||||
|     /> |     /> | ||||||
|   {/each} |   {/each} | ||||||
|  |   <div class="flex self-end mt-1"> | ||||||
|  |     <button class="small" class:disabled={allEnabled} on:click={() => enableAll(true)}> | ||||||
|  |       <Tr t={Translations.t.general.filterPanel.enableAll}/> | ||||||
|  |     </button> | ||||||
|  |     <button class="small"  class:disabled={allDisabled} on:click={() => enableAll(false)}> | ||||||
|  |       <Tr t={Translations.t.general.filterPanel.disableAll}/> | ||||||
|  |     </button> | ||||||
|  |   </div> | ||||||
|  | 
 | ||||||
|   {#each layout.tileLayerSources as tilesource} |   {#each layout.tileLayerSources as tilesource} | ||||||
|     <OverlayToggle |     <OverlayToggle | ||||||
|       layerproperties={tilesource} |       layerproperties={tilesource} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue