Small fixes

This commit is contained in:
Pieter Vander Vennet 2021-05-20 12:27:33 +02:00
parent 092a627b64
commit 95f421a6ae
5 changed files with 17 additions and 9 deletions

View file

@ -110,7 +110,7 @@ Some advanced functions are available on <b>feat</b> as well:
let closestFeature = undefined;
let closestDistance = undefined;
for (const otherFeature of features) {
if (otherFeature == feature) {
if (otherFeature == feature || otherFeature.id == feature.id) {
continue; // We ignore self
}
let distance = undefined;

View file

@ -3,6 +3,7 @@ import SimpleMetaTagger from "./SimpleMetaTagger";
import {ExtraFunction} from "./ExtraFunction";
import {Relation} from "./Osm/ExtractRelations";
import FeatureSource from "./FeatureSource/FeatureSource";
import State from "../State";
interface Params {
@ -48,7 +49,7 @@ export default class MetaTagging {
}
const featuresPerLayer = new Map<string, any[]>();
for (const feature of features) {
for (const feature of (allKnownFeatures.features?.data ?? features ?? [])) {
const key = feature.feature._matching_layer_id;
if (!featuresPerLayer.has(key)) {
@ -57,13 +58,14 @@ export default class MetaTagging {
featuresPerLayer.get(key).push(feature.feature)
}
for (const feature of (allKnownFeatures.features?.data ?? features ?? [])) {
for (const feature of features) {
// @ts-ignore
const key = feature.feature._matching_layer_id;
const f = layerFuncs.get(key);
if (f === undefined) {
continue;
}
try {
f({featuresPerLayer: featuresPerLayer, memberships: relations}, feature.feature)
} catch (e) {
@ -72,6 +74,7 @@ export default class MetaTagging {
}
}
@ -97,14 +100,14 @@ export default class MetaTagging {
const f = (featuresPerLayer, feature: any) => {
try {
let result = func(feature);
if(result === undefined || result === ""){
if (result === undefined || result === "") {
return;
}
if(typeof result !== "string"){
if (typeof result !== "string") {
// Make sure it is a string!
result = "" + result;
}
feature.properties[key] = result;
feature.properties[key] = result;
} catch (e) {
console.error("Could not calculate a metatag defined by " + code + " due to " + e + ". This is code defined in the theme. Are you the theme creator? Doublecheck your code. Note that the metatags might not be stable on new features", e)
}

View file

@ -106,6 +106,8 @@ if (layoutFromBase64.startsWith("http")) {
let parsed = data;
if (typeof parsed == "string") {
parsed = JSON.parse(data);
}else{
data = JSON.stringify(parsed) // De wereld op zijn kop
}
// Overwrite the id to the wiki:value
parsed.id = link;

View file

@ -4,15 +4,18 @@ import {LayerConfigJson} from "../Customizations/JSON/LayerConfigJson";
import {LayoutConfigJson} from "../Customizations/JSON/LayoutConfigJson";
export default class ScriptUtils {
public static readDirRecSync(path): string[] {
public static readDirRecSync(path, maxDepth = 999): string[] {
const result = []
if(maxDepth <= 0){
return []
}
for (const entry of readdirSync(path)) {
const fullEntry = path + "/" + entry
const stats = lstatSync(fullEntry)
if (stats.isDirectory()) {
// Subdirectory
// @ts-ignore
result.push(...ScriptUtils.readDirRecSync(fullEntry))
result.push(...ScriptUtils.readDirRecSync(fullEntry, maxDepth - 1))
} else {
result.push(fullEntry)
}

View file

@ -165,7 +165,7 @@ function genTranslations() {
// Read 'lang/*.json', writes to 'assets/generated/translations.json'
function compileTranslationsFromWeblate() {
const translations = ScriptUtils.readDirRecSync("./langs")
const translations = ScriptUtils.readDirRecSync("./langs", 1)
.filter(path => path.indexOf(".json") > 0)
const allTranslations = new TranslationPart()