diff --git a/modules/presets/collection.js b/modules/presets/collection.js index c2f419cb1..dd1b56021 100644 --- a/modules/presets/collection.js +++ b/modules/presets/collection.js @@ -1,5 +1,4 @@ -import { utilArrayIntersection, utilArrayUniq } from '../util/array'; -import { utilEditDistance } from '../util'; +import { utilArrayUniq, utilEditDistance } from '../util'; // @@ -46,7 +45,7 @@ export function presetCollection(collection) { return _this.item(id); }; - _this.search = (value, geometry, countryCodes) => { + _this.search = (value, geometry, countryCode) => { if (!value) return _this; value = value.toLowerCase().trim(); @@ -84,13 +83,10 @@ export function presetCollection(collection) { } let pool = _this.collection; - if (countryCodes) { - if (typeof countryCodes === 'string') countryCodes = [countryCodes]; - countryCodes = countryCodes.map(code => code.toLowerCase()); - + if (countryCode) { pool = pool.filter(a => { - if (a.countryCodes && !utilArrayIntersection(a.countryCodes, countryCodes).length) return false; - if (a.notCountryCodes && utilArrayIntersection(a.notCountryCodes, countryCodes).length) return false; + if (a.countryCodes && a.countryCodes.indexOf(countryCode) === -1) return false; + if (a.notCountryCodes && a.notCountryCodes.indexOf(countryCode) !== -1) return false; return true; }); } diff --git a/modules/ui/field.js b/modules/ui/field.js index bd92c1afd..d26343bf1 100644 --- a/modules/ui/field.js +++ b/modules/ui/field.js @@ -9,7 +9,6 @@ import { geoExtent } from '../geo/extent'; import { uiFieldHelp } from './field_help'; import { uiFields } from './fields'; import { uiTagReference } from './tag_reference'; -import { utilArrayIntersection } from '../util/array'; import { utilRebind, utilUniqueDomId } from '../util'; @@ -307,14 +306,16 @@ export function uiField(context, presetField, entityIDs, options) { if (!extent) return true; var center = extent.center(); - var codes = countryCoder.iso1A2Codes(center).map(function(code) { - return code.toLowerCase(); - }); + var countryCode = countryCoder.iso1A2Code(center); - if (field.countryCodes && !utilArrayIntersection(codes, field.countryCodes).length) { + if (!countryCode) return false; + + countryCode = countryCode.toLowerCase(); + + if (field.countryCodes && field.countryCodes.indexOf(countryCode) === -1) { return false; } - if (field.notCountryCodes && utilArrayIntersection(codes, field.notCountryCodes).length) { + if (field.notCountryCodes && field.notCountryCodes.indexOf(countryCode) !== -1) { return false; } } diff --git a/modules/ui/preset_list.js b/modules/ui/preset_list.js index aa92d508e..3402918ff 100644 --- a/modules/ui/preset_list.js +++ b/modules/ui/preset_list.js @@ -98,9 +98,9 @@ export function uiPresetList(context) { var results, messageText; if (value.length && extent) { var center = extent.center(); - var countryCodes = countryCoder.iso1A2Codes(center); + var countryCode = countryCoder.iso1A2Code(center); - results = presets.search(value, entityGeometries()[0], countryCodes); + results = presets.search(value, entityGeometries()[0], countryCode && countryCode.toLowerCase()); messageText = t('inspector.results', { n: results.collection.length, search: value