More fixes to fields

This commit is contained in:
Bryan Housel
2016-09-18 12:55:30 -04:00
parent 6346a11880
commit c5a8bcc3a6
9 changed files with 143 additions and 87 deletions
+12 -7
View File
@@ -4,6 +4,7 @@ import { rebind } from '../../util/rebind';
import { getSetValue } from '../../util/get_set_value';
import { d3combobox } from '../../lib/d3.combobox.js';
export function access(field) {
var dispatch = d3.dispatch('change'),
items;
@@ -12,17 +13,18 @@ export function access(field) {
var wrap = selection.selectAll('.preset-input-wrap')
.data([0]);
var divEnter = wrap.enter().append('div')
.attr('class', 'cf preset-input-wrap');
divEnter.append('ul');
wrap = wrap.merge(divEnter);
wrap = wrap.enter()
.append('div')
.attr('class', 'cf preset-input-wrap')
.append('ul')
.merge(wrap);
items = wrap.select('ul').selectAll('li')
.data(field.keys);
// Enter
var enter = items.enter().append('li')
var enter = items.enter()
.append('li')
.attr('class', function(d) { return 'cf preset-access-' + d; });
enter.append('span')
@@ -42,21 +44,23 @@ export function access(field) {
.data(access.options(d)));
});
items = items.merge(enter);
// Update
items = items.merge(enter);
wrap.selectAll('.preset-input-access')
.on('change', change)
.on('blur', change);
}
function change(d) {
var tag = {};
tag[d] = getSetValue(d3.select(this)) || undefined;
dispatch.call('change', this, tag);
}
access.options = function(type) {
var options = ['no', 'permissive', 'private', 'destination'];
@@ -77,6 +81,7 @@ export function access(field) {
});
};
var placeholders = {
footway: {
foot: 'designated',
+15 -5
View File
@@ -21,6 +21,7 @@ export function address(field, context) {
postcode: 1/3
};
function getStreets() {
var extent = entity.extent(context.graph()),
l = extent.center(),
@@ -47,6 +48,7 @@ export function address(field, context) {
}
}
function getCities() {
var extent = entity.extent(context.graph()),
l = extent.center(),
@@ -81,6 +83,7 @@ export function address(field, context) {
}
}
function getPostCodes() {
var extent = entity.extent(context.graph()),
l = extent.center(),
@@ -103,20 +106,22 @@ export function address(field, context) {
}
}
function address(selection) {
isInitialized = false;
wrap = selection.selectAll('.preset-input-wrap')
.data([0]);
// Enter
wrap.enter()
wrap = wrap.enter()
.append('div')
.attr('class', 'preset-input-wrap');
.attr('class', 'preset-input-wrap')
.merge(wrap);
var center = entity.extent(context.graph()).center(),
addressFormat;
nominatim.init();
nominatim.countryCode(center, function (err, countryCode) {
addressFormat = _.find(addressFormats, function (a) {
@@ -152,7 +157,6 @@ export function address(field, context) {
.style('width', function (d) { return d.width * 100 + '%'; });
// Update
wrap.selectAll('.addr-street')
.call(d3combobox()
.fetcher(function(value, callback) {
@@ -183,6 +187,7 @@ export function address(field, context) {
});
}
function change(onInput) {
return function() {
var tags = {};
@@ -196,18 +201,21 @@ export function address(field, context) {
};
}
function updateTags(tags) {
getSetValue(wrap.selectAll('input'), function (field) {
return tags['addr:' + field.id] || '';
});
}
address.entity = function(_) {
if (!arguments.length) return entity;
entity = _;
return address;
};
address.tags = function(tags) {
if (isInitialized) {
updateTags(tags);
@@ -218,10 +226,12 @@ export function address(field, context) {
}
};
address.focus = function() {
var node = wrap.selectAll('input').node();
if (node) node.focus();
};
return rebind(address, dispatch, 'on');
}
+20 -10
View File
@@ -5,12 +5,16 @@ import { oneWayTags } from '../../core/index';
export { check as defaultcheck };
export function check(field) {
var dispatch = d3.dispatch('change'),
options = field.strings && field.strings.options,
values = [],
texts = [],
entity, value, box, text, label;
box = d3.select(null),
text = d3.select(null),
label = d3.select(null),
entity, value;
if (options) {
for (var k in options) {
@@ -26,6 +30,7 @@ export function check(field) {
}
}
var check = function(selection) {
// hack: pretend oneway field is a oneway_yes field
// where implied oneway tag exists (e.g. `junction=roundabout`) #2220, #1841
@@ -43,19 +48,14 @@ export function check(field) {
label = selection.selectAll('.preset-input-wrap')
.data([0]);
var enter = label.enter().append('label')
var enter = label.enter()
.append('label')
.attr('class', 'preset-input-wrap');
enter.append('input')
.property('indeterminate', field.type === 'check')
.attr('type', 'checkbox')
.attr('id', 'preset-input-' + field.id);
enter.append('span')
.text(texts[0])
.attr('class', 'value');
box = label.select('input')
.attr('id', 'preset-input-' + field.id)
.on('click', function() {
var t = {};
t[field.key] = values[(values.indexOf(value) + 1) % values.length];
@@ -63,15 +63,24 @@ export function check(field) {
d3.event.stopPropagation();
});
text = label.select('span.value');
enter.append('span')
.text(texts[0])
.attr('class', 'value');
label = label.merge(enter);
box = label.selectAll('input');
text = label.selectAll('span.value');
};
check.entity = function(_) {
if (!arguments.length) return entity;
entity = _;
return check;
};
check.tags = function(tags) {
value = tags[field.key];
box.property('indeterminate', field.type === 'check' && !value);
@@ -80,6 +89,7 @@ export function check(field) {
label.classed('set', !!value);
};
check.focus = function() {
box.node().focus();
};