Added new quality mode: surface type

Required fork of leaflet-hotline with a new option to disable the
gradient display.
This is was done so that short stretches of very bad surface adjacent to
very good ones are visible.

Also note the eslint-disable-line for this compat warning:
  URLSearchParams is not supported in Safari 7, op_mini all, IE 10, android 4.1
don't seem relevant today because those are EOL for a long time now.
This commit is contained in:
Tobias 2022-08-28 11:46:59 +02:00
parent f41f08c69e
commit 39aa813ea1
4 changed files with 157 additions and 4 deletions

View file

@ -60,6 +60,159 @@ BR.RoutingPathQuality = L.Control.extend({
},
}),
},
surface: {
title: i18next.t('map.route-quality-surface'),
icon: 'fa-road',
provider: new HotLineQualityProvider({
hotlineOptions: {
renderer: renderer,
palette: {
// normal range
0.0: '#ff0000',
0.95: '#00ff00',
// special value for unknown
1.0: '#888888',
},
// note: without this the lib will get min/max from the actual
// values rendering the special values moot
min: 0,
max: 1,
discreteStrokes: true,
},
valueFunction: (function () {
let cache = [];
return function (latLng) {
var feature = latLng.feature;
if (!feature.wayTags) {
return 1.0;
} else if (cache[feature.wayTags]) {
return cache[feature.wayTags];
}
let data = new URLSearchParams(feature.wayTags.replace(/\s+/g, '&')); // eslint-disable-line compat/compat
let surface = null;
switch (data.get('surface')) {
case 'paved':
surface = 0.8;
break;
case 'asphalt':
case 'concrete':
surface = 1;
break;
case 'concrete:lanes':
case 'concrete:plates':
surface = 0.6;
case 'sett':
case 'gravel':
case 'pebblestone':
surface = 0.5;
break;
case 'paving_stones':
case 'compacted':
case 'fine_gravel':
surface = 0.7;
break;
case 'cobblestone':
case 'dirt':
case 'grass':
surface = 0.2;
break;
case 'unhewn_cobblestone':
surface = 0.01;
break;
case 'ground':
case 'earth':
surface = 0.3;
break;
case 'mud':
case 'sand':
surface = 0.01;
break;
case null:
break;
default:
console.warn('unhandled surface type', data.get('surface'));
break;
}
// modifier tracktype; also sometimes only tracktype is available
if (data.get('highway') === 'track') {
switch (data.get('tracktype') || 'unknown') {
case 'grade1':
if (surface === null) {
surface = 0.9;
} /* else {
don't change
} */
break;
case 'grade2':
if (surface === null) {
surface = 0.7;
} else {
surface *= 0.9;
}
break;
case 'grade3':
if (surface === null) {
surface = 0.4;
} else {
surface *= 0.8;
}
break;
case 'grade4':
if (surface === null) {
surface = 0.1;
} else {
surface *= 0.6;
}
break;
case 'grade5':
if (surface === null) {
surface = 0.01;
} else {
surface *= 0.4;
}
break;
}
}
if (surface !== null) {
// modifier for surface quality
switch (data.get('smoothness')) {
case 'excellent':
surface = Math.max(surface * 1.1, 1.0);
break;
case 'good':
surface = Math.max(surface * 1.05, 1.0);
break;
case 'intermediate':
surface *= 0.9;
break;
case 'bad':
surface *= 0.7;
break;
case 'very_bad':
surface *= 0.5;
break;
case 'horrible':
surface *= 0.4;
break;
case 'very_horrible':
surface *= 0.2;
break;
case 'impassable':
surface *= 0.01;
break;
}
}
// limit normal values 0-0.9 so 1.0 can be unknown
const final = surface === null ? 1.0 : surface * 0.9;
cache[feature.wayTags] = final;
return final;
};
})(),
}),
},
cost: {
title: i18next.t('map.route-quality-shortcut', { action: '$t(map.route-quality-cost)', key: 'C' }),
icon: 'fa-usd',