dyomedea/helper.ts

64 lines
1.7 KiB
TypeScript

import {
overlayDefinitions,
osmTags,
} from './src/components/overlays/overlay-definitions';
// One timer
// let tags = {};
// let overlays = {};
// for (const tagName of Object.keys(legacyOverlayDefinitions)) {
// for (const tagValue of Object.keys(legacyOverlayDefinitions[tagName])) {
// tags[tagValue] = { name: tagName, value: tagValue };
// for (const activity of Object.keys(
// legacyOverlayDefinitions[tagName][tagValue]
// )) {
// if (!overlays[activity]) {
// overlays[activity] = {};
// }
// for (const category of Object.keys(
// legacyOverlayDefinitions[tagName][tagValue][activity]
// )) {
// if (!overlays[activity][category]) {
// overlays[activity][category] = [];
// }
// overlays[activity][category].push(tagValue);
// }
// }
// }
// }
// console.log({
// caller: 'onetimer / result',
// tags: JSON.stringify(tags),
// overlays: JSON.stringify(overlays),
// });
// End of one timer
for (const overlayCategory of Object.keys(overlayDefinitions)) {
let filters: any[] = ['any'];
const definitions = overlayDefinitions[overlayCategory];
let tags = {};
for (const category of Object.keys(definitions)) {
//console.log({ category });
for (const tagId of definitions[category]) {
//console.log({ tagId });
const tag = osmTags[tagId];
if (!tags[tag.name]) {
tags[tag.name] = [];
}
tags[tag.name].push(tag.value);
}
}
for (const tagName of Object.keys(tags)) {
let filter = ['in', tagName];
for (const tagValue of tags[tagName]) {
filter.push(tagValue);
}
filters.push(filter);
}
console.log({ overlayCategory, filters: JSON.stringify(filters) });
}