forked from MapComplete/MapComplete
		
	Fix duplicate building upload in GRB theme (hopefully), remove type from method name, improve typing and error messages
This commit is contained in:
		
							parent
							
								
									fc483ed547
								
							
						
					
					
						commit
						b8a631f368
					
				
					 11 changed files with 49 additions and 26 deletions
				
			
		|  | @ -22,7 +22,7 @@ | |||
|             ] | ||||
|           }, | ||||
|           "icon": { | ||||
|             "render": "addSmall:#000", | ||||
|             "render": "addSmall", | ||||
|             "mappings": [ | ||||
|               { | ||||
|                 "if": "detach=yes", | ||||
|  |  | |||
							
								
								
									
										5
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										5
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							|  | @ -1,12 +1,12 @@ | |||
| { | ||||
|   "name": "mapcomplete", | ||||
|   "version": "0.36.9", | ||||
|   "version": "0.36.11", | ||||
|   "lockfileVersion": 2, | ||||
|   "requires": true, | ||||
|   "packages": { | ||||
|     "": { | ||||
|       "name": "mapcomplete", | ||||
|       "version": "0.36.9", | ||||
|       "version": "0.36.11", | ||||
|       "license": "GPL-3.0-or-later", | ||||
|       "dependencies": { | ||||
|         "@rgossiaux/svelte-headlessui": "^1.0.2", | ||||
|  | @ -15,6 +15,7 @@ | |||
|         "@turf/boolean-intersects": "^6.5.0", | ||||
|         "@turf/buffer": "^6.5.0", | ||||
|         "@turf/collect": "^6.5.0", | ||||
|         "@turf/difference": "^6.5.0", | ||||
|         "@turf/distance": "^6.5.0", | ||||
|         "@turf/length": "^6.5.0", | ||||
|         "@turf/turf": "^6.5.0", | ||||
|  |  | |||
|  | @ -103,6 +103,7 @@ | |||
|     "@turf/boolean-intersects": "^6.5.0", | ||||
|     "@turf/buffer": "^6.5.0", | ||||
|     "@turf/collect": "^6.5.0", | ||||
|     "@turf/difference": "^6.5.0", | ||||
|     "@turf/distance": "^6.5.0", | ||||
|     "@turf/length": "^6.5.0", | ||||
|     "@turf/turf": "^6.5.0", | ||||
|  |  | |||
|  | @ -264,7 +264,8 @@ class ClosestNObjectFunc implements ExtraFunction { | |||
|             const bbox = GeoOperations.bbox( | ||||
|                 GeoOperations.buffer(GeoOperations.bbox(feature), maxDistance) | ||||
|             ) | ||||
|             allFeatures = params.getFeaturesWithin(name, new BBox(bbox.geometry.coordinates)) | ||||
|             const coors = <[number, number][]>bbox.geometry.coordinates | ||||
|             allFeatures = params.getFeaturesWithin(name, new BBox(coors)) | ||||
|         } else { | ||||
|             allFeatures = [features] | ||||
|         } | ||||
|  |  | |||
|  | @ -39,8 +39,8 @@ export default class FeatureSourceMerger implements IndexedFeatureSource { | |||
|         }) | ||||
|     } | ||||
| 
 | ||||
|     protected addData(featuress: Feature[][]) { | ||||
|         featuress = Utils.NoNull(featuress) | ||||
|     protected addData(sources: Feature[][]) { | ||||
|         sources = Utils.NoNull(sources) | ||||
|         let somethingChanged = false | ||||
|         const all: Map<string, Feature> = new Map() | ||||
|         const unseen = new Set<string>() | ||||
|  | @ -51,7 +51,7 @@ export default class FeatureSourceMerger implements IndexedFeatureSource { | |||
|             unseen.add(oldValue.properties.id) | ||||
|         } | ||||
| 
 | ||||
|         for (const features of featuress) { | ||||
|         for (const features of sources) { | ||||
|             for (const f of features) { | ||||
|                 const id = f.properties.id | ||||
|                 unseen.delete(id) | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ import FeatureSourceMerger from "../Sources/FeatureSourceMerger" | |||
| 
 | ||||
| /*** | ||||
|  * A tiled source which dynamically loads the required tiles at a fixed zoom level. | ||||
|  * A single featureSource will be initiliased for every tile in view; which will alter be merged into this featureSource | ||||
|  * A single featureSource will be initialized for every tile in view; which will later be merged into this featureSource | ||||
|  */ | ||||
| export default class DynamicTileSource extends FeatureSourceMerger { | ||||
|     constructor( | ||||
|  |  | |||
|  | @ -153,7 +153,7 @@ export class GeoOperations { | |||
|                     continue | ||||
|                 } | ||||
| 
 | ||||
|                 const intersection = GeoOperations.calculateInstersection( | ||||
|                 const intersection = GeoOperations.calculateIntersection( | ||||
|                     feature, | ||||
|                     otherFeature, | ||||
|                     featureBBox | ||||
|  | @ -184,7 +184,7 @@ export class GeoOperations { | |||
| 
 | ||||
|                 // Calculate the surface area of the intersection
 | ||||
| 
 | ||||
|                 const intersection = this.calculateInstersection(feature, otherFeature, featureBBox) | ||||
|                 const intersection = this.calculateIntersection(feature, otherFeature, featureBBox) | ||||
|                 if (intersection === null) { | ||||
|                     continue | ||||
|                 } | ||||
|  | @ -1029,7 +1029,7 @@ export class GeoOperations { | |||
|      * Returns 0 if both are linestrings | ||||
|      * Returns null if the features are not intersecting | ||||
|      */ | ||||
|     private static calculateInstersection( | ||||
|     private static calculateIntersection( | ||||
|         feature, | ||||
|         otherFeature, | ||||
|         featureBBox: BBox, | ||||
|  | @ -1099,7 +1099,7 @@ export class GeoOperations { | |||
|                 return null | ||||
|             } | ||||
|             if (otherFeature.geometry.type === "LineString") { | ||||
|                 return this.calculateInstersection( | ||||
|                 return this.calculateIntersection( | ||||
|                     otherFeature, | ||||
|                     feature, | ||||
|                     otherFeatureBBox, | ||||
|  | @ -1119,6 +1119,19 @@ export class GeoOperations { | |||
|                     // See https://github.com/Turfjs/turf/pull/2238
 | ||||
|                     return null | ||||
|                 } | ||||
|                 if (e.message.indexOf("SweepLine tree") >= 0) { | ||||
|                     console.log("Applying fallback intersection...") | ||||
|                     const intersection = turf.intersect( | ||||
|                         turf.truncate(feature), | ||||
|                         turf.truncate(otherFeature) | ||||
|                     ) | ||||
|                     if (intersection == null) { | ||||
|                         return null | ||||
|                     } | ||||
|                     return turf.area(intersection) // in m²
 | ||||
|                     // Another workaround: https://github.com/Turfjs/turf/issues/2258
 | ||||
|                 } | ||||
| 
 | ||||
|                 throw e | ||||
|             } | ||||
|         } | ||||
|  |  | |||
|  | @ -274,17 +274,20 @@ export default class MetaTagging { | |||
|                     console.warn( | ||||
|                         "Could not calculate a " + | ||||
|                             (isStrict ? "strict " : "") + | ||||
|                             " calculated tag for key " + | ||||
|                             key + | ||||
|                             " defined by " + | ||||
|                             code + | ||||
|                             " (in layer" + | ||||
|                             layerId + | ||||
|                             "calculated tag for key", | ||||
|                         key, | ||||
|                         "for feature", | ||||
|                         feat.properties.id, | ||||
|                         " 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 | ||||
|                         e.stack, | ||||
|                         { feat } | ||||
|                     ) | ||||
|                     MetaTagging.errorPrintCount++ | ||||
|                     if (MetaTagging.errorPrintCount == MetaTagging.stopErrorOutputAt) { | ||||
|  |  | |||
|  | @ -148,7 +148,6 @@ export class Changes { | |||
|     } | ||||
| 
 | ||||
|     public applyChanges(changes: ChangeDescription[]) { | ||||
|         console.log("Received changes:", changes) | ||||
|         this.pendingChanges.data.push(...changes) | ||||
|         this.pendingChanges.ping() | ||||
|         this.allChanges.data.push(...changes) | ||||
|  | @ -191,7 +190,6 @@ export class Changes { | |||
|                 } | ||||
|                 // This is a new object that should be created
 | ||||
|                 states.set(id, "created") | ||||
|                 console.log("Creating object for changeDescription", change) | ||||
|                 let osmObj: OsmObject = undefined | ||||
|                 switch (change.type) { | ||||
|                     case "node": | ||||
|  | @ -255,7 +253,6 @@ export class Changes { | |||
|                         const nlon = Utils.Round7(change.changes.lon) | ||||
|                         const n = <OsmNode>obj | ||||
|                         if (n.lat !== nlat || n.lon !== nlon) { | ||||
|                             console.log("Node moved:", n.lat, nlat, n.lon, nlon) | ||||
|                             n.lat = nlat | ||||
|                             n.lon = nlon | ||||
|                             changed = true | ||||
|  | @ -443,7 +440,6 @@ export class Changes { | |||
|             objects.forEach((obj) => SimpleMetaTagger.removeBothTagging(obj.tags)) | ||||
|         } | ||||
| 
 | ||||
|         console.log("Got the fresh objects!", objects, "pending: ", pending) | ||||
|         if (pending.length == 0) { | ||||
|             console.log("No pending changes...") | ||||
|             return true | ||||
|  | @ -528,9 +524,7 @@ export class Changes { | |||
|         await this._changesetHandler.UploadChangeset( | ||||
|             (csId, remappings) => { | ||||
|                 if (remappings.size > 0) { | ||||
|                     console.log("Rewriting pending changes from", pending, "with", remappings) | ||||
|                     pending = pending.map((ch) => ChangeDescriptionTools.rewriteIds(ch, remappings)) | ||||
|                     console.log("Result is", pending) | ||||
|                 } | ||||
| 
 | ||||
|                 const changes: { | ||||
|  |  | |||
|  | @ -30,6 +30,7 @@ | |||
|   import Direction_gradient from "../../assets/svg/Direction_gradient.svelte" | ||||
|   import Mastodon from "../../assets/svg/Mastodon.svelte" | ||||
|   import Party from "../../assets/svg/Party.svelte" | ||||
|   import AddSmall from "../../assets/svg/AddSmall.svelte" | ||||
| 
 | ||||
|   /** | ||||
|    * Renders a single icon. | ||||
|  | @ -111,6 +112,8 @@ | |||
|     <Mastodon {color} class={clss} /> | ||||
|   {:else if icon === "party"} | ||||
|     <Party {color} class={clss} /> | ||||
|   {:else if icon === "addSmall"} | ||||
|     <AddSmall {color} class={clss} /> | ||||
|   {:else} | ||||
|     <img class={clss ?? "h-full w-full"} src={icon} aria-hidden="true" alt="" /> | ||||
|   {/if} | ||||
|  |  | |||
|  | @ -159,7 +159,7 @@ class ApplyButton extends UIElement { | |||
|     private async Run() { | ||||
|         try { | ||||
|             console.log("Applying auto-action on " + this.target_feature_ids.length + " features") | ||||
| 
 | ||||
|             const appliedOn: string[] = [] | ||||
|             for (let i = 0; i < this.target_feature_ids.length; i++) { | ||||
|                 const targetFeatureId = this.target_feature_ids[i] | ||||
|                 const feature = this.state.indexedFeatures.featuresById.data.get(targetFeatureId) | ||||
|  | @ -190,6 +190,7 @@ class ApplyButton extends UIElement { | |||
|                         specialRendering.args | ||||
|                     ) | ||||
|                 } | ||||
|                 appliedOn.push(targetFeatureId) | ||||
|                 if (i % 50 === 0) { | ||||
|                     await this.state.changes.flushChanges("Auto button: intermediate save") | ||||
|                 } | ||||
|  | @ -198,6 +199,12 @@ class ApplyButton extends UIElement { | |||
|             console.log("Flushing changes...") | ||||
|             await this.state.changes.flushChanges("Auto button: done") | ||||
|             this.buttonState.setData("done") | ||||
|             console.log( | ||||
|                 "Applied changes onto", | ||||
|                 appliedOn.length, | ||||
|                 "items, unique IDs:", | ||||
|                 new Set(appliedOn).size | ||||
|             ) | ||||
|         } catch (e) { | ||||
|             console.error("Error while running autoApply: ", e) | ||||
|             this.buttonState.setData({ error: e }) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue