From d2fe6ca2790248f14becc0ee9661d2765a797e99 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 26 Nov 2012 12:30:44 -0500 Subject: [PATCH] Work on handling modifications as well as creations --- js/iD/Connection.js | 4 ++-- js/iD/format/XML.js | 9 +++++++-- js/iD/graph/Graph.js | 15 +++++++++------ js/iD/renderer/Map.js | 5 ++++- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/js/iD/Connection.js b/js/iD/Connection.js index 55a6aa8bf..e42870ea4 100644 --- a/js/iD/Connection.js +++ b/js/iD/Connection.js @@ -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', diff --git a/js/iD/format/XML.js b/js/iD/format/XML.js index 4b545fc29..c6635f201 100644 --- a/js/iD/format/XML.js +++ b/js/iD/format/XML.js @@ -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; diff --git a/js/iD/graph/Graph.js b/js/iD/graph/Graph.js index 019128b57..a8ca89533 100644 --- a/js/iD/graph/Graph.js +++ b/js/iD/graph/Graph.js @@ -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; }); } }; diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js index 42caf6cec..bf7aac8b7 100644 --- a/js/iD/renderer/Map.js +++ b/js/iD/renderer/Map.js @@ -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;