From 332200b40405e723010aa65035bdd1523ecea433 Mon Sep 17 00:00:00 2001 From: Kushan Joshi <0o3ko0@gmail.com> Date: Wed, 22 Jun 2016 16:20:03 +0530 Subject: [PATCH] display lane count on sidebar --- modules/core/way.js | 22 ++++++++----------- modules/ui/preset/index.js | 1 + modules/ui/preset/lanes.js | 44 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 modules/ui/preset/lanes.js diff --git a/modules/core/way.js b/modules/core/way.js index 1022d1846..96e32aa60 100644 --- a/modules/core/way.js +++ b/modules/core/way.js @@ -101,13 +101,13 @@ _.extend(Way.prototype, { }, lanes: function() { - function parseTurnLane(str) { - if (!str || str === '') return null; - - return str.split('|').map(function(s) { - return s.split(';'); - }); - } + // function parseTurnLane(str) { + // if (!str || str === '') return null; + // + // return str.split('|').map(function(s) { + // return s.split(';'); + // }); + // } if (!this.tags.highway) return null; var defaultLanes = {}, tagged = {}; @@ -121,13 +121,9 @@ _.extend(Way.prototype, { break; } - if (this.isOneWay()) { - tagged.oneway = 'yes'; - } else { - tagged.oneway = 'no'; - } - + tagged.oneway = this.isOneWay(); tagged.lanes = {}; + if (this.tags.lanes) tagged.lanes.count = this.tags.lanes; if (this.tags['lanes:forward']) tagged.lanes.forward = this.tags['lanes:forward']; if (this.tags['lanes:backward']) tagged.lanes.backward = this.tags['lanes:backward']; diff --git a/modules/ui/preset/index.js b/modules/ui/preset/index.js index 264462df9..316e3848e 100644 --- a/modules/ui/preset/index.js +++ b/modules/ui/preset/index.js @@ -5,6 +5,7 @@ export { combo, typeCombo, multiCombo } from './combo'; export { cycleway } from './cycleway'; export { text, url, number, email, tel } from './input'; export { localized } from './localized'; +export { lanes } from './lanes'; export { maxspeed } from './maxspeed'; export { radio } from './radio'; export { restrictions } from './restrictions'; diff --git a/modules/ui/preset/lanes.js b/modules/ui/preset/lanes.js new file mode 100644 index 000000000..57a4bbdf3 --- /dev/null +++ b/modules/ui/preset/lanes.js @@ -0,0 +1,44 @@ +export function lanes(field, context) { + var dispatch = d3.dispatch('change'), + wayID, + laneData; + + function lanes(selection) { + // if form field is hidden or has detached from dom, clean up. + if (!d3.select('.inspector-wrap.inspector-hidden').empty() || !selection.node().parentNode) { + selection.call(lanes.off); + return; + } + + laneData = context.entity(wayID).lanes(); + + var wrap = selection.selectAll('.preset-input-wrap') + .data([0]); + + var enter = wrap.enter() + .append('div') + .attr('class', 'preset-input-wrap'); + + enter + .append('div') + .attr('class', 'lane-count') + .append('span'); + + selection.selectAll('.lane-count') + .text(laneData.tagged.lanes.count || laneData.defaults.lanes.count); + + } + + + lanes.entity = function(_) { + if (!wayID || wayID !== _.id) { + wayID = _.id; + } + }; + + lanes.tags = function() {}; + lanes.focus = function() {}; + lanes.off = function() {}; + + return d3.rebind(lanes, dispatch, 'on'); +}