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',

View file

@ -164,6 +164,7 @@
"route-quality-altitude": "Altitude coding",
"route-quality-cost": "Cost coding",
"route-quality-incline": "Incline coding",
"route-quality-surface": "Road surface/quality",
"route-quality-shortcut": "{{action}} ({{key}} key to toggle)",
"route-tooltip-segment": "Drag to create a new waypoint. Click to toggle straight line.",
"route-tooltip-waypoint": "Waypoint. Drag to move; Click to remove.",

View file

@ -65,7 +65,7 @@
"leaflet-editable": "1.2.0",
"leaflet-filelayer": "1.2.0",
"leaflet-geometryutil": "0.10.1",
"leaflet-hotline": "0.4.0",
"leaflet-hotline": "tbsmark86/Leaflet.hotline#25b2457",
"leaflet-osm-notes": "osmlab/leaflet-osm-notes#af2aa811",
"leaflet-plugins": "3.4.0",
"leaflet-providers": "1.13.0",

View file

@ -8340,10 +8340,9 @@ leaflet-geometryutil@0.10.1:
dependencies:
leaflet "^1.6.0"
leaflet-hotline@0.4.0:
leaflet-hotline@tbsmark86/Leaflet.hotline#25b2457:
version "0.4.0"
resolved "https://registry.yarnpkg.com/leaflet-hotline/-/leaflet-hotline-0.4.0.tgz#e01069836a9d2e2c78b1fa1db2013bd03c8ff8d9"
integrity sha512-+In6c8WxMsRKMmwQ1m2GmbNxbXvA3WsrOilJGK7l4Sj+mUDh1gdyGMYCIoRBtUeX7lMvBc4KKeEVAlwQERKpxg==
resolved "https://codeload.github.com/tbsmark86/Leaflet.hotline/tar.gz/25b24572b99ac66203d857e0fb27f430e2f68448"
leaflet-osm-notes@osmlab/leaflet-osm-notes#af2aa811:
version "0.0.1"