From c95df1c830eaff72f96355f6e40d659deffb36ae Mon Sep 17 00:00:00 2001 From: Kushan Joshi <0o3ko0@gmail.com> Date: Sun, 21 Aug 2016 04:04:42 +0530 Subject: [PATCH] restructure lanesArray --- modules/core/way.js | 58 +++++++++++++++++++++++-------------------- test/spec/core/way.js | 13 +++++++--- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/modules/core/way.js b/modules/core/way.js index fd47c06ec..2b43f7c9f 100644 --- a/modules/core/way.js +++ b/modules/core/way.js @@ -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 }; }, diff --git a/test/spec/core/way.js b/test/spec/core/way.js index 036d72b9e..bccef6f01 100644 --- a/test/spec/core/way.js +++ b/test/spec/core/way.js @@ -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' ]); });