forked from MapComplete/MapComplete
		
	Fixes to caching
This commit is contained in:
		
							parent
							
								
									2bcc573f2a
								
							
						
					
					
						commit
						8bdabe5d73
					
				
					 2 changed files with 31 additions and 13 deletions
				
			
		|  | @ -21,7 +21,9 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource { | |||
|             throw "Invalid layer: geojsonSource expected" | ||||
|         } | ||||
|          | ||||
|         const whitelistUrl = source.geojsonSource.replace("{z}_{x}_{y}.geojson", "overview.json") | ||||
|         const whitelistUrl = source.geojsonSource | ||||
|             .replace("{z}", ""+source.geojsonZoomLevel) | ||||
|             .replace("{x}_{y}.geojson", "overview.json") | ||||
|             .replace("{layer}",layer.layerDef.id) | ||||
|          | ||||
|         let whitelist = undefined | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ import FeatureSource, {FeatureSourceForLayer} from "../Logic/FeatureSource/Featu | |||
| import StaticFeatureSource from "../Logic/FeatureSource/Sources/StaticFeatureSource"; | ||||
| import TiledFeatureSource from "../Logic/FeatureSource/TiledFeatureSource/TiledFeatureSource"; | ||||
| import Constants from "../Models/Constants"; | ||||
| import {GeoOperations} from "../Logic/GeoOperations"; | ||||
| 
 | ||||
| 
 | ||||
| ScriptUtils.fixUtils() | ||||
|  | @ -170,11 +171,11 @@ function loadAllTiles(targetdir: string, r: TileRange, theme: LayoutConfig, extr | |||
| /** | ||||
|  * Load all the tiles into memory from disk | ||||
|  */ | ||||
| function postProcess(allFeatures: FeatureSource, theme: LayoutConfig, relationsTracker: RelationsTracker, targetdir: string) { | ||||
| 
 | ||||
| 
 | ||||
| function sliceToTiles(allFeatures: FeatureSource, theme: LayoutConfig, relationsTracker: RelationsTracker, targetdir: string, pointsOnlyLayers: string[]) { | ||||
|     function handleLayer(source: FeatureSourceForLayer) { | ||||
|         const layer = source.layer.layerDef; | ||||
|         const targetZoomLevel = layer.source.geojsonZoomLevel ?? 0 | ||||
|          | ||||
|         const layerId = layer.id | ||||
|         if (layer.source.isOsmCacheLayer !== true) { | ||||
|             return; | ||||
|  | @ -200,13 +201,10 @@ function postProcess(allFeatures: FeatureSource, theme: LayoutConfig, relationsT | |||
|         // At this point, we have all the features of the entire area.
 | ||||
|         // However, we want to export them per tile of a fixed size, so we use a dynamicTileSOurce to split it up
 | ||||
|         TiledFeatureSource.createHierarchy(source, { | ||||
|             minZoomLevel: 14, | ||||
|             maxZoomLevel: 14, | ||||
|             minZoomLevel: targetZoomLevel, | ||||
|             maxZoomLevel: targetZoomLevel, | ||||
|             maxFeatureCount: undefined, | ||||
|             registerTile: tile => { | ||||
|                 if (tile.z < 12) { | ||||
|                     return; | ||||
|                 } | ||||
|                 if (tile.features.data.length === 0) { | ||||
|                     return | ||||
|                 } | ||||
|  | @ -229,7 +227,7 @@ function postProcess(allFeatures: FeatureSource, theme: LayoutConfig, relationsT | |||
| 
 | ||||
|         // All the tiles are written at this point
 | ||||
|         // Only thing left to do is to create the index
 | ||||
|         const path = targetdir + "_" + layerId + "_overview.json" | ||||
|         const path = targetdir + "_" + layerId + "_" + targetZoomLevel + "_overview.json" | ||||
|         const perX = {} | ||||
|         createdTiles.map(i => Tiles.tile_from_index(i)).forEach(([z, x, y]) => { | ||||
|             const key = "" + x | ||||
|  | @ -240,7 +238,18 @@ function postProcess(allFeatures: FeatureSource, theme: LayoutConfig, relationsT | |||
|         }) | ||||
|         writeFileSync(path, JSON.stringify(perX)) | ||||
| 
 | ||||
| 
 | ||||
|         // And, if needed, to create a points-only layer
 | ||||
|         if(pointsOnlyLayers.indexOf(layer.id) >= 0){ | ||||
|             const features = source.features.data.map(f => f.feature) | ||||
|             const points = features.map(feature => GeoOperations.centerpoint(feature)) | ||||
|             console.log("Writing points overview for ", layerId) | ||||
|             const targetPath = targetdir+"_"+layerId+"_points.geojson" | ||||
|             // This is the geojson file containing all features for this tile
 | ||||
|             writeFileSync(targetPath, JSON.stringify({ | ||||
|                 type: "FeatureCollection", | ||||
|                 features: points | ||||
|             }, null, " ")) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     new PerLayerFeatureSourceSplitter( | ||||
|  | @ -255,10 +264,11 @@ function postProcess(allFeatures: FeatureSource, theme: LayoutConfig, relationsT | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| async function main(args: string[]) { | ||||
| 
 | ||||
|     if (args.length == 0) { | ||||
|         console.error("Expected arguments are: theme zoomlevel targetdirectory lat0 lon0 lat1 lon1 [--generate-point-overview layer-name]") | ||||
|         console.error("Expected arguments are: theme zoomlevel targetdirectory lat0 lon0 lat1 lon1 [--generate-point-overview layer-name,layer-name,...]") | ||||
|         return; | ||||
|     } | ||||
|     const themeName = args[0] | ||||
|  | @ -269,6 +279,12 @@ async function main(args: string[]) { | |||
|     const lat1 = Number(args[5]) | ||||
|     const lon1 = Number(args[6]) | ||||
|      | ||||
|     let generatePointLayersFor = [] | ||||
|     if(args[7] == "--generate-point-overview"){ | ||||
|         generatePointLayersFor = args[8].split(",") | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     const tileRange = Tiles.TileRangeBetween(zoomlevel, lat0, lon0, lat1, lon1) | ||||
| 
 | ||||
|     const theme = AllKnownLayouts.allKnownLayouts.get(themeName) | ||||
|  | @ -293,7 +309,7 @@ async function main(args: string[]) { | |||
| 
 | ||||
|     const extraFeatures = await downloadExtraData(theme); | ||||
|     const allFeaturesSource = loadAllTiles(targetdir, tileRange, theme, extraFeatures) | ||||
|     postProcess(allFeaturesSource, theme, relationTracker, targetdir) | ||||
|     sliceToTiles(allFeaturesSource, theme, relationTracker, targetdir, generatePointLayersFor) | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue