mirror of
https://github.com/FoggedLens/iD.git
synced 2026-06-04 05:58:09 +02:00
58 lines
2.0 KiB
JavaScript
58 lines
2.0 KiB
JavaScript
iD.XML = {
|
|
mapping: function(entity) {
|
|
if (this.mappings[entity.type]) {
|
|
return this.mappings[entity.type](entity);
|
|
}
|
|
},
|
|
decode: function(s) {
|
|
return s.replace(/>/g,'>').
|
|
replace(/</g,'<').
|
|
replace(/"/g,'"');
|
|
},
|
|
mappings: {
|
|
node: function(entity) {
|
|
return iD.XML.decode((new XMLSerializer()).serializeToString(
|
|
JXON.unbuild({
|
|
node: {
|
|
'@id': entity.id,
|
|
'@lat': entity.lat,
|
|
'@lon': entity.lon,
|
|
'tag': _.map(entity.tags, function(k, v) {
|
|
return {
|
|
keyAttributes: {
|
|
k: k,
|
|
v: v
|
|
}
|
|
};
|
|
})
|
|
}
|
|
})
|
|
));
|
|
},
|
|
way: function(entity) {
|
|
return iD.XML.decode(
|
|
(new XMLSerializer()).serializeToString(
|
|
JXON.unbuild({
|
|
way: {
|
|
'@id': entity.id,
|
|
'nd': entity.children.map(function(e) {
|
|
return {
|
|
keyAttributes: {
|
|
ref: e.id
|
|
}
|
|
};
|
|
}),
|
|
'tag': _.map(entity.tags, function(k, v) {
|
|
return {
|
|
keyAttributes: {
|
|
k: k,
|
|
v: v
|
|
}
|
|
};
|
|
})
|
|
}
|
|
})));
|
|
}
|
|
}
|
|
};
|