forked from MapComplete/MapComplete
		
	Refactoring: split rendering of centroid to PointRendering
This commit is contained in:
		
							parent
							
								
									ad8674dd70
								
							
						
					
					
						commit
						584ade8e61
					
				
					 8 changed files with 509 additions and 440 deletions
				
			
		|  | @ -1,4 +1,3 @@ | |||
| 
 | ||||
| /* | ||||
|  * This script reads all theme and layer files and reformats them inplace | ||||
|  * Use with caution, make a commit beforehand! | ||||
|  | @ -6,29 +5,47 @@ | |||
| 
 | ||||
| 
 | ||||
| import ScriptUtils from "./ScriptUtils"; | ||||
| import {readFileSync, writeFileSync} from "fs"; | ||||
| import {tag} from "@turf/turf"; | ||||
| import {writeFileSync} from "fs"; | ||||
| import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson"; | ||||
| 
 | ||||
| /** | ||||
|  * In place fix | ||||
|  */ | ||||
| function fixLayerConfig(config: LayerConfigJson) : void{ | ||||
|     if(config.tagRenderings === undefined){ | ||||
|         return | ||||
|     } | ||||
|      | ||||
|     for (const tagRendering of config.tagRenderings) { | ||||
|         if(tagRendering["#"] !== undefined){ | ||||
|             tagRendering["id"] = tagRendering["#"] | ||||
|             delete tagRendering["#"] | ||||
|         } | ||||
|         if(tagRendering["id"] === undefined){ | ||||
|             if(tagRendering["freeform"]?.key !== undefined ) { | ||||
|                 tagRendering["id"] = config.id+"-"+tagRendering["freeform"]["key"] | ||||
| function fixLayerConfig(config: LayerConfigJson): void { | ||||
|     if (config.tagRenderings !== undefined) { | ||||
|         for (const tagRendering of config.tagRenderings) { | ||||
|             if (tagRendering["#"] !== undefined) { | ||||
|                 tagRendering["id"] = tagRendering["#"] | ||||
|                 delete tagRendering["#"] | ||||
|             } | ||||
|             if (tagRendering["id"] === undefined) { | ||||
|                 if (tagRendering["freeform"]?.key !== undefined) { | ||||
|                     tagRendering["id"] = config.id + "-" + tagRendering["freeform"]["key"] | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     if(config.mapRendering === undefined){ | ||||
|         // This is a legacy format, lets create a pointRendering
 | ||||
|         let location: ("point"|"centroid")[] = ["point"] | ||||
|         if(config.wayHandling === 2){ | ||||
|             location = ["point", "centroid"] | ||||
|         } | ||||
|         config.mapRendering = [ | ||||
|             { | ||||
|                 icon: config["icon"], | ||||
|                 iconOverlays: config["iconOverlays"], | ||||
|                 label: config["label"], | ||||
|                 iconSize: config["iconSize"], | ||||
|                 location, | ||||
|                 rotation: config["rotation"] | ||||
|             } | ||||
|         ] | ||||
|          | ||||
|          | ||||
|     } | ||||
|      | ||||
| } | ||||
| 
 | ||||
| const layerFiles = ScriptUtils.getLayerFiles(); | ||||
|  | @ -40,7 +57,7 @@ for (const layerFile of layerFiles) { | |||
| const themeFiles = ScriptUtils.getThemeFiles() | ||||
| for (const themeFile of themeFiles) { | ||||
|     for (const layerConfig of themeFile.parsed.layers ?? []) { | ||||
|         if(typeof layerConfig === "string" || layerConfig["builtin"]!== undefined){ | ||||
|         if (typeof layerConfig === "string" || layerConfig["builtin"] !== undefined) { | ||||
|             continue | ||||
|         } | ||||
|         // @ts-ignore
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue