Merge pull request #2056 from cschwarz/search-improvements

Adds support for ids and locations as search input
This commit is contained in:
John Firebaugh
2013-12-15 11:55:41 -08:00
3 changed files with 43 additions and 3 deletions

View File

@@ -209,6 +209,10 @@ en:
yes: Yes
no: No
none: None
node: Node
way: Way
relation: Relation
location: Location
background:
title: Background
description: Background settings

View File

@@ -256,7 +256,11 @@
"yes": "Yes",
"no": "No"
},
"none": "None"
"none": "None",
"node": "Node",
"way": "Way",
"relation": "Relation",
"location": "Location"
},
"background": {
"title": "Background",

View File

@@ -12,7 +12,7 @@ iD.ui.FeatureList = function(context) {
var q = search.property('value'),
items = list.selectAll('.feature-list-item');
if (d3.event.keyCode === 13 && q.length && items.size()) {
click(items.datum().entity);
click(items.datum());
}
}
@@ -56,6 +56,29 @@ iD.ui.FeatureList = function(context) {
if (!q) return result;
var idMatch = q.match(/^([nwr])([0-9]+)$/);
if (idMatch) {
result.push({
id: idMatch[0],
geometry: idMatch[1] === 'n' ? 'point' : idMatch[1] === 'w' ? 'line' : 'relation',
type: idMatch[1] === 'n' ? t('inspector.node') : idMatch[1] === 'w' ? t('inspector.way') : t('inspector.relation'),
name: idMatch[2]
});
}
var locationMatch = q.match(/^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)$/);
if (locationMatch) {
result.push({
id: -1,
geometry: 'point',
type: t('inspector.location'),
name: locationMatch[0],
location: [parseFloat(locationMatch[1]), parseFloat(locationMatch[2])]
});
}
function addEntity(entity) {
if (entity.id in entities || result.length > 200)
return;
@@ -141,6 +164,10 @@ iD.ui.FeatureList = function(context) {
list.selectAll('.geocode-item')
.style('display', (value && geocodeResults === undefined) ? 'block' : 'none');
list.selectAll('.feature-list-item')
.data([-1])
.remove();
var items = list.selectAll('.feature-list-item')
.data(results, function(d) { return d.id; });
@@ -175,6 +202,8 @@ iD.ui.FeatureList = function(context) {
}
function mouseover(d) {
if (d.id === -1) return;
context.surface().selectAll(iD.util.entityOrMemberSelector([d.id], context.graph()))
.classed('hover', true);
}
@@ -186,7 +215,10 @@ iD.ui.FeatureList = function(context) {
function click(d) {
d3.event.preventDefault();
if (d.entity) {
if (d.location) {
context.map().centerZoom([d.location[1], d.location[0]], 20);
}
else if (d.entity) {
context.enter(iD.modes.Select(context, [d.entity.id]));
} else {
context.loadEntity(d.id);