Search all downloaded features instead of just visible ones on 2.x (re: #6516, re: 480140442677644ba3d758565b7d08672d037976)

This commit is contained in:
Quincy Morgan
2019-12-12 13:05:55 -05:00
parent f6266de357
commit a319bf75d6
3 changed files with 24 additions and 32 deletions
-1
View File
@@ -506,7 +506,6 @@ en:
note: note
geocoder:
search: Search worldwide...
no_results_visible: No results in visible map area
no_results_worldwide: No results found
geolocate:
title: Show My Location
-1
View File
@@ -635,7 +635,6 @@
},
"geocoder": {
"search": "Search worldwide...",
"no_results_visible": "No results in visible map area",
"no_results_worldwide": "No results found"
},
"geolocate": {
+24 -30
View File
@@ -7,6 +7,7 @@ import * as sexagesimal from '@mapbox/sexagesimal';
import { t } from '../util/locale';
import { dmsCoordinatePair } from '../util/units';
import { coreGraph } from '../core/graph';
import { geoSphericalDistance } from '../geo/geo';
import { geoExtent, geoChooseEdge } from '../geo';
import { modeSelect } from '../modes/select';
import { osmEntity } from '../osm/entity';
@@ -113,9 +114,9 @@ export function uiFeatureList(context) {
function features() {
var entities = {};
var result = [];
var graph = context.graph();
var visibleCenter = context.map().extent().center();
var q = search.property('value').toLowerCase();
if (!q) return result;
@@ -144,37 +145,32 @@ export function uiFeatureList(context) {
});
}
function addEntity(entity) {
if (entity.id in entities || result.length > 200)
return;
entities[entity.id] = true;
var allEntities = graph.entities;
var localResults = [];
for (var id in allEntities) {
var entity = allEntities[id];
var name = utilDisplayName(entity) || '';
if (name.toLowerCase().indexOf(q) >= 0) {
var matched = context.presets().match(entity, graph);
var type = (matched && matched.name()) || utilDisplayType(entity.id);
if (name.toLowerCase().indexOf(q) < 0) continue;
var matched = context.presets().match(entity, graph);
var type = (matched && matched.name()) || utilDisplayType(entity.id);
var extent = entity.extent(graph);
var distance = extent ? geoSphericalDistance(visibleCenter, extent.center()) : 0;
result.push({
id: entity.id,
entity: entity,
geometry: context.geometry(entity.id),
type: type,
name: name
});
}
graph.parentRelations(entity).forEach(function(parent) {
addEntity(parent);
localResults.push({
id: entity.id,
entity: entity,
geometry: context.geometry(entity.id),
type: type,
name: name,
distance: distance
});
}
var visible = context.surface().selectAll('.point, .line, .area').nodes();
for (var i = 0; i < visible.length && result.length <= 200; i++) {
var datum = visible[i].__data__;
var entity = datum && datum.properties && datum.properties.entity;
if (entity) { addEntity(entity); }
if (localResults.length > 100) break;
}
localResults = localResults.sort(function byDistance(a, b) {
return a.distance - b.distance;
});
result = result.concat(localResults);
(_geocodeResults || []).forEach(function(d) {
if (d.osm_type && d.osm_id) { // some results may be missing these - #1890
@@ -239,8 +235,6 @@ export function uiFeatureList(context) {
list.classed('filtered', value.length);
var noResultsWorldwide = _geocodeResults && _geocodeResults.length === 0;
var resultsIndicator = list.selectAll('.no-results-item')
.data([0])
.enter()
@@ -253,7 +247,7 @@ export function uiFeatureList(context) {
.attr('class', 'entity-name');
list.selectAll('.no-results-item .entity-name')
.text(noResultsWorldwide ? t('geocoder.no_results_worldwide') : t('geocoder.no_results_visible'));
.text(t('geocoder.no_results_worldwide'));
if (services.geocoder) {
list.selectAll('.geocode-item')