From edbbc810f007cfb1b5f0708f581d003704ecf318 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 20 Feb 2013 12:28:13 -0500 Subject: [PATCH] Add address ui --- js/id/ui/address.js | 67 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 js/id/ui/address.js diff --git a/js/id/ui/address.js b/js/id/ui/address.js new file mode 100644 index 000000000..c3902aec8 --- /dev/null +++ b/js/id/ui/address.js @@ -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'); +};