mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-19 23:14:47 +02:00
Merge branch 'master' of github.com:systemed/iD
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<title>iD</title>
|
||||
<link rel='stylesheet' href='css/reset.css'>
|
||||
<link rel='stylesheet' href='css/map.css'>
|
||||
<link rel='stylesheet' href='css/app.css'>
|
||||
|
||||
<!-- mobile devices -->
|
||||
<meta name='viewport' content='initial-scale=1.0 maximum-scale=1.0'>
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
|
||||
<script src='iD.min.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="iD"></div><script>
|
||||
var id = iD(document.getElementById('iD'));
|
||||
</script></body>
|
||||
</html>
|
||||
@@ -27,19 +27,18 @@ iD.actions.remove = function(node) {
|
||||
};
|
||||
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as
|
||||
iD.actions.addWayNode = function(way, node) {
|
||||
iD.actions.addWayNode = function(way, node, index) {
|
||||
return function(graph) {
|
||||
return graph.replace(way.update({
|
||||
nodes: way.nodes.slice()
|
||||
})).replace(node, 'added to a road');
|
||||
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) {
|
||||
return graph.replace(way.update({
|
||||
nodes: way.nodes.slice()
|
||||
})).remove(node, 'removed from a road');
|
||||
var nodes = _.without(way.nodes, node.id);
|
||||
return graph.replace(way.update({nodes: nodes}), 'removed from a road');
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
+17
-42
@@ -80,8 +80,7 @@ iD.modes.AddRoad = {
|
||||
node = iD.modes._node(this.map.projection.invert(
|
||||
d3.mouse(surface.node())));
|
||||
var connectedWay = this.history.graph().entity(t.datum().id);
|
||||
connectedWay.nodes.splice(index, 0, node.id);
|
||||
this.history.perform(iD.actions.addWayNode(connectedWay, node));
|
||||
this.history.perform(iD.actions.addWayNode(connectedWay, node, index));
|
||||
} else {
|
||||
node = iD.modes._node(this.map.projection.invert(
|
||||
d3.mouse(surface.node())));
|
||||
@@ -89,7 +88,6 @@ iD.modes.AddRoad = {
|
||||
|
||||
if (start) {
|
||||
this.history.perform(iD.actions.startWay(way));
|
||||
way.nodes.push(node.id);
|
||||
this.history.perform(iD.actions.addWayNode(way, node));
|
||||
}
|
||||
|
||||
@@ -118,7 +116,7 @@ iD.modes.DrawRoad = function(way_id, direction) {
|
||||
this.map.dblclickEnable(false);
|
||||
this.map.dragEnable(false);
|
||||
|
||||
var push = (direction === 'forward') ? 'push' : 'unshift',
|
||||
var index = (direction === 'forward') ? undefined : -1,
|
||||
pop = (direction === 'forward') ? 'pop' : 'shift',
|
||||
surface = this.map.surface,
|
||||
nextnode = iD.modes._node([NaN, NaN]),
|
||||
@@ -127,16 +125,14 @@ iD.modes.DrawRoad = function(way_id, direction) {
|
||||
firstNode = way.nodes[0],
|
||||
lastNode = _.last(way.nodes);
|
||||
|
||||
way.nodes[push](nextnode_id);
|
||||
this.history.perform(iD.actions.addWayNode(way, nextnode));
|
||||
this.history.perform(iD.actions.addWayNode(way, nextnode, index));
|
||||
|
||||
function mousemove() {
|
||||
var ll = this.map.projection.invert(d3.mouse(surface.node()));
|
||||
var way = this.history.graph().entity(way_id);
|
||||
var node = iD.Entity(this.history.graph().entity(nextnode_id), {
|
||||
lon: ll[0], lat: ll[1]
|
||||
});
|
||||
this.history.replace(iD.actions.addWayNode(way, node));
|
||||
this.history.replace(iD.actions.addWayNode(way, node, index));
|
||||
}
|
||||
|
||||
function click() {
|
||||
@@ -147,19 +143,14 @@ iD.modes.DrawRoad = function(way_id, direction) {
|
||||
|
||||
if (t.datum() && t.datum().type === 'node') {
|
||||
if (t.datum().id == firstNode || t.datum().id == lastNode) {
|
||||
var l = this.history.graph().entity(way.nodes[pop]());
|
||||
this.history.perform(iD.actions.removeWayNode(way, l));
|
||||
|
||||
// If this is drawing a loop and this is not the drawing
|
||||
// end of the stick, finish the circle
|
||||
if (direction === 'forward' && t.datum().id == firstNode) {
|
||||
way.nodes[push](firstNode);
|
||||
this.history.perform(iD.actions.addWayNode(way,
|
||||
this.history.graph().entity(firstNode)));
|
||||
this.history.replace(iD.actions.addWayNode(way,
|
||||
this.history.graph().entity(firstNode), index));
|
||||
} else if (direction === 'backward' && t.datum().id == lastNode) {
|
||||
way.nodes[push](lastNode);
|
||||
this.history.perform(iD.actions.addWayNode(way,
|
||||
this.history.graph().entity(lastNode)));
|
||||
this.history.replace(iD.actions.addWayNode(way,
|
||||
this.history.graph().entity(lastNode), index));
|
||||
}
|
||||
|
||||
delete way.tags.elastic;
|
||||
@@ -171,26 +162,22 @@ iD.modes.DrawRoad = function(way_id, direction) {
|
||||
} else {
|
||||
// connect a way to an existing way
|
||||
node = t.datum();
|
||||
this.history.replace(iD.actions.addWayNode(way, node, index));
|
||||
}
|
||||
} else if (t.datum() && t.datum().type === 'way') {
|
||||
var index = iD.modes.chooseIndex(t.datum(), d3.mouse(surface.node()), this.map);
|
||||
var connectedIndex = iD.modes.chooseIndex(t.datum(), d3.mouse(surface.node()), this.map);
|
||||
node = iD.modes._node(this.map.projection.invert(
|
||||
d3.mouse(surface.node())));
|
||||
this.history.replace(iD.actions.addWayNode(way, node, index));
|
||||
|
||||
var connectedWay = this.history.graph().entity(t.datum().id);
|
||||
connectedWay.nodes.splice(1, 0, node.id);
|
||||
this.history.perform(iD.actions.addWayNode(connectedWay, node));
|
||||
this.history.perform(iD.actions.addWayNode(connectedWay, node, connectedIndex));
|
||||
} else {
|
||||
node = iD.modes._node(this.map.projection.invert(
|
||||
d3.mouse(surface.node())));
|
||||
this.history.replace(iD.actions.addWayNode(way, node, index));
|
||||
}
|
||||
|
||||
var old = this.history.graph().entity(way.nodes[pop]());
|
||||
this.history.perform(iD.actions.removeWayNode(way, old));
|
||||
|
||||
way.nodes[push](node.id);
|
||||
this.history.perform(iD.actions.addWayNode(way, node));
|
||||
way.nodes = way.nodes.slice();
|
||||
|
||||
this.controller.enter(iD.modes.DrawRoad(way_id, direction));
|
||||
}
|
||||
|
||||
@@ -242,7 +229,6 @@ iD.modes.AddArea = {
|
||||
}
|
||||
|
||||
this.history.perform(iD.actions.startWay(way));
|
||||
way.nodes.push(node.id);
|
||||
this.history.perform(iD.actions.addWayNode(way, node));
|
||||
this.map.selectEntity(way);
|
||||
this.controller.enter(iD.modes.DrawArea(way.id));
|
||||
@@ -275,12 +261,10 @@ iD.modes.DrawArea = function(way_id) {
|
||||
nextnode = iD.modes._node([NaN, NaN]),
|
||||
nextnode_id = nextnode.id;
|
||||
|
||||
way.nodes.push(nextnode_id);
|
||||
this.history.perform(iD.actions.addWayNode(way, nextnode));
|
||||
|
||||
function mousemove() {
|
||||
var ll = this.map.projection.invert(d3.mouse(surface.node()));
|
||||
var way = this.history.graph().entity(way_id);
|
||||
var node = iD.Entity(this.history.graph().entity(nextnode_id), {
|
||||
lon: ll[0],
|
||||
lat: ll[1]
|
||||
@@ -296,11 +280,7 @@ iD.modes.DrawArea = function(way_id) {
|
||||
|
||||
if (t.datum() && t.datum().type === 'node') {
|
||||
if (t.datum().id == firstnode_id) {
|
||||
var l = this.history.graph().entity(way.nodes.pop());
|
||||
this.history.perform(iD.actions.removeWayNode(way, l));
|
||||
|
||||
way.nodes.push(way.nodes[0]);
|
||||
this.history.perform(iD.actions.addWayNode(way,
|
||||
this.history.replace(iD.actions.addWayNode(way,
|
||||
this.history.graph().entity(way.nodes[0])));
|
||||
|
||||
delete way.tags.elastic;
|
||||
@@ -311,19 +291,14 @@ iD.modes.DrawArea = function(way_id) {
|
||||
} else {
|
||||
// connect a way to an existing way
|
||||
node = t.datum();
|
||||
this.history.replace(iD.actions.addWayNode(way, node));
|
||||
}
|
||||
} else {
|
||||
node = iD.modes._node(this.map.projection.invert(
|
||||
d3.mouse(surface.node())));
|
||||
this.history.replace(iD.actions.addWayNode(way, node));
|
||||
}
|
||||
|
||||
var old = this.history.graph().entity(way.nodes.pop());
|
||||
this.history.perform(iD.actions.removeWayNode(way, old));
|
||||
|
||||
way.nodes.push(node.id);
|
||||
this.history.perform(iD.actions.addWayNode(way, node));
|
||||
way.nodes = way.nodes.slice();
|
||||
|
||||
this.controller.enter(iD.modes.DrawArea(way_id));
|
||||
}
|
||||
|
||||
|
||||
@@ -27,11 +27,8 @@ iD.Map = function() {
|
||||
|
||||
if (!dragging) {
|
||||
if (entity.accuracy) {
|
||||
var index = entity.index, wayid = entity.way;
|
||||
entity = iD.Node(entity);
|
||||
var connectedWay = history.graph().entity(wayid);
|
||||
connectedWay.nodes.splice(index, 0, entity.id);
|
||||
history.perform(iD.actions.addWayNode(connectedWay, entity));
|
||||
var way = history.graph().entity(entity.way);
|
||||
history.perform(iD.actions.addWayNode(way, iD.Node(entity), entity.index));
|
||||
}
|
||||
|
||||
dragging = iD.util.trueObj([entity.id].concat(
|
||||
@@ -370,7 +367,6 @@ iD.Map = function() {
|
||||
history.graph().parents(entity.id)
|
||||
.filter(function(d) { return d.type === 'way'; })
|
||||
.forEach(function(parent) {
|
||||
parent.nodes = _.without(parent.nodes, entity.id);
|
||||
history.perform(iD.actions.removeWayNode(parent, entity));
|
||||
});
|
||||
deselectClick();
|
||||
|
||||
@@ -63,6 +63,8 @@
|
||||
</script>
|
||||
|
||||
<!-- include spec files here... -->
|
||||
<script src="spec/actions/add_way_node.js"></script>
|
||||
<script src="spec/actions/remove_way_node.js"></script>
|
||||
<script src="spec/format/geojson.js"></script>
|
||||
<script src="spec/format/xml.js"></script>
|
||||
<script src="spec/graph/graph.js"></script>
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
</script>
|
||||
|
||||
<!-- include spec files here... -->
|
||||
<script src="spec/actions/add_way_node.js"></script>
|
||||
<script src="spec/actions/remove_way_node.js"></script>
|
||||
<script src="spec/format/geojson.js"></script>
|
||||
<script src="spec/format/xml.js"></script>
|
||||
<script src="spec/graph/graph.js"></script>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
describe("iD.actions.addWayNode", function () {
|
||||
it("adds a node to the end of a way", function () {
|
||||
var way = iD.Way(),
|
||||
node = iD.Node({id: "n1"}),
|
||||
graph = iD.actions.addWayNode(way, node)(iD.Graph());
|
||||
expect(graph.entity(way.id).nodes).to.eql(["n1"]);
|
||||
});
|
||||
|
||||
it("adds a node to a way at the specified index", function () {
|
||||
var way = iD.Way({nodes: ["n1", "n3"]}),
|
||||
node = iD.Node({id: "n2"}),
|
||||
graph = iD.actions.addWayNode(way, node, 1)(iD.Graph());
|
||||
expect(graph.entity(way.id).nodes).to.eql(["n1", "n2", "n3"]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
describe("iD.actions.removeWayNode", function () {
|
||||
it("removes a node from a way", function () {
|
||||
var node = iD.Node({id: "n1"}),
|
||||
way = iD.Way({id: "w1", nodes: ["n1"]}),
|
||||
graph = iD.actions.removeWayNode(way, node)(iD.Graph({n1: node, w1: way}));
|
||||
expect(graph.entity(way.id).nodes).to.eql([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user