forked from MapComplete/MapComplete
		
	Fix calculated tags
This commit is contained in:
		
							parent
							
								
									a482c5b1d0
								
							
						
					
					
						commit
						0ad16cfe3f
					
				
					 3 changed files with 30 additions and 24 deletions
				
			
		|  | @ -31,11 +31,12 @@ export default class FeaturePipeline implements FeatureSource { | ||||||
|         // first we metatag, then we save to get the metatags into storage too
 |         // first we metatag, then we save to get the metatags into storage too
 | ||||||
|         // Note that we need to register before we do metatagging (as it expects the event sources)
 |         // Note that we need to register before we do metatagging (as it expects the event sources)
 | ||||||
| 
 | 
 | ||||||
|  |         // AT last, the metaTagging also needs to be run _after_ the duplicatorPerLayer
 | ||||||
|         const amendedOverpassSource = |         const amendedOverpassSource = | ||||||
|             new RememberingSource( |             new RememberingSource( | ||||||
|                 new LocalStorageSaver( |                 new LocalStorageSaver( | ||||||
|                     new FeatureDuplicatorPerLayer(flayers, |                     new MetaTaggingFeatureSource( | ||||||
|                         new MetaTaggingFeatureSource( |                         new FeatureDuplicatorPerLayer(flayers, | ||||||
|                             new RegisteringFeatureSource( |                             new RegisteringFeatureSource( | ||||||
|                                 updater) |                                 updater) | ||||||
|                         )), layout)); |                         )), layout)); | ||||||
|  | @ -48,12 +49,14 @@ export default class FeaturePipeline implements FeatureSource { | ||||||
|             new RememberingSource(new RegisteringFeatureSource(new FeatureDuplicatorPerLayer(flayers, new LocalStorageSource(layout)) |             new RememberingSource(new RegisteringFeatureSource(new FeatureDuplicatorPerLayer(flayers, new LocalStorageSource(layout)) | ||||||
|             )); |             )); | ||||||
| 
 | 
 | ||||||
|         newPoints = new MetaTaggingFeatureSource(new FeatureDuplicatorPerLayer(flayers, |         newPoints = new MetaTaggingFeatureSource( | ||||||
|             new RegisteringFeatureSource(newPoints))); |             new FeatureDuplicatorPerLayer(flayers, | ||||||
|  |                 new RegisteringFeatureSource(newPoints))); | ||||||
| 
 | 
 | ||||||
|         const amendedOsmApiSource = new RememberingSource( |         const amendedOsmApiSource = new RememberingSource( | ||||||
|             new FeatureDuplicatorPerLayer(flayers, |             new MetaTaggingFeatureSource( | ||||||
|                 new MetaTaggingFeatureSource( |                 new FeatureDuplicatorPerLayer(flayers, | ||||||
|  | 
 | ||||||
|                     new RegisteringFeatureSource(fromOsmApi)))); |                     new RegisteringFeatureSource(fromOsmApi)))); | ||||||
| 
 | 
 | ||||||
|         const merged = |         const merged = | ||||||
|  |  | ||||||
|  | @ -22,12 +22,13 @@ export default class MetaTagging { | ||||||
|      * The features are a list of geojson-features, with a "properties"-field and geometry |      * The features are a list of geojson-features, with a "properties"-field and geometry | ||||||
|      */ |      */ | ||||||
|     static addMetatags(features: { feature: any; freshness: Date }[], |     static addMetatags(features: { feature: any; freshness: Date }[], | ||||||
|                        relations: Map<string, { role: string, relation: Relation }[]>,  |                        relations: Map<string, { role: string, relation: Relation }[]>, | ||||||
|                        layers: LayerConfig[], |                        layers: LayerConfig[], | ||||||
|                        includeDates = true) { |                        includeDates = true) { | ||||||
| 
 | 
 | ||||||
|  |         console.debug("Adding meta tags to all features") | ||||||
|         for (const metatag of SimpleMetaTagger.metatags) { |         for (const metatag of SimpleMetaTagger.metatags) { | ||||||
|             if(metatag.includesDates && !includeDates){ |             if (metatag.includesDates && !includeDates) { | ||||||
|                 // We do not add dated entries
 |                 // We do not add dated entries
 | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|  | @ -62,12 +63,12 @@ export default class MetaTagging { | ||||||
|             if (f === undefined) { |             if (f === undefined) { | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|             try{ |             try { | ||||||
|                 f({featuresPerLayer: featuresPerLayer, memberships: relations}, feature.feature) |                 f({featuresPerLayer: featuresPerLayer, memberships: relations}, feature.feature) | ||||||
|             }catch(e){ |             } catch (e) { | ||||||
|                 console.error(e) |                 console.error(e) | ||||||
|             } |             } | ||||||
|             | 
 | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
|  | @ -89,19 +90,21 @@ export default class MetaTagging { | ||||||
|             } |             } | ||||||
|             const func = new Function("feat", "return " + code + ";"); |             const func = new Function("feat", "return " + code + ";"); | ||||||
| 
 | 
 | ||||||
|             try{ |             try { | ||||||
|                  | 
 | ||||||
|             | 
 | ||||||
|             const f = (featuresPerLayer, feature: any) => { |                 const f = (featuresPerLayer, feature: any) => { | ||||||
|                 try{ |                     try { | ||||||
|                     feature.properties[key] = func(feature); |                        const result = func(feature); | ||||||
|                 }catch(e){ |                        console.debug("Calculated tag with code ", code, " returned ", result) | ||||||
|                     console.error("Could not calculate a metatag defined by "+code+" due to "+e+". This is code defined in the theme. Are you the theme creator? Doublecheck your code. Note that the metatags might not be stable on new features") |                         feature.properties[key] =result; | ||||||
|  |                     } catch (e) { | ||||||
|  |                         console.error("Could not calculate a metatag defined by " + code + " due to " + e + ". This is code defined in the theme. Are you the theme creator? Doublecheck your code. Note that the metatags might not be stable on new features") | ||||||
|  |                     } | ||||||
|  | 
 | ||||||
|                 } |                 } | ||||||
|                |                 functions.push(f) | ||||||
|             } |             } catch (e) { | ||||||
|             functions.push(f) |  | ||||||
|             }catch(e){ |  | ||||||
|                 console.error("Could not create a dynamic function: ", e) |                 console.error("Could not create a dynamic function: ", e) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import { Utils } from "../Utils"; | ||||||
| 
 | 
 | ||||||
| export default class Constants { | export default class Constants { | ||||||
|      |      | ||||||
|     public static vNumber = "0.7.2"; |     public static vNumber = "0.7.2a"; | ||||||
| 
 | 
 | ||||||
|     // The user journey states thresholds when a new feature gets unlocked
 |     // The user journey states thresholds when a new feature gets unlocked
 | ||||||
|     public static userJourney = { |     public static userJourney = { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue