mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Get node-dependent osmChange working
This commit is contained in:
@@ -55,7 +55,11 @@ iD.modes.AddPlace = {
|
||||
iD.modes.AddRoad = {
|
||||
title: "+ Road",
|
||||
way: function() {
|
||||
return iD.Way({tags: {highway: 'residential'}});
|
||||
return iD.Way({
|
||||
tags: {
|
||||
highway: 'residential'
|
||||
}
|
||||
});
|
||||
},
|
||||
enter: function() {
|
||||
var surface = this.map.surface;
|
||||
@@ -73,7 +77,7 @@ iD.modes.AddRoad = {
|
||||
});
|
||||
});
|
||||
|
||||
surface.on('click.addroad', function() {
|
||||
function addRoad() {
|
||||
var t = d3.select(d3.event.target),
|
||||
node,
|
||||
way = this.way();
|
||||
@@ -91,7 +95,9 @@ iD.modes.AddRoad = {
|
||||
this.map.perform(iD.actions.addWayNode(way, node));
|
||||
this.map.selectClick(way);
|
||||
this.controller.enter(iD.modes.DrawRoad(way.id));
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
surface.on('click.addroad', addRoad.bind(this));
|
||||
|
||||
d3.select(document).on('keydown.addroad', function() {
|
||||
if (d3.event.keyCode === 27) this.exit();
|
||||
@@ -130,7 +136,7 @@ iD.modes.DrawRoad = function(way_id) {
|
||||
this.map.redraw(only);
|
||||
}.bind(this));
|
||||
|
||||
surface.on('click.drawroad', function() {
|
||||
function drawRoad() {
|
||||
var t = d3.select(d3.event.target);
|
||||
d3.event.stopPropagation();
|
||||
if (t.data() && t.data()[0] && t.data()[0].type === 'node') {
|
||||
@@ -152,7 +158,9 @@ iD.modes.DrawRoad = function(way_id) {
|
||||
this.map.perform(iD.actions.addWayNode(way, node));
|
||||
way.nodes = way.nodes.slice();
|
||||
this.controller.enter(iD.modes.DrawRoad(way_id));
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
surface.on('click.drawroad', drawRoad.bind(this));
|
||||
},
|
||||
exit: function() {
|
||||
this.map.surface.on('mousemove.drawroad', null);
|
||||
@@ -166,7 +174,11 @@ iD.modes.DrawRoad = function(way_id) {
|
||||
iD.modes.AddArea = {
|
||||
title: "+ Area",
|
||||
way: function() {
|
||||
return iD.Way({tags: {building: 'yes'}});
|
||||
return iD.Way({
|
||||
tags: {
|
||||
building: 'yes'
|
||||
}
|
||||
});
|
||||
},
|
||||
enter: function() {
|
||||
var surface = this.map.surface;
|
||||
|
||||
@@ -7,6 +7,8 @@ iD.format.XML = {
|
||||
rep: function(entity) {
|
||||
if (iD.format.XML.reps[entity.type]) {
|
||||
return iD.format.XML.reps[entity.type](entity);
|
||||
} else {
|
||||
if (typeof console !== 'undefined') console.log(entity.type);
|
||||
}
|
||||
},
|
||||
decode: function(s) {
|
||||
@@ -31,17 +33,30 @@ iD.format.XML = {
|
||||
// Generate [osmChange](http://wiki.openstreetmap.org/wiki/OsmChange)
|
||||
// XML. Returns a string.
|
||||
osmChange: function(userid, changeset_id, changes) {
|
||||
return (new XMLSerializer()).serializeToString(
|
||||
JXON.unbuild({
|
||||
function nest(x) {
|
||||
var groups = {};
|
||||
for (var i = 0; i < x.length; i++) {
|
||||
var tagName = Object.keys(x[i])[0];
|
||||
if (!groups[tagName]) groups[tagName] = [];
|
||||
groups[tagName].push(x[i][tagName]);
|
||||
}
|
||||
var order = ['node', 'way', 'relation'];
|
||||
var ordered = {};
|
||||
order.forEach(function(o) {
|
||||
if (groups[o]) ordered[o] = groups[o];
|
||||
});
|
||||
return ordered;
|
||||
}
|
||||
var rep = {
|
||||
osmChange: {
|
||||
'@version': 0.3,
|
||||
'@generator': 'iD',
|
||||
// TODO: copy elements first
|
||||
create: changes.create.map(function(c) {
|
||||
var x = Object.create(c);
|
||||
create: nest(changes.create.map(function(c) {
|
||||
var x = iD.Entity(c);
|
||||
x.changeset = changeset_id;
|
||||
return x;
|
||||
}).map(iD.format.XML.rep),
|
||||
}).map(iD.format.XML.rep)),
|
||||
modify: changes.modify.map(function(c) {
|
||||
var x = Object.create(c);
|
||||
x.changeset = changeset_id;
|
||||
@@ -53,7 +68,9 @@ iD.format.XML = {
|
||||
return x;
|
||||
}).map(iD.format.XML.rep)
|
||||
}
|
||||
}));
|
||||
};
|
||||
console.log(rep);
|
||||
return (new XMLSerializer()).serializeToString(JXON.unbuild(rep));
|
||||
},
|
||||
reps: {
|
||||
node: function(entity) {
|
||||
@@ -75,7 +92,7 @@ iD.format.XML = {
|
||||
way: {
|
||||
'@id': entity.id.replace('w', ''),
|
||||
nd: entity.nodes.map(function(e) {
|
||||
return { keyAttributes: { ref: e.id } };
|
||||
return { keyAttributes: { ref: e.id.replace('n', '') } };
|
||||
}),
|
||||
tag: _.map(entity.tags, function(v, k) {
|
||||
return { keyAttributes: { k: k, v: v } };
|
||||
|
||||
@@ -34,13 +34,13 @@ iD.Entity.prototype = {
|
||||
};
|
||||
|
||||
iD.Node = function (attrs) {
|
||||
return iD.Entity(_.extend({}, attrs, {type: 'node'}));
|
||||
return iD.Entity(_.extend({}, attrs || {}, {type: 'node'}));
|
||||
};
|
||||
|
||||
iD.Way = function (attrs) {
|
||||
return iD.Entity(_.extend({}, attrs, {type: 'way', nodes: []}));
|
||||
return iD.Entity(_.extend({}, attrs || {}, {type: 'way', nodes: []}));
|
||||
};
|
||||
|
||||
iD.Relation = function (attrs) {
|
||||
return iD.Entity(_.extend({}, attrs, {type: 'relation'}));
|
||||
return iD.Entity(_.extend({}, attrs || {}, {type: 'relation'}));
|
||||
};
|
||||
|
||||
@@ -99,10 +99,18 @@ iD.Graph.prototype = {
|
||||
},
|
||||
|
||||
modifications: function() {
|
||||
return _.filter(this.entities, function(entity) { return entity.modified(); });
|
||||
return _.filter(this.entities, function(entity) {
|
||||
return entity.modified();
|
||||
}).map(function(e) {
|
||||
return this.fetch(e.id);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
creations: function() {
|
||||
return _.filter(this.entities, function(entity) { return entity.created(); });
|
||||
return _.filter(this.entities, function(entity) {
|
||||
return entity.created();
|
||||
}).map(function(e) {
|
||||
return this.fetch(e.id);
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -70,9 +70,7 @@ iD.History.prototype = {
|
||||
return _.difference(
|
||||
_.pluck(this.stack[0].entities, 'id'),
|
||||
_.pluck(this.stack[this.index].entities, 'id')
|
||||
).map(function(id) {
|
||||
return this.stack[0].entity(id);
|
||||
}.bind(this));
|
||||
);
|
||||
},
|
||||
|
||||
changes: function() {
|
||||
|
||||
@@ -29,9 +29,11 @@ iD.commit = function() {
|
||||
li.append('strong').text(function(d) {
|
||||
return d.type + ' ';
|
||||
});
|
||||
li.append('span').text(function(d) {
|
||||
return iD.Util.friendlyName(d);
|
||||
});
|
||||
li.append('span')
|
||||
.text(function(d) {
|
||||
return iD.Util.friendlyName(d);
|
||||
})
|
||||
.attr('title', iD.Util.tagText);
|
||||
|
||||
body.append('textarea')
|
||||
.attr('class', 'changeset-comment')
|
||||
|
||||
@@ -43,3 +43,9 @@ iD.Util.codeWindow = function(content) {
|
||||
top.win.document.writeln('<pre>' + content + '</pre>');
|
||||
top.win.document.close();
|
||||
};
|
||||
|
||||
iD.Util.tagText = function(entity) {
|
||||
return d3.entries(entity.tags).map(function(e) {
|
||||
return e.key + ': ' + e.value;
|
||||
}).join('\n');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user