forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
94c61744c0
commit
04c8ccb0d2
89 changed files with 2353 additions and 1390 deletions
|
|
@ -69,15 +69,13 @@ export class AvailableRasterLayers {
|
|||
console.log("Invalid layers:", JSON.stringify(joined.filter((l) => !l.id)))
|
||||
throw "Detected invalid global layer with invalid id"
|
||||
}
|
||||
return joined.map(
|
||||
(properties) => {
|
||||
return <RasterLayerPolygon>{
|
||||
type: "Feature",
|
||||
properties,
|
||||
geometry: BBox.global.asGeometry(),
|
||||
}
|
||||
return joined.map((properties) => {
|
||||
return <RasterLayerPolygon>{
|
||||
type: "Feature",
|
||||
properties,
|
||||
geometry: BBox.global.asGeometry(),
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -170,7 +170,10 @@ class DetectInline extends DesugaringStep<QuestionableTagRenderingConfigJson> {
|
|||
|
||||
export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
||||
constructor() {
|
||||
super("AddQuestionBox", "Adds a 'questions'-object if no question element is added yet. Will ignore all elements which were previously asked for (and questions labeled with 'hidden')")
|
||||
super(
|
||||
"AddQuestionBox",
|
||||
"Adds a 'questions'-object if no question element is added yet. Will ignore all elements which were previously asked for (and questions labeled with 'hidden')"
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -210,14 +213,12 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
(sp) => sp.args.length === 0 || sp.args[0].trim() === ""
|
||||
)
|
||||
|
||||
|
||||
if (noLabels.length > 1) {
|
||||
context.err(
|
||||
"Multiple 'questions'-visualisations found which would show _all_ questions. Don't do this - questions will be shown twice. Did you perhaps import all questions from another layer?",
|
||||
"Multiple 'questions'-visualisations found which would show _all_ questions. Don't do this - questions will be shown twice. Did you perhaps import all questions from another layer?"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* We want to construct a questionbox that shows all leftover questions.
|
||||
* For this, we need to determine what those leftover questions _are_ in the first place.
|
||||
|
|
@ -227,14 +228,14 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
|
||||
// ALl labels that are used in this layer
|
||||
const allLabels = new Set(
|
||||
json.tagRenderings.flatMap(
|
||||
(tr) => (<QuestionableTagRenderingConfigJson>tr).labels ?? []
|
||||
)
|
||||
json.tagRenderings.flatMap(
|
||||
(tr) => (<QuestionableTagRenderingConfigJson>tr).labels ?? []
|
||||
)
|
||||
)
|
||||
/**
|
||||
* The essence of all questionboxes: what is whitelisted, what is blacklisted?
|
||||
*/
|
||||
const questionBoxes: { blacklist: string[], whitelist: string[] }[] = []
|
||||
const questionBoxes: { blacklist: string[]; whitelist: string[] }[] = []
|
||||
for (const questionSpecial of questionSpecials) {
|
||||
if (typeof questionSpecial === "string") {
|
||||
// Probably a header or something
|
||||
|
|
@ -273,7 +274,7 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
for (const { blacklist, whitelist } of questionBoxes) {
|
||||
if (whitelist.length > 0 && blacklist.length == 0) {
|
||||
// All questions from "whitelist" are guaranteed to be used here
|
||||
whitelist.forEach(label => usedLabels.add(label))
|
||||
whitelist.forEach((label) => usedLabels.add(label))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -281,12 +282,14 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
* Can we say that the whitelisted items are fully consumed?
|
||||
*/
|
||||
let needsEvaluation = true
|
||||
let toEvaluate = questionBoxes.filter(q => q.whitelist.length > 0 && q.blacklist.length > 0)
|
||||
let toEvaluate = questionBoxes.filter(
|
||||
(q) => q.whitelist.length > 0 && q.blacklist.length > 0
|
||||
)
|
||||
while (needsEvaluation && toEvaluate.length > 0) {
|
||||
needsEvaluation = false
|
||||
const toReEvaluate = []
|
||||
for (const { blacklist, whitelist } of toEvaluate) {
|
||||
const blacklistRest = blacklist.filter(label => !usedLabels.has(label))
|
||||
const blacklistRest = blacklist.filter((label) => !usedLabels.has(label))
|
||||
if (blacklistRest.length == 0) {
|
||||
// All items from the blacklist have been handled by a different questionbox
|
||||
// We can safely say that all whitelisted items are consumed
|
||||
|
|
@ -294,7 +297,7 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
// Even better: this questionbox will show all leftover questions
|
||||
return json
|
||||
}
|
||||
whitelist.forEach(label => {
|
||||
whitelist.forEach((label) => {
|
||||
usedLabels.add(label)
|
||||
})
|
||||
needsEvaluation = true
|
||||
|
|
@ -312,11 +315,12 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
|
||||
context.err(
|
||||
"Could not calculate a non-ambiguous leftover questions block. A {questions()}-special rendering is found which has both a whitelist and a blacklist; where the blacklist was not fully consumed by other tagRenderings\n\t" +
|
||||
JSON.stringify(toEvaluate)+"\n\tConsumed labels are: "+Array.from(usedLabels).join(", "),
|
||||
JSON.stringify(toEvaluate) +
|
||||
"\n\tConsumed labels are: " +
|
||||
Array.from(usedLabels).join(", ")
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/* At this point, we know which question labels are not yet handled and which already are handled, and we
|
||||
* know there is no previous catch-all questions
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -6,17 +6,24 @@ import SpecialVisualizations from "../../UI/SpecialVisualizations"
|
|||
import { LayerConfigJson } from "./Json/LayerConfigJson"
|
||||
|
||||
export default class DependencyCalculator {
|
||||
|
||||
/**
|
||||
* For every tagRendering in the listed layers, determines in what layers they end up
|
||||
*/
|
||||
public static tagRenderingImportedBy(questionedLayer: LayerConfig, layers: LayerConfig[]): Map<string, {
|
||||
layer: string
|
||||
}[]> {
|
||||
public static tagRenderingImportedBy(
|
||||
questionedLayer: LayerConfig,
|
||||
layers: LayerConfig[]
|
||||
): Map<
|
||||
string,
|
||||
{
|
||||
layer: string
|
||||
}[]
|
||||
> {
|
||||
const result: Map<string, { layer: string }[]> = new Map()
|
||||
|
||||
for (const layer of layers) {
|
||||
const hasRightContext = layer.tagRenderings.filter(tr => tr._definedIn !== undefined && tr?._definedIn?.[0] === questionedLayer.id)
|
||||
const hasRightContext = layer.tagRenderings.filter(
|
||||
(tr) => tr._definedIn !== undefined && tr?._definedIn?.[0] === questionedLayer.id
|
||||
)
|
||||
for (const tr of hasRightContext) {
|
||||
const id = tr._definedIn[1]
|
||||
if (!result.has(id)) {
|
||||
|
|
|
|||
|
|
@ -438,17 +438,23 @@ export default class LayerConfig extends WithContextLoader {
|
|||
)
|
||||
}
|
||||
|
||||
public generateDocumentation(
|
||||
{ usedInThemes = [], layerIsNeededBy, dependencies = [], addedByDefault = false, canBeIncluded = true, lang = "en", reusedTagRenderings }: {
|
||||
usedInThemes?: string[],
|
||||
layerIsNeededBy?: Map<string, string[]>,
|
||||
dependencies?: { context?: string; reason: string; neededLayer: string }[],
|
||||
addedByDefault?: boolean,
|
||||
canBeIncluded?: boolean,
|
||||
reusedTagRenderings?: Map<string, {layer: string}[]>,
|
||||
lang?: string
|
||||
}
|
||||
): string {
|
||||
public generateDocumentation({
|
||||
usedInThemes = [],
|
||||
layerIsNeededBy,
|
||||
dependencies = [],
|
||||
addedByDefault = false,
|
||||
canBeIncluded = true,
|
||||
lang = "en",
|
||||
reusedTagRenderings,
|
||||
}: {
|
||||
usedInThemes?: string[]
|
||||
layerIsNeededBy?: Map<string, string[]>
|
||||
dependencies?: { context?: string; reason: string; neededLayer: string }[]
|
||||
addedByDefault?: boolean
|
||||
canBeIncluded?: boolean
|
||||
reusedTagRenderings?: Map<string, { layer: string }[]>
|
||||
lang?: string
|
||||
}): string {
|
||||
const extraProps: string[] = []
|
||||
extraProps.push("This layer is shown at zoomlevel **" + this.minzoom + "** and higher")
|
||||
|
||||
|
|
@ -669,7 +675,12 @@ export default class LayerConfig extends WithContextLoader {
|
|||
this.generateDocumentationQuickTable(),
|
||||
...this.tagRenderings
|
||||
.filter((tr) => tr.labels.indexOf("ignore_docs") < 0)
|
||||
.map((tr) => tr.generateDocumentation(lang, reusedTagRenderings?.get(tr.id)?.map(l => l.layer))),
|
||||
.map((tr) =>
|
||||
tr.generateDocumentation(
|
||||
lang,
|
||||
reusedTagRenderings?.get(tr.id)?.map((l) => l.layer)
|
||||
)
|
||||
),
|
||||
...filterDocs,
|
||||
].join("\n\n")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1020,10 +1020,11 @@ export default class TagRenderingConfig {
|
|||
...this.labels.map((label) => "`" + label + "`"),
|
||||
].join(" ")
|
||||
}
|
||||
let reuse : string = undefined
|
||||
if(usedInLayers?.length > 0){
|
||||
reuse = [`This tagRendering is used in ${usedInLayers.length} layers:`,
|
||||
...usedInLayers.map(l => `[${l}](./Layers/${l}.md)`)
|
||||
let reuse: string = undefined
|
||||
if (usedInLayers?.length > 0) {
|
||||
reuse = [
|
||||
`This tagRendering is used in ${usedInLayers.length} layers:`,
|
||||
...usedInLayers.map((l) => `[${l}](./Layers/${l}.md)`),
|
||||
].join(" ")
|
||||
}
|
||||
|
||||
|
|
@ -1038,7 +1039,7 @@ export default class TagRenderingConfig {
|
|||
condition,
|
||||
labels,
|
||||
"",
|
||||
reuse
|
||||
reuse,
|
||||
]).join("\n")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,8 +131,9 @@ export class WithLayoutSourceState extends WithSelectedElementState {
|
|||
|
||||
protected setSelectedElement(feature: Feature) {
|
||||
// The given feature might be a partial one from the cache
|
||||
if(feature !== undefined){
|
||||
feature = this.indexedFeatures.featuresById.data?.get(feature?.properties?.id) ?? feature
|
||||
if (feature !== undefined) {
|
||||
feature =
|
||||
this.indexedFeatures.featuresById.data?.get(feature?.properties?.id) ?? feature
|
||||
}
|
||||
super.setSelectedElement(feature)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,9 @@ export class WithSearchState extends WithVisualFeedbackState {
|
|||
this.searchState = new SearchState(this)
|
||||
this.initHotkeysSearch()
|
||||
this.displaySearchLayer()
|
||||
|
||||
}
|
||||
|
||||
private displaySearchLayer() {
|
||||
|
||||
const source = this.searchState.locationResults
|
||||
const flayer = this.layerState.filteredLayers.get("search")
|
||||
this.featureProperties.trackFeatureSource(source)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue