Merge pull request #599 from porjo/master

Use OSM Nominatim API for search
This commit is contained in:
Tom MacWright
2013-02-01 14:27:38 -08:00
+8 -6
View File
@@ -6,18 +6,20 @@ iD.ui.geocoder = function() {
function keydown() {
if (d3.event.keyCode !== 13) return;
d3.event.preventDefault();
d3.json('http://a.tiles.mapbox.com/v3/openstreetmap.map-hn253zqn/geocode/' +
encodeURIComponent(this.value) + '.json', function(err, resp) {
var searchVal = this.value;
d3.json('http://nominatim.openstreetmap.org/search/' +
encodeURIComponent(searchVal) + '?limit=10&format=json', function(err, resp) {
if (err) return hide();
hide();
if (!resp.results.length) {
if (!resp.length) {
return iD.ui.flash()
.select('.content')
.append('h3')
.text('No location found for "' + resp.query[0] + '"');
.text('No location found for "' + searchVal + '"');
}
var bounds = resp.results[0][0].bounds;
map.extent(iD.geo.Extent([bounds[0], bounds[1]], [bounds[2], bounds[3]]));
var bounds = resp[0].boundingbox;
map.extent(iD.geo.Extent([parseFloat(bounds[3]), parseFloat(bounds[0])], [parseFloat(bounds[2]), parseFloat(bounds[1])]));
if (map.zoom() > 19) map.zoom(19);
});
}