This commit fixes the incomplete/buggy implementation of the fix for #494. Values are now converted to the expected format before returned from `wayTagsNormalize()`.
This commit is contained in:
parent
22d7dfd610
commit
8750c37901
1 changed files with 40 additions and 18 deletions
|
|
@ -206,7 +206,7 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
* @returns {*[]}
|
* @returns {*[]}
|
||||||
*/
|
*/
|
||||||
normalizeWayTags: function (wayTags, routingType) {
|
normalizeWayTags: function (wayTags, routingType) {
|
||||||
let normalizedWayTags = [];
|
let normalizedWayTags = {};
|
||||||
let surfaceTags = {};
|
let surfaceTags = {};
|
||||||
let smoothnessTags = {};
|
let smoothnessTags = {};
|
||||||
for (let wayTagIndex = 0; wayTagIndex < wayTags.length; wayTagIndex++) {
|
for (let wayTagIndex = 0; wayTagIndex < wayTags.length; wayTagIndex++) {
|
||||||
|
|
@ -215,7 +215,7 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
const tagValue = wayTagParts[1];
|
const tagValue = wayTagParts[1];
|
||||||
|
|
||||||
if (tagName === 'surface') {
|
if (tagName === 'surface') {
|
||||||
surfaceTags['default'] = tagValue;
|
surfaceTags.default = tagValue;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (tagName.indexOf(':surface') !== -1) {
|
if (tagName.indexOf(':surface') !== -1) {
|
||||||
|
|
@ -225,7 +225,7 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tagName === 'smoothness') {
|
if (tagName === 'smoothness') {
|
||||||
smoothnessTags['default'] = tagValue;
|
smoothnessTags.default = tagValue;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (tagName.indexOf(':smoothness') !== -1) {
|
if (tagName.indexOf(':smoothness') !== -1) {
|
||||||
|
|
@ -239,23 +239,27 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
|
|
||||||
switch (routingType) {
|
switch (routingType) {
|
||||||
case 'cycling':
|
case 'cycling':
|
||||||
if (typeof surfaceTags['cycleway'] === 'string') {
|
if (typeof surfaceTags.cycleway === 'string') {
|
||||||
normalizedWayTags['surface'] = surfaceTags['cycleway'];
|
normalizedWayTags.surface = surfaceTags.cycleway;
|
||||||
|
} else if (typeof surfaceTags.default === 'string') {
|
||||||
|
normalizedWayTags.surface = surfaceTags.default;
|
||||||
}
|
}
|
||||||
if (typeof smoothnessTags['cycleway'] === 'string') {
|
if (typeof smoothnessTags.cycleway === 'string') {
|
||||||
normalizedWayTags['smoothness'] = smoothnessTags['cycleway'];
|
normalizedWayTags.smoothness = smoothnessTags.cycleway;
|
||||||
|
} else if (typeof smoothnessTags.default === 'string') {
|
||||||
|
normalizedWayTags.smoothness = smoothnessTags.default;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (typeof surfaceTags['default'] === 'string') {
|
if (typeof surfaceTags.default === 'string') {
|
||||||
normalizedWayTags['surface'] = surfaceTags['default'];
|
normalizedWayTags.surface = surfaceTags.default;
|
||||||
}
|
}
|
||||||
if (typeof smoothnessTags['default'] === 'string') {
|
if (typeof smoothnessTags.default === 'string') {
|
||||||
normalizedWayTags['smoothness'] = smoothnessTags['default'];
|
normalizedWayTags.smoothness = smoothnessTags.default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return normalizedWayTags;
|
return this.wayTagsToArray(normalizedWayTags);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -528,7 +532,7 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
wayTagsMatchesData: function (wayTags, dataType, dataName, trackType) {
|
wayTagsMatchesData: function (wayTags, dataType, dataName, trackType) {
|
||||||
var parsed = this.parseWayTags(wayTags);
|
const parsed = this.wayTagsToObject(wayTags);
|
||||||
|
|
||||||
switch (dataType) {
|
switch (dataType) {
|
||||||
case 'highway':
|
case 'highway':
|
||||||
|
|
@ -579,15 +583,33 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
*
|
*
|
||||||
* @returns {object}
|
* @returns {object}
|
||||||
*/
|
*/
|
||||||
parseWayTags: function (wayTags) {
|
wayTagsToObject: function (wayTags) {
|
||||||
var result = {};
|
let result = {};
|
||||||
var wayTagPairs = wayTags.feature.wayTags.split(' ');
|
const wayTagPairs = wayTags.feature.wayTags.split(' ');
|
||||||
|
|
||||||
for (var j = 0; j < wayTagPairs.length; j++) {
|
for (let j = 0; j < wayTagPairs.length; j++) {
|
||||||
var wayTagParts = wayTagPairs[j].split('=');
|
const wayTagParts = wayTagPairs[j].split('=');
|
||||||
result[wayTagParts[0]] = wayTagParts[1];
|
result[wayTagParts[0]] = wayTagParts[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform a way tags object into an array representation, for example:
|
||||||
|
*
|
||||||
|
* { 'highway' : 'path', 'surface' : 'sand' } => ['highway=path', 'surface=sand']
|
||||||
|
*
|
||||||
|
* @param wayTags The way tags in object representation
|
||||||
|
*
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
wayTagsToArray: function (wayTags) {
|
||||||
|
let wayTagsArray = [];
|
||||||
|
for (let wayTagKey in wayTags) {
|
||||||
|
wayTagsArray.push(wayTagKey + '=' + wayTags[wayTagKey]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return wayTagsArray;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue