Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

climbing: add osmappRouteCount to priortize Map labels #294

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 83 additions & 88 deletions src/components/Map/styles/layers/climbingLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ import type {
LayerSpecification,
} from '@maplibre/maplibre-gl-style-spec';

const linearFadeOut = (from: number, to: number): ExpressionSpecification => [
'interpolate',
['linear'],
['zoom'],
from,
1,
to,
0.3,
];

const linear = (
from: number,
num1: number,
Expand All @@ -28,13 +18,15 @@ const linear = (
num2,
];

export const climbingLayers: LayerSpecification[] = [
const linearFadeOut = (from: number, to: number): ExpressionSpecification =>
linear(from, 1, to, 0.3);

const routes: LayerSpecification[] = [
{
id: 'climbing-3-routes-circle',
type: 'circle',
source: 'climbing',
minzoom: 16,

filter: [
'all',
['==', 'osmappType', 'node'],
Expand Down Expand Up @@ -79,83 +71,86 @@ export const climbingLayers: LayerSpecification[] = [
'text-halo-color': '#ffffff',
},
},
];

{
id: 'climbing-2-crags',
type: 'symbol',
source: 'climbing',
minzoom: 15,
maxzoom: 20,
filter: [
'all',
['==', 'osmappType', 'relationPoint'],
['==', 'climbing', 'crag'],
const crags: LayerSpecification = {
id: 'climbing-2-crags',
type: 'symbol',
source: 'climbing',
minzoom: 15,
maxzoom: 20,
filter: [
'all',
['==', 'osmappType', 'relationPoint'],
['==', 'climbing', 'crag'],
],
layout: {
'text-padding': 2,
'text-font': ['Noto Sans Bold'],
'text-anchor': 'top',
'icon-image': 'circle_11',
'text-field': '{name}',
'text-offset': [
'step',
['zoom'],
['literal', [0, 0.6]],
18.5,
['literal', [0, 0.8]],
],
layout: {
'text-padding': 2,
'text-font': ['Noto Sans Bold'],
'text-anchor': 'top',
'icon-image': 'circle_11',
'text-field': '{name}',
'text-offset': [
'step',
['zoom'],
['literal', [0, 0.6]],
18.5,
['literal', [0, 0.8]],
],
'text-size': linear(15, 12, 21, 18),
'text-max-width': 9,
'icon-optional': false,
'icon-ignore-placement': false,
'icon-allow-overlap': false,
'text-ignore-placement': false,
'text-allow-overlap': false,
'text-optional': true,
'icon-size': linear(15, 1, 21, 2),
},
paint: {
'text-halo-blur': 0.5,
'text-color': '#ea5540',
'text-halo-width': 2,
'text-halo-color': '#ffffff',
},
'text-size': linear(15, 12, 21, 18),
'text-max-width': 9,
'icon-optional': false,
'icon-ignore-placement': false,
'icon-allow-overlap': false,
'text-ignore-placement': false,
'text-allow-overlap': false,
'text-optional': true,
'icon-size': linear(15, 1, 21, 2),
'symbol-sort-key': ['*', -1, ['to-number', ['get', 'osmappRouteCount']]],
},

{
id: 'climbing-1-areas',
type: 'symbol',
source: 'climbing',
minzoom: 5,
maxzoom: 16,
filter: [
'all',
['==', 'osmappType', 'relationPoint'],
['==', 'climbing', 'area'],
],
layout: {
'text-padding': 2,
'text-font': ['Noto Sans Bold'],
'text-anchor': 'top',
'icon-image': 'square_11',
'text-field': '{name}',
'text-offset': [0, 0.6],
'text-size': ['interpolate', ['linear'], ['zoom'], 11.5, 14],
// 'icon-size': 1.5,
'text-max-width': 9,
'icon-optional': false,
'icon-ignore-placement': false,
'icon-allow-overlap': false,
'text-ignore-placement': false,
'text-allow-overlap': false,
'text-optional': true,
},
paint: {
'icon-opacity': linearFadeOut(14, 16),
'text-opacity': linearFadeOut(14, 16),
'text-color': 'rgba(0, 95, 204, 1)',
'text-halo-color': 'rgba(250, 250, 250, 1)',
'text-halo-width': 2,
},
paint: {
'text-halo-blur': 0.5,
'text-color': '#ea5540',
'text-halo-width': 2,
'text-halo-color': '#ffffff',
},
];
};
const areas: LayerSpecification = {
id: 'climbing-1-areas',
type: 'symbol',
source: 'climbing',
minzoom: 5,
maxzoom: 16,
filter: [
'all',
['==', 'osmappType', 'relationPoint'],
['==', 'climbing', 'area'],
],
layout: {
'text-padding': 2,
'text-font': ['Noto Sans Bold'],
'text-anchor': 'top',
'icon-image': 'square_11',
'text-field': '{name}',
'text-offset': [0, 0.6],
'text-size': ['interpolate', ['linear'], ['zoom'], 11.5, 14],
// 'icon-size': 1.5,
'text-max-width': 9,
'icon-optional': false,
'icon-ignore-placement': false,
'icon-allow-overlap': false,
'text-ignore-placement': false,
'text-allow-overlap': false,
'text-optional': true,
'symbol-sort-key': ['*', -1, ['to-number', ['get', 'osmappRouteCount']]],
},
paint: {
'icon-opacity': linearFadeOut(14, 16),
'text-opacity': linearFadeOut(14, 16),
'text-color': 'rgba(0, 95, 204, 1)',
'text-halo-color': 'rgba(250, 250, 250, 1)',
'text-halo-width': 2,
},
};

export const climbingLayers: LayerSpecification[] = [...routes, crags, areas];
41 changes: 30 additions & 11 deletions src/services/__tests__/fetchCrags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const anotherNode = {
id: 123,
lat: 55,
lon: 10,
tags: {},
tags: { climbing: 'crag', 'climbing:sport': '30' },
};
const areaRelation = {
type: 'relation',
Expand Down Expand Up @@ -72,8 +72,18 @@ const geojson = [
geometry: { coordinates: [10, 55], type: 'Point' },
id: 1230,
osmMeta: { id: 123, type: 'node' },
properties: { class: 'information', osmappType: 'node' },
tags: {},
properties: {
class: 'climbing',
climbing: 'crag',
'climbing:sport': '30',
osmappRouteCount: 30,
osmappType: 'node',
subclass: 'crag',
},
tags: {
climbing: 'crag',
'climbing:sport': '30',
},
type: 'Feature',
},
{
Expand Down Expand Up @@ -111,9 +121,14 @@ const geojson = [
climbing: 'area',
name: 'Lomy nad Velkou',
osmappType: 'relation',
osmappRouteCount: 31,
},
tags: { climbing: 'area', name: 'Lomy nad Velkou' },
type: 'Feature',
members: [
{ type: 'relation', ref: 17089246, role: '' },
{ type: 'node', ref: 123, role: '' },
],
},
{
center: [14.25, 49.65],
Expand All @@ -129,13 +144,15 @@ const geojson = [
climbing: 'crag',
name: 'Borová věž',
osmappType: 'relation',
osmappRouteCount: 1,
},
tags: { climbing: 'crag', name: 'Borová věž' },
type: 'Feature',
members: [{ type: 'node', ref: 11557711620, role: '' }],
},
];

test('conversion', () => {
test('basic conversion', () => {
expect(cragsToGeojson(response)).toEqual(geojson);
});

Expand All @@ -152,28 +169,30 @@ const crag2 = {
members: [],
tags: {},
};
test('conversion with centers', () => {
test('conversion with centers instead of geometries', () => {
expect(cragsToGeojson({ elements: [area2, crag2] })).toEqual([
{
type: 'Feature',
osmMeta: { id: 555, type: 'relation' },
id: 5554,
center: [14, 51],
geometry: {
geometries: [{ coordinates: [14, 51], type: 'Point' }],
type: 'GeometryCollection',
},
id: 5554,
osmMeta: { id: 555, type: 'relation' },
properties: { class: 'information', osmappType: 'relation' },
tags: {},
type: 'Feature',
members: [{ type: 'relation', ref: 17089246, role: '' }],
},
{
type: 'Feature',
osmMeta: { id: 17089246, type: 'relation' },
id: 170892464,
center: [14, 51],
geometry: { coordinates: [14, 51], type: 'Point' },
id: 170892464,
osmMeta: { id: 17089246, type: 'relation' },
properties: { class: 'information', osmappType: 'relation' },
tags: {},
type: 'Feature',
members: [],
},
]);
});
Loading
Loading