If a way segment contains more than one `surface` tags (e.g. `surface=*` and `cycleway:surface=*`), the tag best suited for the current routing type (currently only *cycling* is supported) is selected. i.e. if a `cycleway:surface=` tag belongs to the current way segment it will be used for the analysis exclusively (all other `surface` tags are skipped from now on).
This commit is contained in:
parent
0fc60c1821
commit
4b5d08e5ed
1 changed files with 64 additions and 22 deletions
|
|
@ -122,7 +122,7 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
calcStats: function (polyline, segments) {
|
calcStats: function (polyline, segments) {
|
||||||
var analysis = {
|
const analysis = {
|
||||||
highway: {},
|
highway: {},
|
||||||
surface: {},
|
surface: {},
|
||||||
smoothness: {},
|
smoothness: {},
|
||||||
|
|
@ -130,23 +130,24 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
|
|
||||||
this.totalRouteDistance = 0.0;
|
this.totalRouteDistance = 0.0;
|
||||||
|
|
||||||
for (var segmentIndex = 0; segments && segmentIndex < segments.length; segmentIndex++) {
|
for (let segmentIndex = 0; segments && segmentIndex < segments.length; segmentIndex++) {
|
||||||
for (
|
for (
|
||||||
var messageIndex = 1;
|
let messageIndex = 1;
|
||||||
messageIndex < segments[segmentIndex].feature.properties.messages.length;
|
messageIndex < segments[segmentIndex].feature.properties.messages.length;
|
||||||
messageIndex++
|
messageIndex++
|
||||||
) {
|
) {
|
||||||
this.totalRouteDistance += parseFloat(
|
this.totalRouteDistance += parseFloat(
|
||||||
segments[segmentIndex].feature.properties.messages[messageIndex][3]
|
segments[segmentIndex].feature.properties.messages[messageIndex][3]
|
||||||
);
|
);
|
||||||
var wayTags = segments[segmentIndex].feature.properties.messages[messageIndex][9].split(' ');
|
let wayTags = segments[segmentIndex].feature.properties.messages[messageIndex][9].split(' ');
|
||||||
for (var wayTagIndex = 0; wayTagIndex < wayTags.length; wayTagIndex++) {
|
wayTags = this.normalizeWayTags(wayTags, 'cycling');
|
||||||
var wayTagParts = wayTags[wayTagIndex].split('=');
|
for (let wayTagIndex = 0; wayTagIndex < wayTags.length; wayTagIndex++) {
|
||||||
var tagName = this.normalizeTagName(wayTagParts[0]);
|
let wayTagParts = wayTags[wayTagIndex].split('=');
|
||||||
|
let tagName = wayTagParts[0];
|
||||||
switch (tagName) {
|
switch (tagName) {
|
||||||
case 'highway':
|
case 'highway':
|
||||||
var highwayType = wayTagParts[1];
|
let highwayType = wayTagParts[1];
|
||||||
var trackType = '';
|
let trackType = '';
|
||||||
if (highwayType === 'track') {
|
if (highwayType === 'track') {
|
||||||
trackType = this.getTrackType(wayTags);
|
trackType = this.getTrackType(wayTags);
|
||||||
highwayType = 'Track ' + trackType;
|
highwayType = 'Track ' + trackType;
|
||||||
|
|
@ -194,26 +195,67 @@ BR.TrackAnalysis = L.Class.extend({
|
||||||
/**
|
/**
|
||||||
* Normalize the tag name.
|
* Normalize the tag name.
|
||||||
*
|
*
|
||||||
* Motivation: The `surface` tag comes in different variations,
|
* Motivation: The `surface` and `smoothness` tags come in different variations,
|
||||||
* e.g. `surface`, `cycleway:surface` etc. We're only interested
|
* e.g. `surface`, `cycleway:surface` etc. We're only interested
|
||||||
* in the main tag so all other variations are normalized.
|
* in the tag which matches the given routing type. All other variations
|
||||||
|
* are dropped. If no specialized surface/smoothness tag is found, the default value
|
||||||
|
* is returned, i.e. `smoothness` or `surface`.
|
||||||
*
|
*
|
||||||
* @param {string} tagName
|
* @param wayTags tags + values for a way segment
|
||||||
* @returns {string}
|
* @param routingType currently only 'cycling' is supported, can be extended in the future (walking, driving, etc.)
|
||||||
|
* @returns {*[]}
|
||||||
*/
|
*/
|
||||||
normalizeTagName: function (tagName) {
|
normalizeWayTags: function (wayTags, routingType) {
|
||||||
// we assume that a tag belongs to the category `surface`,
|
let normalizedWayTags = [];
|
||||||
// if that string is contained anywhere in the tag name:
|
let surfaceTags = {};
|
||||||
if (tagName.indexOf('surface') !== -1) {
|
let smoothnessTags = {};
|
||||||
return 'surface';
|
for (let wayTagIndex = 0; wayTagIndex < wayTags.length; wayTagIndex++) {
|
||||||
|
let wayTagParts = wayTags[wayTagIndex].split('=');
|
||||||
|
const tagName = wayTagParts[0];
|
||||||
|
const tagValue = wayTagParts[1];
|
||||||
|
|
||||||
|
if (tagName === 'surface') {
|
||||||
|
surfaceTags['default'] = tagValue;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (tagName.indexOf(':surface') !== -1) {
|
||||||
|
let tagNameParts = tagName.split(':');
|
||||||
|
surfaceTags[tagNameParts[0]] = tagValue;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the same applies to `smoothness`
|
if (tagName === 'smoothness') {
|
||||||
if (tagName.indexOf('smoothness') !== -1) {
|
smoothnessTags['default'] = tagValue;
|
||||||
return 'smoothness';
|
continue;
|
||||||
|
}
|
||||||
|
if (tagName.indexOf(':smoothness') !== -1) {
|
||||||
|
let tagNameParts = tagName.split(':');
|
||||||
|
smoothnessTags[tagNameParts[0]] = tagValue;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tagName;
|
normalizedWayTags[tagName] = tagValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (routingType) {
|
||||||
|
case 'cycling':
|
||||||
|
if (typeof surfaceTags['cycleway'] === 'string') {
|
||||||
|
normalizedWayTags['surface'] = surfaceTags['cycleway'];
|
||||||
|
}
|
||||||
|
if (typeof smoothnessTags['cycleway'] === 'string') {
|
||||||
|
normalizedWayTags['smoothness'] = smoothnessTags['cycleway'];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (typeof surfaceTags['default'] === 'string') {
|
||||||
|
normalizedWayTags['surface'] = surfaceTags['default'];
|
||||||
|
}
|
||||||
|
if (typeof smoothnessTags['default'] === 'string') {
|
||||||
|
normalizedWayTags['smoothness'] = smoothnessTags['default'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalizedWayTags;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue