mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-04 18:33:38 +00:00
Switched to Nominatim api for now
This commit is contained in:
@@ -3,11 +3,11 @@
|
||||
"format": [["number", "street"], ["city", "postcode"]]
|
||||
},
|
||||
{
|
||||
"countryCodes": ["GB"],
|
||||
"countryCodes": ["gb"],
|
||||
"format": [["housename"], ["number", "street"], ["city", "postcode"]]
|
||||
},
|
||||
{
|
||||
"countryCodes": ["AT", "CH", "DE"],
|
||||
"countryCodes": ["at", "ch", "de"],
|
||||
"format": [["street", "number"], ["postcode", "city"]]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,35 +1,36 @@
|
||||
iD.countryCode = function() {
|
||||
var countryCode = {},
|
||||
endpoint = 'http://countrycode.refactory.at/api/1/?';
|
||||
endpoint = 'http://nominatim.openstreetmap.org/reverse?';
|
||||
|
||||
if (!iD.countryCode.cache) {
|
||||
iD.countryCode.cache = [];
|
||||
iD.countryCode.cache = rbush();
|
||||
}
|
||||
|
||||
var cache = iD.countryCode.cache;
|
||||
|
||||
countryCode.search = function(location, callback) {
|
||||
var country = _.find(cache, function (country) {
|
||||
return iD.geo.pointInFeature(location, country);
|
||||
});
|
||||
var countryCodes = cache.search([location[0], location[1], location[0], location[1]]);
|
||||
|
||||
if (country)
|
||||
return callback(null, country);
|
||||
if (countryCodes.length > 0)
|
||||
return callback(null, countryCodes[0][4]);
|
||||
|
||||
d3.json(endpoint +
|
||||
iD.util.qsString({
|
||||
format: 'json',
|
||||
addressdetails: 1,
|
||||
lat: location[1],
|
||||
lon: location[0],
|
||||
geometry: 1
|
||||
}), function(err, country) {
|
||||
lon: location[0]
|
||||
}), function(err, result) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
else if (country && country.error)
|
||||
return callback(country.error);
|
||||
else if (result && result.error)
|
||||
return callback(result.error);
|
||||
|
||||
cache.push(country);
|
||||
var extent = iD.geo.Extent(location).padByMeters(1000);
|
||||
|
||||
callback(null, country);
|
||||
cache.insert([extent[0][0], extent[0][1], extent[1][0], extent[1][1], result.address.country_code]);
|
||||
|
||||
callback(null, result.address.country_code);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -92,7 +92,6 @@ iD.ui.preset.address = function(field, context) {
|
||||
function address(selection) {
|
||||
var wrap = selection.selectAll('.preset-input-wrap').data([0]),
|
||||
center = entity.extent(context.graph()).center(),
|
||||
countryCode,
|
||||
addressFormat;
|
||||
|
||||
// Enter
|
||||
@@ -100,10 +99,7 @@ iD.ui.preset.address = function(field, context) {
|
||||
var enter = wrap.enter().append('div')
|
||||
.attr('class', 'preset-input-wrap');
|
||||
|
||||
iD.countryCode().search(center, function (err, result) {
|
||||
if (result)
|
||||
countryCode = result.countryCode;
|
||||
|
||||
iD.countryCode().search(center, function (err, countryCode) {
|
||||
addressFormat = _.find(iD.data.addressFormats, function (a) {
|
||||
return a && a.countryCodes && _.contains(a.countryCodes, countryCode);
|
||||
}) || _.first(iD.data.addressFormats);
|
||||
|
||||
Reference in New Issue
Block a user