forked from MapComplete/MapComplete
		
	The OsmFeature source now filters features based on the layers in the layout. Fixes #500
This commit is contained in:
		
							parent
							
								
									7ec0fec575
								
							
						
					
					
						commit
						5e36ae48c1
					
				
					 2 changed files with 18 additions and 1 deletions
				
			
		|  | @ -8,6 +8,9 @@ import {FeatureSourceForLayer, Tiled} from "../FeatureSource"; | ||||||
| import {Tiles} from "../../../Models/TileRange"; | import {Tiles} from "../../../Models/TileRange"; | ||||||
| import {BBox} from "../../BBox"; | import {BBox} from "../../BBox"; | ||||||
| import {OsmConnection} from "../../Osm/OsmConnection"; | import {OsmConnection} from "../../Osm/OsmConnection"; | ||||||
|  | import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig"; | ||||||
|  | import {Or} from "../../Tags/Or"; | ||||||
|  | import {TagsFilter} from "../../Tags/TagsFilter"; | ||||||
| 
 | 
 | ||||||
| export default class OsmFeatureSource { | export default class OsmFeatureSource { | ||||||
|     private readonly _backend: string; |     private readonly _backend: string; | ||||||
|  | @ -26,6 +29,7 @@ export default class OsmFeatureSource { | ||||||
|         markTileVisited?: (tileId: number) => void |         markTileVisited?: (tileId: number) => void | ||||||
|     }; |     }; | ||||||
|     private readonly downloadedTiles = new Set<number>() |     private readonly downloadedTiles = new Set<number>() | ||||||
|  |     private readonly allowedTags: TagsFilter; | ||||||
| 
 | 
 | ||||||
|     constructor(options: { |     constructor(options: { | ||||||
|         handleTile: (tile: FeatureSourceForLayer & Tiled) => void; |         handleTile: (tile: FeatureSourceForLayer & Tiled) => void; | ||||||
|  | @ -34,6 +38,7 @@ export default class OsmFeatureSource { | ||||||
|         state: { |         state: { | ||||||
|             readonly filteredLayers: UIEventSource<FilteredLayer[]>; |             readonly filteredLayers: UIEventSource<FilteredLayer[]>; | ||||||
|             readonly osmConnection: OsmConnection; |             readonly osmConnection: OsmConnection; | ||||||
|  |             readonly layoutToUse: LayoutConfig | ||||||
|         }, |         }, | ||||||
|         markTileVisited?: (tileId: number) => void |         markTileVisited?: (tileId: number) => void | ||||||
|     }) { |     }) { | ||||||
|  | @ -64,6 +69,12 @@ export default class OsmFeatureSource { | ||||||
|             } |             } | ||||||
|             self.isRunning.setData(false) |             self.isRunning.setData(false) | ||||||
|         }) |         }) | ||||||
|  |          | ||||||
|  |          | ||||||
|  |         const neededLayers = options.state.layoutToUse.layers | ||||||
|  |             .filter(            layer => !layer.doNotDownload        ) | ||||||
|  |             .filter(layer => layer.source.geojsonSource === undefined || layer.source.isOsmCacheLayer) | ||||||
|  |         this.allowedTags = new Or(neededLayers.map(l => l.source.osmTags)) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private async LoadTile(z, x, y): Promise<void> { |     private async LoadTile(z, x, y): Promise<void> { | ||||||
|  | @ -85,6 +96,12 @@ export default class OsmFeatureSource { | ||||||
|                     { |                     { | ||||||
|                         flatProperties: true |                         flatProperties: true | ||||||
|                     }); |                     }); | ||||||
|  |                  | ||||||
|  |                 // The geojson contains _all_ features at the given location
 | ||||||
|  |                 // We only keep what is needed
 | ||||||
|  |                  | ||||||
|  |                 geojson.features = geojson.features.filter(feature => this.allowedTags.matchesProperties(feature.properties)) | ||||||
|  |                  | ||||||
|                 console.log("Tile geojson:", z, x, y, "is", geojson) |                 console.log("Tile geojson:", z, x, y, "is", geojson) | ||||||
|                 const index =  Tiles.tile_index(z, x, y); |                 const index =  Tiles.tile_index(z, x, y); | ||||||
|                 new PerLayerFeatureSourceSplitter(this.filteredLayers, |                 new PerLayerFeatureSourceSplitter(this.filteredLayers, | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import {Utils} from "../Utils"; | ||||||
| 
 | 
 | ||||||
| export default class Constants { | export default class Constants { | ||||||
| 
 | 
 | ||||||
|     public static vNumber = "0.10.1"; |     public static vNumber = "0.10.2"; | ||||||
|     public static ImgurApiKey = '7070e7167f0a25a' |     public static ImgurApiKey = '7070e7167f0a25a' | ||||||
|     public static readonly mapillary_client_token_v3 = 'TXhLaWthQ1d4RUg0czVxaTVoRjFJZzowNDczNjUzNmIyNTQyYzI2' |     public static readonly mapillary_client_token_v3 = 'TXhLaWthQ1d4RUg0czVxaTVoRjFJZzowNDczNjUzNmIyNTQyYzI2' | ||||||
|     public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85" |     public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue