Work on handling modifications as well as creations

This commit is contained in:
Tom MacWright
2012-11-26 12:30:44 -05:00
parent 3b3d2be89f
commit d2fe6ca279
4 changed files with 22 additions and 11 deletions

View File

@@ -97,7 +97,7 @@ iD.Connection = function() {
return oauth.authenticated();
}
function createChangeset(modified) {
function createChangeset(changes) {
oauth.xhr({
method: 'PUT',
path: '/changeset/create',
@@ -109,7 +109,7 @@ iD.Connection = function() {
method: 'POST',
path: '/changeset/' + changeset_id + '/upload',
options: { header: { 'Content-Type': 'text/xml' } },
content: iD.format.XML.osmChange(user.id, changeset_id, modified)
content: iD.format.XML.osmChange(user.id, changeset_id, changes)
}, function () {
oauth.xhr({
method: 'PUT',

View File

@@ -27,14 +27,19 @@ iD.format.XML = {
}
}));
},
osmChange: function(userid, changeset, created) {
osmChange: function(userid, changeset, changes) {
return (new XMLSerializer()).serializeToString(
JXON.unbuild({
osmChange: {
'@version': 0.3,
'@generator': 'iD',
// TODO: copy elements first
'create': created.map(function(c) {
create: changes.created.map(function(c) {
var x = Object.create(c);
x.changeset = changeset;
return x;
}).map(iD.format.XML.rep),
modify: changes.modified.map(function(c) {
var x = Object.create(c);
x.changeset = changeset;
return x;

View File

@@ -5,9 +5,7 @@ iD.Graph = function(entities, annotation) {
// TODO: update extents that need it.
if (this.entities[id].type === 'way' && !this.entities[id]._extent) {
// top left, bottom right
var extent = [
[-Infinity, Infinity],
[Infinity, -Infinity]];
var extent = [[-Infinity, Infinity], [Infinity, -Infinity]];
var w = this.fetch(id);
for (var j = 0, l = w.nodes.length; j < l; j++) {
if (w.nodes[j].lon > extent[0][0]) extent[0][0] = w.nodes[j].lon;
@@ -76,9 +74,8 @@ iD.Graph.prototype = {
// Resolve the id references in a way, replacing them with actual objects.
fetch: function(id) {
var entity = iD.Entity(this.entities[id]);
var entity = iD.Entity(this.entities[id]), nodes = [];
if (!entity.nodes || !entity.nodes.length) return entity;
var nodes = [];
for (var i = 0, l = entity.nodes.length; i < l; i++) {
nodes[i] = this.fetch(entity.nodes[i]);
}
@@ -88,7 +85,13 @@ iD.Graph.prototype = {
modifications: function() {
return _.filter(this.entities, function(entity) {
return entity.modified;
return (entity.id > 0) && entity.modified;
});
},
creations: function() {
return _.filter(this.entities, function(entity) {
return (entity.id < 0) && entity.modified;
});
}
};

View File

@@ -527,7 +527,10 @@ iD.Map = function(elem, connection) {
}
function commit() {
connection.createChangeset(history.graph().modifications());
connection.createChangeset({
modified: history.graph().modifications(),
created: history.graph().creations()
});
}
map.handleDrag = handleDrag;