mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-31 01:09:22 +02:00
Add country-coder as a dependency
Use country-coder to code addresses (re: #6941)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import CountryCoder from 'country-coder';
|
||||
|
||||
import serviceKeepRight from './keepRight';
|
||||
import serviceImproveOSM from './improveOSM';
|
||||
import serviceMapillary from './mapillary';
|
||||
@@ -14,6 +16,7 @@ import serviceWikipedia from './wikipedia';
|
||||
|
||||
|
||||
export var services = {
|
||||
countryCoder: new CountryCoder(),
|
||||
geocoder: serviceNominatim,
|
||||
keepRight: serviceKeepRight,
|
||||
improveOSM: serviceImproveOSM,
|
||||
|
||||
@@ -10,7 +10,7 @@ import { utilArrayUniqBy, utilGetSetValue, utilNoAuto, utilRebind } from '../../
|
||||
|
||||
export function uiFieldAddress(field, context) {
|
||||
var dispatch = d3_dispatch('init', 'change');
|
||||
var nominatim = services.geocoder;
|
||||
var countryCoder = services.countryCoder;
|
||||
var wrap = d3_select(null);
|
||||
var _isInitialized = false;
|
||||
var _entity;
|
||||
@@ -109,8 +109,8 @@ export function uiFieldAddress(field, context) {
|
||||
}
|
||||
|
||||
|
||||
function countryCallback(err, countryCode) {
|
||||
if (err) return;
|
||||
function updateForCountryCode(countryCode) {
|
||||
if (!countryCode) return;
|
||||
countryCode = countryCode.toLowerCase();
|
||||
|
||||
var addressFormat;
|
||||
@@ -210,9 +210,10 @@ export function uiFieldAddress(field, context) {
|
||||
.attr('class', 'form-field-input-wrap form-field-input-' + field.type)
|
||||
.merge(wrap);
|
||||
|
||||
if (nominatim && _entity) {
|
||||
if (countryCoder && _entity) {
|
||||
var center = _entity.extent(context.graph()).center();
|
||||
nominatim.countryCode(center, countryCallback);
|
||||
var countryCode = countryCoder.iso1A2Code(center);
|
||||
updateForCountryCode(countryCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
"abortcontroller-polyfill": "^1.4.0",
|
||||
"alif-toolkit": "^1.2.6",
|
||||
"browser-polyfills": "~1.5.0",
|
||||
"country-coder": "^1.0.2",
|
||||
"diacritics": "1.3.0",
|
||||
"fast-deep-equal": "~2.0.1",
|
||||
"fast-json-stable-stringify": "2.0.0",
|
||||
|
||||
Reference in New Issue
Block a user