mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-24 17:14:04 +02:00
Merge branch 'master' of github.com:systemed/iD
This commit is contained in:
@@ -0,0 +1 @@
|
||||
iD.actions = {};
|
||||
@@ -1,80 +0,0 @@
|
||||
iD.actions = {};
|
||||
|
||||
iD.actions.noop = function() {
|
||||
return function(graph) {
|
||||
return graph;
|
||||
};
|
||||
};
|
||||
|
||||
// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/AddCommand.java
|
||||
iD.actions.addNode = function(node) {
|
||||
return function(graph) {
|
||||
return graph.replace(node, 'added a place');
|
||||
};
|
||||
};
|
||||
|
||||
iD.actions.startWay = function(way) {
|
||||
return function(graph) {
|
||||
return graph.replace(way, 'started a road');
|
||||
};
|
||||
};
|
||||
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as
|
||||
iD.actions.remove = function(node) {
|
||||
return function(graph) {
|
||||
return graph.remove(node, 'removed a feature');
|
||||
};
|
||||
};
|
||||
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as
|
||||
iD.actions.addWayNode = function(way, node, index) {
|
||||
return function(graph) {
|
||||
var nodes = way.nodes.slice();
|
||||
nodes.splice(index || nodes.length, 0, node.id);
|
||||
return graph.replace(way.update({nodes: nodes})).replace(node, 'added to a road');
|
||||
};
|
||||
};
|
||||
|
||||
iD.actions.removeWayNode = function(way, node) {
|
||||
return function(graph) {
|
||||
var nodes = _.without(way.nodes, node.id);
|
||||
return graph.replace(way.update({nodes: nodes}), 'removed from a road');
|
||||
};
|
||||
};
|
||||
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as
|
||||
iD.actions.changeWayDirection = function(way) {
|
||||
return function(graph) {
|
||||
return graph.replace(way.update({
|
||||
nodes: way.nodes.slice()
|
||||
}), 'changed way direction');
|
||||
};
|
||||
};
|
||||
|
||||
iD.actions.changeTags = function(node, tags) {
|
||||
return function(graph) {
|
||||
return graph.replace(node.update({
|
||||
tags: tags
|
||||
}), 'changed tags');
|
||||
};
|
||||
};
|
||||
|
||||
// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/MoveCommand.java
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/MoveNodeAction.as
|
||||
iD.actions.move = function(entity, loc) {
|
||||
return function(graph) {
|
||||
return graph.replace(entity.update({loc: loc}), 'moved an element');
|
||||
};
|
||||
};
|
||||
|
||||
iD.actions.addTemporary = function(node) {
|
||||
return function(graph) {
|
||||
return graph.replace(node);
|
||||
};
|
||||
};
|
||||
|
||||
iD.actions.removeTemporary = function(node) {
|
||||
return function(graph) {
|
||||
return graph.remove(node);
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/AddCommand.java
|
||||
iD.actions.addNode = function(node) {
|
||||
return function(graph) {
|
||||
return graph.replace(node, 'added a place');
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as
|
||||
iD.actions.addWayNode = function(way, node, index) {
|
||||
return function(graph) {
|
||||
var nodes = way.nodes.slice();
|
||||
nodes.splice(index || nodes.length, 0, node.id);
|
||||
return graph.replace(way.update({nodes: nodes})).replace(node, 'added to a road');
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
iD.actions.changeTags = function(node, tags) {
|
||||
return function(graph) {
|
||||
return graph.replace(node.update({
|
||||
tags: tags
|
||||
}), 'changed tags');
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as
|
||||
iD.actions.changeWayDirection = function(way) {
|
||||
return function(graph) {
|
||||
return graph.replace(way.update({
|
||||
nodes: way.nodes.slice()
|
||||
}), 'changed way direction');
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteNodeAction.as
|
||||
iD.actions.DeleteNode = function(node) {
|
||||
return function(graph) {
|
||||
graph.parentWays(node.id)
|
||||
.forEach(function(parent) {
|
||||
graph = iD.actions.removeWayNode(parent, node)(graph);
|
||||
});
|
||||
|
||||
graph.parentRelations(node.id)
|
||||
.forEach(function(parent) {
|
||||
graph = iD.actions.removeRelationEntity(parent, node)(graph);
|
||||
});
|
||||
|
||||
return graph.remove(node, 'removed a node');
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as
|
||||
iD.actions.DeleteWay = function(way) {
|
||||
return function(graph) {
|
||||
graph.parentRelations(way.id)
|
||||
.forEach(function(parent) {
|
||||
graph = iD.actions.removeRelationEntity(parent, way)(graph);
|
||||
});
|
||||
|
||||
way.nodes.forEach(function (id) {
|
||||
var node = graph.entity(id);
|
||||
|
||||
graph = iD.actions.removeWayNode(way, node)(graph);
|
||||
|
||||
if (!graph.parentWays(id).length && !graph.parentRelations(id).length) {
|
||||
graph = graph.remove(node);
|
||||
}
|
||||
});
|
||||
|
||||
return graph.remove(way, 'removed a way');
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/MoveCommand.java
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/MoveNodeAction.as
|
||||
iD.actions.move = function(entity, loc) {
|
||||
return function(graph) {
|
||||
return graph.replace(entity.update({loc: loc}), 'moved an element');
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
iD.actions.noop = function() {
|
||||
return function(graph) {
|
||||
return graph;
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
iD.actions.removeRelationEntity = function(relation, entity) {
|
||||
return function(graph) {
|
||||
var members = _.without(relation.members, entity.id);
|
||||
return graph.replace(relation.update({members: members}), 'removed from a relation');
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
iD.actions.removeWayNode = function(way, node) {
|
||||
return function(graph) {
|
||||
var nodes = _.without(way.nodes, node.id);
|
||||
return graph.replace(way.update({nodes: nodes}), 'removed from a road');
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
iD.actions.startWay = function(way) {
|
||||
return function(graph) {
|
||||
return graph.replace(way, 'started a road');
|
||||
};
|
||||
};
|
||||
@@ -12,6 +12,9 @@ iD.Entity = function(a, b, c) {
|
||||
if (iD.debug) {
|
||||
Object.freeze(this);
|
||||
Object.freeze(this.tags);
|
||||
|
||||
if (this.nodes) Object.freeze(this.nodes);
|
||||
if (this.members) Object.freeze(this.members);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -30,11 +33,11 @@ iD.Entity.prototype = {
|
||||
};
|
||||
|
||||
iD.Node = function(attrs) {
|
||||
return iD.Entity({tags: {}}, attrs || {}, {type: 'node'});
|
||||
return iD.Entity(attrs || {}, {type: 'node'});
|
||||
};
|
||||
|
||||
iD.Way = function(attrs) {
|
||||
return iD.Entity({tags: {}, nodes: []}, attrs || {}, {type: 'way'});
|
||||
return iD.Entity({nodes: []}, attrs || {}, {type: 'way'});
|
||||
};
|
||||
|
||||
iD.Way.isOneWay = function(d) {
|
||||
@@ -50,5 +53,5 @@ iD.Way.isArea = function(d) {
|
||||
};
|
||||
|
||||
iD.Relation = function(attrs) {
|
||||
return iD.Entity({tags: {}}, attrs || {}, {type: 'relation'});
|
||||
return iD.Entity({members: []}, attrs || {}, {type: 'relation'});
|
||||
};
|
||||
|
||||
+18
-4
@@ -1,7 +1,15 @@
|
||||
iD.Graph = function(entities, annotation) {
|
||||
if (!(this instanceof iD.Graph)) return new iD.Graph(entities, annotation);
|
||||
|
||||
this.entities = entities || {};
|
||||
if (_.isArray(entities)) {
|
||||
this.entities = {};
|
||||
for (var i = 0; i < entities.length; i++) {
|
||||
this.entities[entities[i].id] = entities[i];
|
||||
}
|
||||
} else {
|
||||
this.entities = entities || {};
|
||||
}
|
||||
|
||||
this.annotation = annotation;
|
||||
|
||||
if (iD.debug) {
|
||||
@@ -15,11 +23,17 @@ iD.Graph.prototype = {
|
||||
return this.entities[id];
|
||||
},
|
||||
|
||||
parents: function(id) {
|
||||
parentWays: function(id) {
|
||||
// This is slow and a bad hack.
|
||||
return _.filter(this.entities, function(e) {
|
||||
if (e.type !== 'way') return false;
|
||||
return e.nodes.indexOf(id) !== -1;
|
||||
return e.type === 'way' && e.nodes.indexOf(id) !== -1;
|
||||
});
|
||||
},
|
||||
|
||||
parentRelations: function(id) {
|
||||
// This is slow and a bad hack.
|
||||
return _.filter(this.entities, function(e) {
|
||||
return e.type === 'relation' && e.members.indexOf(id) !== -1;
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ iD.modes.AddRoad = function() {
|
||||
node = datum;
|
||||
|
||||
var id = datum.id;
|
||||
var parents = mode.history.graph().parents(id);
|
||||
var parents = mode.history.graph().parentWays(id);
|
||||
if (parents.length) {
|
||||
if (parents[0].nodes[0] === id) {
|
||||
way = parents[0];
|
||||
|
||||
@@ -27,8 +27,7 @@ iD.modes.DrawArea = function(way_id) {
|
||||
mode.history.replace(iD.actions.addWayNode(way,
|
||||
mode.history.graph().entity(way.nodes[0])));
|
||||
|
||||
delete way.tags.elastic;
|
||||
mode.history.perform(iD.actions.changeTags(way, way.tags));
|
||||
mode.history.perform(iD.actions.changeTags(way, _.omit(way.tags, 'elastic')));
|
||||
|
||||
// End by clicking on own tail
|
||||
return mode.controller.enter(iD.modes.Select(way));
|
||||
|
||||
@@ -37,8 +37,7 @@ iD.modes.DrawRoad = function(way_id, direction) {
|
||||
mode.history.graph().entity(lastNode), index));
|
||||
}
|
||||
|
||||
delete way.tags.elastic;
|
||||
mode.history.perform(iD.actions.changeTags(way, way.tags));
|
||||
mode.history.perform(iD.actions.changeTags(way, _.omit(way.tags, 'elastic')));
|
||||
|
||||
// End by clicking on own tail
|
||||
return mode.controller.enter(iD.modes.Select(way));
|
||||
|
||||
@@ -15,7 +15,7 @@ iD.modes.Select = function (entity) {
|
||||
|
||||
if (!dragging) {
|
||||
dragging = iD.util.trueObj([entity.id].concat(
|
||||
_.pluck(mode.history.graph().parents(entity.id), 'id')));
|
||||
_.pluck(mode.history.graph().parentWays(entity.id), 'id')));
|
||||
mode.history.perform(iD.actions.noop());
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ iD.modes.Select = function (entity) {
|
||||
});
|
||||
|
||||
function remove() {
|
||||
// Remove this node from any ways that is a member of
|
||||
mode.history.graph().parents(entity.id)
|
||||
.filter(function(d) { return d.type === 'way'; })
|
||||
.forEach(function(parent) {
|
||||
mode.history.perform(iD.actions.removeWayNode(parent, entity));
|
||||
});
|
||||
mode.history.perform(iD.actions.remove(entity));
|
||||
switch (entity.type) {
|
||||
case 'way':
|
||||
mode.history.perform(iD.actions.DeleteWay(entity));
|
||||
case 'node':
|
||||
mode.history.perform(iD.actions.DeleteNode(entity));
|
||||
}
|
||||
|
||||
mode.controller.exit();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ iD.Map = function() {
|
||||
}
|
||||
|
||||
dragging = iD.util.trueObj([entity.id].concat(
|
||||
_.pluck(history.graph().parents(entity.id), 'id')));
|
||||
_.pluck(history.graph().parentWays(entity.id), 'id')));
|
||||
history.perform(iD.actions.noop());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user