|
|
|
@ -136,19 +136,24 @@ function patchBuggyResponses(response){
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// generate an index to avoid multiple iterations over the response array
|
|
|
|
|
let idx = {}; |
|
|
|
|
response.forEach((res, pos) => idx[res.label] = _.assign({ _pos: pos }, res)); |
|
|
|
|
|
|
|
|
|
// known bug where the street name is only a directional, in this case we will merge it
|
|
|
|
|
// with the subsequent element.
|
|
|
|
|
// note: the bug only affects diagonals, not N,S,E,W
|
|
|
|
|
// https://github.com/OpenTransitTools/trimet-mod-pelias/issues/20#issuecomment-417732128
|
|
|
|
|
for( var i=0; i<response.length-1; i++ ){ // dont bother checking the last element
|
|
|
|
|
if( 'road' !== response[i].label ){ continue; } |
|
|
|
|
if( 'string' !== typeof response[i].value ){ continue; } |
|
|
|
|
if( 2 !== response[i].value.length ){ continue; } |
|
|
|
|
if( DIAGONAL_DIRECTIONALS.includes( response[i].value.toLowerCase() ) ){ |
|
|
|
|
if( 'string' !== typeof response[i+1].value ){ continue; } |
|
|
|
|
response[i].value += ' ' + response[i+1].value; // merge elements
|
|
|
|
|
response.splice(i+1, 1); // remove merged element
|
|
|
|
|
break; |
|
|
|
|
if( response.length > 1 ){ |
|
|
|
|
let road = _.get(idx, 'road'); |
|
|
|
|
if( _.isPlainObject(road) && _.isString(road.value) && road.value.length === 2 ){ |
|
|
|
|
if( DIAGONAL_DIRECTIONALS.includes( road.value.toLowerCase() ) ){ |
|
|
|
|
let subsequentElement = response[road._pos+1]; |
|
|
|
|
if( _.isString(subsequentElement.value) ){ |
|
|
|
|
response[road._pos].value += ' ' + subsequentElement.value; // merge elements
|
|
|
|
|
response.splice(road._pos+1, 1); // remove merged element
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|