forked from MapComplete/MapComplete
		
	Fix: show favourites in loaded layers if favourites are enabled
This commit is contained in:
		
							parent
							
								
									ca3a1acf53
								
							
						
					
					
						commit
						e65f61d296
					
				
					 3 changed files with 50 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -36,7 +36,7 @@ export default class FilteredLayer {
 | 
			
		|||
    constructor(
 | 
			
		||||
        layer: LayerConfig,
 | 
			
		||||
        appliedFilters?: ReadonlyMap<string, UIEventSource<undefined | number | string>>,
 | 
			
		||||
        isDisplayed?: UIEventSource<boolean>
 | 
			
		||||
        isDisplayed?: UIEventSource<boolean>,
 | 
			
		||||
    ) {
 | 
			
		||||
        this.layerDef = layer
 | 
			
		||||
        this.isDisplayed = isDisplayed ?? new UIEventSource(true)
 | 
			
		||||
| 
						 | 
				
			
			@ -82,25 +82,25 @@ export default class FilteredLayer {
 | 
			
		|||
        layer: LayerConfig,
 | 
			
		||||
        context: string,
 | 
			
		||||
        osmConnection: OsmConnection,
 | 
			
		||||
        enabledByDefault?: Store<boolean>
 | 
			
		||||
        enabledByDefault?: Store<boolean>,
 | 
			
		||||
    ) {
 | 
			
		||||
        let isDisplayed: UIEventSource<boolean>
 | 
			
		||||
        if (layer.syncSelection === "local") {
 | 
			
		||||
            isDisplayed = LocalStorageSource.getParsed(
 | 
			
		||||
                context + "-layer-" + layer.id + "-enabled",
 | 
			
		||||
                layer.shownByDefault
 | 
			
		||||
                layer.shownByDefault,
 | 
			
		||||
            )
 | 
			
		||||
        } else if (layer.syncSelection === "theme-only") {
 | 
			
		||||
            isDisplayed = FilteredLayer.getPref(
 | 
			
		||||
                osmConnection,
 | 
			
		||||
                context + "-layer-" + layer.id + "-enabled",
 | 
			
		||||
                layer
 | 
			
		||||
                layer,
 | 
			
		||||
            )
 | 
			
		||||
        } else if (layer.syncSelection === "global") {
 | 
			
		||||
            isDisplayed = FilteredLayer.getPref(
 | 
			
		||||
                osmConnection,
 | 
			
		||||
                "layer-" + layer.id + "-enabled",
 | 
			
		||||
                layer
 | 
			
		||||
                layer,
 | 
			
		||||
            )
 | 
			
		||||
        } else {
 | 
			
		||||
            let isShown = layer.shownByDefault
 | 
			
		||||
| 
						 | 
				
			
			@ -110,7 +110,7 @@ export default class FilteredLayer {
 | 
			
		|||
            isDisplayed = QueryParameters.GetBooleanQueryParameter(
 | 
			
		||||
                FilteredLayer.queryParameterKey(layer),
 | 
			
		||||
                isShown,
 | 
			
		||||
                "Whether or not layer " + layer.id + " is shown"
 | 
			
		||||
                "Whether or not layer " + layer.id + " is shown",
 | 
			
		||||
            )
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -145,7 +145,7 @@ export default class FilteredLayer {
 | 
			
		|||
     */
 | 
			
		||||
    private static fieldsToTags(
 | 
			
		||||
        option: FilterConfigOption,
 | 
			
		||||
        fieldstate: string | Record<string, string>
 | 
			
		||||
        fieldstate: string | Record<string, string>,
 | 
			
		||||
    ): TagsFilter | undefined {
 | 
			
		||||
        let properties: Record<string, string>
 | 
			
		||||
        if (typeof fieldstate === "string") {
 | 
			
		||||
| 
						 | 
				
			
			@ -181,7 +181,7 @@ export default class FilteredLayer {
 | 
			
		|||
    private static getPref(
 | 
			
		||||
        osmConnection: OsmConnection,
 | 
			
		||||
        key: string,
 | 
			
		||||
        layer: LayerConfig
 | 
			
		||||
        layer: LayerConfig,
 | 
			
		||||
    ): UIEventSource<boolean> {
 | 
			
		||||
        return osmConnection.GetPreference(key, layer.shownByDefault + "").sync(
 | 
			
		||||
            (v) => {
 | 
			
		||||
| 
						 | 
				
			
			@ -196,7 +196,7 @@ export default class FilteredLayer {
 | 
			
		|||
                    return undefined
 | 
			
		||||
                }
 | 
			
		||||
                return "" + b
 | 
			
		||||
            }
 | 
			
		||||
            },
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -216,10 +216,16 @@ export default class FilteredLayer {
 | 
			
		|||
        }
 | 
			
		||||
        for (const globalFilter of globalFilters ?? []) {
 | 
			
		||||
            const neededTags = globalFilter.osmTags
 | 
			
		||||
            if (neededTags !== undefined && !neededTags.matchesProperties(properties)) {
 | 
			
		||||
            if (neededTags !== undefined) {
 | 
			
		||||
                const doesMatch = neededTags.matchesProperties(properties)
 | 
			
		||||
                if (globalFilter.forceShowOnMatch) {
 | 
			
		||||
                    return doesMatch || this.isDisplayed.data
 | 
			
		||||
                }
 | 
			
		||||
                if (!doesMatch) {
 | 
			
		||||
                    return false
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        {
 | 
			
		||||
            const isShown: TagsFilter = this.layerDef.isShown
 | 
			
		||||
            if (isShown !== undefined && !isShown.matchesProperties(properties)) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,10 @@ import { TagsFilter } from "../Logic/Tags/TagsFilter"
 | 
			
		|||
 | 
			
		||||
export interface GlobalFilter {
 | 
			
		||||
    osmTags: TagsFilter
 | 
			
		||||
    /**
 | 
			
		||||
     * If set, this object will be shown instead of hidden, even if the layer is not displayed
 | 
			
		||||
     */
 | 
			
		||||
    forceShowOnMatch?: boolean,
 | 
			
		||||
    state: number | string | undefined
 | 
			
		||||
    id: string
 | 
			
		||||
    onNewPoint: {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -76,6 +76,7 @@ import { GeocodeResult, GeocodingUtils } from "../Logic/Search/GeocodingProvider
 | 
			
		|||
import SearchState from "../Logic/State/SearchState"
 | 
			
		||||
import { ShowDataLayerOptions } from "../UI/Map/ShowDataLayerOptions"
 | 
			
		||||
import { PanoramaxUploader } from "../Logic/ImageProviders/Panoramax"
 | 
			
		||||
import { Tag } from "../Logic/Tags/Tag"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -443,9 +444,16 @@ export default class ThemeViewState implements SpecialVisualizationState {
 | 
			
		|||
        const filteringFeatureSource = new Map<string, FilteringFeatureSource>()
 | 
			
		||||
        this.perLayer.forEach((fs, layerName) => {
 | 
			
		||||
            const doShowLayer = this.mapProperties.zoom.map(
 | 
			
		||||
                (z) =>
 | 
			
		||||
                    (fs.layer.isDisplayed?.data ?? true) && z >= (fs.layer.layerDef?.minzoom ?? 0),
 | 
			
		||||
                [fs.layer.isDisplayed]
 | 
			
		||||
                (z) => {
 | 
			
		||||
                    if ((fs.layer.isDisplayed?.data ?? true) && z >= (fs.layer.layerDef?.minzoom ?? 0)){
 | 
			
		||||
                        return true
 | 
			
		||||
                    }
 | 
			
		||||
                    if(this.layerState.globalFilters.data.some(f => f.forceShowOnMatch)){
 | 
			
		||||
                        return true
 | 
			
		||||
                    }
 | 
			
		||||
                    return false
 | 
			
		||||
                },
 | 
			
		||||
                [fs.layer.isDisplayed, this.layerState.globalFilters]
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
            if (!doShowLayer.data && this.featureSwitches.featureSwitchFilter.data === false) {
 | 
			
		||||
| 
						 | 
				
			
			@ -984,6 +992,24 @@ export default class ThemeViewState implements SpecialVisualizationState {
 | 
			
		|||
        this.userRelatedState.showScale.addCallbackAndRun((showScale) => {
 | 
			
		||||
            this.mapProperties.showScale.set(showScale)
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        this.layerState.filteredLayers.get("favourite").isDisplayed.addCallbackAndRunD(favouritesShown => {
 | 
			
		||||
            const oldGlobal = this.layerState.globalFilters.data
 | 
			
		||||
            const key = "show-favourite"
 | 
			
		||||
            if(favouritesShown){
 | 
			
		||||
                this.layerState.globalFilters.set([...oldGlobal, {
 | 
			
		||||
                    forceShowOnMatch: true,
 | 
			
		||||
                    id:key,
 | 
			
		||||
                    osmTags: new Tag("_favourite","yes"),
 | 
			
		||||
                    state: 0,
 | 
			
		||||
                    onNewPoint: undefined
 | 
			
		||||
                }])
 | 
			
		||||
            }else{
 | 
			
		||||
                this.layerState.globalFilters.set(oldGlobal.filter(gl => gl.id !== key))
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        new ThemeViewStateHashActor(this)
 | 
			
		||||
        new MetaTagging(this)
 | 
			
		||||
        new TitleHandler(this.selectedElement, this)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue