Refactoring osm tags (wip)

This commit is contained in:
Eric van der Vlist 2023-06-09 15:49:50 +02:00
parent 29f92dca10
commit c2705def86
5 changed files with 18 additions and 57 deletions

View File

@ -23,6 +23,7 @@ import { getZoomInteger } from '../map/Map';
import {
getHighlightedTagValue,
getTagType,
isHighlightedTagType,
} from '../map-tile-provider/MapTileProvider';
import { getCenter } from 'ol/extent';
import { getVectorTileFeatureType } from '../overlays/overlay-definitions';
@ -33,7 +34,6 @@ interface StyleParameters {
isSelected: boolean;
}
const icons = {
note: {
src: noteIcon,
@ -567,8 +567,8 @@ const styles = {
if (getZoomInteger() < 16) {
return null;
}
const highlightedTagValue = getHighlightedTagValue(feature);
const isHighlightedFeature = !!highlightedTagValue;
const tagType = getTagType(feature);
const isHighlightedFeature = isHighlightedTagType(tagType);
if (
(isHighlightedFeature && getZoomInteger() < 16) ||
(!isHighlightedFeature && getZoomInteger() < 18)
@ -577,9 +577,7 @@ const styles = {
}
return {
name: feature.get('name'),
poiType: isHighlightedFeature
? highlightedTagValue
: getTagType(feature),
poiType: tagType,
isHighlighted: isHighlightedFeature,
isTextHidden: getZoomInteger() < 19,
};

View File

@ -15,7 +15,7 @@ import { GpxViewer } from '../gpx';
import { Browser } from '@capacitor/browser';
import { isHighlighted } from '../map-tile-provider';
import {
getHighlightedTagValue,
isHighlightedTagType,
getTagType,
} from '../map-tile-provider/MapTileProvider';
import style from '../gpx/styles';
@ -216,9 +216,10 @@ const Infos: Component<{}> = (props) => {
<>
{console.log({
caller: 'Infos / vector layer feature',
highlightedTagValue:
getHighlightedTagValue(feature),
isHighlighted: isHighlighted(feature),
isHighlighted: isHighlightedTagType(
getTagType(feature)
),
tagValue: getTagType(feature),
properties: feature.getProperties(),
style: style(feature),

View File

@ -156,9 +156,6 @@ const currentOverlayHighlightedKey = () =>
? currentOverlay().highlighted
: 'none';
export const currentOverlayHighlightedDefinition = () =>
currentCategory()[currentOverlayHighlightedKey()];
export const highlightedTags = () => {
let result = {};
Object.keys(legacyOverlayDefinitions).forEach((tagName) => {
@ -218,42 +215,6 @@ export const highlightedTags = () => {
// });
// });
export const getHighlightedTagValue = (feature: Feature) => {
let result = false;
Object.keys(highlightedTags()).every((tagName) => {
const value = feature.get(tagName);
const highlightedValues = highlightedTags()[tagName];
// console.log({
// caller: 'MapTileProviders / highlightedTag / found',
// feature,
// feature_values: feature.values_,
// highlightedTags,
// tagName,
// tag_value: value,
// highlightedValues,
// });
if (value !== undefined && highlightedValues.includes(value)) {
result = value;
return false;
}
return true;
});
// console.log({
// caller: 'MapTileProviders / highlightedTag / result',
// feature,
// feature_values: feature.values_,
// highlightedTags,
// result,
// });
return result;
};
export const isHighlighted = (feature: Feature) => {
return !!getHighlightedTagValue(feature);
};
export const getTagType = (feature: Feature) => {
for (const tagType of Object.keys(osmTags)) {
const tag: OsmTag = osmTags[tagType];
@ -265,6 +226,13 @@ export const getTagType = (feature: Feature) => {
return false;
};
export const isHighlightedTagType = (tagType: string) => {
const currentOverlayHighlightedDefinition: string[] =
overlayDefinitions[currentOverlayKey()][currentOverlayHighlightedKey()];
return currentOverlayHighlightedDefinition.includes(tagType);
};
const MapTilesProvider: Component<{}> = (props) => {
const [open, setOpen] = createSignal(false);

View File

@ -2,6 +2,5 @@ export {
default,
mapTileProviders,
currentCategory as currentOverlayDefinition,
currentOverlayHighlightedDefinition,
isHighlighted,
isHighlightedTagType,
} from './MapTileProvider';

View File

@ -1,11 +1,7 @@
import { Component, createEffect, onMount } from 'solid-js';
import OlMap from 'ol/Map';
import {
currentOverlayDefinition,
currentOverlayHighlightedDefinition,
isHighlighted,
} from '../map-tile-provider';
import { currentOverlayDefinition, isHighlightedTagType } from '../map-tile-provider';
import { Feature } from 'ol';
import MVT from 'ol/format/MVT';
import { Point } from 'ol/geom';
@ -174,7 +170,6 @@ export const Overlays: Component<Props> = ({ map }) => {
createEffect(() => {
const overlayDefinition = currentOverlayDefinition();
const overlayHighlightedDefinition = currentOverlayHighlightedDefinition();
const olMap = getMap();
if (olMap) {
olMap.removeLayer(clusterLayer);