| 
									
										
										
										
											2021-12-12 17:15:31 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Generates an overview for which tiles exist and which don't | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import ScriptUtils from "./ScriptUtils" | 
					
						
							|  |  |  | import { writeFileSync } from "fs" | 
					
						
							| 
									
										
										
										
											2021-12-12 17:15:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | function main(args: string[]) { | 
					
						
							|  |  |  |     const directory = args[0] | 
					
						
							|  |  |  |     let zoomLevel = args[1] | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     const files = ScriptUtils.readDirRecSync(directory, 1).filter((f) => f.endsWith(".geojson")) | 
					
						
							| 
									
										
										
										
											2021-12-12 17:15:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const indices /* Map<string, number[]>*/ = {} | 
					
						
							|  |  |  |     for (const path of files) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const match = path.match(".*_([0-9]*)_([0-9]*)_([0-9]*).geojson") | 
					
						
							| 
									
										
										
										
											2021-12-12 17:15:31 +01:00
										 |  |  |         if (match === null) { | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         const z = match[1] | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  |         if (zoomLevel === undefined) { | 
					
						
							| 
									
										
										
										
											2021-12-12 17:15:31 +01:00
										 |  |  |             zoomLevel = z | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  |         } else if (zoomLevel !== z) { | 
					
						
							| 
									
										
										
										
											2021-12-12 17:15:31 +01:00
										 |  |  |             throw "Mixed zoomlevels detected" | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-12 17:15:31 +01:00
										 |  |  |         const x = match[2] | 
					
						
							|  |  |  |         const y = match[3] | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  |         if (indices[x] === undefined) { | 
					
						
							| 
									
										
										
										
											2021-12-12 17:15:31 +01:00
										 |  |  |             indices[x] = [] | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-12-13 02:05:34 +01:00
										 |  |  |         indices[x].push(Number(y)) | 
					
						
							| 
									
										
										
										
											2021-12-12 17:15:31 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     indices["zoom"] = zoomLevel | 
					
						
							|  |  |  |     const match = files[0].match("(.*)_([0-9]*)_([0-9]*)_([0-9]*).geojson") | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  |     const path = match[1] + "_" + zoomLevel + "_overview.json" | 
					
						
							|  |  |  |     writeFileSync(path, JSON.stringify(indices)) | 
					
						
							| 
									
										
										
										
											2021-12-12 17:15:31 +01:00
										 |  |  |     console.log("Written overview for", files.length, " tiles at", path) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let args = [...process.argv] | 
					
						
							|  |  |  | args.splice(0, 2) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | args.forEach((file) => { | 
					
						
							| 
									
										
										
										
											2021-12-12 17:15:31 +01:00
										 |  |  |     try { | 
					
						
							|  |  |  |         main(args) | 
					
						
							|  |  |  |     } catch (e) { | 
					
						
							|  |  |  |         console.error("Could not handle file ", file, " due to ", e) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | }) |