mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Define Relation#asJXON (allow relations to be saved)
This commit is contained in:
@@ -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:?/));
|
||||
},
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user