Skip to content

Commit

Permalink
layers: show climbing=area + number in supscript
Browse files Browse the repository at this point in the history
  • Loading branch information
zbycz committed Apr 16, 2024
1 parent 82c053f commit d879871
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/Map/styles/layers/climbingLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const crags: LayerSpecification = {
'text-font': ['Noto Sans Bold'],
'text-anchor': 'top',
'icon-image': 'circle_11',
'text-field': '{name}\n{osmappRouteCount}',
'text-field': '{osmappLabel}',
'text-offset': [
'step',
['zoom'],
Expand Down Expand Up @@ -130,7 +130,7 @@ const areas: LayerSpecification = {
'text-font': ['Noto Sans Bold'],
'text-anchor': 'top',
'icon-image': 'square_11',
'text-field': '{name}\n{osmappRouteCount}',
'text-field': '{osmappLabel}',
'text-offset': [0, 0.6],
'text-size': ['interpolate', ['linear'], ['zoom'], 11.5, 14],
// 'icon-size': 1.5,
Expand Down
27 changes: 21 additions & 6 deletions src/services/fetchCrags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,32 @@ function getItems(elements) {
return { nodes, ways, relations };
}

const numberToSuperScript = (number: number) =>
number.toString().replace(/\d/g, (d) => '⁰¹²³⁴⁵⁶⁷⁸⁹'[+d]);

const getLabel = (tags: {}, osmappRouteCount) =>
`${tags.name}${
osmappRouteCount ? `\n${numberToSuperScript(osmappRouteCount)}` : ''
}`;

const convert = (
element: any,
geometryFn: (element: any) => FeatureGeometry,
): Feature => {
const { type, id, tags = {} } = element;
const geometry = geometryFn(element);
const center = getCenter(geometry) ?? undefined;
const osmappRouteCount =
element.tags.climbing === 'crag'
? element.members?.length ??
parseInt(element.tags['climbing:sport'] ?? 0, 10)
: undefined;
const properties = {
...getPoiClass(tags),
...tags,
osmappType: type,
osmappRouteCount:
element.tags.climbing === 'crag'
? element.members?.length ??
parseInt(element.tags['climbing:sport'] ?? 0, 10)
: undefined,
osmappRouteCount,
osmappLabel: getLabel(tags, osmappRouteCount),
};

return {
Expand Down Expand Up @@ -110,7 +120,11 @@ const getRelationWithAreaCount = (
const osmappRouteCount = cragsCount.reduce((acc, count) => acc + count);
return {
...relation,
properties: { ...relation.properties, osmappRouteCount },
properties: {
...relation.properties,
osmappRouteCount,
osmappLabel: getLabel(relation.tags, osmappRouteCount),
},
};
}

Expand Down Expand Up @@ -190,6 +204,7 @@ export const fetchCrags = async () => {
nwr["climbing"](49.64474,14.21855,49.67273,14.28025);
>;<;
rel["climbing"="crag"];
rel["climbing"="area"];
);
(
._;
Expand Down

0 comments on commit d879871

Please sign in to comment.