Merge pull request #460 from mjaschen/fix/github-438
Normalize `surface` and `smoothness` variants
This commit is contained in:
commit
e822a97ed0
1 changed files with 50 additions and 15 deletions
|
|
@ -142,7 +142,8 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
var wayTags = segments[segmentIndex].feature.properties.messages[messageIndex][9].split(' ');
|
var wayTags = segments[segmentIndex].feature.properties.messages[messageIndex][9].split(' ');
|
||||||
for (var wayTagIndex = 0; wayTagIndex < wayTags.length; wayTagIndex++) {
|
for (var wayTagIndex = 0; wayTagIndex < wayTags.length; wayTagIndex++) {
|
||||||
var wayTagParts = wayTags[wayTagIndex].split('=');
|
var wayTagParts = wayTags[wayTagIndex].split('=');
|
||||||
switch (wayTagParts[0]) {
|
var tagName = this.normalizeTagName(wayTagParts[0]);
|
||||||
|
switch (tagName) {
|
||||||
case 'highway':
|
case 'highway':
|
||||||
var highwayType = wayTagParts[1];
|
var highwayType = wayTagParts[1];
|
||||||
var trackType = '';
|
var trackType = '';
|
||||||
|
|
@ -167,10 +168,10 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
break;
|
break;
|
||||||
case 'surface':
|
case 'surface':
|
||||||
case 'smoothness':
|
case 'smoothness':
|
||||||
if (typeof analysis[wayTagParts[0]][wayTagParts[1]] === 'undefined') {
|
if (typeof analysis[tagName][wayTagParts[1]] === 'undefined') {
|
||||||
analysis[wayTagParts[0]][wayTagParts[1]] = {
|
analysis[tagName][wayTagParts[1]] = {
|
||||||
formatted_name: i18next.t(
|
formatted_name: i18next.t(
|
||||||
'sidebar.analysis.data.' + wayTagParts[0] + '.' + wayTagParts[1],
|
'sidebar.analysis.data.' + tagName + '.' + wayTagParts[1],
|
||||||
wayTagParts[1]
|
wayTagParts[1]
|
||||||
),
|
),
|
||||||
name: wayTagParts[1],
|
name: wayTagParts[1],
|
||||||
|
|
@ -178,7 +179,7 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
distance: 0.0,
|
distance: 0.0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
analysis[wayTagParts[0]][wayTagParts[1]].distance += parseFloat(
|
analysis[tagName][wayTagParts[1]].distance += parseFloat(
|
||||||
segments[segmentIndex].feature.properties.messages[messageIndex][3]
|
segments[segmentIndex].feature.properties.messages[messageIndex][3]
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
@ -190,6 +191,31 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
return this.sortAnalysisData(analysis);
|
return this.sortAnalysisData(analysis);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize the tag name.
|
||||||
|
*
|
||||||
|
* Motivation: The `surface` tag comes in different variations,
|
||||||
|
* e.g. `surface`, `cycleway:surface` etc. We're only interested
|
||||||
|
* in the main tag so all other variations are normalized.
|
||||||
|
*
|
||||||
|
* @param {string} tagName
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
normalizeTagName: function (tagName) {
|
||||||
|
// we assume that a tag belongs to the category `surface`,
|
||||||
|
// if that string is contained anywhere in the tag name:
|
||||||
|
if (tagName.indexOf('surface') !== -1) {
|
||||||
|
return 'surface';
|
||||||
|
}
|
||||||
|
|
||||||
|
// the same applies to `smoothness`
|
||||||
|
if (tagName.indexOf('smoothness') !== -1) {
|
||||||
|
return 'smoothness';
|
||||||
|
}
|
||||||
|
|
||||||
|
return tagName;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform analysis data for each type into an array, sort it
|
* Transform analysis data for each type into an array, sort it
|
||||||
* by distance descending and convert it back to an object.
|
* by distance descending and convert it back to an object.
|
||||||
|
|
@ -474,22 +500,31 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
|
|
||||||
return parsed.highway === dataName;
|
return parsed.highway === dataName;
|
||||||
case 'surface':
|
case 'surface':
|
||||||
if (dataName === 'internal-unknown' && typeof parsed.surface !== 'string') {
|
return this.singleWayTagMatchesData('surface', parsed, dataName);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return typeof parsed.surface === 'string' && parsed.surface === dataName;
|
|
||||||
case 'smoothness':
|
case 'smoothness':
|
||||||
if (dataName === 'internal-unknown' && typeof parsed.smoothness !== 'string') {
|
return this.singleWayTagMatchesData('smoothness', parsed, dataName);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return typeof parsed.smoothness === 'string' && parsed.smoothness === dataName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
singleWayTagMatchesData: function (category, parsedData, lookupValue) {
|
||||||
|
var foundValue = null;
|
||||||
|
|
||||||
|
for (var iterationKey in parsedData) {
|
||||||
|
if (iterationKey.indexOf(category) !== -1) {
|
||||||
|
foundValue = parsedData[iterationKey];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lookupValue === 'internal-unknown' && foundValue === null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return foundValue === lookupValue;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform a way tags string into an object, for example:
|
* Transform a way tags string into an object, for example:
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue