Update country-coder to 2.0.0 (close #7029)

Localize address field in walkthrough without overwriting country coder function
This commit is contained in:
Quincy Morgan
2019-11-07 18:45:46 +01:00
parent 2a4841f517
commit d89996e52c
8 changed files with 21 additions and 22 deletions

View File

@@ -1,5 +1,3 @@
import CountryCoder from 'country-coder';
import serviceKeepRight from './keepRight';
import serviceImproveOSM from './improveOSM';
import serviceMapillary from './mapillary';
@@ -16,7 +14,6 @@ import serviceWikipedia from './wikipedia';
export var services = {
countryCoder: new CountryCoder(),
geocoder: serviceNominatim,
keepRight: serviceKeepRight,
improveOSM: serviceImproveOSM,

View File

@@ -1,9 +1,9 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { select as d3_select } from 'd3-selection';
import * as countryCoder from 'country-coder';
import { dataAddressFormats } from '../../../data';
import { geoExtent, geoChooseEdge, geoSphericalDistance } from '../../geo';
import { services } from '../../services';
import { uiCombobox } from '../combobox';
import { utilArrayUniqBy, utilGetSetValue, utilNoAuto, utilRebind } from '../../util';
@@ -208,9 +208,15 @@ export function uiFieldAddress(field, context) {
.attr('class', 'form-field-input-wrap form-field-input-' + field.type)
.merge(wrap);
if (services.countryCoder && _entity) {
var center = _entity.extent(context.graph()).center();
var countryCode = services.countryCoder.iso1A2Code(center);
if (_entity) {
var countryCode;
if (context.inIntro()) {
// localize the address format for the walkthrough
countryCode = t('intro.graph.countrycode');
} else {
var center = _entity.extent(context.graph()).center();
countryCode = countryCoder.iso1A2Code(center);
}
if (countryCode) updateForCountryCode(countryCode);
}
}

View File

@@ -1,5 +1,6 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { event as d3_event, select as d3_select } from 'd3-selection';
import * as countryCoder from 'country-coder';
import { osmEntity } from '../../osm/entity';
import { t } from '../../util/locale';
@@ -17,7 +18,6 @@ export {
export function uiFieldCombo(field, context) {
var dispatch = d3_dispatch('change');
var countryCoder = services.countryCoder;
var taginfo = services.taginfo;
var isMulti = (field.type === 'multiCombo');
var isNetwork = (field.type === 'networkCombo');
@@ -351,7 +351,7 @@ export function uiFieldCombo(field, context) {
.call(initCombo, selection)
.merge(input);
if (isNetwork && countryCoder && _entity) {
if (isNetwork && _entity) {
var center = _entity.extent(context.graph()).center();
var countryCode = countryCoder.iso1A2Code(center);
_countryCode = countryCode && countryCode.toLowerCase();

View File

@@ -1,5 +1,6 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { select as d3_select, event as d3_event } from 'd3-selection';
import * as countryCoder from 'country-coder';
import { t, textDirection } from '../../util/locale';
import { dataPhoneFormats } from '../../../data';
@@ -55,9 +56,9 @@ export function uiFieldText(field, context) {
.on('change', change());
if (field.type === 'tel' && services.countryCoder && _entity) {
if (field.type === 'tel' && _entity) {
var center = _entity.extent(context.graph()).center();
var countryCode = services.countryCoder.iso1A2Code(center);
var countryCode = countryCoder.iso1A2Code(center);
var format = countryCode && dataPhoneFormats[countryCode.toLowerCase()];
if (format) {
wrap.selectAll('#' + fieldID)

View File

@@ -1,5 +1,6 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { select as d3_select, event as d3_event } from 'd3-selection';
import * as countryCoder from 'country-coder';
import { currentLocale, t, languageName } from '../../util/locale';
import { dataLanguages } from '../../../data';
@@ -574,7 +575,7 @@ export function uiFieldLocalized(field, context) {
function loadCountryCode() {
var center = _entity.extent(context.graph()).center();
var countryCode = services.countryCoder.iso1A2Code(center);
var countryCode = countryCoder.iso1A2Code(center);
_countryCode = countryCode && countryCode.toLowerCase();
}

View File

@@ -70,7 +70,6 @@ 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.countryCoder.iso1A2Code;
// Show sidebar and disable the sidebar resizing button
// (this needs to be before `context.inIntro(true)`)
@@ -106,11 +105,6 @@ export function uiIntro(context) {
}
});
// Mock geocoder
services.countryCoder.iso1A2Code = function() {
return t('intro.graph.countrycode');
};
d3_selectAll('#map .layer-background').style('opacity', 1);
@@ -168,7 +162,6 @@ export function uiIntro(context) {
if (history) { context.history().fromJSON(history, false); }
context.map().centerZoom(center, zoom);
window.location.replace(hash);
services.countryCoder.iso1A2Code = countryCode;
context.inIntro(false);
});

View File

@@ -1,4 +1,5 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import * as countryCoder from 'country-coder';
import {
event as d3_event,
@@ -101,9 +102,9 @@ export function uiPresetList(context) {
list.classed('filtered', value.length);
var entity = context.entity(_entityID);
var results, messageText;
if (value.length && entity && services.countryCoder) {
if (value.length && entity) {
var center = entity.extent(context.graph()).center();
var countryCode = services.countryCoder.iso1A2Code(center);
var countryCode = countryCoder.iso1A2Code(center);
results = presets.search(value, geometry, countryCode && countryCode.toLowerCase());
messageText = t('inspector.results', {

View File

@@ -41,7 +41,7 @@
"abortcontroller-polyfill": "^1.4.0",
"alif-toolkit": "^1.2.6",
"browser-polyfills": "~1.5.0",
"country-coder": "^1.0.2",
"country-coder": "^2.0.0",
"diacritics": "1.3.0",
"fast-deep-equal": "~2.0.1",
"fast-json-stable-stringify": "2.0.0",