mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Add connection#loadEntityVersion to fetch specific version
This commit is contained in:
@@ -60,6 +60,17 @@ iD.Connection = function() {
|
||||
});
|
||||
};
|
||||
|
||||
connection.loadEntityVersion = function(id, version, callback) {
|
||||
var type = iD.Entity.id.type(id),
|
||||
osmID = iD.Entity.id.toOSM(id);
|
||||
|
||||
connection.loadFromURL(
|
||||
url + '/api/0.6/' + type + '/' + osmID + '/' + version,
|
||||
function(err, entities) {
|
||||
if (callback) callback(err, {data: entities});
|
||||
});
|
||||
};
|
||||
|
||||
connection.loadMultiple = function(ids, callback) {
|
||||
_.each(_.groupBy(_.uniq(ids), iD.Entity.id.type), function(v, k) {
|
||||
var type = k + 's',
|
||||
|
||||
@@ -75,11 +75,13 @@ describe('iD.Connection', function () {
|
||||
|
||||
describe('#loadEntity', function () {
|
||||
var server,
|
||||
nodeXML = '<?xml version="1.0" encoding="UTF-8"?><osm><node id="1" version="1" changeset="1" lat="0" lon="0" visible="true" timestamp="2009-03-07T03:26:33Z"></node></osm>',
|
||||
nodeXML = '<?xml version="1.0" encoding="UTF-8"?><osm>' +
|
||||
'<node id="1" version="1" changeset="1" lat="0" lon="0" visible="true" timestamp="2009-03-07T03:26:33Z"></node>' +
|
||||
'</osm>',
|
||||
wayXML = '<?xml version="1.0" encoding="UTF-8"?><osm>' +
|
||||
'<node id="1" version="1" changeset="2817006" lat="0" lon="0" visible="true" timestamp="2009-10-11T18:03:23Z"/>' +
|
||||
'<way id="1" visible="true" timestamp="2008-01-03T05:24:43Z" version="1" changeset="522559"><nd ref="1"/></way>' +
|
||||
'</osm>';
|
||||
'<node id="1" version="1" changeset="2817006" lat="0" lon="0" visible="true" timestamp="2009-10-11T18:03:23Z"/>' +
|
||||
'<way id="1" visible="true" timestamp="2008-01-03T05:24:43Z" version="1" changeset="522559"><nd ref="1"/></way>' +
|
||||
'</osm>';
|
||||
|
||||
beforeEach(function() {
|
||||
server = sinon.fakeServer.create();
|
||||
@@ -116,6 +118,50 @@ describe('iD.Connection', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#loadEntityVersion', function () {
|
||||
var server,
|
||||
nodeXML = '<?xml version="1.0" encoding="UTF-8"?><osm>' +
|
||||
'<node id="1" version="1" changeset="1" lat="0" lon="0" visible="true" timestamp="2009-03-07T03:26:33Z"></node>' +
|
||||
'</osm>',
|
||||
wayXML = '<?xml version="1.0" encoding="UTF-8"?><osm>' +
|
||||
'<way id="1" visible="true" timestamp="2008-01-03T05:24:43Z" version="1" changeset="522559"><nd ref="1"/></way>' +
|
||||
'</osm>';
|
||||
|
||||
beforeEach(function() {
|
||||
server = sinon.fakeServer.create();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
server.restore();
|
||||
});
|
||||
|
||||
it('loads a node', function(done) {
|
||||
var id = 'n1';
|
||||
c.loadEntityVersion(id, 1, function(err, result) {
|
||||
var entity = _.find(result.data, function(e) { return e.id === id; });
|
||||
expect(entity).to.be.an.instanceOf(iD.Node);
|
||||
done();
|
||||
});
|
||||
|
||||
server.respondWith("GET", "http://www.openstreetmap.org/api/0.6/node/1/1",
|
||||
[200, { "Content-Type": "text/xml" }, nodeXML]);
|
||||
server.respond();
|
||||
});
|
||||
|
||||
it('loads a way', function(done) {
|
||||
var id = 'w1';
|
||||
c.loadEntityVersion(id, 1, function(err, result) {
|
||||
var entity = _.find(result.data, function(e) { return e.id === id; });
|
||||
expect(entity).to.be.an.instanceOf(iD.Way);
|
||||
done();
|
||||
});
|
||||
|
||||
server.respondWith("GET", "http://www.openstreetmap.org/api/0.6/way/1/1",
|
||||
[200, { "Content-Type": "text/xml" }, wayXML]);
|
||||
server.respond();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#loadMultiple', function () {
|
||||
beforeEach(function() {
|
||||
server = sinon.fakeServer.create();
|
||||
|
||||
Reference in New Issue
Block a user