Define Relation#asJXON (allow relations to be saved)

This commit is contained in:
John Firebaugh
2013-01-28 10:17:23 -05:00
parent f6ff3e678b
commit 08bd7e583a
2 changed files with 32 additions and 0 deletions

View File

@@ -66,6 +66,23 @@ _.extend(iD.Relation.prototype, {
return this.update({members: members});
},
asJXON: function(changeset_id) {
var r = {
relation: {
'@id': this.osmId(),
'@version': this.version || 0,
member: _.map(this.members, function(member) {
return { keyAttributes: { type: member.type, role: member.role, ref: iD.Entity.id.toOSM(member.id) } };
}),
tag: _.map(this.tags, function(v, k) {
return { keyAttributes: { k: k, v: v } };
})
}
};
if (changeset_id) r.relation['@changeset'] = changeset_id;
return r;
},
isRestriction: function() {
return !!(this.tags.type && this.tags.type.match(/^restriction:?/));
},

View File

@@ -140,6 +140,21 @@ describe('iD.Relation', function () {
});
});
describe("#asJXON", function () {
it('converts a relation to jxon', function() {
var relation = iD.Relation({id: 'r-1', members: [{id: 'w1', role: 'forward', type: 'way'}], tags: {type: 'route'}});
expect(relation.asJXON()).to.eql({relation: {
'@id': '-1',
'@version': 0,
member: [{keyAttributes: {ref: '1', role: 'forward', type: 'way'}}],
tag: [{keyAttributes: {k: 'type', v: 'route'}}]}});
});
it('includes changeset if provided', function() {
expect(iD.Relation().asJXON('1234').relation['@changeset']).to.equal('1234');
});
});
describe("#multipolygon", function () {
specify("single polygon consisting of a single way", function () {
var a = iD.Node(),