Fix duplicate buildings for grb layer; add default flag for filters, performance improvement

This commit is contained in:
Pieter Vander Vennet 2022-02-11 03:57:39 +01:00
parent 31205f3430
commit 695a0867c7
13 changed files with 157 additions and 111 deletions

View file

@ -58,39 +58,9 @@ class ApplyButton extends UIElement {
this.text = options.text
this.icon = options.icon
this.layer = this.state.filteredLayers.data.find(l => l.layerDef.id === this.target_layer_id)
this. tagRenderingConfig = this.layer.layerDef.tagRenderings.find(tr => tr.id === this.targetTagRendering)
this.tagRenderingConfig = this.layer.layerDef.tagRenderings.find(tr => tr.id === this.targetTagRendering)
}
private async Run() {
this.buttonState.setData("running")
try {
console.log("Applying auto-action on " + this.target_feature_ids.length + " features")
for (const targetFeatureId of this.target_feature_ids) {
const featureTags = this.state.allElements.getEventSourceById(targetFeatureId)
const rendering = this.tagRenderingConfig.GetRenderValue(featureTags.data).txt
const specialRenderings = Utils.NoNull(SubstitutedTranslation.ExtractSpecialComponents(rendering)
.map(x => x.special))
.filter(v => v.func["supportsAutoAction"] === true)
if(specialRenderings.length == 0){
console.warn("AutoApply: feature "+targetFeatureId+" got a rendering without supported auto actions:", rendering)
}
for (const specialRendering of specialRenderings) {
const action = <AutoAction>specialRendering.func
await action.applyActionOn(this.state, featureTags, specialRendering.args)
}
}
console.log("Flushing changes...")
await this.state.changes.flushChanges("Auto button")
this.buttonState.setData("done")
} catch (e) {
console.error("Error while running autoApply: ", e)
this. buttonState.setData({error: e})
}
}
protected InnerRender(): string | BaseUIElement {
if (this.target_feature_ids.length === 0) {
@ -105,7 +75,13 @@ class ApplyButton extends UIElement {
const button = new SubtleButton(
new Img(this.icon),
this.text
).onClick(() => self.Run());
).onClick(() => {
this.buttonState.setData("running")
window.setTimeout(() => {
self.Run();
}, 50)
});
const explanation = new Combine(["The following objects will be updated: ",
...this.target_feature_ids.map(id => new Combine([new Link(id, "https:/ /openstreetmap.org/" + id, true), ", "]))]).SetClass("subtle")
@ -124,7 +100,7 @@ class ApplyButton extends UIElement {
zoomToFeatures: true,
features: new StaticFeatureSource(features, false),
state: this.state,
layerToShow:this. layer.layerDef,
layerToShow: this.layer.layerDef,
})
@ -145,6 +121,37 @@ class ApplyButton extends UIElement {
))
}
private async Run() {
try {
console.log("Applying auto-action on " + this.target_feature_ids.length + " features")
for (const targetFeatureId of this.target_feature_ids) {
const featureTags = this.state.allElements.getEventSourceById(targetFeatureId)
const rendering = this.tagRenderingConfig.GetRenderValue(featureTags.data).txt
const specialRenderings = Utils.NoNull(SubstitutedTranslation.ExtractSpecialComponents(rendering)
.map(x => x.special))
.filter(v => v.func["supportsAutoAction"] === true)
if (specialRenderings.length == 0) {
console.warn("AutoApply: feature " + targetFeatureId + " got a rendering without supported auto actions:", rendering)
}
for (const specialRendering of specialRenderings) {
const action = <AutoAction>specialRendering.func
await action.applyActionOn(this.state, featureTags, specialRendering.args)
}
}
console.log("Flushing changes...")
await this.state.changes.flushChanges("Auto button")
this.buttonState.setData("done")
} catch (e) {
console.error("Error while running autoApply: ", e)
this.buttonState.setData({error: e})
}
}
}
export default class AutoApplyButton implements SpecialVisualization {
@ -215,15 +222,13 @@ export default class AutoApplyButton implements SpecialVisualization {
const loading = new Loading("Gathering which elements support auto-apply... ");
return new VariableUiElement(to_parse.map(ids => {
if(ids === undefined){
if (ids === undefined) {
return loading
}
return new ApplyButton(state, JSON.parse(ids), options);
}))
})
} catch (e) {