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'; import {
overlayDefinitions,
let filters: any[] = ['any']; osmTags,
} from './src/components/overlays/overlay-definitions';
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];
});
// One timer // One timer
let tags = {}; // let tags = {};
let overlays = {}; // let overlays = {};
for (const tagName of Object.keys(legacyOverlayDefinitions)) { // for (const tagName of Object.keys(legacyOverlayDefinitions)) {
for (const tagValue of Object.keys(legacyOverlayDefinitions[tagName])) { // for (const tagValue of Object.keys(legacyOverlayDefinitions[tagName])) {
tags[tagValue] = { name: tagName, value: tagValue }; // tags[tagValue] = { name: tagName, value: tagValue };
for (const activity of Object.keys( // for (const activity of Object.keys(
legacyOverlayDefinitions[tagName][tagValue] // legacyOverlayDefinitions[tagName][tagValue]
)) { // )) {
if (!overlays[activity]) { // if (!overlays[activity]) {
overlays[activity] = {}; // overlays[activity] = {};
} // }
for (const category of Object.keys( // for (const category of Object.keys(
legacyOverlayDefinitions[tagName][tagValue][activity] // legacyOverlayDefinitions[tagName][tagValue][activity]
)) { // )) {
if (!overlays[activity][category]) { // if (!overlays[activity][category]) {
overlays[activity][category] = []; // overlays[activity][category] = [];
} // }
overlays[activity][category].push(tagValue); // overlays[activity][category].push(tagValue);
} // }
} // }
} // }
} // }
console.log({ // console.log({
caller: 'onetimer / result', // caller: 'onetimer / result',
tags: JSON.stringify(tags), // tags: JSON.stringify(tags),
overlays: JSON.stringify(overlays), // overlays: JSON.stringify(overlays),
}); // });
// End of one timer // End of one timer
// console.log({ for (const overlayCategory of Object.keys(overlayDefinitions)) {
// legacyOverlayDefinitions, let filters: any[] = ['any'];
// filters, const definitions = overlayDefinitions[overlayCategory];
// json: JSON.stringify(filters), let tags = {};
// overlays: JSON.stringify(overlays), 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 osmIcons from './osm-icons';
import { getZoomInteger } from '../map/Map'; import { getZoomInteger } from '../map/Map';
import { import { isHighlightedTagType } from '../map-tile-provider/MapTileProvider';
getTagType,
isHighlightedTagType,
} from '../map-tile-provider/MapTileProvider';
import { getCenter } from 'ol/extent'; import { getCenter } from 'ol/extent';
import { getVectorTileFeatureType } from '../overlays/overlay-definitions'; import {
getVectorTileFeatureType,
getTagType,
} from '../overlays/overlay-definitions';
import { Category } from '../wpt/WptEditDialog'; import { Category } from '../wpt/WptEditDialog';
interface StyleParameters { interface StyleParameters {

View File

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

View File

@ -1,9 +1,7 @@
import OSM from 'ol/source/OSM'; import OSM from 'ol/source/OSM';
import XYZ from 'ol/source/XYZ'; import XYZ from 'ol/source/XYZ';
import { Component, createEffect, createSignal, For, Show } from 'solid-js'; import { Component, createEffect, createSignal, For, Show } from 'solid-js';
import { import { useI18n } from '@solid-primitives/i18n';
useI18n,
} from '@solid-primitives/i18n';
import style from './MapTileProvider.module.css'; import style from './MapTileProvider.module.css';
import LayersIcon from '@suid/icons-material/Layers'; import LayersIcon from '@suid/icons-material/Layers';
@ -25,6 +23,7 @@ import {
overlayDefinitions, overlayDefinitions,
osmTags, osmTags,
OsmTag, OsmTag,
getTagType,
} from '../overlays/overlay-definitions'; } from '../overlays/overlay-definitions';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
@ -152,17 +151,6 @@ const currentOverlayHighlightedKey = () =>
? currentOverlay().highlighted ? currentOverlay().highlighted
: 'none'; : '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) => { export const isHighlightedTagType = (tagType: string) => {
const currentOverlayHighlightedDefinition: string[] = const currentOverlayHighlightedDefinition: string[] =
overlayDefinitions[currentOverlayKey()][currentOverlayHighlightedKey()]; 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 { Feature } from 'ol';
import { getTagType } from '../map-tile-provider/MapTileProvider';
export interface OsmTag { export interface OsmTag {
name: string; 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) => { export const getVectorTileFeatureType = (feature: Feature) => {
if ( if (
['hiking'].includes(feature.get('route')) || ['hiking'].includes(feature.get('route')) ||

View File

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