Change search to use OSM Nominatim API

This commit is contained in:
Dr Ian
2013-02-01 22:23:30 +01:00
parent 7235632a63
commit 7bfdf4de1a
2 changed files with 11 additions and 6 deletions
+4
View File
@@ -346,6 +346,10 @@ iD.Map = function(context) {
vZoomDiff = Math.log(Math.abs(vFactor)) / Math.LN2,
newZoom = map.zoom() - Math.max(hZoomDiff, vZoomDiff);
if(newZoom > 19){
newZoom = 19;
}
map.centerZoom(extent.center(), newZoom);
}
};
+7 -6
View File
@@ -6,18 +6,19 @@ 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])]));
});
}