forked from MapComplete/MapComplete
		
	Quickfix for loading external themes
This commit is contained in:
		
							parent
							
								
									e404e48f29
								
							
						
					
					
						commit
						848a05a21f
					
				
					 3 changed files with 34 additions and 36 deletions
				
			
		|  | @ -156,17 +156,8 @@ export default class DetermineLayout { | |||
|         try { | ||||
| 
 | ||||
|             let parsed = await Utils.downloadJson(link) | ||||
|             console.log("Got ", parsed) | ||||
|             parsed = new FixLegacyTheme().convertStrict({ | ||||
|                 tagRenderings: SharedTagRenderings.SharedTagRenderingJson, | ||||
|                 sharedLayers: new Map<string, LayerConfigJson>() // FIXME: actually add the layers
 | ||||
|             }, parsed, "While loading a dynamic theme") | ||||
| 
 | ||||
| 
 | ||||
|                 parsed.id = link; | ||||
| 
 | ||||
| 
 | ||||
|             try { | ||||
|                 parsed.id = link; | ||||
|                 const layoutToUse = DetermineLayout.prepCustomTheme(parsed) | ||||
|                 return new LayoutConfig(layoutToUse,false).patchImages(link, JSON.stringify(layoutToUse)); | ||||
|             } catch (e) { | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ import {Utils} from "../Utils"; | |||
| 
 | ||||
| export default class Constants { | ||||
| 
 | ||||
|     public static vNumber = "0.14.3"; | ||||
|     public static vNumber = "0.14.4"; | ||||
|     public static ImgurApiKey = '7070e7167f0a25a' | ||||
|     public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85" | ||||
| 
 | ||||
|  |  | |||
|  | @ -184,8 +184,7 @@ class AddMiniMap extends DesugaringStep<LayerConfigJson> { | |||
|     convert(state: DesugaringContext, layerConfig: LayerConfigJson, context: string): { result: LayerConfigJson; errors: string[]; warnings: string[] } { | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|         const hasMinimap = layerConfig.tagRenderings?.some(tr => AddMiniMap.hasMinimap(<TagRenderingConfigJson> tr)) ?? true | ||||
|         const hasMinimap = layerConfig.tagRenderings?.some(tr => AddMiniMap.hasMinimap(<TagRenderingConfigJson>tr)) ?? true | ||||
|         if (!hasMinimap) { | ||||
|             layerConfig = {...layerConfig} | ||||
|             layerConfig.tagRenderings = [...layerConfig.tagRenderings] | ||||
|  | @ -193,7 +192,7 @@ class AddMiniMap extends DesugaringStep<LayerConfigJson> { | |||
|         } | ||||
| 
 | ||||
|         return { | ||||
|             errors:[], | ||||
|             errors: [], | ||||
|             warnings: [], | ||||
|             result: layerConfig | ||||
|         }; | ||||
|  | @ -448,9 +447,13 @@ export class UpdateLegacyLayer extends DesugaringStep<LayerConfigJson | string | | |||
|         if (typeof json === "string") { | ||||
|             return json | ||||
|         } | ||||
|         console.log("Updating legacy layer", json) | ||||
|         if (json["builtin"] !== undefined) { | ||||
|             // @ts-ignore
 | ||||
|             return json; | ||||
|             return { | ||||
|                 result: json, | ||||
|                 errors: [], | ||||
|                 warnings: [] | ||||
|             }; | ||||
|         } | ||||
|         let config: any = {...json}; | ||||
| 
 | ||||
|  | @ -572,6 +575,9 @@ class UpdateLegacyTheme extends DesugaringStep<LayoutConfigJson> { | |||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         oldThemeConfig.layers = Utils.NoNull(oldThemeConfig.layers) | ||||
| 
 | ||||
|         return { | ||||
|             errors: [], | ||||
|             warnings: [], | ||||
|  | @ -874,7 +880,7 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> { | |||
|         const knownTagRenderings: Map<string, TagRenderingConfigJson> = state.tagRenderings; | ||||
|         const errors = []; | ||||
|         const warnings = []; | ||||
|         const layers: LayerConfigJson[] = <LayerConfigJson[]> theme.layers; // Layers should be expanded at this point
 | ||||
|         const layers: LayerConfigJson[] = <LayerConfigJson[]>theme.layers; // Layers should be expanded at this point
 | ||||
| 
 | ||||
|         knownTagRenderings.forEach((value, key) => { | ||||
|             value.id = key; | ||||
|  | @ -943,6 +949,7 @@ class SubstituteLayer extends Conversion<(string | LayerConfigJson), LayerConfig | |||
|     convert(state: DesugaringContext, json: string | LayerConfigJson, context: string): { result: LayerConfigJson[]; errors: string[]; warnings: string[] } { | ||||
|         const errors = [] | ||||
|         const warnings = [] | ||||
|         console.log("Substituting layer ", json) | ||||
|         if (typeof json === "string") { | ||||
|             const found = state.sharedLayers.get(json) | ||||
|             if (found === undefined) { | ||||
|  | @ -1011,10 +1018,10 @@ class AddDefaultLayers extends DesugaringStep<LayoutConfigJson> { | |||
|             for (const publicLayer of AllKnownLayouts.AllPublicLayers()) { | ||||
|                 const id = publicLayer.id | ||||
|                 const config = state.sharedLayers.get(id) | ||||
|                 if(Constants.added_by_default.indexOf(id) >= 0){ | ||||
|                 if (Constants.added_by_default.indexOf(id) >= 0) { | ||||
|                     continue; | ||||
|                 } | ||||
|                 if(config === undefined){ | ||||
|                 if (config === undefined) { | ||||
|                     // This is a layer which is coded within a public theme, not as separate .json
 | ||||
|                     continue | ||||
|                 } | ||||
|  | @ -1044,14 +1051,14 @@ class AddDefaultLayers extends DesugaringStep<LayoutConfigJson> { | |||
| export class ApplyOverrideAll extends DesugaringStep<LayoutConfigJson> { | ||||
| 
 | ||||
|     constructor() { | ||||
|         super("Applies 'overrideAll' onto every 'layer'. The 'overrideAll'-field is removed afterwards",["overrideAll","layers"]); | ||||
|         super("Applies 'overrideAll' onto every 'layer'. The 'overrideAll'-field is removed afterwards", ["overrideAll", "layers"]); | ||||
|     } | ||||
| 
 | ||||
|     convert(state: DesugaringContext, json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors: string[]; warnings: string[] } { | ||||
| 
 | ||||
|         const overrideAll = json.overrideAll; | ||||
|         if(overrideAll === undefined){ | ||||
|             return {result :json, warnings: [], errors: []} | ||||
|         if (overrideAll === undefined) { | ||||
|             return {result: json, warnings: [], errors: []} | ||||
|         } | ||||
| 
 | ||||
|         json = {...json} | ||||
|  | @ -1060,13 +1067,13 @@ export class ApplyOverrideAll extends DesugaringStep<LayoutConfigJson> { | |||
|         const newLayers = [] | ||||
|         for (let layer of json.layers) { | ||||
|             layer = {...<LayerConfigJson>layer} | ||||
|             Utils.Merge(overrideAll,  layer) | ||||
|             Utils.Merge(overrideAll, layer) | ||||
|             newLayers.push(layer) | ||||
|         } | ||||
|         json.layers = newLayers | ||||
| 
 | ||||
| 
 | ||||
|         return {result :json, warnings: [], errors: []}; | ||||
|         return {result: json, warnings: [], errors: []}; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue