Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 50 additions & 10 deletions modules/ui/feature_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
utilHighlightEntities,
utilNoAuto
} from '../util';
const tagRegex = /^([a-zA-Z0-9:_-]+)=([a-zA-Z0-9:_-]+)$/;


export const idMatch = q => {
Expand Down Expand Up @@ -103,6 +104,20 @@ export function uiFeatureList(context) {
if (d3_event.keyCode === 13 && // ↩ Return
q.length &&
items.size()) {
const tagMatch = q.match(tagRegex);
if (tagMatch) {
const ids = [];

items.each(function(d) {
if (d.entity) {
ids.push(d.entity.id);
}
});
if (ids.length) {
context.enter(modeSelect(context, ids));
}
return;
}
click(d3_event, items.datum());
}
}
Expand Down Expand Up @@ -131,6 +146,7 @@ export function uiFeatureList(context) {
var graph = context.graph();
var visibleCenter = context.map().extent().center();
var q = search.property('value').toLowerCase().trim();
const tagMatch = q.match(tagRegex);

if (!q) return [];

Expand Down Expand Up @@ -183,9 +199,33 @@ export function uiFeatureList(context) {
}

var allEntities = graph.entities;
const tagResults = [];
if (tagMatch) {
const key = tagMatch[1];
const value = tagMatch[2];
const extent = context.map().extent();

for (var id in allEntities) {
var entity = allEntities[id];
if (!entity || !entity.tags) continue;

if (entity.tags[key] === value) {
if (!extent.intersects(entity.extent(graph))) continue;

tagResults.push({
id: entity.id,
entity: entity,
geometry: entity.geometry(graph),
type: utilDisplayType(entity.id),
name: utilDisplayName(entity) || key + '=' + value
});
}
if (tagResults.length > 100) break;
}
}
const localResults = [];
for (var id in allEntities) {
var entity = allEntities[id];
for (const id in allEntities) {
const entity = allEntities[id];
if (!entity) continue;

var matched = presetManager.match(entity, graph);
Expand Down Expand Up @@ -214,19 +254,19 @@ export function uiFeatureList(context) {

// Make a temporary osmEntity so we can preset match
// and better localize the search result - #4725
var id = osmEntity.id.fromOSM(d.osm_type, d.osm_id);
var tags = {};
const id = osmEntity.id.fromOSM(d.osm_type, d.osm_id);
const tags = {};
tags[d.class] = d.type;

var attrs = { id: id, type: d.osm_type, tags: tags };
const attrs = { id: id, type: d.osm_type, tags: tags };
if (d.osm_type === 'way') { // for ways, add some fake closed nodes
attrs.nodes = ['a','a']; // so that geometry area is possible
}

var tempEntity = osmEntity(attrs);
var tempGraph = coreGraph([tempEntity]);
var matched = presetManager.match(tempEntity, tempGraph);
var type = (matched && matched.name()) || utilDisplayType(id);
const tempEntity = osmEntity(attrs);
const tempGraph = coreGraph([tempEntity]);
const matched = presetManager.match(tempEntity, tempGraph);
const type = (matched && matched.name()) || utilDisplayType(id);

geocodeResults.push({
id: tempEntity.id,
Expand Down Expand Up @@ -269,7 +309,7 @@ export function uiFeatureList(context) {
});
}

return [...idResult, ...localResults, ...coordResult, ...geocodeResults, ...extraResults];
return [...tagResults, ...idResult, ...localResults, ...coordResult, ...geocodeResults, ...extraResults];
}


Expand Down