mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
Add imageryBlacklists function to get blacklists from OSM API
(for #3623)
This commit is contained in:
+35
-1
@@ -25,6 +25,7 @@ var dispatch = d3.dispatch('authLoading', 'authDone', 'change', 'loading', 'load
|
||||
}),
|
||||
rateLimitError,
|
||||
userDetails,
|
||||
capabilities,
|
||||
off;
|
||||
|
||||
|
||||
@@ -161,6 +162,7 @@ export default {
|
||||
reset: function() {
|
||||
userDetails = undefined;
|
||||
rateLimitError = undefined;
|
||||
capabilities = undefined;
|
||||
_.forEach(inflight, abortRequest);
|
||||
loadedTiles = {};
|
||||
inflight = {};
|
||||
@@ -429,22 +431,54 @@ export default {
|
||||
},
|
||||
|
||||
|
||||
// `status` will always request the `api/capabilities` resource..
|
||||
status: function(callback) {
|
||||
function done(capabilities) {
|
||||
function done(xml) {
|
||||
capabilities = xml;
|
||||
|
||||
if (rateLimitError) {
|
||||
callback(rateLimitError, 'rateLimited');
|
||||
} else {
|
||||
var apiStatus = capabilities.getElementsByTagName('status'),
|
||||
val = apiStatus[0].getAttribute('api');
|
||||
|
||||
callback(undefined, val);
|
||||
}
|
||||
}
|
||||
|
||||
d3.xml(urlroot + '/api/capabilities').get()
|
||||
.on('load', done)
|
||||
.on('error', callback);
|
||||
},
|
||||
|
||||
|
||||
// `imageryBlacklists` will reuse the previous `api/capabilities` result, if available..
|
||||
imageryBlacklists: function(callback) {
|
||||
function done(xml) {
|
||||
capabilities = xml;
|
||||
|
||||
var elements = capabilities.getElementsByTagName('blacklist'),
|
||||
blacklists = [];
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
var regex = elements[i].getAttribute('regex'); // needs unencode?
|
||||
if (regex) {
|
||||
blacklists.push(regex);
|
||||
}
|
||||
}
|
||||
|
||||
callback(undefined, blacklists);
|
||||
}
|
||||
|
||||
if (capabilities) {
|
||||
done(capabilities);
|
||||
} else {
|
||||
d3.xml(urlroot + '/api/capabilities').get()
|
||||
.on('load', done)
|
||||
.on('error', callback);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
tileZoom: function(_) {
|
||||
if (!arguments.length) return tileZoom;
|
||||
tileZoom = _;
|
||||
|
||||
@@ -445,4 +445,58 @@ describe('iD.serviceOsm', function () {
|
||||
expect(connection.changesetTags('2.0.0', '', [])).not.to.have.property('comment');
|
||||
});
|
||||
});
|
||||
|
||||
describe('API capabilities', function() {
|
||||
var server,
|
||||
capabilitiesXML = '<?xml version="1.0" encoding="UTF-8"?><osm>' +
|
||||
'<api>' +
|
||||
'<version minimum="0.6" maximum="0.6"/>' +
|
||||
'<area maximum="0.25"/>' +
|
||||
'<tracepoints per_page="5000"/>' +
|
||||
'<waynodes maximum="2000"/>' +
|
||||
'<changesets maximum_elements="50000"/>' +
|
||||
'<timeout seconds="300"/>' +
|
||||
'<status database="online" api="online" gpx="online"/>' +
|
||||
'</api>' +
|
||||
'<policy><imagery><blacklist regex=".*\.google(apis)?\..*/(vt|kh)[\?/].*([xyz]=.*){3}.*"/></imagery></policy>' +
|
||||
'</osm>';
|
||||
|
||||
|
||||
beforeEach(function() {
|
||||
server = sinon.fakeServer.create();
|
||||
// connection.reset();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
server.restore();
|
||||
});
|
||||
|
||||
describe('#status', function() {
|
||||
it('gets API status', function(done) {
|
||||
connection.status(function(err, val) {
|
||||
expect(val).to.eql('online');
|
||||
done();
|
||||
});
|
||||
|
||||
server.respondWith('GET', 'http://www.openstreetmap.org/api/capabilities',
|
||||
[200, { 'Content-Type': 'text/xml' }, capabilitiesXML]);
|
||||
server.respond();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#imageryBlacklists', function() {
|
||||
it('gets imagery blacklists', function(done) {
|
||||
connection.imageryBlacklists(function(err, val) {
|
||||
expect(val).to.eql(['.*\.google(apis)?\..*/(vt|kh)[\?/].*([xyz]=.*){3}.*']);
|
||||
done();
|
||||
});
|
||||
|
||||
server.respondWith('GET', 'http://www.openstreetmap.org/api/capabilities',
|
||||
[200, { 'Content-Type': 'text/xml' }, capabilitiesXML]);
|
||||
server.respond();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user