adding a lanes() to return lane data

This commit is contained in:
Kushan Joshi
2016-06-07 20:24:57 +05:30
committed by Bryan Housel
parent 645fcbeea8
commit 4083a0e29e
9 changed files with 91 additions and 11 deletions

View File

@@ -472,8 +472,6 @@ en:
lanes:
# 'lanes=*'
label: Lanes
# lanes field placeholder
placeholder: '1, 2, 3...'
layer:
# 'layer=*'
label: Layer

View File

@@ -647,9 +647,8 @@
},
"lanes": {
"key": "lanes",
"type": "number",
"label": "Lanes",
"placeholder": "1, 2, 3..."
"type": "lanes",
"label": "Lanes"
},
"layer": {
"key": "layer",

View File

@@ -1,6 +1,5 @@
{
"key": "lanes",
"type": "number",
"label": "Lanes",
"placeholder":"1, 2, 3..."
"type": "lanes",
"label": "Lanes"
}

View File

@@ -66,7 +66,8 @@
"localized",
"wikipedia",
"typeCombo",
"restrictions"
"restrictions",
"lanes"
],
"required": true
},

View File

@@ -1046,8 +1046,7 @@
"label": "Type"
},
"lanes": {
"label": "Lanes",
"placeholder": "1, 2, 3..."
"label": "Lanes"
},
"layer": {
"label": "Layer"

View File

@@ -48,6 +48,7 @@
<script src='data/data_dev.js'></script>
<script src='js/lib/locale.js'></script>
<script src='data/introGraph.js'></script>
</head>
<body>

39
js/id/ui/preset/lanes.js Normal file
View File

@@ -0,0 +1,39 @@
iD.ui.preset.lanes = function(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;
}
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-help');
laneData = context.entity(wayID).lanes();
}
lanes.entity = function(_) {
if (!wayID || wayID !== _.id) {
wayID = _.id;
}
};
lanes.tags = function() {};
lanes.focus = function() {};
lanes.off = function() {};
return d3.rebind(lanes, dispatch, 'on');
};

View File

@@ -100,6 +100,46 @@ _.extend(Way.prototype, {
return false;
},
lanes: function() {
if (!this.tags.highway) return null;
var defaultLanes = {}, tagged = {};
switch (this.tags.highway) {
case 'service':
case 'track':
case 'path':
defaultLanes.count = this.isOneWay() ? 1 : 2;
break;
case 'trunk':
case 'motorway':
defaultLanes.count = this.isOneWay() ? 2 : 4;
break;
default:
defaultLanes.count = this.isOneWay() ? 1 : 2;
break;
}
if (!this.isOneWay()) {
defaultLanes.forward = defaultLanes.count/2;
defaultLanes.backward = defaultLanes.count/2;
} else {
tagged.oneway = 'yes';
}
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'];
return {
defaults: {
lanes: defaultLanes
},
tagged: tagged
};
},
isClosed: function() {
return this.nodes.length > 0 && this.first() === this.last();
},

View File

@@ -88,6 +88,10 @@ export function preset(context) {
fields.push(UIField(context.presets().field('restrictions'), entity, true));
}
if (entity.lanes(context.graph())) {
fields.push(UIField(context.presets().field('lanes'), entity, true));
}
context.presets().universal().forEach(function(field) {
if (preset.fields.indexOf(field) < 0) {
fields.push(UIField(field, entity));