mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Localize maxspeed field (mph and km/h)
This commit is contained in:
3
build.js
3
build.js
@@ -100,7 +100,8 @@ fs.writeFileSync('data/data.js', 'iD.data = ' + stringify({
|
||||
defaults: rp('defaults.json'),
|
||||
categories: rp('categories.json'),
|
||||
fields: rp('fields.json')
|
||||
}
|
||||
},
|
||||
imperial: r('imperial.json')
|
||||
}) + ';');
|
||||
|
||||
// Push changes from data/core.yaml into data/locales.js
|
||||
|
||||
18
css/app.css
18
css/app.css
@@ -1144,6 +1144,24 @@ input[type=number] {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#preset-input-maxspeed {
|
||||
border-right: none;
|
||||
border-radius: 0;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.form-field .maxspeed-unit {
|
||||
border-radius: 0 0 4px 0;
|
||||
border: 1px solid #ccc;
|
||||
border-top: none;
|
||||
height: 30px;
|
||||
width: 20%;
|
||||
float: right;
|
||||
padding: 5px;
|
||||
text-align: center;
|
||||
|
||||
}
|
||||
|
||||
/* Preset form address */
|
||||
|
||||
.form-field .addr-housename {
|
||||
|
||||
@@ -13,7 +13,8 @@ iD.data = {
|
||||
path + 'data/presets/presets.json',
|
||||
path + 'data/presets/defaults.json',
|
||||
path + 'data/presets/categories.json',
|
||||
path + 'data/presets/fields.json'
|
||||
path + 'data/presets/fields.json',
|
||||
path + 'data/imperial.json'
|
||||
], d3.json, function (err, data) {
|
||||
|
||||
iD.data = {
|
||||
@@ -27,7 +28,8 @@ iD.data = {
|
||||
defaults: data[6],
|
||||
categories: data[7],
|
||||
fields: data[8]
|
||||
}
|
||||
},
|
||||
imperial: data[9]
|
||||
};
|
||||
|
||||
callback();
|
||||
|
||||
9
data/imperial.json
Normal file
9
data/imperial.json
Normal file
File diff suppressed because one or more lines are too long
@@ -198,7 +198,7 @@
|
||||
},
|
||||
"maxspeed": {
|
||||
"key": "maxspeed",
|
||||
"type": "combo",
|
||||
"type": "maxspeed",
|
||||
"label": "Speed Limit"
|
||||
},
|
||||
"name": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"key": "maxspeed",
|
||||
"type": "combo",
|
||||
"type": "maxspeed",
|
||||
"label": "Speed Limit"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"combo",
|
||||
"defaultcheck",
|
||||
"text",
|
||||
"maxspeed",
|
||||
"number",
|
||||
"tel",
|
||||
"email",
|
||||
|
||||
@@ -100,6 +100,7 @@
|
||||
<script src='js/id/ui/preset/combo.js'></script>
|
||||
<script src='js/id/ui/preset/defaultcheck.js'></script>
|
||||
<script src='js/id/ui/preset/input.js'></script>
|
||||
<script src='js/id/ui/preset/maxspeed.js'></script>
|
||||
<script src='js/id/ui/preset/radio.js'></script>
|
||||
<script src='js/id/ui/preset/textarea.js'></script>
|
||||
<script src='js/id/ui/preset/wikipedia.js'></script>
|
||||
|
||||
@@ -15,7 +15,9 @@ iD.ui.preset = function(context, entity, preset) {
|
||||
|
||||
field.reference = iD.ui.TagReference(entity, {key: field.key});
|
||||
|
||||
if (field.type === 'address' || field.type === 'wikipedia') {
|
||||
if (field.type === 'address' ||
|
||||
field.type === 'wikipedia' ||
|
||||
field.type === 'maxspeed') {
|
||||
field.input.entity(entity);
|
||||
}
|
||||
|
||||
|
||||
73
js/id/ui/preset/maxspeed.js
Normal file
73
js/id/ui/preset/maxspeed.js
Normal file
@@ -0,0 +1,73 @@
|
||||
iD.ui.preset.maxspeed = function(field, context) {
|
||||
|
||||
var event = d3.dispatch('change', 'close'),
|
||||
entity,
|
||||
imperial,
|
||||
input;
|
||||
|
||||
var metricValues = [20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],
|
||||
imperialValues = [20, 25, 30, 40, 45, 50, 55, 65, 70];
|
||||
|
||||
function maxspeed(selection) {
|
||||
var combobox = d3.combobox();
|
||||
|
||||
input = selection.append('input')
|
||||
.attr('type', 'text')
|
||||
.attr('id', 'preset-input-' + field.id)
|
||||
.on('change', change)
|
||||
.on('blur', change)
|
||||
.call(combobox);
|
||||
|
||||
var childNodes = context.graph().childNodes(context.entity(entity.id)),
|
||||
centroid = d3.geom.polygon(_.pluck(childNodes, 'loc')).centroid();
|
||||
|
||||
imperial = _.any(iD.data.imperial.features, function(f) {
|
||||
return _.any(f.geometry.coordinates, function(d) {
|
||||
return iD.geo.pointInPolygon(centroid, d[0]);
|
||||
});
|
||||
});
|
||||
|
||||
selection.append('span')
|
||||
.attr('class', 'maxspeed-unit')
|
||||
.text(imperial ? 'mph' : 'km/h');
|
||||
|
||||
combobox.data((imperial ? imperialValues : metricValues).map(function(d) {
|
||||
return {
|
||||
value: d.toString(),
|
||||
title: d.toString()
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
function change() {
|
||||
var value = input.property('value');
|
||||
var t = {};
|
||||
if (value) {
|
||||
if (isNaN(value) || !imperial) {
|
||||
t[field.key] = value;
|
||||
} else {
|
||||
t[field.key] = value + ' mph';
|
||||
}
|
||||
} else {
|
||||
t[field.key] = '';
|
||||
}
|
||||
event.change(t);
|
||||
}
|
||||
|
||||
maxspeed.tags = function(tags) {
|
||||
var value = tags[field.key];
|
||||
if (value && isNaN(value) && value.indexOf('mph') >= 0) value = parseInt(value, 10);
|
||||
input.property('value', value || '');
|
||||
};
|
||||
|
||||
maxspeed.focus = function() {
|
||||
input.node().focus();
|
||||
};
|
||||
|
||||
maxspeed.entity = function(_) {
|
||||
entity = _;
|
||||
};
|
||||
|
||||
return d3.rebind(maxspeed, event, 'on');
|
||||
};
|
||||
Reference in New Issue
Block a user