Skip to content

Commit

Permalink
Add address ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Feb 20, 2013
1 parent 4f87d8d commit edbbc81
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions js/id/ui/address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
iD.ui.preset.address = function() {

var event = d3.dispatch(),
context,
entity;

function getStreets() {

var l = entity.loc,
dist = iD.geo.metresToCoordinates(entity.loc, [200, 200]),
extent = iD.geo.Extent(
[entity.loc[0] - dist[0], entity.loc[1] - dist[1]],
[entity.loc[0] + dist[0], entity.loc[1] + dist[1]]);

return context.intersects(extent)
.filter(isAddressable)
.map(function(d) {
var loc = context.projection(entity.loc),
closest = context.projection(iD.geo.chooseIndex(d, loc, context).loc);
return {
title: d.tags.name,
value: d.tags.name,
dist: iD.geo.dist(closest, loc)
};
}).sort(function(a, b) {
return a.dist - b.dist;
});

function isAddressable(d) {
return d.tags.highway && d.tags.name && d.type === 'way';
}
}

function address(selection) {

selection.append('input')
.property('type', 'text')
.attr('placeholder', '123')
.attr('class', 'addr-number')
.data({ 'key': 'addr:housenumber' });

var streetwrap = selection.append('span')
.attr('class', 'input-wrap-position');

streetwrap.append('input')
.property('type', 'text')
.attr('placeholder', 'Oak Street')
.attr('class', 'addr-streetname')
.data({ 'key': 'addr:streetname' });

streetwrap.call(d3.combobox().data(getStreets()));
}

address.entity = function(_) {
if (!arguments.length) return entity;
entity = _;
return address;
};

address.context = function(_) {
if (!arguments.length) return context;
context = _;
return address;
};

return d3.rebind(address, event, 'on');
};

0 comments on commit edbbc81

Please sign in to comment.