diff --git a/modules/presets/collection.js b/modules/presets/collection.js index 7ddc72d18..fa867fb14 100644 --- a/modules/presets/collection.js +++ b/modules/presets/collection.js @@ -1,4 +1,5 @@ -import { utilArrayUniq, utilEditDistance } from '../util'; +import { utilArrayIntersection, utilArrayUniq } from '../util/array'; +import { utilEditDistance } from '../util'; // @@ -45,7 +46,7 @@ export function presetCollection(collection) { return _this.item(id); }; - _this.search = (value, geometry, countryCode) => { + _this.search = (value, geometry, countryCodes) => { if (!value) return _this; value = value.toLowerCase().trim(); @@ -87,11 +88,14 @@ export function presetCollection(collection) { } let pool = _this.collection; - if (countryCode) { + if (countryCodes) { + if (typeof countryCodes === 'string') countryCodes = [countryCodes]; + countryCodes = countryCodes.map(code => code.toLowerCase()); + pool = pool.filter(a => { if (a.locationSet) { - if (a.locationSet.include && a.locationSet.include.indexOf(countryCode) === -1) return false; - if (a.locationSet.exclude && a.locationSet.exclude.indexOf(countryCode) !== -1) return false; + if (a.locationSet.include && !utilArrayIntersection(a.locationSet.include, countryCodes).length) return false; + if (a.locationSet.exclude && utilArrayIntersection(a.locationSet.exclude, countryCodes).length) return false; } return true; }); diff --git a/modules/ui/field.js b/modules/ui/field.js index f2e2ebbff..96718a7e4 100644 --- a/modules/ui/field.js +++ b/modules/ui/field.js @@ -9,6 +9,7 @@ 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'; @@ -306,16 +307,14 @@ export function uiField(context, presetField, entityIDs, options) { if (!extent) return true; var center = extent.center(); - var countryCode = countryCoder.iso1A2Code(center); + var codes = countryCoder.iso1A2Codes(center).map(function(code) { + return code.toLowerCase(); + }); - if (!countryCode) return false; - - countryCode = countryCode.toLowerCase(); - - if (field.locationSet.include && field.locationSet.include.indexOf(countryCode) === -1) { + if (field.locationSet.include && !utilArrayIntersection(codes, field.locationSet.include).length) { return false; } - if (field.locationSet.exclude && field.locationSet.exclude.indexOf(countryCode) !== -1) { + if (field.locationSet.exclude && utilArrayIntersection(codes, field.locationSet.exclude).length) { return false; } } diff --git a/modules/ui/preset_list.js b/modules/ui/preset_list.js index e365a3150..aa92d508e 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 countryCode = countryCoder.iso1A2Code(center); + var countryCodes = countryCoder.iso1A2Codes(center); - results = presets.search(value, entityGeometries()[0], countryCode); + results = presets.search(value, entityGeometries()[0], countryCodes); messageText = t('inspector.results', { n: results.collection.length, search: value diff --git a/package.json b/package.json index a140b4677..e86f8f513 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "translations": "node scripts/update_locales.js" }, "dependencies": { - "@ideditor/country-coder": "^3.2.0", + "@ideditor/country-coder": "^4.0.0", "@ideditor/location-conflation": "~0.6.0", "@mapbox/geojson-rewind": "^0.5.0", "@mapbox/sexagesimal": "1.2.0", @@ -126,4 +126,4 @@ "browserslist": [ "> 0.2%, last 6 major versions, Firefox ESR, IE 11, maintained node versions" ] -} \ No newline at end of file +}