mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
Replace remaining nominatim countryCode calls with country-coder calls (close #6941)
This commit is contained in:
@@ -10,7 +10,6 @@ import { utilArrayUniqBy, utilGetSetValue, utilNoAuto, utilRebind } from '../../
|
||||
|
||||
export function uiFieldAddress(field, context) {
|
||||
var dispatch = d3_dispatch('init', 'change');
|
||||
var countryCoder = services.countryCoder;
|
||||
var wrap = d3_select(null);
|
||||
var _isInitialized = false;
|
||||
var _entity;
|
||||
@@ -110,7 +109,6 @@ export function uiFieldAddress(field, context) {
|
||||
|
||||
|
||||
function updateForCountryCode(countryCode) {
|
||||
if (!countryCode) return;
|
||||
countryCode = countryCode.toLowerCase();
|
||||
|
||||
var addressFormat;
|
||||
@@ -210,10 +208,10 @@ export function uiFieldAddress(field, context) {
|
||||
.attr('class', 'form-field-input-wrap form-field-input-' + field.type)
|
||||
.merge(wrap);
|
||||
|
||||
if (countryCoder && _entity) {
|
||||
if (services.countryCoder && _entity) {
|
||||
var center = _entity.extent(context.graph()).center();
|
||||
var countryCode = countryCoder.iso1A2Code(center);
|
||||
updateForCountryCode(countryCode);
|
||||
var countryCode = services.countryCoder.iso1A2Code(center);
|
||||
if (countryCode) updateForCountryCode(countryCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ export {
|
||||
|
||||
export function uiFieldCombo(field, context) {
|
||||
var dispatch = d3_dispatch('change');
|
||||
var nominatim = services.geocoder;
|
||||
var countryCoder = services.countryCoder;
|
||||
var taginfo = services.taginfo;
|
||||
var isMulti = (field.type === 'multiCombo');
|
||||
var isNetwork = (field.type === 'networkCombo');
|
||||
@@ -35,7 +35,7 @@ export function uiFieldCombo(field, context) {
|
||||
var _comboData = [];
|
||||
var _multiData = [];
|
||||
var _entity;
|
||||
var _country;
|
||||
var _countryCode;
|
||||
|
||||
// ensure multiCombo field.key ends with a ':'
|
||||
if (isMulti && /[^:]$/.test(field.key)) {
|
||||
@@ -163,9 +163,9 @@ export function uiFieldCombo(field, context) {
|
||||
function setTaginfoValues(q, callback) {
|
||||
var fn = isMulti ? 'multikeys' : 'values';
|
||||
var query = (isMulti ? field.key : '') + q;
|
||||
var hasCountryPrefix = isNetwork && _country && _country.indexOf(q.toLowerCase()) === 0;
|
||||
var hasCountryPrefix = isNetwork && _countryCode && _countryCode.indexOf(q.toLowerCase()) === 0;
|
||||
if (hasCountryPrefix) {
|
||||
query = _country + ':';
|
||||
query = _countryCode + ':';
|
||||
}
|
||||
|
||||
var params = {
|
||||
@@ -191,7 +191,7 @@ export function uiFieldCombo(field, context) {
|
||||
|
||||
if (hasCountryPrefix) {
|
||||
data = data.filter(function(d) {
|
||||
return d.value.toLowerCase().indexOf(_country + ':') === 0;
|
||||
return d.value.toLowerCase().indexOf(_countryCode + ':') === 0;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -351,11 +351,10 @@ export function uiFieldCombo(field, context) {
|
||||
.call(initCombo, selection)
|
||||
.merge(input);
|
||||
|
||||
if (isNetwork && nominatim && _entity) {
|
||||
if (isNetwork && countryCoder && _entity) {
|
||||
var center = _entity.extent(context.graph()).center();
|
||||
nominatim.countryCode(center, function (err, code) {
|
||||
_country = code;
|
||||
});
|
||||
var countryCode = countryCoder.iso1A2Code(center);
|
||||
_countryCode = countryCode && countryCode.toLowerCase();
|
||||
}
|
||||
|
||||
input
|
||||
|
||||
@@ -17,7 +17,6 @@ export {
|
||||
|
||||
export function uiFieldText(field, context) {
|
||||
var dispatch = d3_dispatch('change');
|
||||
var nominatim = services.geocoder;
|
||||
var input = d3_select(null);
|
||||
var _entity;
|
||||
|
||||
@@ -56,13 +55,14 @@ export function uiFieldText(field, context) {
|
||||
.on('change', change());
|
||||
|
||||
|
||||
if (field.type === 'tel' && nominatim && _entity) {
|
||||
if (field.type === 'tel' && services.countryCoder && _entity) {
|
||||
var center = _entity.extent(context.graph()).center();
|
||||
nominatim.countryCode(center, function (err, countryCode) {
|
||||
if (err || !dataPhoneFormats[countryCode]) return;
|
||||
var countryCode = services.countryCoder.iso1A2Code(center);
|
||||
var format = countryCode && dataPhoneFormats[countryCode.toLowerCase()];
|
||||
if (format) {
|
||||
wrap.selectAll('#' + fieldID)
|
||||
.attr('placeholder', dataPhoneFormats[countryCode]);
|
||||
});
|
||||
.attr('placeholder', format);
|
||||
}
|
||||
|
||||
} else if (field.type === 'number') {
|
||||
var rtl = (textDirection === 'rtl');
|
||||
|
||||
@@ -574,11 +574,8 @@ export function uiFieldLocalized(field, context) {
|
||||
|
||||
function loadCountryCode() {
|
||||
var center = _entity.extent(context.graph()).center();
|
||||
services.geocoder.countryCode(center, function(err, result) {
|
||||
if (!err && result) {
|
||||
_countryCode = result;
|
||||
}
|
||||
});
|
||||
var countryCode = services.countryCoder.iso1A2Code(center);
|
||||
_countryCode = countryCode && countryCode.toLowerCase();
|
||||
}
|
||||
|
||||
return utilRebind(localized, dispatch, 'on');
|
||||
|
||||
@@ -70,7 +70,7 @@ export function uiIntro(context) {
|
||||
var opacity = d3_selectAll('#map .layer-background').style('opacity');
|
||||
var caches = osm && osm.caches();
|
||||
var baseEntities = context.history().graph().base().entities;
|
||||
var countryCode = services.geocoder.countryCode;
|
||||
var countryCode = services.countryCoder.iso1A2Code;
|
||||
|
||||
// Show sidebar and disable the sidebar resizing button
|
||||
// (this needs to be before `context.inIntro(true)`)
|
||||
@@ -107,8 +107,8 @@ export function uiIntro(context) {
|
||||
});
|
||||
|
||||
// Mock geocoder
|
||||
services.geocoder.countryCode = function(location, callback) {
|
||||
callback(null, t('intro.graph.countrycode'));
|
||||
services.countryCoder.iso1A2Code = function() {
|
||||
return t('intro.graph.countrycode');
|
||||
};
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ export function uiIntro(context) {
|
||||
if (history) { context.history().fromJSON(history, false); }
|
||||
context.map().centerZoom(center, zoom);
|
||||
window.location.replace(hash);
|
||||
services.geocoder.countryCode = countryCode;
|
||||
services.countryCoder.iso1A2Code = countryCode;
|
||||
context.inIntro(false);
|
||||
});
|
||||
|
||||
|
||||
+14
-26
@@ -22,7 +22,6 @@ export function uiPresetList(context) {
|
||||
var _entityID;
|
||||
var _currentPreset;
|
||||
var _autofocus = false;
|
||||
var geocoder = services.geocoder;
|
||||
|
||||
|
||||
function presetList(selection) {
|
||||
@@ -100,34 +99,23 @@ export function uiPresetList(context) {
|
||||
function inputevent() {
|
||||
var value = search.property('value');
|
||||
list.classed('filtered', value.length);
|
||||
if (value.length) {
|
||||
var entity = context.entity(_entityID);
|
||||
if (geocoder && entity) {
|
||||
var center = entity.extent(context.graph()).center();
|
||||
geocoder.countryCode(center, function countryCallback(err, countryCode) {
|
||||
// get the input value again because it may have changed
|
||||
var currentValue = search.property('value');
|
||||
var entity = context.entity(_entityID);
|
||||
var results, messageText;
|
||||
if (value.length && entity && services.countryCoder) {
|
||||
var center = entity.extent(context.graph()).center();
|
||||
var countryCode = services.countryCoder.iso1A2Code(center);
|
||||
|
||||
if (!currentValue.length) return;
|
||||
|
||||
var results;
|
||||
if (!err && countryCode) {
|
||||
countryCode = countryCode.toLowerCase();
|
||||
results = presets.search(currentValue, geometry, countryCode);
|
||||
} else {
|
||||
results = presets.search(currentValue, geometry);
|
||||
}
|
||||
message.text(t('inspector.results', {
|
||||
n: results.collection.length,
|
||||
search: currentValue
|
||||
}));
|
||||
list.call(drawList, results);
|
||||
});
|
||||
}
|
||||
results = presets.search(value, geometry, countryCode && countryCode.toLowerCase());
|
||||
messageText = t('inspector.results', {
|
||||
n: results.collection.length,
|
||||
search: value
|
||||
});
|
||||
} else {
|
||||
list.call(drawList, context.presets().defaults(geometry, 36));
|
||||
message.text(t('inspector.choose'));
|
||||
results = context.presets().defaults(geometry, 36);
|
||||
messageText = t('inspector.choose');
|
||||
}
|
||||
list.call(drawList, results);
|
||||
message.text(messageText);
|
||||
}
|
||||
|
||||
var searchWrap = selection
|
||||
|
||||
Reference in New Issue
Block a user