Moving stuff around so that helper.ts works again

This commit is contained in:
Eric van der Vlist 2023-06-09 18:15:02 +02:00
parent ba09d5ef50
commit 28271da640
7 changed files with 95 additions and 82 deletions

100
helper.ts
View File

@ -1,53 +1,63 @@
import { legacyOverlayDefinitions } from './src/components/overlays/overlay-definitions';
let filters: any[] = ['any'];
Object.keys(legacyOverlayDefinitions).forEach((key) => {
const definition = legacyOverlayDefinitions[key];
let filter: any[] = ['in', key];
Object.keys(definition).forEach((subKey) => {
filter = [...filter, subKey];
});
filters = [...filters, filter];
});
import {
overlayDefinitions,
osmTags,
} from './src/components/overlays/overlay-definitions';
// One timer
let tags = {};
let overlays = {};
// 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);
}
}
}
}
// 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),
});
// console.log({
// caller: 'onetimer / result',
// tags: JSON.stringify(tags),
// overlays: JSON.stringify(overlays),
// });
// End of one timer
// console.log({
// legacyOverlayDefinitions,
// filters,
// json: JSON.stringify(filters),
// overlays: JSON.stringify(overlays),
// });
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) });
}

View File

@ -20,12 +20,12 @@ import { createDefaultStyle } from 'ol/style/Style';
import osmIcons from './osm-icons';
import { getZoomInteger } from '../map/Map';
import {
getTagType,
isHighlightedTagType,
} from '../map-tile-provider/MapTileProvider';
import { isHighlightedTagType } from '../map-tile-provider/MapTileProvider';
import { getCenter } from 'ol/extent';
import { getVectorTileFeatureType } from '../overlays/overlay-definitions';
import {
getVectorTileFeatureType,
getTagType,
} from '../overlays/overlay-definitions';
import { Category } from '../wpt/WptEditDialog';
interface StyleParameters {

View File

@ -13,14 +13,11 @@ import Dialog from '../dialog';
import Tree from '../tree';
import { GpxViewer } from '../gpx';
import { Browser } from '@capacitor/browser';
import { isHighlighted } from '../map-tile-provider';
import {
isHighlightedTagType,
getTagType,
} from '../map-tile-provider/MapTileProvider';
import { isHighlightedTagType } from '../map-tile-provider/MapTileProvider';
import style from '../gpx/styles';
import OsmFindAll from './OsmFindAll';
import { toLonLat } from 'ol/proj';
import { getTagType } from '../overlays/overlay-definitions';
const Item = styled(Paper)(({ theme }) => ({
...theme.typography.body2,

View File

@ -1,9 +1,7 @@
import OSM from 'ol/source/OSM';
import XYZ from 'ol/source/XYZ';
import { Component, createEffect, createSignal, For, Show } from 'solid-js';
import {
useI18n,
} from '@solid-primitives/i18n';
import { useI18n } from '@solid-primitives/i18n';
import style from './MapTileProvider.module.css';
import LayersIcon from '@suid/icons-material/Layers';
@ -25,6 +23,7 @@ import {
overlayDefinitions,
osmTags,
OsmTag,
getTagType,
} from '../overlays/overlay-definitions';
import { cloneDeep } from 'lodash';
@ -152,17 +151,6 @@ const currentOverlayHighlightedKey = () =>
? currentOverlay().highlighted
: 'none';
export const getTagType = (feature: Feature) => {
for (const tagType of Object.keys(osmTags)) {
const tag: OsmTag = osmTags[tagType];
const tagValue = feature.get(tag.name);
if (tagValue === tag.value) {
return tagType;
}
}
return false;
};
export const isHighlightedTagType = (tagType: string) => {
const currentOverlayHighlightedDefinition: string[] =
overlayDefinitions[currentOverlayKey()][currentOverlayHighlightedKey()];

View File

@ -1 +1,6 @@
import { overlayDefinitions, OsmTag, osmTags } from './overlay-definitions';
import {
overlayDefinitions,
OsmTag,
osmTags,
getTagType,
} from './overlay-definitions';

View File

@ -1,5 +1,4 @@
import { Feature } from 'ol';
import { getTagType } from '../map-tile-provider/MapTileProvider';
export interface OsmTag {
name: string;
@ -270,6 +269,17 @@ export const overlayDefinitions = {
},
};
export const getTagType = (feature: Feature) => {
for (const tagType of Object.keys(osmTags)) {
const tag: OsmTag = osmTags[tagType];
const tagValue = feature.get(tag.name);
if (tagValue === tag.value) {
return tagType;
}
}
return false;
};
export const getVectorTileFeatureType = (feature: Feature) => {
if (
['hiking'].includes(feature.get('route')) ||

View File

@ -49,27 +49,31 @@
"in",
"amenity",
"bar",
"pub",
"cafe",
"drinking_water",
"water_point",
"fast_food",
"food_court",
"pub",
"restaurant",
"cafe",
"atm",
"bank",
"atm",
"bank",
"waste_basket",
"waste_disposal",
"vending_machine",
"doctors",
"hospital",
"pharmacy",
"police",
"fire_station",
"drinking_water",
"water_point",
"waste_basket",
"waste_disposal",
"vending_machine"
"fire_station"
],
[
"in",
"shop",
"water",
"bakery",
"butcher",
"cheese",
@ -82,13 +86,12 @@
"pasta",
"pastry",
"seafood",
"water",
"department_store",
"general",
"mall",
"supermarket",
"wholesale",
"outdoor",
"department_store",
"general",
"mall",
"laundry"
],
[