mirror of
https://github.com/FoggedLens/iD.git
synced 2026-06-03 05:28:03 +02:00
053074d076
(closes #3324) Previously we allowed devs to swap out services that they didn't need. This became difficult now that ES6 exports are immutable bindings. But we can wrap the immutable bindings themselves in a live object, to get back the flexibility that we used to have. This change also drops the `taginfo` accessor on Context, since devs who want to swap out taginfo service with something else can now do so through the live binding. `iD.services.taginfo = myTaginfo()`
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
import * as d3 from 'd3';
|
|
import rbush from 'rbush';
|
|
import { geoExtent } from '../geo/index';
|
|
import { utilQsString } from '../util/index';
|
|
|
|
|
|
var endpoint = 'https://nominatim.openstreetmap.org/reverse?',
|
|
nominatimCache;
|
|
|
|
|
|
export default {
|
|
|
|
init: function() { nominatimCache = rbush(); },
|
|
reset: function() { nominatimCache = rbush(); },
|
|
|
|
|
|
countryCode: function (location, callback) {
|
|
var countryCodes = nominatimCache.search(
|
|
{ minX: location[0], minY: location[1], maxX: location[0], maxY: location[1] }
|
|
);
|
|
|
|
if (countryCodes.length > 0) {
|
|
return callback(null, countryCodes[0].data);
|
|
}
|
|
|
|
d3.json(endpoint +
|
|
utilQsString({
|
|
format: 'json',
|
|
addressdetails: 1,
|
|
lat: location[1],
|
|
lon: location[0]
|
|
}), function(err, result) {
|
|
if (err)
|
|
return callback(err);
|
|
else if (result && result.error)
|
|
return callback(result.error);
|
|
|
|
var extent = geoExtent(location).padByMeters(1000);
|
|
nominatimCache.insert(Object.assign(extent.bbox(),
|
|
{ data: result.address.country_code }
|
|
));
|
|
|
|
callback(null, result.address.country_code);
|
|
}
|
|
);
|
|
}
|
|
|
|
};
|