forked from MapComplete/MapComplete
		
	Add toggle to disable squares on low zoom levels, fix maxzoom property
This commit is contained in:
		
							parent
							
								
									6330bd5bfd
								
							
						
					
					
						commit
						9e7dec0101
					
				
					 5 changed files with 43 additions and 24 deletions
				
			
		| 
						 | 
					@ -426,10 +426,10 @@ export class InitUiElements {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const clustering = State.state.layoutToUse.clustering
 | 
				
			||||||
        const clusterCounter = TileHierarchyAggregator.createHierarchy()
 | 
					        const clusterCounter = TileHierarchyAggregator.createHierarchy()
 | 
				
			||||||
        new ShowDataLayer({
 | 
					        new ShowDataLayer({
 | 
				
			||||||
            features: clusterCounter.getCountsForZoom(State.state.locationControl, State.state.layoutToUse.clustering.minNeededElements),
 | 
					            features: clusterCounter.getCountsForZoom(clustering, State.state.locationControl, State.state.layoutToUse.clustering.minNeededElements),
 | 
				
			||||||
            leafletMap: State.state.leafletMap,
 | 
					            leafletMap: State.state.leafletMap,
 | 
				
			||||||
            layerToShow: ShowTileInfo.styling,
 | 
					            layerToShow: ShowTileInfo.styling,
 | 
				
			||||||
            enablePopups: false
 | 
					            enablePopups: false
 | 
				
			||||||
| 
						 | 
					@ -440,7 +440,7 @@ export class InitUiElements {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                clusterCounter.addTile(source)
 | 
					                clusterCounter.addTile(source)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                const clustering = State.state.layoutToUse.clustering
 | 
					                // Do show features indicates if the 'showDataLayer' should be shown
 | 
				
			||||||
                const doShowFeatures = source.features.map(
 | 
					                const doShowFeatures = source.features.map(
 | 
				
			||||||
                    f => {
 | 
					                    f => {
 | 
				
			||||||
                        const z = State.state.locationControl.data.zoom
 | 
					                        const z = State.state.locationControl.data.zoom
 | 
				
			||||||
| 
						 | 
					@ -449,6 +449,18 @@ export class InitUiElements {
 | 
				
			||||||
                            return false;
 | 
					                            return false;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        const bounds = State.state.currentBounds.data
 | 
				
			||||||
 | 
					                        if(bounds === undefined){
 | 
				
			||||||
 | 
					                            // Map is not yet displayed
 | 
				
			||||||
 | 
					                            return false;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        if (!source.bbox.overlapsWith(bounds)) {
 | 
				
			||||||
 | 
					                            // Not within range -> features are hidden
 | 
				
			||||||
 | 
					                            return false
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (z < source.layer.layerDef.minzoom) {
 | 
					                        if (z < source.layer.layerDef.minzoom) {
 | 
				
			||||||
                            // Layer is always hidden for this zoom level
 | 
					                            // Layer is always hidden for this zoom level
 | 
				
			||||||
                            return false;
 | 
					                            return false;
 | 
				
			||||||
| 
						 | 
					@ -473,20 +485,12 @@ export class InitUiElements {
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            if (clusterCounter.getTile(Tiles.tile_index(tileZ, tileX, tileY))?.totalValue > clustering.minNeededElements) {
 | 
					                            if (clusterCounter.getTile(Tiles.tile_index(tileZ, tileX, tileY))?.totalValue > clustering.minNeededElements) {
 | 
				
			||||||
 | 
					                                // To much elements
 | 
				
			||||||
                                return false
 | 
					                                return false
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        const bounds = State.state.currentBounds.data
 | 
					 | 
				
			||||||
                        if(bounds === undefined){
 | 
					 | 
				
			||||||
                            // Map is not yet displayed
 | 
					 | 
				
			||||||
                            return false;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        if (!source.bbox.overlapsWith(bounds)) {
 | 
					 | 
				
			||||||
                            // Not within range
 | 
					 | 
				
			||||||
                            return false
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                      
 | 
					                      
 | 
				
			||||||
                        return true
 | 
					                        return true
 | 
				
			||||||
                    }, [State.state.currentBounds, source.layer.isDisplayed]
 | 
					                    }, [State.state.currentBounds, source.layer.isDisplayed]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -237,6 +237,12 @@ export interface LayoutConfigJson {
 | 
				
			||||||
         * If clustering is defined, defaults to 25
 | 
					         * If clustering is defined, defaults to 25
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        minNeededElements?: number
 | 
					        minNeededElements?: number
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         * By default, a box is shown indicating the number of features even if the map is zoomed out beyond the minzoom of the layer.
 | 
				
			||||||
 | 
					         * This flag switches this behaviour to not show these boxes.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        hideClustersAboveMinZoom?: boolean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					@ -253,7 +259,7 @@ export interface LayoutConfigJson {
 | 
				
			||||||
     * If set to [[lat0, lon0], [lat1, lon1]], the map will not scroll outside of those bounds.
 | 
					     * If set to [[lat0, lon0], [lat1, lon1]], the map will not scroll outside of those bounds.
 | 
				
			||||||
     * Off by default, which will enable panning to the entire world
 | 
					     * Off by default, which will enable panning to the entire world
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    lockLocation?: boolean | [[number, number], [number, number]];
 | 
					    lockLocation?: boolean | [[number, number], [number, number]] | number[][];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    enableUserBadge?: boolean;
 | 
					    enableUserBadge?: boolean;
 | 
				
			||||||
    enableShareScreen?: boolean;
 | 
					    enableShareScreen?: boolean;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,8 @@ export default class LayoutConfig {
 | 
				
			||||||
    public layers: LayerConfig[];
 | 
					    public layers: LayerConfig[];
 | 
				
			||||||
    public readonly clustering?: {
 | 
					    public readonly clustering?: {
 | 
				
			||||||
        maxZoom: number,
 | 
					        maxZoom: number,
 | 
				
			||||||
        minNeededElements: number
 | 
					        minNeededElements: number,
 | 
				
			||||||
 | 
					        hideClustersAboveMinzoom: boolean
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    public readonly hideFromOverview: boolean;
 | 
					    public readonly hideFromOverview: boolean;
 | 
				
			||||||
    public lockLocation: boolean | [[number, number], [number, number]];
 | 
					    public lockLocation: boolean | [[number, number], [number, number]];
 | 
				
			||||||
| 
						 | 
					@ -139,12 +140,14 @@ export default class LayoutConfig {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.clustering = {
 | 
					        this.clustering = {
 | 
				
			||||||
            maxZoom: 16,
 | 
					            maxZoom: 16,
 | 
				
			||||||
            minNeededElements: 25
 | 
					            minNeededElements: 25,
 | 
				
			||||||
 | 
					            hideClustersAboveMinzoom: false
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        if (json.clustering) {
 | 
					        if (json.clustering) {
 | 
				
			||||||
            this.clustering = {
 | 
					            this.clustering = {
 | 
				
			||||||
                maxZoom: json.clustering.maxZoom ?? 18,
 | 
					                maxZoom: json.clustering.maxZoom ?? 18,
 | 
				
			||||||
                minNeededElements: json.clustering.minNeededElements ?? 25
 | 
					                minNeededElements: json.clustering.minNeededElements ?? 25,
 | 
				
			||||||
 | 
					                hideClustersAboveMinzoom: json.clustering.hideClustersAboveMinZoom ?? false
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -153,7 +156,7 @@ export default class LayoutConfig {
 | 
				
			||||||
        if (json.hideInOverview) {
 | 
					        if (json.hideInOverview) {
 | 
				
			||||||
            throw "The json for " + this.id + " contains a 'hideInOverview'. Did you mean hideFromOverview instead?"
 | 
					            throw "The json for " + this.id + " contains a 'hideInOverview'. Did you mean hideFromOverview instead?"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        this.lockLocation = json.lockLocation ?? undefined;
 | 
					        this.lockLocation = <[[number, number], [number, number]]> json.lockLocation ?? undefined;
 | 
				
			||||||
        this.enableUserBadge = json.enableUserBadge ?? true;
 | 
					        this.enableUserBadge = json.enableUserBadge ?? true;
 | 
				
			||||||
        this.enableShareScreen = json.enableShareScreen ?? true;
 | 
					        this.enableShareScreen = json.enableShareScreen ?? true;
 | 
				
			||||||
        this.enableMoreQuests = json.enableMoreQuests ?? true;
 | 
					        this.enableMoreQuests = json.enableMoreQuests ?? true;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -153,13 +153,18 @@ export class TileHierarchyAggregator implements FeatureSource {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    getCountsForZoom(locationControl: UIEventSource<{ zoom : number }>, cutoff: number = 0) : FeatureSource{
 | 
					    getCountsForZoom(clusteringConfig: {maxZoom: number}, locationControl: UIEventSource<{ zoom : number }>, cutoff: number = 0) : FeatureSource{
 | 
				
			||||||
        const self = this
 | 
					        const self = this
 | 
				
			||||||
        
 | 
					        const empty = []
 | 
				
			||||||
        return new StaticFeatureSource(
 | 
					        return new StaticFeatureSource(
 | 
				
			||||||
            locationControl.map(loc => {
 | 
					            locationControl.map(loc => {
 | 
				
			||||||
                const features = []
 | 
					 | 
				
			||||||
                const targetZoom = loc.zoom
 | 
					                const targetZoom = loc.zoom
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                if(targetZoom > clusteringConfig.maxZoom){
 | 
				
			||||||
 | 
					                    return empty
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                const features = []
 | 
				
			||||||
                self.visitSubTiles(aggr => {
 | 
					                self.visitSubTiles(aggr => {
 | 
				
			||||||
                    if(aggr.totalValue < cutoff) {
 | 
					                    if(aggr.totalValue < cutoff) {
 | 
				
			||||||
                        return false
 | 
					                        return false
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,7 +34,8 @@
 | 
				
			||||||
  "hideFromOverview": true,
 | 
					  "hideFromOverview": true,
 | 
				
			||||||
  "clustering": {
 | 
					  "clustering": {
 | 
				
			||||||
    "#": "Disable clustering for this theme",
 | 
					    "#": "Disable clustering for this theme",
 | 
				
			||||||
    "maxZoom": 1
 | 
					    "maxZoom": 1,
 | 
				
			||||||
 | 
					    "hideBoxesAboveMinZoom": true
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "layers": [
 | 
					  "layers": [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					@ -109,7 +110,7 @@
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
          },
 | 
					          },
 | 
				
			||||||
          "geoJson": "https://pietervdvn.github.io/natuurpunt_cache/natuurpunt_{layer}_{z}_{x}_{y}.geojson",
 | 
					          "geoJson": "https://pietervdvn.github.io/natuurpunt_cache/natuurpunt_{layer}_{z}_{x}_{y}.geojson",
 | 
				
			||||||
          "geoJsonZoomLevel": 12,
 | 
					          "geoJsonZoomLevel": 10,
 | 
				
			||||||
          "isOsmCache": true
 | 
					          "isOsmCache": true
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        "minzoom": "13",
 | 
					        "minzoom": "13",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue