mirror of
https://github.com/FoggedLens/iD.git
synced 2026-06-02 21:21:37 +02:00
Add countryCodes property to preset schema
Copy countryCodes from name suggestion index Use countryCodes to filter the preset search results (close #6124)
This commit is contained in:
@@ -41,7 +41,7 @@ export function presetCollection(collection) {
|
||||
return this.item(id);
|
||||
},
|
||||
|
||||
search: function(value, geometry) {
|
||||
search: function(value, geometry, countryCode) {
|
||||
if (!value) return this;
|
||||
|
||||
value = value.toLowerCase();
|
||||
@@ -78,11 +78,17 @@ export function presetCollection(collection) {
|
||||
return aCompare.length - bCompare.length;
|
||||
}
|
||||
|
||||
|
||||
var searchable = this.collection.filter(function(a) {
|
||||
var pool = this.collection;
|
||||
if (countryCode) {
|
||||
pool = pool.filter(function(a) {
|
||||
if (!a.countryCodes) return true;
|
||||
return a.countryCodes.indexOf(countryCode) !== -1;
|
||||
});
|
||||
}
|
||||
var searchable = pool.filter(function(a) {
|
||||
return a.searchable !== false && a.suggestion !== true;
|
||||
});
|
||||
var suggestions = this.collection.filter(function(a) {
|
||||
var suggestions = pool.filter(function(a) {
|
||||
return a.suggestion === true;
|
||||
});
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
import { t, textDirection } from '../util/locale';
|
||||
import { actionChangePreset } from '../actions/index';
|
||||
import { operationDelete } from '../operations/index';
|
||||
import { services } from '../services';
|
||||
import { svgIcon } from '../svg/index';
|
||||
import { tooltip } from '../util/tooltip';
|
||||
import { uiPresetIcon } from './preset_icon';
|
||||
@@ -21,6 +22,7 @@ export function uiPresetList(context) {
|
||||
var _entityID;
|
||||
var _currentPreset;
|
||||
var _autofocus = false;
|
||||
var geocoder = services.geocoder;
|
||||
|
||||
|
||||
function presetList(selection) {
|
||||
@@ -99,12 +101,24 @@ export function uiPresetList(context) {
|
||||
var value = search.property('value');
|
||||
list.classed('filtered', value.length);
|
||||
if (value.length) {
|
||||
var results = presets.search(value, geometry);
|
||||
message.text(t('inspector.results', {
|
||||
n: results.collection.length,
|
||||
search: value
|
||||
}));
|
||||
list.call(drawList, results);
|
||||
var entity = context.entity(_entityID);
|
||||
if (geocoder && entity) {
|
||||
var center = entity.extent(context.graph()).center();
|
||||
geocoder.countryCode(center, function countryCallback(err, countryCode) {
|
||||
var results;
|
||||
if (!err && countryCode) {
|
||||
countryCode = countryCode.toLowerCase();
|
||||
results = presets.search(value, geometry, countryCode);
|
||||
} else {
|
||||
results = presets.search(value, geometry);
|
||||
}
|
||||
message.text(t('inspector.results', {
|
||||
n: results.collection.length,
|
||||
search: value
|
||||
}));
|
||||
list.call(drawList, results);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
list.call(drawList, context.presets().defaults(geometry, 36));
|
||||
message.text(t('inspector.choose'));
|
||||
|
||||
Reference in New Issue
Block a user