Fix duplicate building upload in GRB theme (hopefully), remove type from method name, improve typing and error messages

This commit is contained in:
Pieter Vander Vennet 2024-01-04 23:42:47 +01:00
parent fc483ed547
commit b8a631f368
11 changed files with 49 additions and 26 deletions

View file

@ -22,7 +22,7 @@
] ]
}, },
"icon": { "icon": {
"render": "addSmall:#000", "render": "addSmall",
"mappings": [ "mappings": [
{ {
"if": "detach=yes", "if": "detach=yes",

5
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "mapcomplete", "name": "mapcomplete",
"version": "0.36.9", "version": "0.36.11",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "mapcomplete", "name": "mapcomplete",
"version": "0.36.9", "version": "0.36.11",
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"dependencies": { "dependencies": {
"@rgossiaux/svelte-headlessui": "^1.0.2", "@rgossiaux/svelte-headlessui": "^1.0.2",
@ -15,6 +15,7 @@
"@turf/boolean-intersects": "^6.5.0", "@turf/boolean-intersects": "^6.5.0",
"@turf/buffer": "^6.5.0", "@turf/buffer": "^6.5.0",
"@turf/collect": "^6.5.0", "@turf/collect": "^6.5.0",
"@turf/difference": "^6.5.0",
"@turf/distance": "^6.5.0", "@turf/distance": "^6.5.0",
"@turf/length": "^6.5.0", "@turf/length": "^6.5.0",
"@turf/turf": "^6.5.0", "@turf/turf": "^6.5.0",

View file

@ -103,6 +103,7 @@
"@turf/boolean-intersects": "^6.5.0", "@turf/boolean-intersects": "^6.5.0",
"@turf/buffer": "^6.5.0", "@turf/buffer": "^6.5.0",
"@turf/collect": "^6.5.0", "@turf/collect": "^6.5.0",
"@turf/difference": "^6.5.0",
"@turf/distance": "^6.5.0", "@turf/distance": "^6.5.0",
"@turf/length": "^6.5.0", "@turf/length": "^6.5.0",
"@turf/turf": "^6.5.0", "@turf/turf": "^6.5.0",

View file

@ -264,7 +264,8 @@ class ClosestNObjectFunc implements ExtraFunction {
const bbox = GeoOperations.bbox( const bbox = GeoOperations.bbox(
GeoOperations.buffer(GeoOperations.bbox(feature), maxDistance) 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 { } else {
allFeatures = [features] allFeatures = [features]
} }

View file

@ -39,8 +39,8 @@ export default class FeatureSourceMerger implements IndexedFeatureSource {
}) })
} }
protected addData(featuress: Feature[][]) { protected addData(sources: Feature[][]) {
featuress = Utils.NoNull(featuress) sources = Utils.NoNull(sources)
let somethingChanged = false let somethingChanged = false
const all: Map<string, Feature> = new Map() const all: Map<string, Feature> = new Map()
const unseen = new Set<string>() const unseen = new Set<string>()
@ -51,7 +51,7 @@ export default class FeatureSourceMerger implements IndexedFeatureSource {
unseen.add(oldValue.properties.id) unseen.add(oldValue.properties.id)
} }
for (const features of featuress) { for (const features of sources) {
for (const f of features) { for (const f of features) {
const id = f.properties.id const id = f.properties.id
unseen.delete(id) unseen.delete(id)

View file

@ -6,7 +6,7 @@ import FeatureSourceMerger from "../Sources/FeatureSourceMerger"
/*** /***
* A tiled source which dynamically loads the required tiles at a fixed zoom level. * 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 { export default class DynamicTileSource extends FeatureSourceMerger {
constructor( constructor(

View file

@ -153,7 +153,7 @@ export class GeoOperations {
continue continue
} }
const intersection = GeoOperations.calculateInstersection( const intersection = GeoOperations.calculateIntersection(
feature, feature,
otherFeature, otherFeature,
featureBBox featureBBox
@ -184,7 +184,7 @@ export class GeoOperations {
// Calculate the surface area of the intersection // Calculate the surface area of the intersection
const intersection = this.calculateInstersection(feature, otherFeature, featureBBox) const intersection = this.calculateIntersection(feature, otherFeature, featureBBox)
if (intersection === null) { if (intersection === null) {
continue continue
} }
@ -1029,7 +1029,7 @@ export class GeoOperations {
* Returns 0 if both are linestrings * Returns 0 if both are linestrings
* Returns null if the features are not intersecting * Returns null if the features are not intersecting
*/ */
private static calculateInstersection( private static calculateIntersection(
feature, feature,
otherFeature, otherFeature,
featureBBox: BBox, featureBBox: BBox,
@ -1099,7 +1099,7 @@ export class GeoOperations {
return null return null
} }
if (otherFeature.geometry.type === "LineString") { if (otherFeature.geometry.type === "LineString") {
return this.calculateInstersection( return this.calculateIntersection(
otherFeature, otherFeature,
feature, feature,
otherFeatureBBox, otherFeatureBBox,
@ -1119,6 +1119,19 @@ export class GeoOperations {
// See https://github.com/Turfjs/turf/pull/2238 // See https://github.com/Turfjs/turf/pull/2238
return null 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 throw e
} }
} }

View file

@ -274,17 +274,20 @@ export default class MetaTagging {
console.warn( console.warn(
"Could not calculate a " + "Could not calculate a " +
(isStrict ? "strict " : "") + (isStrict ? "strict " : "") +
" calculated tag for key " + "calculated tag for key",
key + key,
" defined by " + "for feature",
code + feat.properties.id,
" (in layer" + " defined by",
layerId + code,
"(in layer",
layerId +
") due to \n" + ") due to \n" +
e + e +
"\n. Are you the theme creator? Doublecheck your code. Note that the metatags might not be stable on new features", "\n. Are you the theme creator? Doublecheck your code. Note that the metatags might not be stable on new features",
e, e,
e.stack e.stack,
{ feat }
) )
MetaTagging.errorPrintCount++ MetaTagging.errorPrintCount++
if (MetaTagging.errorPrintCount == MetaTagging.stopErrorOutputAt) { if (MetaTagging.errorPrintCount == MetaTagging.stopErrorOutputAt) {

View file

@ -148,7 +148,6 @@ export class Changes {
} }
public applyChanges(changes: ChangeDescription[]) { public applyChanges(changes: ChangeDescription[]) {
console.log("Received changes:", changes)
this.pendingChanges.data.push(...changes) this.pendingChanges.data.push(...changes)
this.pendingChanges.ping() this.pendingChanges.ping()
this.allChanges.data.push(...changes) this.allChanges.data.push(...changes)
@ -191,7 +190,6 @@ export class Changes {
} }
// This is a new object that should be created // This is a new object that should be created
states.set(id, "created") states.set(id, "created")
console.log("Creating object for changeDescription", change)
let osmObj: OsmObject = undefined let osmObj: OsmObject = undefined
switch (change.type) { switch (change.type) {
case "node": case "node":
@ -255,7 +253,6 @@ export class Changes {
const nlon = Utils.Round7(change.changes.lon) const nlon = Utils.Round7(change.changes.lon)
const n = <OsmNode>obj const n = <OsmNode>obj
if (n.lat !== nlat || n.lon !== nlon) { if (n.lat !== nlat || n.lon !== nlon) {
console.log("Node moved:", n.lat, nlat, n.lon, nlon)
n.lat = nlat n.lat = nlat
n.lon = nlon n.lon = nlon
changed = true changed = true
@ -443,7 +440,6 @@ export class Changes {
objects.forEach((obj) => SimpleMetaTagger.removeBothTagging(obj.tags)) objects.forEach((obj) => SimpleMetaTagger.removeBothTagging(obj.tags))
} }
console.log("Got the fresh objects!", objects, "pending: ", pending)
if (pending.length == 0) { if (pending.length == 0) {
console.log("No pending changes...") console.log("No pending changes...")
return true return true
@ -528,9 +524,7 @@ export class Changes {
await this._changesetHandler.UploadChangeset( await this._changesetHandler.UploadChangeset(
(csId, remappings) => { (csId, remappings) => {
if (remappings.size > 0) { if (remappings.size > 0) {
console.log("Rewriting pending changes from", pending, "with", remappings)
pending = pending.map((ch) => ChangeDescriptionTools.rewriteIds(ch, remappings)) pending = pending.map((ch) => ChangeDescriptionTools.rewriteIds(ch, remappings))
console.log("Result is", pending)
} }
const changes: { const changes: {

View file

@ -30,6 +30,7 @@
import Direction_gradient from "../../assets/svg/Direction_gradient.svelte" import Direction_gradient from "../../assets/svg/Direction_gradient.svelte"
import Mastodon from "../../assets/svg/Mastodon.svelte" import Mastodon from "../../assets/svg/Mastodon.svelte"
import Party from "../../assets/svg/Party.svelte" import Party from "../../assets/svg/Party.svelte"
import AddSmall from "../../assets/svg/AddSmall.svelte"
/** /**
* Renders a single icon. * Renders a single icon.
@ -111,6 +112,8 @@
<Mastodon {color} class={clss} /> <Mastodon {color} class={clss} />
{:else if icon === "party"} {:else if icon === "party"}
<Party {color} class={clss} /> <Party {color} class={clss} />
{:else if icon === "addSmall"}
<AddSmall {color} class={clss} />
{:else} {:else}
<img class={clss ?? "h-full w-full"} src={icon} aria-hidden="true" alt="" /> <img class={clss ?? "h-full w-full"} src={icon} aria-hidden="true" alt="" />
{/if} {/if}

View file

@ -159,7 +159,7 @@ class ApplyButton extends UIElement {
private async Run() { private async Run() {
try { try {
console.log("Applying auto-action on " + this.target_feature_ids.length + " features") 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++) { for (let i = 0; i < this.target_feature_ids.length; i++) {
const targetFeatureId = this.target_feature_ids[i] const targetFeatureId = this.target_feature_ids[i]
const feature = this.state.indexedFeatures.featuresById.data.get(targetFeatureId) const feature = this.state.indexedFeatures.featuresById.data.get(targetFeatureId)
@ -190,6 +190,7 @@ class ApplyButton extends UIElement {
specialRendering.args specialRendering.args
) )
} }
appliedOn.push(targetFeatureId)
if (i % 50 === 0) { if (i % 50 === 0) {
await this.state.changes.flushChanges("Auto button: intermediate save") await this.state.changes.flushChanges("Auto button: intermediate save")
} }
@ -198,6 +199,12 @@ class ApplyButton extends UIElement {
console.log("Flushing changes...") console.log("Flushing changes...")
await this.state.changes.flushChanges("Auto button: done") await this.state.changes.flushChanges("Auto button: done")
this.buttonState.setData("done") this.buttonState.setData("done")
console.log(
"Applied changes onto",
appliedOn.length,
"items, unique IDs:",
new Set(appliedOn).size
)
} catch (e) { } catch (e) {
console.error("Error while running autoApply: ", e) console.error("Error while running autoApply: ", e)
this.buttonState.setData({ error: e }) this.buttonState.setData({ error: e })