restructure lanesArray

This commit is contained in:
Kushan Joshi
2016-08-21 04:04:42 +05:30
parent ce948f7563
commit c95df1c830
2 changed files with 40 additions and 31 deletions

View File

@@ -225,6 +225,21 @@ _.extend(Way.prototype, {
return parsedArray;
}
function addToLanesArray(data, key) {
if (data.forward) data.forward.forEach(function(l, i) {
if (!lanesArray.forward[i]) lanesArray.forward[i] = {};
lanesArray.forward[i][key] = l;
});
if (data.backward) data.backward.forEach(function(l, i) {
if (!lanesArray.backward[i]) lanesArray.backward[i] = {};
lanesArray.backward[i][key] = l;
});
if (data.unspecified) data.unspecified.forEach(function(l, i) {
if (!lanesArray.unspecified[i]) lanesArray.unspecified[i] = {};
lanesArray.unspecified[i][key] = l;
});
}
if (!this.tags.highway) return null;
var tags = this.tags;
@@ -278,32 +293,20 @@ _.extend(Way.prototype, {
bicyclewayLanes.forward = parseBicycleWay('bicycleway:lanes:forward');
bicyclewayLanes.backward = parseBicycleWay('bicycleway:lanes:backward');
// fill each undefined lanesArray's direction element with 'forward/bothways/backward'.
// smartFill(lanesArray, 'direction', _.fill(Array(forward), 'forward'));
// smartFill(lanesArray, 'direction', _.fill(Array(bothways), 'bothways'));
// smartFill(lanesArray, 'direction', _.fill(Array(backward), 'backward'));
//
// // parse turn:lanes:forward/backward first
//
// if (!oneway && this.tags['turn:lanes:forward'] && this.tags['turn:lanes:backward']) {
// smartFill(lanesArray, 'turnLane', turnLanesForward);
// // if both_ways fill it with null
// smartFill(lanesArray, 'turnLane', _.fill(Array(bothways), null));
// smartFill(lanesArray, 'turnLane', turnLanesBackward);
// }
// else if (this.tags['turn:lanes']) {
// smartFill(lanesArray, 'turnLane', turnLanes);
// }
//
// // parse max speed
// if (!oneway && this.tags['maxspeed:lanes:forward'] && this.tags['maxspeed:lanes:backward']) {
// smartFill(lanesArray, 'maxspeed', maxspeedLanesForward);
// smartFill(lanesArray, 'maxspeed', _.fill(Array(bothways), null));
// smartFill(lanesArray, 'maxspeed', maxspeedLanesBackward);
// }
// else if (this.tags['maxspeed:lanes']) {
// smartFill(lanesArray, 'maxspeed', maxspeedLanes);
// }
var lanesArray = {
forward: [],
backward: [],
unspecified: []
};
addToLanesArray(turnLanes, 'turnLane');
addToLanesArray(maxspeedLanes, 'maxspeed');
addToLanesArray(psvLanes, 'psv');
addToLanesArray(busLanes, 'bus');
addToLanesArray(taxiLanes, 'taxi');
addToLanesArray(hovLanes, 'hov');
addToLanesArray(hgvLanes, 'hgv');
addToLanesArray(bicyclewayLanes, 'bicycle');
return {
metadata: {
@@ -321,7 +324,8 @@ _.extend(Way.prototype, {
hovLanes: hovLanes,
hgvLanes: hgvLanes,
bicyclewayLanes: bicyclewayLanes
}
},
lanes: lanesArray
};
},

View File

@@ -1487,15 +1487,20 @@ describe('iD.Way', function() {
});
it('should parse correctly when some values maxspeed:lanes are implied by x||| notation', function() {
var maxspeedLanes = iD.Way({
var lanes = iD.Way({
tags: {
highway: 'residential',
lanes: 4,
lanes: 5,
'lanes:forward': 1,
'lanes:both_ways': 1,
'turn:lanes:forward': 'slight_left',
'turn:lanes:backward': 'none|through|through;slight_right',
maxspeed: '60kmh',
'maxspeed:lanes': '30|||'
}
}).lanes().metadata.maxspeedLanes;
expect(maxspeedLanes.unspecified).to.deep.equal([
}).lanes();
console.log(JSON.stringify(lanes.lanes, null, '\t'));
expect(lanes.metadata.maxspeedLanes.unspecified).to.deep.equal([
30, 'none', 'none', 'none'
]);
});