mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 05:30:35 +02:00
Support territories in preset and field country limiters (re: #8102)
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();
|
||||
@@ -83,10 +84,13 @@ 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.countryCodes && a.countryCodes.indexOf(countryCode) === -1) return false;
|
||||
if (a.notCountryCodes && a.notCountryCodes.indexOf(countryCode) !== -1) return false;
|
||||
if (a.countryCodes && !utilArrayIntersection(a.countryCodes, countryCodes).length) return false;
|
||||
if (a.notCountryCodes && utilArrayIntersection(a.notCountryCodes, countryCodes).length) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
+6
-7
@@ -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.countryCodes && field.countryCodes.indexOf(countryCode) === -1) {
|
||||
if (field.countryCodes && !utilArrayIntersection(codes, field.countryCodes).length) {
|
||||
return false;
|
||||
}
|
||||
if (field.notCountryCodes && field.notCountryCodes.indexOf(countryCode) !== -1) {
|
||||
if (field.notCountryCodes && utilArrayIntersection(codes, field.notCountryCodes).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 && countryCode.toLowerCase());
|
||||
results = presets.search(value, entityGeometries()[0], countryCodes);
|
||||
messageText = t('inspector.results', {
|
||||
n: results.collection.length,
|
||||
search: value
|
||||
|
||||
Reference in New Issue
Block a user