forked from MapComplete/MapComplete
		
	Some fixes in the rewrite of the maprendering
This commit is contained in:
		
							parent
							
								
									9f3a23843c
								
							
						
					
					
						commit
						67c8d08f3e
					
				
					 9 changed files with 117 additions and 19 deletions
				
			
		|  | @ -2,7 +2,7 @@ import {Utils} from "../Utils"; | |||
| 
 | ||||
| export default class Constants { | ||||
| 
 | ||||
|     public static vNumber = "0.16.4"; | ||||
|     public static vNumber = "0.17.0-alpha"; | ||||
|      | ||||
|     public static ImgurApiKey = '7070e7167f0a25a' | ||||
|     public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85" | ||||
|  |  | |||
|  | @ -113,7 +113,9 @@ export class OnEveryConcat<X, T> extends DesugaringStep<T> { | |||
|         } | ||||
|         const r = step.convertAll((<X[]>values), context + "." + key) | ||||
|         const vals: X[][] = r.result | ||||
|          | ||||
|         json[key] = [].concat(...vals) | ||||
|          | ||||
|         return { | ||||
|             ...r, | ||||
|             result: json, | ||||
|  |  | |||
|  | @ -279,25 +279,27 @@ class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[]> { | |||
|     * Every 'keyToRewrite' will be replaced with 'target' recursively. This substitution will happen in place in the object 'tr' */ | ||||
|     public static RewriteParts<T>(keyToRewrite: string, target: string | any, tr: T): T { | ||||
| 
 | ||||
|         const isTranslation = typeof target !== "string" | ||||
| 
 | ||||
|         function replaceRecursive(transl: string | any) { | ||||
|              | ||||
|             if(transl === keyToRewrite){ | ||||
|                 return target | ||||
|             } | ||||
|              | ||||
|             if (typeof transl === "string") { | ||||
|                 // This is a simple string - we do a simple replace
 | ||||
|                 return transl.replace(keyToRewrite, target) | ||||
|             } | ||||
|             if (transl.map !== undefined) { | ||||
|             if (Array.isArray(transl)) { | ||||
|                 // This is a list of items
 | ||||
|                 return transl.map(o => replaceRecursive(o)) | ||||
|             } | ||||
| 
 | ||||
|             if (Translations.isProbablyATranslation(transl) && isTranslation) { | ||||
|                 return Translations.T(transl).Fuse(new Translation(target), keyToRewrite).translations | ||||
|             } | ||||
| 
 | ||||
|             transl = {...transl} | ||||
|             for (const key in transl) { | ||||
|                 transl[key] = replaceRecursive(transl[key]) | ||||
|             if(typeof transl === "object"){ | ||||
|                 transl = {...transl} | ||||
|                 for (const key in transl) { | ||||
|                     transl[key] = replaceRecursive(transl[key]) | ||||
|                 } | ||||
|                 return transl | ||||
|             } | ||||
|             return transl | ||||
|         } | ||||
|  | @ -318,10 +320,19 @@ class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[]> { | |||
|         } | ||||
| 
 | ||||
|         const rewrite = <RewritableConfigJson<T>>json; | ||||
|         let toRewrite: T = rewrite.renderings | ||||
|         const keysToRewrite = rewrite.rewrite | ||||
|         const keysToRewrite  = rewrite.rewrite | ||||
|         const ts : T[] = [] | ||||
| 
 | ||||
|         for (let i = 0; i < keysToRewrite.sourceString.length; i++){ | ||||
|             const guard = keysToRewrite.sourceString[i]; | ||||
|             for (let j = i + 1; j < keysToRewrite.sourceString.length; j++) { | ||||
|                 const toRewrite = keysToRewrite.sourceString[j] | ||||
|                 if(toRewrite.indexOf(guard) >= 0){ | ||||
|                     throw `${context} Error in rewrite: sourcestring[${i}] is a substring of sourcestring[${j}]: ${guard} will be substituted away before ${toRewrite} is reached.` | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         for (let i = 0; i < keysToRewrite.into[0].length; i++){ | ||||
|             let t = Utils.Clone(rewrite.renderings) | ||||
|             for (let i1 = 0; i1 < keysToRewrite.sourceString.length; i1++){ | ||||
|  | @ -338,6 +349,22 @@ class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[]> { | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| class ExpandRewriteWithFlatten<T> extends Conversion<T | RewritableConfigJson<T | T[]>, T[]> { | ||||
| 
 | ||||
|     private _rewrite = new ExpandRewrite<T>() | ||||
| 
 | ||||
|     constructor() { | ||||
|         super("Applies a rewrite, the result is flattened if it is an array", [], "ExpandRewriteWithFlatten"); | ||||
|     } | ||||
| 
 | ||||
|     convert(json: RewritableConfigJson<T[] | T> | T, context: string): { result: T[]; errors?: string[]; warnings?: string[]; information?: string[] } { | ||||
|         return undefined; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| export class PrepareLayer extends Fuse<LayerConfigJson> { | ||||
|     constructor(state: DesugaringContext) { | ||||
|         super( | ||||
|  |  | |||
|  | @ -179,7 +179,7 @@ export interface LayerConfigJson { | |||
|     /** | ||||
|      * Visualisation of the items on the map | ||||
|      */ | ||||
|     mapRendering: null | (PointRenderingConfigJson | LineRenderingConfigJson | RewritableConfigJson<LineRenderingConfigJson | PointRenderingConfigJson>)[] | ||||
|     mapRendering: null | (PointRenderingConfigJson | LineRenderingConfigJson | RewritableConfigJson<LineRenderingConfigJson | PointRenderingConfigJson | LineRenderingConfigJson[] | PointRenderingConfigJson[]>)[] | ||||
| 
 | ||||
|     /** | ||||
|      * If set, this layer will pass all the features it receives onto the next layer. | ||||
|  |  | |||
|  | @ -11,6 +11,7 @@ export class Translation extends BaseUIElement { | |||
|     constructor(translations: object, context?: string) { | ||||
|         super() | ||||
|         if (translations === undefined) { | ||||
|             console.error("Translation without content at "+context) | ||||
|             throw `Translation without content (${context})` | ||||
|         } | ||||
|         if (typeof translations === "string") { | ||||
|  | @ -29,7 +30,8 @@ export class Translation extends BaseUIElement { | |||
|         } | ||||
|         this.translations = translations; | ||||
|         if (count === 0) { | ||||
|             throw `No translations given in the object (${context})` | ||||
|             console.error("Constructing a translation, but the object containing translations is empty "+context) | ||||
|             throw `Constructing a translation, but the object containing translations is empty (${context})` | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -94,7 +94,15 @@ export default class Translations { | |||
|         if(typeof transl !== "object"){ | ||||
|             return false; | ||||
|         } | ||||
|         if(Object.keys(transl).length == 0){ | ||||
|             // No translations found; not a translation
 | ||||
|             return false | ||||
|         } | ||||
|         // is a weird key found?
 | ||||
|         return !Object.keys(transl).some(key => !this.knownLanguages.has(key)) | ||||
|         if(Object.keys(transl).some(key => !this.knownLanguages.has(key))){ | ||||
|             return false | ||||
|         } | ||||
|          | ||||
|         return true; | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -157,7 +157,6 @@ | |||
|         "hu": "Anyag: {material}", | ||||
|         "it": "Materiale: {material}", | ||||
|         "ru": "Материал: {material}", | ||||
|         "zh_Hanå¨s": "材质: {material}", | ||||
|         "zh_Hant": "材質:{material}", | ||||
|         "nb_NO": "Materiale: {material}", | ||||
|         "fi": "Materiaali: {material}", | ||||
|  |  | |||
|  | @ -879,6 +879,17 @@ | |||
|                         "question": "What kind of building is this?" | ||||
|                     } | ||||
|                 } | ||||
|             }, | ||||
|             "6": { | ||||
|                 "tagRenderings": { | ||||
|                     "Import-button": { | ||||
|                         "mappings": { | ||||
|                             "0": { | ||||
|                                 "then": "Did not yet calculate the metatags... Reopen this popup" | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     }, | ||||
|  |  | |||
|  | @ -581,7 +581,7 @@ export default class LegacyThemeLoaderSpec extends T { | |||
|                                     {"if": "parking:condition:left=disc", | ||||
|                                         "then": "#219991"}] | ||||
|                             },  | ||||
|                             "offset":   "-6" | ||||
|                             "offset":   -6 | ||||
|                         }, { | ||||
|                             "color": { | ||||
|                                 "render": "#888", | ||||
|  | @ -592,7 +592,7 @@ export default class LegacyThemeLoaderSpec extends T { | |||
|                                     {"if": "parking:condition:right=disc", | ||||
|                                         "then": "#219991"}] | ||||
|                             },  | ||||
|                             "offset": "6" | ||||
|                             "offset": 6 | ||||
|                         }], | ||||
|                         "titleIcons": [{"render": "defaults", "id": "defaults"}] | ||||
|                     } | ||||
|  | @ -601,7 +601,56 @@ export default class LegacyThemeLoaderSpec extends T { | |||
|                    Assert.equal(JSON.stringify(result), JSON.stringify(expected)) | ||||
|                 } | ||||
| 
 | ||||
|                 ], | ||||
|             ["Advanced rewriting of the mapRendering",() => { | ||||
|                 const source = {"mapRendering": [ | ||||
|                     { | ||||
|                         "rewrite": { | ||||
|                             "sourceString": ["left|right", "lr_offset"], | ||||
|                             "into": [ | ||||
|                                 ["left", "right"], | ||||
|                                 [-6, 6] | ||||
|                             ] | ||||
|                         }, | ||||
|                         "renderings": [ | ||||
|                             { | ||||
|                                 "color": { | ||||
|                                     "render": "#888", | ||||
|                                     "mappings": [ | ||||
|                                         { | ||||
|                                             "if": "parking:condition:left|right=free", | ||||
|                                             "then": "#299921" | ||||
|                                         }, | ||||
|                                         { | ||||
|                                             "if": "parking:condition:left|right=ticket", | ||||
|                                             "then": "#219991" | ||||
|                                         } | ||||
|                                     ] | ||||
|                                 }, | ||||
|                                 "width": { | ||||
|                                     "render": 6, | ||||
|                                     "mappings": [ | ||||
|                                         { | ||||
|                                             "if": { | ||||
|                                                 "or": [ | ||||
|                                                     "parking:lane:left|right=no", | ||||
|                                                     "parking:lane:left|right=separate" | ||||
|                                                 ] | ||||
|                                             }, | ||||
|                                             "then": 0 | ||||
|                                         } | ||||
|                                     ] | ||||
|                                 }, | ||||
|                                 "offset": "lr_offset", | ||||
|                                 "lineCap": "butt" | ||||
|                             } | ||||
|                         ] | ||||
|                     } | ||||
|                 ] | ||||
|             }} | ||||
|              | ||||
|              | ||||
|             ] | ||||
|             ] | ||||
|         ); | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue