mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-27 16:03:52 +00:00
Merge pull request #8110 from openstreetmap/country-coder-4
Update country-coder to v4.0.0
This commit is contained in:
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user