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
42 changes: 41 additions & 1 deletion 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,6 +199,30 @@ 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];
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