mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-19 01:23:25 +00:00
Work on handling modifications as well as creations
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user