Skip to content

Commit

Permalink
Merge remote-tracking branch 'openstreetmap/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
MKuranowski committed Dec 4, 2016
2 parents 4827b74 + b9888e4 commit 955b8de
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
36 changes: 35 additions & 1 deletion modules/services/osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var dispatch = d3.dispatch('authLoading', 'authDone', 'change', 'loading', 'load
}),
rateLimitError,
userDetails,
capabilities,
off;


Expand Down Expand Up @@ -161,6 +162,7 @@ export default {
reset: function() {
userDetails = undefined;
rateLimitError = undefined;
capabilities = undefined;
_.forEach(inflight, abortRequest);
loadedTiles = {};
inflight = {};
Expand Down Expand Up @@ -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 = _;
Expand Down
54 changes: 54 additions & 0 deletions test/spec/services/osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

});

});

0 comments on commit 955b8de

Please sign in to comment.