Fix autoapply for GRB theme
This commit is contained in:
parent
db770f2c35
commit
30be86668e
16 changed files with 392 additions and 209 deletions
|
@ -50,7 +50,7 @@ class MetatagUpdater {
|
||||||
this.isDirty.setData(true)
|
this.isDirty.setData(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateMetaTags() {
|
public updateMetaTags() {
|
||||||
const features = this.source.features.data
|
const features = this.source.features.data
|
||||||
|
|
||||||
if (features.length === 0) {
|
if (features.length === 0) {
|
||||||
|
@ -77,12 +77,23 @@ export default class MetaTagRecalculator {
|
||||||
private readonly _notifiers: MetatagUpdater[] = []
|
private readonly _notifiers: MetatagUpdater[] = []
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The meta tag recalculator receives tiles of layers.
|
* The meta tag recalculator receives tiles of layers via the 'registerSource'-function.
|
||||||
* It keeps track of which sources have had their share calculated, and which should be re-updated if some other data is loaded
|
* It keeps track of which sources have had their share calculated, and which should be re-updated if some other data is loaded
|
||||||
*/
|
*/
|
||||||
constructor(state: { allElements?: ElementStorage }, featurePipeline: FeaturePipeline) {
|
constructor(state: { allElements?: ElementStorage, currentView: FeatureSourceForLayer & Tiled }, featurePipeline: FeaturePipeline) {
|
||||||
this._featurePipeline = featurePipeline;
|
this._featurePipeline = featurePipeline;
|
||||||
this._state = state;
|
this._state = state;
|
||||||
|
|
||||||
|
if(state.currentView !== undefined){
|
||||||
|
const currentViewUpdater = new MetatagUpdater(state.currentView, this._state, this._featurePipeline)
|
||||||
|
this._alreadyRegistered.add(state.currentView)
|
||||||
|
this._notifiers.push(currentViewUpdater)
|
||||||
|
state.currentView.features.addCallback(_ => {
|
||||||
|
console.debug("Requesting an update for currentView")
|
||||||
|
currentViewUpdater.updateMetaTags();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public registerSource(source: FeatureSourceForLayer & Tiled, recalculateOnEveryChange = false) {
|
public registerSource(source: FeatureSourceForLayer & Tiled, recalculateOnEveryChange = false) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {LocalStorageSource} from "../Web/LocalStorageSource";
|
||||||
import {GeoOperations} from "../GeoOperations";
|
import {GeoOperations} from "../GeoOperations";
|
||||||
import TitleHandler from "../Actors/TitleHandler";
|
import TitleHandler from "../Actors/TitleHandler";
|
||||||
import {BBox} from "../BBox";
|
import {BBox} from "../BBox";
|
||||||
|
import MetaTagging from "../MetaTagging";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains all the leaflet-map related state
|
* Contains all the leaflet-map related state
|
||||||
|
|
|
@ -18,11 +18,15 @@ export abstract class Conversion<TIn, TOut> {
|
||||||
this.name = name ?? this.constructor.name
|
this.name = name ?? this.constructor.name
|
||||||
}
|
}
|
||||||
|
|
||||||
public static strict<T>(fixed: { errors?: string[], warnings?: string[], result?: T }): T {
|
public static strict<T>(fixed: { errors?: string[], warnings?: string[], information?: string[], result?: T }): T {
|
||||||
if (fixed?.errors !== undefined && fixed?.errors?.length > 0) {
|
if (fixed?.errors !== undefined && fixed?.errors?.length > 0) {
|
||||||
throw fixed.errors.join("\n\n");
|
throw fixed.errors.join("\n\n");
|
||||||
}
|
}
|
||||||
fixed.warnings?.forEach(w => console.warn(w))
|
fixed.information?.forEach(i => console.log(" ", i))
|
||||||
|
const yellow = (s) => "\x1b[33m"+s+"\x1b[0m"
|
||||||
|
const red = s => '\x1b[31m'+s+'\x1b[0m'
|
||||||
|
|
||||||
|
fixed.warnings?.forEach(w => console.warn(red(`<!> `), yellow (w)))
|
||||||
return fixed.result;
|
return fixed.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,26 +35,29 @@ export abstract class Conversion<TIn, TOut> {
|
||||||
return DesugaringStep.strict(fixed)
|
return DesugaringStep.strict(fixed)
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract convert(json: TIn, context: string): { result: TOut, errors?: string[], warnings?: string[] }
|
abstract convert(json: TIn, context: string): { result: TOut, errors?: string[], warnings?: string[], information?: string[] }
|
||||||
|
|
||||||
public convertAll(jsons: TIn[], context: string): { result: TOut[], errors: string[], warnings: string[] } {
|
public convertAll(jsons: TIn[], context: string): { result: TOut[], errors: string[], warnings: string[], information?: string[] } {
|
||||||
if(jsons === undefined){
|
if(jsons === undefined){
|
||||||
throw "convertAll received undefined - don't do this (at "+context+")"
|
throw "convertAll received undefined - don't do this (at "+context+")"
|
||||||
}
|
}
|
||||||
const result = []
|
const result = []
|
||||||
const errors = []
|
const errors = []
|
||||||
const warnings = []
|
const warnings = []
|
||||||
|
const information = []
|
||||||
for (let i = 0; i < jsons.length; i++) {
|
for (let i = 0; i < jsons.length; i++) {
|
||||||
const json = jsons[i];
|
const json = jsons[i];
|
||||||
const r = this.convert(json, context + "[" + i + "]")
|
const r = this.convert(json, context + "[" + i + "]")
|
||||||
result.push(r.result)
|
result.push(r.result)
|
||||||
errors.push(...r.errors ?? [])
|
errors.push(...r.errors ?? [])
|
||||||
warnings.push(...r.warnings ?? [])
|
warnings.push(...r.warnings ?? [])
|
||||||
|
information.push(...r.information ?? [])
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
result,
|
result,
|
||||||
errors,
|
errors,
|
||||||
warnings
|
warnings,
|
||||||
|
information
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,16 +76,15 @@ export class OnEvery<X, T> extends DesugaringStep<T> {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(json: T, context: string): { result: T; errors?: string[]; warnings?: string[] } {
|
convert(json: T, context: string): { result: T; errors?: string[]; warnings?: string[], information?: string[] } {
|
||||||
json = {...json}
|
json = {...json}
|
||||||
const step = this.step
|
const step = this.step
|
||||||
const key = this.key;
|
const key = this.key;
|
||||||
const r = step.convertAll((<X[]>json[key]), context + "." + key)
|
const r = step.convertAll((<X[]>json[key]), context + "." + key)
|
||||||
json[key] = r.result
|
json[key] = r.result
|
||||||
return {
|
return {
|
||||||
|
...r,
|
||||||
result: json,
|
result: json,
|
||||||
errors: r.errors,
|
|
||||||
warnings: r.warnings
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +100,7 @@ export class OnEveryConcat<X, T> extends DesugaringStep<T> {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(json: T, context: string): { result: T; errors: string[]; warnings: string[] } {
|
convert(json: T, context: string): { result: T; errors?: string[]; warnings?: string[], information?: string[] } {
|
||||||
json = {...json}
|
json = {...json}
|
||||||
const step = this.step
|
const step = this.step
|
||||||
const key = this.key;
|
const key = this.key;
|
||||||
|
@ -103,17 +109,14 @@ export class OnEveryConcat<X, T> extends DesugaringStep<T> {
|
||||||
// Move on - nothing to see here!
|
// Move on - nothing to see here!
|
||||||
return {
|
return {
|
||||||
result: json,
|
result: json,
|
||||||
errors: [],
|
|
||||||
warnings: []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const r = step.convertAll((<X[]>values), context + "." + key)
|
const r = step.convertAll((<X[]>values), context + "." + key)
|
||||||
const vals: X[][] = r.result
|
const vals: X[][] = r.result
|
||||||
json[key] = [].concat(...vals)
|
json[key] = [].concat(...vals)
|
||||||
return {
|
return {
|
||||||
|
...r,
|
||||||
result: json,
|
result: json,
|
||||||
errors: r.errors,
|
|
||||||
warnings: r.warnings
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -129,14 +132,16 @@ export class Fuse<T> extends DesugaringStep<T> {
|
||||||
this.steps = steps;
|
this.steps = steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(json: T, context: string): { result: T; errors: string[]; warnings: string[] } {
|
convert(json: T, context: string): { result: T; errors: string[]; warnings: string[], information: string[] } {
|
||||||
const errors = []
|
const errors = []
|
||||||
const warnings = []
|
const warnings = []
|
||||||
|
const information = []
|
||||||
for (let i = 0; i < this.steps.length; i++) {
|
for (let i = 0; i < this.steps.length; i++) {
|
||||||
const step = this.steps[i];
|
const step = this.steps[i];
|
||||||
let r = step.convert(json, "While running step " +step.name + ": " + context)
|
let r = step.convert(json, "While running step " +step.name + ": " + context)
|
||||||
errors.push(...r.errors ?? [])
|
errors.push(...r.errors ?? [])
|
||||||
warnings.push(...r.warnings ?? [])
|
warnings.push(...r.warnings ?? [])
|
||||||
|
information.push(...r.information ?? [])
|
||||||
json = r.result
|
json = r.result
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -145,7 +150,8 @@ export class Fuse<T> extends DesugaringStep<T> {
|
||||||
return {
|
return {
|
||||||
result: json,
|
result: json,
|
||||||
errors,
|
errors,
|
||||||
warnings
|
warnings,
|
||||||
|
information
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,14 +169,13 @@ export class SetDefault<T> extends DesugaringStep<T> {
|
||||||
this._overrideEmptyString = overrideEmptyString;
|
this._overrideEmptyString = overrideEmptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(json: T, context: string): { result: T; errors: string[]; warnings: string[] } {
|
convert(json: T, context: string): { result: T } {
|
||||||
if (json[this.key] === undefined || (json[this.key] === "" && this._overrideEmptyString)) {
|
if (json[this.key] === undefined || (json[this.key] === "" && this._overrideEmptyString)) {
|
||||||
json = {...json}
|
json = {...json}
|
||||||
json[this.key] = this.value
|
json[this.key] = this.value
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
errors: [], warnings: [],
|
|
||||||
result: json
|
result: json
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,7 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
|
||||||
this._includeClosedNotesDays = includeClosedNotesDays;
|
this._includeClosedNotesDays = includeClosedNotesDays;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(layerJson: LayerConfigJson, context: string): { result: LayerConfigJson; errors: string[]; warnings: string[] } {
|
convert(layerJson: LayerConfigJson, context: string): { result: LayerConfigJson } {
|
||||||
const errors = []
|
|
||||||
const warnings = []
|
|
||||||
const t = Translations.t.importLayer;
|
const t = Translations.t.importLayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -182,8 +180,7 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
result,
|
result
|
||||||
errors, warnings
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
|
||||||
this._knownImages = knownImages;
|
this._knownImages = knownImages;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors?: string[]; warnings?: string[] } {
|
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson } {
|
||||||
let url: URL;
|
let url: URL;
|
||||||
try {
|
try {
|
||||||
url = new URL(json.id)
|
url = new URL(json.id)
|
||||||
|
|
|
@ -213,7 +213,6 @@ class ExpandGroupRewrite extends Conversion<{
|
||||||
for (let i = 0; i < sourceStrings.length; i++) {
|
for (let i = 0; i < sourceStrings.length; i++) {
|
||||||
const source = sourceStrings[i]
|
const source = sourceStrings[i]
|
||||||
const target = targets[i] // This is a string OR a translation
|
const target = targets[i] // This is a string OR a translation
|
||||||
console.log("Replacing every "+source+" with "+JSON.stringify(target))
|
|
||||||
rewritten = this.prepConfig(source, target, rewritten)
|
rewritten = this.prepConfig(source, target, rewritten)
|
||||||
}
|
}
|
||||||
rewritten.group = rewritten.group ?? groupName
|
rewritten.group = rewritten.group ?? groupName
|
||||||
|
|
|
@ -20,8 +20,9 @@ class SubstituteLayer extends Conversion<(string | LayerConfigJson), LayerConfig
|
||||||
this._state = state;
|
this._state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(json: string | LayerConfigJson, context: string): { result: LayerConfigJson[]; errors: string[], warnings?: string[] } {
|
convert(json: string | LayerConfigJson, context: string): { result: LayerConfigJson[]; errors: string[], information?: string[] } {
|
||||||
const errors = []
|
const errors = []
|
||||||
|
const information = []
|
||||||
const state= this._state
|
const state= this._state
|
||||||
function reportNotFound(name: string){
|
function reportNotFound(name: string){
|
||||||
const knownLayers = Array.from(state.sharedLayers.keys())
|
const knownLayers = Array.from(state.sharedLayers.keys())
|
||||||
|
@ -55,7 +56,6 @@ class SubstituteLayer extends Conversion<(string | LayerConfigJson), LayerConfig
|
||||||
names = [names]
|
names = [names]
|
||||||
}
|
}
|
||||||
const layers = []
|
const layers = []
|
||||||
const warnings = []
|
|
||||||
|
|
||||||
for (const name of names) {
|
for (const name of names) {
|
||||||
const found = Utils.Clone(state.sharedLayers.get(name))
|
const found = Utils.Clone(state.sharedLayers.get(name))
|
||||||
|
@ -84,20 +84,20 @@ class SubstituteLayer extends Conversion<(string | LayerConfigJson), LayerConfig
|
||||||
const forbiddenLabel = labels.findIndex(l => hideLabels.has(l))
|
const forbiddenLabel = labels.findIndex(l => hideLabels.has(l))
|
||||||
if(forbiddenLabel >= 0){
|
if(forbiddenLabel >= 0){
|
||||||
usedLabels.add(labels[forbiddenLabel])
|
usedLabels.add(labels[forbiddenLabel])
|
||||||
warnings.push(context+": Dropping tagRendering "+tr["id"]+" as it has a forbidden label: "+labels[forbiddenLabel])
|
information.push(context+": Dropping tagRendering "+tr["id"]+" as it has a forbidden label: "+labels[forbiddenLabel])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hideLabels.has(tr["id"])){
|
if(hideLabels.has(tr["id"])){
|
||||||
usedLabels.add(tr["id"])
|
usedLabels.add(tr["id"])
|
||||||
warnings.push(context+": Dropping tagRendering "+tr["id"]+" as its id is a forbidden label")
|
information.push(context+": Dropping tagRendering "+tr["id"]+" as its id is a forbidden label")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hideLabels.has(tr["group"])){
|
if(hideLabels.has(tr["group"])){
|
||||||
usedLabels.add(tr["group"])
|
usedLabels.add(tr["group"])
|
||||||
warnings.push(context+": Dropping tagRendering "+tr["id"]+" as its group `"+tr["group"]+"` is a forbidden label")
|
information.push(context+": Dropping tagRendering "+tr["id"]+" as its group `"+tr["group"]+"` is a forbidden label")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ class SubstituteLayer extends Conversion<(string | LayerConfigJson), LayerConfig
|
||||||
return {
|
return {
|
||||||
result: layers,
|
result: layers,
|
||||||
errors,
|
errors,
|
||||||
warnings
|
information
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -185,9 +185,8 @@ class AddImportLayers extends DesugaringStep<LayoutConfigJson> {
|
||||||
super("For every layer in the 'layers'-list, create a new layer which'll import notes. (Note that priviliged layers and layers which have a geojson-source set are ignored)", ["layers"]);
|
super("For every layer in the 'layers'-list, create a new layer which'll import notes. (Note that priviliged layers and layers which have a geojson-source set are ignored)", ["layers"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors: string[]; warnings: string[] } {
|
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors: string[] } {
|
||||||
const errors = []
|
const errors = []
|
||||||
const warnings = []
|
|
||||||
|
|
||||||
json = {...json}
|
json = {...json}
|
||||||
const allLayers: LayerConfigJson[] = <LayerConfigJson[]>json.layers;
|
const allLayers: LayerConfigJson[] = <LayerConfigJson[]>json.layers;
|
||||||
|
@ -221,8 +220,6 @@ class AddImportLayers extends DesugaringStep<LayoutConfigJson> {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const importLayerResult = creator.convert(layer, context + ".(noteimportlayer)[" + i1 + "]")
|
const importLayerResult = creator.convert(layer, context + ".(noteimportlayer)[" + i1 + "]")
|
||||||
errors.push(...importLayerResult.errors)
|
|
||||||
warnings.push(...importLayerResult.warnings)
|
|
||||||
if (importLayerResult.result !== undefined) {
|
if (importLayerResult.result !== undefined) {
|
||||||
json.layers.push(importLayerResult.result)
|
json.layers.push(importLayerResult.result)
|
||||||
}
|
}
|
||||||
|
@ -234,7 +231,6 @@ class AddImportLayers extends DesugaringStep<LayoutConfigJson> {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
errors,
|
errors,
|
||||||
warnings,
|
|
||||||
result: json
|
result: json
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -274,7 +270,7 @@ export class AddMiniMap extends DesugaringStep<LayerConfigJson> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(layerConfig: LayerConfigJson, context: string): { result: LayerConfigJson; errors: string[]; warnings: string[] } {
|
convert(layerConfig: LayerConfigJson, context: string): { result: LayerConfigJson } {
|
||||||
|
|
||||||
const state = this._state;
|
const state = this._state;
|
||||||
const hasMinimap = layerConfig.tagRenderings?.some(tr => AddMiniMap.hasMinimap(<TagRenderingConfigJson>tr)) ?? true
|
const hasMinimap = layerConfig.tagRenderings?.some(tr => AddMiniMap.hasMinimap(<TagRenderingConfigJson>tr)) ?? true
|
||||||
|
@ -286,8 +282,6 @@ export class AddMiniMap extends DesugaringStep<LayerConfigJson> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
errors: [],
|
|
||||||
warnings: [],
|
|
||||||
result: layerConfig
|
result: layerConfig
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -384,12 +378,11 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(theme: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors: string[]; warnings: string[] } {
|
convert(theme: LayoutConfigJson, context: string): { result: LayoutConfigJson; information: string[] } {
|
||||||
const state = this._state
|
const state = this._state
|
||||||
const allKnownLayers: Map<string, LayerConfigJson> = state.sharedLayers;
|
const allKnownLayers: Map<string, LayerConfigJson> = state.sharedLayers;
|
||||||
const knownTagRenderings: Map<string, TagRenderingConfigJson> = state.tagRenderings;
|
const knownTagRenderings: Map<string, TagRenderingConfigJson> = state.tagRenderings;
|
||||||
const errors = [];
|
const information = [];
|
||||||
const warnings = [];
|
|
||||||
const layers: LayerConfigJson[] = <LayerConfigJson[]>theme.layers; // Layers should be expanded at this point
|
const layers: LayerConfigJson[] = <LayerConfigJson[]>theme.layers; // Layers should be expanded at this point
|
||||||
|
|
||||||
knownTagRenderings.forEach((value, key) => {
|
knownTagRenderings.forEach((value, key) => {
|
||||||
|
@ -399,7 +392,7 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
|
||||||
const dependencies = AddDependencyLayersToTheme.CalculateDependencies(layers, allKnownLayers, theme.id);
|
const dependencies = AddDependencyLayersToTheme.CalculateDependencies(layers, allKnownLayers, theme.id);
|
||||||
if (dependencies.length > 0) {
|
if (dependencies.length > 0) {
|
||||||
|
|
||||||
warnings.push(context + ": added " + dependencies.map(d => d.id).join(", ") + " to the theme as they are needed")
|
information.push(context + ": added " + dependencies.map(d => d.id).join(", ") + " to the theme as they are needed")
|
||||||
}
|
}
|
||||||
layers.unshift(...dependencies);
|
layers.unshift(...dependencies);
|
||||||
|
|
||||||
|
@ -408,8 +401,7 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
|
||||||
...theme,
|
...theme,
|
||||||
layers: layers
|
layers: layers
|
||||||
},
|
},
|
||||||
errors,
|
information
|
||||||
warnings
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import LayoutConfig from "../LayoutConfig";
|
||||||
import {TagRenderingConfigJson} from "../Json/TagRenderingConfigJson";
|
import {TagRenderingConfigJson} from "../Json/TagRenderingConfigJson";
|
||||||
import {TagUtils} from "../../../Logic/Tags/TagUtils";
|
import {TagUtils} from "../../../Logic/Tags/TagUtils";
|
||||||
import {ExtractImages} from "./FixImages";
|
import {ExtractImages} from "./FixImages";
|
||||||
|
import ScriptUtils from "../../../scripts/ScriptUtils";
|
||||||
|
|
||||||
|
|
||||||
class ValidateLanguageCompleteness extends DesugaringStep<any> {
|
class ValidateLanguageCompleteness extends DesugaringStep<any> {
|
||||||
|
@ -55,9 +56,10 @@ class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
|
||||||
this._isBuiltin = isBuiltin;
|
this._isBuiltin = isBuiltin;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors: string[], warnings: string[] } {
|
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors: string[], warnings: string[], information: string[] } {
|
||||||
const errors = []
|
const errors = []
|
||||||
const warnings = []
|
const warnings = []
|
||||||
|
const information = []
|
||||||
{
|
{
|
||||||
// Legacy format checks
|
// Legacy format checks
|
||||||
if (this._isBuiltin) {
|
if (this._isBuiltin) {
|
||||||
|
@ -70,7 +72,7 @@ class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// Check for remote images
|
// Check images: are they local, are the licenses there, is the theme icon square, ...
|
||||||
const images = new ExtractImages().convertStrict(json, "validation")
|
const images = new ExtractImages().convertStrict(json, "validation")
|
||||||
const remoteImages = images.filter(img => img.indexOf("http") == 0)
|
const remoteImages = images.filter(img => img.indexOf("http") == 0)
|
||||||
for (const remoteImage of remoteImages) {
|
for (const remoteImage of remoteImages) {
|
||||||
|
@ -78,7 +80,7 @@ class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
|
||||||
}
|
}
|
||||||
for (const image of images) {
|
for (const image of images) {
|
||||||
if (image.indexOf("{") >= 0) {
|
if (image.indexOf("{") >= 0) {
|
||||||
warnings.push("Ignoring image with { in the path: ", image)
|
information.push("Ignoring image with { in the path: " + image)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +98,22 @@ class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (json.icon.endsWith(".svg")) {
|
||||||
|
try {
|
||||||
|
ScriptUtils.ReadSvgSync(json.icon, svg => {
|
||||||
|
const width: string = svg.$.width;
|
||||||
|
const height: string = svg.$.height;
|
||||||
|
if (width !== height) {
|
||||||
|
const e = `the icon for theme ${json.id} is not square. Please square the icon at ${json.icon}` +
|
||||||
|
` Width = ${width} height = ${height}`;
|
||||||
|
(json.hideFromOverview ? warnings : errors).push(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Could not read " + json.icon + " due to " + e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const theme = new LayoutConfig(json, true, "test")
|
const theme = new LayoutConfig(json, true, "test")
|
||||||
|
@ -127,7 +145,8 @@ class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
|
||||||
return {
|
return {
|
||||||
result: json,
|
result: json,
|
||||||
errors,
|
errors,
|
||||||
warnings
|
warnings,
|
||||||
|
information
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,8 +344,6 @@ export class ValidateLayer extends DesugaringStep<LayerConfigJson> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
result: json,
|
result: json,
|
||||||
errors,
|
errors,
|
||||||
|
|
|
@ -126,6 +126,9 @@ export default class MoreScreen extends Combine {
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
str += allPreferences[id + "-" + i]
|
str += allPreferences[id + "-" + i]
|
||||||
}
|
}
|
||||||
|
if(str === undefined || str === "undefined"){
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const value: {
|
const value: {
|
||||||
id: string
|
id: string
|
||||||
|
@ -157,13 +160,9 @@ export default class MoreScreen extends Combine {
|
||||||
|
|
||||||
return ids
|
return ids
|
||||||
});
|
});
|
||||||
currentIds.addCallback(ids => {
|
|
||||||
console.log("Current special ids are:", ids)
|
|
||||||
})
|
|
||||||
var stableIds = UIEventSource.ListStabilized<string>(currentIds)
|
var stableIds = UIEventSource.ListStabilized<string>(currentIds)
|
||||||
currentIds.addCallback(ids => {
|
|
||||||
console.log("Stabilized special ids are:", ids)
|
|
||||||
})
|
|
||||||
return new VariableUiElement(
|
return new VariableUiElement(
|
||||||
stableIds.map(ids => {
|
stableIds.map(ids => {
|
||||||
const allThemes: BaseUIElement[] = []
|
const allThemes: BaseUIElement[] = []
|
||||||
|
|
|
@ -19,6 +19,10 @@ import {OsmConnection} from "../../Logic/Osm/OsmConnection";
|
||||||
import Translations from "../i18n/Translations";
|
import Translations from "../i18n/Translations";
|
||||||
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
|
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
|
||||||
import {Changes} from "../../Logic/Osm/Changes";
|
import {Changes} from "../../Logic/Osm/Changes";
|
||||||
|
import {UIElement} from "../UIElement";
|
||||||
|
import FilteredLayer from "../../Models/FilteredLayer";
|
||||||
|
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
||||||
|
import Lazy from "../Base/Lazy";
|
||||||
|
|
||||||
export interface AutoAction extends SpecialVisualization {
|
export interface AutoAction extends SpecialVisualization {
|
||||||
supportsAutoAction: boolean
|
supportsAutoAction: boolean
|
||||||
|
@ -29,6 +33,120 @@ export interface AutoAction extends SpecialVisualization {
|
||||||
}, tagSource: UIEventSource<any>, argument: string[]): Promise<void>
|
}, tagSource: UIEventSource<any>, argument: string[]): Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ApplyButton extends UIElement {
|
||||||
|
private readonly icon: string;
|
||||||
|
private readonly text: string;
|
||||||
|
private readonly targetTagRendering: string;
|
||||||
|
private readonly target_layer_id: string;
|
||||||
|
private readonly state: FeaturePipelineState;
|
||||||
|
private readonly target_feature_ids: string[];
|
||||||
|
private readonly buttonState = new UIEventSource<"idle" | "running" | "done" | { error: string }>("idle")
|
||||||
|
private readonly layer: FilteredLayer;
|
||||||
|
private readonly tagRenderingConfig: TagRenderingConfig;
|
||||||
|
|
||||||
|
constructor(state: FeaturePipelineState, target_feature_ids: string[], options: {
|
||||||
|
target_layer_id: string,
|
||||||
|
targetTagRendering: string,
|
||||||
|
text: string,
|
||||||
|
icon: string
|
||||||
|
}) {
|
||||||
|
super()
|
||||||
|
this.state = state;
|
||||||
|
this.target_feature_ids = target_feature_ids;
|
||||||
|
this.target_layer_id = options.target_layer_id;
|
||||||
|
this.targetTagRendering = options.targetTagRendering;
|
||||||
|
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)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
return new FixedUiElement("No elements found to perform action")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (this.tagRenderingConfig === undefined) {
|
||||||
|
return new FixedUiElement("Target tagrendering " + this.targetTagRendering + " not found").SetClass("alert")
|
||||||
|
}
|
||||||
|
const self = this;
|
||||||
|
const button = new SubtleButton(
|
||||||
|
new Img(this.icon),
|
||||||
|
this.text
|
||||||
|
).onClick(() => self.Run());
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
const previewMap = Minimap.createMiniMap({
|
||||||
|
allowMoving: false,
|
||||||
|
background: this.state.backgroundLayer,
|
||||||
|
addLayerControl: true,
|
||||||
|
}).SetClass("h-48")
|
||||||
|
|
||||||
|
const features = this.target_feature_ids.map(id => this.state.allElements.ContainingFeatures.get(id))
|
||||||
|
|
||||||
|
new ShowDataLayer({
|
||||||
|
leafletMap: previewMap.leafletMap,
|
||||||
|
popup: undefined,
|
||||||
|
zoomToFeatures: true,
|
||||||
|
features: new StaticFeatureSource(features, false),
|
||||||
|
state: this.state,
|
||||||
|
layerToShow:this. layer.layerDef,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
return new VariableUiElement(this.buttonState.map(
|
||||||
|
st => {
|
||||||
|
if (st === "idle") {
|
||||||
|
return new Combine([button, previewMap, explanation]);
|
||||||
|
}
|
||||||
|
if (st === "done") {
|
||||||
|
return new FixedUiElement("All done!").SetClass("thanks")
|
||||||
|
}
|
||||||
|
if (st === "running") {
|
||||||
|
return new Loading("Applying changes...")
|
||||||
|
}
|
||||||
|
const error = st.error
|
||||||
|
return new Combine([new FixedUiElement("Something went wrong...").SetClass("alert"), new FixedUiElement(error).SetClass("subtle")]).SetClass("flex flex-col")
|
||||||
|
}
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export default class AutoApplyButton implements SpecialVisualization {
|
export default class AutoApplyButton implements SpecialVisualization {
|
||||||
public readonly docs: string;
|
public readonly docs: string;
|
||||||
public readonly funcName: string = "auto_apply";
|
public readonly funcName: string = "auto_apply";
|
||||||
|
@ -72,109 +190,44 @@ export default class AutoApplyButton implements SpecialVisualization {
|
||||||
}
|
}
|
||||||
|
|
||||||
constr(state: FeaturePipelineState, tagSource: UIEventSource<any>, argument: string[], guistate: DefaultGuiState): BaseUIElement {
|
constr(state: FeaturePipelineState, tagSource: UIEventSource<any>, argument: string[], guistate: DefaultGuiState): BaseUIElement {
|
||||||
|
try {
|
||||||
|
|
||||||
if (!state.layoutToUse.official && !(state.featureSwitchIsTesting.data || state.osmConnection._oauth_config.url === OsmConnection.oauth_configs["osm-test"].url)) {
|
if (!state.layoutToUse.official && !(state.featureSwitchIsTesting.data || state.osmConnection._oauth_config.url === OsmConnection.oauth_configs["osm-test"].url)) {
|
||||||
const t = Translations.t.general.add.import;
|
const t = Translations.t.general.add.import;
|
||||||
return new Combine([new FixedUiElement("The auto-apply button is only available in official themes (or in testing mode)").SetClass("alert"), t.howToTest])
|
return new Combine([new FixedUiElement("The auto-apply button is only available in official themes (or in testing mode)").SetClass("alert"), t.howToTest])
|
||||||
}
|
}
|
||||||
|
|
||||||
const to_parse = tagSource.data[argument[1]]
|
|
||||||
if (to_parse === undefined) {
|
|
||||||
return new Loading("Gathering which elements support auto-apply... ")
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
|
|
||||||
|
|
||||||
const target_layer_id = argument[0]
|
const target_layer_id = argument[0]
|
||||||
const target_feature_ids = <string[]>JSON.parse(to_parse)
|
|
||||||
|
|
||||||
if (target_feature_ids.length === 0) {
|
|
||||||
return new FixedUiElement("No elements found to perform action")
|
|
||||||
}
|
|
||||||
|
|
||||||
const targetTagRendering = argument[2]
|
const targetTagRendering = argument[2]
|
||||||
const text = argument[3]
|
const text = argument[3]
|
||||||
const icon = argument[4]
|
const icon = argument[4]
|
||||||
|
const options = {
|
||||||
const layer = state.filteredLayers.data.filter(l => l.layerDef.id === target_layer_id)[0]
|
target_layer_id, targetTagRendering, text, icon
|
||||||
|
|
||||||
const tagRenderingConfig = layer.layerDef.tagRenderings.filter(tr => tr.id === targetTagRendering)[0]
|
|
||||||
|
|
||||||
if (tagRenderingConfig === undefined) {
|
|
||||||
return new FixedUiElement("Target tagrendering " + targetTagRendering + " not found").SetClass("alert")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const buttonState = new UIEventSource<"idle" | "running" | "done" | { error: string }>("idle")
|
return new Lazy(() => {
|
||||||
|
const to_parse = new UIEventSource(undefined)
|
||||||
|
// Very ugly hack: read the value every 500ms
|
||||||
|
UIEventSource.Chronic(500, () => to_parse.data === undefined).addCallback(() => {
|
||||||
|
const applicable = tagSource.data[argument[1]]
|
||||||
|
console.log("Current applicable value is: ", applicable)
|
||||||
|
to_parse.setData(applicable)
|
||||||
|
})
|
||||||
|
|
||||||
const button = new SubtleButton(
|
const loading = new Loading("Gathering which elements support auto-apply... ");
|
||||||
new Img(icon),
|
return new VariableUiElement(to_parse.map(ids => {
|
||||||
text
|
if(ids === undefined){
|
||||||
).onClick(async () => {
|
return loading
|
||||||
buttonState.setData("running")
|
|
||||||
try {
|
|
||||||
|
|
||||||
|
|
||||||
for (const targetFeatureId of target_feature_ids) {
|
|
||||||
const featureTags = state.allElements.getEventSourceById(targetFeatureId)
|
|
||||||
const rendering = tagRenderingConfig.GetRenderValue(featureTags.data).txt
|
|
||||||
const specialRenderings = Utils.NoNull(SubstitutedTranslation.ExtractSpecialComponents(rendering)
|
|
||||||
.map(x => x.special))
|
|
||||||
.filter(v => v.func["supportsAutoAction"] === true)
|
|
||||||
|
|
||||||
for (const specialRendering of specialRenderings) {
|
|
||||||
const action = <AutoAction>specialRendering.func
|
|
||||||
await action.applyActionOn(state, featureTags, specialRendering.args)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
console.log("Flushing changes...")
|
|
||||||
await state.changes.flushChanges("Auto button")
|
|
||||||
buttonState.setData("done")
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Error while running autoApply: ", e)
|
|
||||||
buttonState.setData({error: e})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const explanation = new Combine(["The following objects will be updated: ",
|
return new ApplyButton(state, JSON.parse(ids), options);
|
||||||
...target_feature_ids.map(id => new Combine([new Link(id, "https:/ /openstreetmap.org/" + id, true), ", "]))]).SetClass("subtle")
|
}))
|
||||||
|
|
||||||
const previewMap = Minimap.createMiniMap({
|
|
||||||
allowMoving: false,
|
|
||||||
background: state.backgroundLayer,
|
|
||||||
addLayerControl: true,
|
|
||||||
}).SetClass("h-48")
|
|
||||||
|
|
||||||
const features = target_feature_ids.map(id => state.allElements.ContainingFeatures.get(id))
|
|
||||||
|
|
||||||
new ShowDataLayer({
|
|
||||||
leafletMap: previewMap.leafletMap,
|
|
||||||
popup: undefined,
|
|
||||||
zoomToFeatures: true,
|
|
||||||
features: new StaticFeatureSource(features, false),
|
|
||||||
state,
|
|
||||||
layerToShow: layer.layerDef,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
return new VariableUiElement(buttonState.map(
|
|
||||||
st => {
|
|
||||||
if (st === "idle") {
|
|
||||||
return new Combine([button, previewMap, explanation]);
|
|
||||||
}
|
|
||||||
if (st === "done") {
|
|
||||||
return new FixedUiElement("All done!").SetClass("thanks")
|
|
||||||
}
|
|
||||||
if (st === "running") {
|
|
||||||
return new Loading("Applying changes...")
|
|
||||||
}
|
|
||||||
const error = st.error
|
|
||||||
return new Combine([new FixedUiElement("Something went wrong...").SetClass("alert"), new FixedUiElement(error).SetClass("subtle")]).SetClass("flex flex-col")
|
|
||||||
}
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("To parse is", to_parse)
|
|
||||||
return new FixedUiElement("Could not generate a auto_apply-button for key " + argument[0] + " due to " + e).SetClass("alert")
|
return new FixedUiElement("Could not generate a auto_apply-button for key " + argument[0] + " due to " + e).SetClass("alert")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ export default class EditableTagRendering extends Toggle {
|
||||||
const editMode = options.editMode ?? new UIEventSource<boolean>(false)
|
const editMode = options.editMode ?? new UIEventSource<boolean>(false)
|
||||||
let rendering = EditableTagRendering.CreateRendering(state, tags, configuration, units, editMode);
|
let rendering = EditableTagRendering.CreateRendering(state, tags, configuration, units, editMode);
|
||||||
rendering.SetClass(options.innerElementClasses)
|
rendering.SetClass(options.innerElementClasses)
|
||||||
if(state.featureSwitchIsDebugging.data){
|
if(state.featureSwitchIsDebugging.data || state.featureSwitchIsTesting.data){
|
||||||
rendering = new Combine([
|
rendering = new Combine([
|
||||||
new FixedUiElement(configuration.id).SetClass("self-end subtle"),
|
new FixedUiElement(configuration.id).SetClass("self-end subtle"),
|
||||||
rendering
|
rendering
|
||||||
|
|
|
@ -21,7 +21,7 @@ import ShowDataLayer from "../ShowDataLayer/ShowDataLayer";
|
||||||
import StaticFeatureSource from "../../Logic/FeatureSource/Sources/StaticFeatureSource";
|
import StaticFeatureSource from "../../Logic/FeatureSource/Sources/StaticFeatureSource";
|
||||||
import ShowDataMultiLayer from "../ShowDataLayer/ShowDataMultiLayer";
|
import ShowDataMultiLayer from "../ShowDataLayer/ShowDataMultiLayer";
|
||||||
import CreateWayWithPointReuseAction, {MergePointConfig} from "../../Logic/Osm/Actions/CreateWayWithPointReuseAction";
|
import CreateWayWithPointReuseAction, {MergePointConfig} from "../../Logic/Osm/Actions/CreateWayWithPointReuseAction";
|
||||||
import OsmChangeAction, {OsmCreateAction} from "../../Logic/Osm/Actions/OsmChangeAction";
|
import OsmChangeAction from "../../Logic/Osm/Actions/OsmChangeAction";
|
||||||
import FeatureSource from "../../Logic/FeatureSource/FeatureSource";
|
import FeatureSource from "../../Logic/FeatureSource/FeatureSource";
|
||||||
import {OsmObject, OsmWay} from "../../Logic/Osm/OsmObject";
|
import {OsmObject, OsmWay} from "../../Logic/Osm/OsmObject";
|
||||||
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState";
|
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState";
|
||||||
|
@ -37,12 +37,17 @@ import LayerConfig from "../../Models/ThemeConfig/LayerConfig";
|
||||||
import * as conflation_json from "../../assets/layers/conflation/conflation.json";
|
import * as conflation_json from "../../assets/layers/conflation/conflation.json";
|
||||||
import {GeoOperations} from "../../Logic/GeoOperations";
|
import {GeoOperations} from "../../Logic/GeoOperations";
|
||||||
import {LoginToggle} from "./LoginButton";
|
import {LoginToggle} from "./LoginButton";
|
||||||
|
import {AutoAction} from "./AutoApplyButton";
|
||||||
|
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
|
||||||
|
import {Changes} from "../../Logic/Osm/Changes";
|
||||||
|
import {ElementStorage} from "../../Logic/ElementStorage";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper class for the various import-flows.
|
* A helper class for the various import-flows.
|
||||||
* An import-flow always starts with a 'Import this'-button. Upon click, a custom confirmation panel is provided
|
* An import-flow always starts with a 'Import this'-button. Upon click, a custom confirmation panel is provided
|
||||||
*/
|
*/
|
||||||
abstract class AbstractImportButton implements SpecialVisualizations {
|
abstract class AbstractImportButton implements SpecialVisualizations {
|
||||||
|
protected static importedIds = new Set<string>()
|
||||||
public readonly funcName: string
|
public readonly funcName: string
|
||||||
public readonly docs: string
|
public readonly docs: string
|
||||||
public readonly args: { name: string, defaultValue?: string, doc: string }[]
|
public readonly args: { name: string, defaultValue?: string, doc: string }[]
|
||||||
|
@ -157,7 +162,10 @@ ${Utils.special_visualizations_importRequirementDocs}
|
||||||
state.featureSwitchUserbadge)
|
state.featureSwitchUserbadge)
|
||||||
|
|
||||||
|
|
||||||
const isImported = tagSource.map(tags => tags._imported === "yes")
|
const isImported = tagSource.map(tags => {
|
||||||
|
AbstractImportButton.importedIds.add(tags.id)
|
||||||
|
return tags._imported === "yes";
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
/**** THe actual panel showing the import guiding map ****/
|
/**** THe actual panel showing the import guiding map ****/
|
||||||
|
@ -269,7 +277,7 @@ ${Utils.special_visualizations_importRequirementDocs}
|
||||||
return new Combine([confirmationMap, confirmButton, cancel]).SetClass("flex flex-col")
|
return new Combine([confirmationMap, confirmButton, cancel]).SetClass("flex flex-col")
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseArgs(argsRaw: string[], originalFeatureTags: UIEventSource<any>): { minzoom: string, max_snap_distance: string, snap_onto_layers: string, icon: string, text: string, tags: string, targetLayer: string, newTags: UIEventSource<Tag[]> } {
|
protected parseArgs(argsRaw: string[], originalFeatureTags: UIEventSource<any>): { minzoom: string, max_snap_distance: string, snap_onto_layers: string, icon: string, text: string, tags: string, targetLayer: string, newTags: UIEventSource<Tag[]> } {
|
||||||
const baseArgs = Utils.ParseVisArgs(this.args, argsRaw)
|
const baseArgs = Utils.ParseVisArgs(this.args, argsRaw)
|
||||||
if (originalFeatureTags !== undefined) {
|
if (originalFeatureTags !== undefined) {
|
||||||
|
|
||||||
|
@ -351,7 +359,8 @@ export class ConflateButton extends AbstractImportButton {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ImportWayButton extends AbstractImportButton {
|
export class ImportWayButton extends AbstractImportButton implements AutoAction {
|
||||||
|
public readonly supportsAutoAction = true;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super("import_way_button",
|
super("import_way_button",
|
||||||
|
@ -386,6 +395,39 @@ export class ImportWayButton extends AbstractImportButton {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async applyActionOn(state: { layoutToUse: LayoutConfig; changes: Changes, allElements: ElementStorage },
|
||||||
|
originalFeatureTags: UIEventSource<any>,
|
||||||
|
argument: string[]): Promise<void> {
|
||||||
|
const id = originalFeatureTags.data.id;
|
||||||
|
if (AbstractImportButton.importedIds.has(originalFeatureTags.data.id)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AbstractImportButton.importedIds.add(originalFeatureTags.data.id)
|
||||||
|
const args = this.parseArgs(argument, originalFeatureTags)
|
||||||
|
const feature = state.allElements.ContainingFeatures.get(id)
|
||||||
|
console.log("Geometry to auto-import is:", feature)
|
||||||
|
const geom = feature.geometry
|
||||||
|
let coordinates: [number, number][]
|
||||||
|
if (geom.type === "LineString") {
|
||||||
|
coordinates = geom.coordinates
|
||||||
|
} else if (geom.type === "Polygon") {
|
||||||
|
coordinates = geom.coordinates[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const mergeConfigs = this.GetMergeConfig(args);
|
||||||
|
|
||||||
|
const action = this.CreateAction(
|
||||||
|
feature,
|
||||||
|
args,
|
||||||
|
<FeaturePipelineState>state,
|
||||||
|
mergeConfigs,
|
||||||
|
coordinates
|
||||||
|
)
|
||||||
|
await state.changes.applyAction(action)
|
||||||
|
}
|
||||||
|
|
||||||
canBeImported(feature: any) {
|
canBeImported(feature: any) {
|
||||||
const type = feature.geometry.type
|
const type = feature.geometry.type
|
||||||
return type === "LineString" || type === "Polygon"
|
return type === "LineString" || type === "Polygon"
|
||||||
|
@ -420,7 +462,24 @@ export class ImportWayButton extends AbstractImportButton {
|
||||||
} else if (geom.type === "Polygon") {
|
} else if (geom.type === "Polygon") {
|
||||||
coordinates = geom.coordinates[0]
|
coordinates = geom.coordinates[0]
|
||||||
}
|
}
|
||||||
|
const mergeConfigs = this.GetMergeConfig(args);
|
||||||
|
|
||||||
|
|
||||||
|
let action = this.CreateAction(feature, args, state, mergeConfigs, coordinates);
|
||||||
|
|
||||||
|
return this.createConfirmPanelForWay(
|
||||||
|
state,
|
||||||
|
args,
|
||||||
|
feature,
|
||||||
|
originalFeatureTags,
|
||||||
|
action,
|
||||||
|
onCancel
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private GetMergeConfig(args: { max_snap_distance: string; snap_onto_layers: string; icon: string; text: string; tags: string; newTags: UIEventSource<any>; targetLayer: string })
|
||||||
|
: MergePointConfig[] {
|
||||||
const nodesMustMatch = args["snap_to_point_if"]?.split(";")?.map((tag, i) => TagUtils.Tag(tag, "TagsSpec for import button " + i))
|
const nodesMustMatch = args["snap_to_point_if"]?.split(";")?.map((tag, i) => TagUtils.Tag(tag, "TagsSpec for import button " + i))
|
||||||
|
|
||||||
const mergeConfigs = []
|
const mergeConfigs = []
|
||||||
|
@ -446,14 +505,21 @@ export class ImportWayButton extends AbstractImportButton {
|
||||||
mergeConfigs.push(mergeConfig)
|
mergeConfigs.push(mergeConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
let action: OsmCreateAction & { getPreview(): Promise<FeatureSource> };
|
return mergeConfigs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CreateAction(feature,
|
||||||
|
args: { max_snap_distance: string; snap_onto_layers: string; icon: string; text: string; tags: string; newTags: UIEventSource<any>; targetLayer: string },
|
||||||
|
state: FeaturePipelineState,
|
||||||
|
mergeConfigs: any[],
|
||||||
|
coordinates: [number, number][]) {
|
||||||
|
|
||||||
const coors = feature.geometry.coordinates
|
const coors = feature.geometry.coordinates
|
||||||
if (feature.geometry.type === "Polygon" && coors.length > 1) {
|
if (feature.geometry.type === "Polygon" && coors.length > 1) {
|
||||||
const outer = coors[0]
|
const outer = coors[0]
|
||||||
const inner = [...coors]
|
const inner = [...coors]
|
||||||
inner.splice(0, 1)
|
inner.splice(0, 1)
|
||||||
action = new CreateMultiPolygonWithPointReuseAction(
|
return new CreateMultiPolygonWithPointReuseAction(
|
||||||
args.newTags.data,
|
args.newTags.data,
|
||||||
outer,
|
outer,
|
||||||
inner,
|
inner,
|
||||||
|
@ -463,24 +529,13 @@ export class ImportWayButton extends AbstractImportButton {
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
action = new CreateWayWithPointReuseAction(
|
return new CreateWayWithPointReuseAction(
|
||||||
args.newTags.data,
|
args.newTags.data,
|
||||||
coordinates,
|
coordinates,
|
||||||
state,
|
state,
|
||||||
mergeConfigs
|
mergeConfigs
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return this.createConfirmPanelForWay(
|
|
||||||
state,
|
|
||||||
args,
|
|
||||||
feature,
|
|
||||||
originalFeatureTags,
|
|
||||||
action,
|
|
||||||
onCancel
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ export default class NoteCommentElement extends Combine {
|
||||||
} else if (comment.action === "closed") {
|
} else if (comment.action === "closed") {
|
||||||
actionIcon = Svg.resolved_svg()
|
actionIcon = Svg.resolved_svg()
|
||||||
} else {
|
} else {
|
||||||
actionIcon = Svg.addSmall_svg()
|
actionIcon = Svg.speech_bubble_svg()
|
||||||
}
|
}
|
||||||
|
|
||||||
let user: BaseUIElement
|
let user: BaseUIElement
|
||||||
|
|
|
@ -534,7 +534,7 @@ export default class SpecialVisualizations {
|
||||||
funcName: "multi_apply",
|
funcName: "multi_apply",
|
||||||
docs: "A button to apply the tagging of this object onto a list of other features. This is an advanced feature for which you'll need calculatedTags",
|
docs: "A button to apply the tagging of this object onto a list of other features. This is an advanced feature for which you'll need calculatedTags",
|
||||||
args: [
|
args: [
|
||||||
{name: "feature_ids", doc: "A JSOn-serialized list of IDs of features to apply the tagging on"},
|
{name: "feature_ids", doc: "A JSON-serialized list of IDs of features to apply the tagging on"},
|
||||||
{
|
{
|
||||||
name: "keys",
|
name: "keys",
|
||||||
doc: "One key (or multiple keys, seperated by ';') of the attribute that should be copied onto the other features."
|
doc: "One key (or multiple keys, seperated by ';') of the attribute that should be copied onto the other features."
|
||||||
|
@ -725,7 +725,7 @@ export default class SpecialVisualizations {
|
||||||
textField.SetClass("rounded-l border border-grey")
|
textField.SetClass("rounded-l border border-grey")
|
||||||
const txt = textField.GetValue()
|
const txt = textField.GetValue()
|
||||||
|
|
||||||
const addCommentButton = new SubtleButton(Svg.addSmall_svg().SetClass("max-h-7"), t.addCommentPlaceholder)
|
const addCommentButton = new SubtleButton(Svg.speech_bubble_svg().SetClass("max-h-7"), t.addCommentPlaceholder)
|
||||||
.onClick(async () => {
|
.onClick(async () => {
|
||||||
const id = tags.data[args[1] ?? "id"]
|
const id = tags.data[args[1] ?? "id"]
|
||||||
|
|
||||||
|
@ -778,7 +778,9 @@ export default class SpecialVisualizations {
|
||||||
new Combine([
|
new Combine([
|
||||||
new Title("Add a comment"),
|
new Title("Add a comment"),
|
||||||
textField,
|
textField,
|
||||||
new Combine([addCommentButton.SetClass("mr-2"), stateButtons]).SetClass("flex justify-end")
|
new Combine([
|
||||||
|
new Toggle(addCommentButton, undefined, textField.GetValue().map(t => t !==undefined && t.length > 1)).SetClass("mr-2")
|
||||||
|
, stateButtons]).SetClass("flex justify-end")
|
||||||
]).SetClass("border-2 border-black rounded-xl p-4 block"),
|
]).SetClass("border-2 border-black rounded-xl p-4 block"),
|
||||||
t.loginToAddComment, state)
|
t.loginToAddComment, state)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
"hu": "Ez a sablon a flandriai GRB épületimportálás automatizlását kívánja megkönnyíteni."
|
"hu": "Ez a sablon a flandriai GRB épületimportálás automatizlását kívánja megkönnyíteni."
|
||||||
},
|
},
|
||||||
"maintainer": "",
|
"maintainer": "",
|
||||||
"icon": "./assets/themes/grb_import/housenumber_blank.svg",
|
"icon": "./assets/themes/grb_import/logo.svg",
|
||||||
"version": "0",
|
"version": "0",
|
||||||
"startLat": 51.0249,
|
"startLat": 51.0249,
|
||||||
"startLon": 4.026489,
|
"startLon": 4.026489,
|
||||||
|
@ -447,7 +447,7 @@
|
||||||
"title": "GRB outline",
|
"title": "GRB outline",
|
||||||
"calculatedTags": [
|
"calculatedTags": [
|
||||||
"_overlaps_with_buildings=feat.overlapWith('osm-buildings').filter(f => f.feat.properties.id.indexOf('-') < 0)",
|
"_overlaps_with_buildings=feat.overlapWith('osm-buildings').filter(f => f.feat.properties.id.indexOf('-') < 0)",
|
||||||
"_overlaps_with=feat.get('_overlaps_with_buildings').filter(f => f.overlap > 1 /* square meter */ )[0] ?? ''",
|
"_overlaps_with=feat.get('_overlaps_with_buildings').find(f => f.overlap > 1 /* square meter */ )",
|
||||||
"_osm_obj:source:ref=feat.get('_overlaps_with')?.feat?.properties['source:geometry:ref']",
|
"_osm_obj:source:ref=feat.get('_overlaps_with')?.feat?.properties['source:geometry:ref']",
|
||||||
"_osm_obj:id=feat.get('_overlaps_with')?.feat?.properties?.id",
|
"_osm_obj:id=feat.get('_overlaps_with')?.feat?.properties?.id",
|
||||||
"_osm_obj:source:date=feat.get('_overlaps_with')?.feat?.properties['source:geometry:date'].replace(/\\//g, '-')",
|
"_osm_obj:source:date=feat.get('_overlaps_with')?.feat?.properties['source:geometry:date'].replace(/\\//g, '-')",
|
||||||
|
@ -650,6 +650,59 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"builtin": "current_view",
|
||||||
|
"override": {
|
||||||
|
"calculatedTags": [
|
||||||
|
"_overlapping=Number(feat.properties.zoom) >= 16 ? feat.overlapWith('grb').map(ff => ff.feat.properties) : undefined",
|
||||||
|
"_applicable=feat.get('_overlapping')?.filter(p => (p._imported_osm_object_found !== 'true' && p._intersects_with_other_features === ''))?.map(p => p.id)",
|
||||||
|
"_applicable_count=feat.get('_applicable')?.length"
|
||||||
|
],
|
||||||
|
"tagRenderings": [
|
||||||
|
{
|
||||||
|
"id": "hw",
|
||||||
|
"render": "There are {_applicable_count} applicable elements in view",
|
||||||
|
"mappings": [
|
||||||
|
{
|
||||||
|
"if": "zoom<14",
|
||||||
|
"then": "Zoom in more to see the automatic action"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"if": "_applicable_count=",
|
||||||
|
"then": "Loading..."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"if": "_applicable_count=0",
|
||||||
|
"then": "No importable buildins in view"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "autoapply",
|
||||||
|
"render": "{auto_apply(grb, _applicable, Import-button, Import or conflate all non-conflicting buildings in view)}",
|
||||||
|
"mappings": [
|
||||||
|
{
|
||||||
|
"if": "zoom<16",
|
||||||
|
"then": "Zoom in more to import"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"+mapRendering": [
|
||||||
|
{
|
||||||
|
"location": [
|
||||||
|
"point"
|
||||||
|
],
|
||||||
|
"icon": {
|
||||||
|
"render": "./assets/svg/robot.svg"
|
||||||
|
},
|
||||||
|
"iconSize": "15,15,center"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"hideFromOverview": true,
|
"hideFromOverview": true,
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
"builtin": "crab_address",
|
"builtin": "crab_address",
|
||||||
"override": {
|
"override": {
|
||||||
"source": {
|
"source": {
|
||||||
"geoJson": "http://127.0.0.1:8080/tile_{z}_{x}_{y}.geojson",
|
"geoJson": "https://raw.githubusercontent.com/pietervdvn/MapComplete-data/main/CRAB_2021_10_26/tile_{z}_{x}_{y}.geojson",
|
||||||
"geoJsonZoomLevel": 18
|
"geoJsonZoomLevel": 18
|
||||||
},
|
},
|
||||||
"mapRendering": [
|
"mapRendering": [
|
||||||
|
@ -135,7 +135,6 @@
|
||||||
"tagRenderings": [
|
"tagRenderings": [
|
||||||
{
|
{
|
||||||
"id": "apply_streetname",
|
"id": "apply_streetname",
|
||||||
"group": "auto",
|
|
||||||
"render": "{tag_apply(addr:street=$_name_to_apply ,Apply the CRAB-street onto this building)}",
|
"render": "{tag_apply(addr:street=$_name_to_apply ,Apply the CRAB-street onto this building)}",
|
||||||
"mappings": [
|
"mappings": [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue