forked from MapComplete/MapComplete
		
	First draft of loading 'notes'
This commit is contained in:
		
							parent
							
								
									bafaba7011
								
							
						
					
					
						commit
						ebb510da04
					
				
					 20 changed files with 580 additions and 199 deletions
				
			
		|  | @ -93,7 +93,7 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled { | |||
|                     for (const key in props) { | ||||
|                         if (typeof props[key] !== "string") { | ||||
|                             // Make sure all the values are string, it crashes stuff otherwise
 | ||||
|                             props[key] = "" + props[key] | ||||
|                             props[key] = JSON.stringify(props[key]) | ||||
|                         } | ||||
|                     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -104,8 +104,8 @@ export default class MetaTagging { | |||
|         } | ||||
|         return atLeastOneFeatureChanged | ||||
|     } | ||||
|     public static createFunctionsForFeature(layerId: string, calculatedTags: [string, string, boolean][]): ((feature: any) => boolean)[] { | ||||
|         const functions: ((feature: any) => boolean)[] = []; | ||||
|     public static createFunctionsForFeature(layerId: string, calculatedTags: [string, string, boolean][]): ((feature: any) => void)[] { | ||||
|         const functions: ((feature: any) => any)[] = []; | ||||
|          | ||||
|         for (const entry of calculatedTags) { | ||||
|             const key = entry[0] | ||||
|  | @ -115,9 +115,8 @@ export default class MetaTagging { | |||
|                 continue; | ||||
|             } | ||||
| 
 | ||||
|             const calculateAndAssign: ((feat: any) => boolean) = (feat) => { | ||||
|             const calculateAndAssign: ((feat: any) => any) = (feat) => { | ||||
|                 try { | ||||
|                     let oldValue = isStrict ? feat.properties[key] : undefined | ||||
|                     let result = new Function("feat", "return " + code + ";")(feat); | ||||
|                     if (result === "") { | ||||
|                         result === undefined | ||||
|  | @ -128,7 +127,7 @@ export default class MetaTagging { | |||
|                     } | ||||
|                     delete feat.properties[key] | ||||
|                     feat.properties[key] = result; | ||||
|                     return result === oldValue; | ||||
|                     return result | ||||
|                 }catch(e){ | ||||
|                     if (MetaTagging.errorPrintCount < MetaTagging.stopErrorOutputAt) { | ||||
|                         console.warn("Could not calculate a " + (isStrict ? "strict " : "") + " calculated tag for key " + key + " defined by " + code + " (in layer" + layerId + ") due to \n" + e + "\n. Are you the theme creator? Doublecheck your code. Note that the metatags might not be stable on new features", e, e.stack) | ||||
|  | @ -137,7 +136,7 @@ export default class MetaTagging { | |||
|                             console.error("Got ", MetaTagging.stopErrorOutputAt, " errors calculating this metatagging - stopping output now") | ||||
|                         } | ||||
|                     } | ||||
|                     return false; | ||||
|                     return undefined; | ||||
|                 } | ||||
|             }  | ||||
|                  | ||||
|  | @ -154,11 +153,10 @@ export default class MetaTagging { | |||
|                     configurable: true, | ||||
|                     enumerable: false, // By setting this as not enumerable, the localTileSaver will _not_ calculate this
 | ||||
|                     get: function () { | ||||
|                         calculateAndAssign(feature) | ||||
|                         return feature.properties[key] | ||||
|                         return calculateAndAssign(feature) | ||||
|                     } | ||||
|                 }) | ||||
|                 return true | ||||
|                 return undefined | ||||
|             } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -167,7 +165,7 @@ export default class MetaTagging { | |||
|         return functions; | ||||
|     } | ||||
| 
 | ||||
|     private static retaggingFuncCache = new Map<string, ((feature: any) => boolean)[]>() | ||||
|     private static retaggingFuncCache = new Map<string, ((feature: any) => void)[]>() | ||||
| 
 | ||||
|     /** | ||||
|      * Creates the function which adds all the calculated tags to a feature. Called once per layer | ||||
|  | @ -183,7 +181,7 @@ export default class MetaTagging { | |||
|             return undefined; | ||||
|         } | ||||
| 
 | ||||
|         let functions :((feature: any) => boolean)[] = MetaTagging.retaggingFuncCache.get(layer.id); | ||||
|         let functions :((feature: any) => void)[] = MetaTagging.retaggingFuncCache.get(layer.id); | ||||
|         if (functions === undefined) { | ||||
|             functions = MetaTagging.createFunctionsForFeature(layer.id, calculatedTags) | ||||
|             MetaTagging.retaggingFuncCache.set(layer.id, functions) | ||||
|  |  | |||
|  | @ -218,6 +218,24 @@ export class OsmConnection { | |||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     public closeNote(id: number | string): Promise<any> { | ||||
|         return new Promise((ok, error) => { | ||||
|             this.auth.xhr({ | ||||
|                 method: 'POST', | ||||
|                 path: `/api/0.6/notes/${id}/close` | ||||
|             }, function (err, response) { | ||||
|                 console.log("Closing note gave:", err, response) | ||||
|                 if (err !== null) { | ||||
|                     error(err) | ||||
|                 } else { | ||||
|                     ok() | ||||
|                 } | ||||
|             }) | ||||
| 
 | ||||
|         }) | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private updateAuthObject() { | ||||
|         let pwaStandAloneMode = false; | ||||
|         try { | ||||
|  | @ -260,6 +278,4 @@ export class OsmConnection { | |||
|         }); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue