Skip to content

Commit

Permalink
Add country-coder as a dependency
Browse files Browse the repository at this point in the history
Use country-coder to code addresses (re: #6941)
  • Loading branch information
quincylvania committed Nov 1, 2019
1 parent 9224b0a commit 51dbdb4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions modules/services/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import CountryCoder from 'country-coder';

import serviceKeepRight from './keepRight';
import serviceImproveOSM from './improveOSM';
import serviceMapillary from './mapillary';
Expand All @@ -14,6 +16,7 @@ import serviceWikipedia from './wikipedia';


export var services = {
countryCoder: new CountryCoder(),
geocoder: serviceNominatim,
keepRight: serviceKeepRight,
improveOSM: serviceImproveOSM,
Expand Down
11 changes: 6 additions & 5 deletions modules/ui/fields/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 51dbdb4

Please sign in to comment.