mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Move node update into addWayNode action
This commit is contained in:
57
index_packaged.html
Normal file
57
index_packaged.html
Normal file
@@ -0,0 +1,57 @@
|
||||
<!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='js/lib/lodash.js'></script>
|
||||
<script src='js/lib/d3.v3.js'></script>
|
||||
<script src='js/lib/sha.js'></script>
|
||||
<script src='js/lib/ohauth.js'></script>
|
||||
<script src='js/lib/jxon.js'></script>
|
||||
<script src='js/lib/d3.typeahead.js'></script>
|
||||
<script src='js/lib/d3.geo.tile.js'></script>
|
||||
<script src='js/lib/d3.size.js'></script>
|
||||
<script src='js/lib/d3.keybinding.js'></script>
|
||||
|
||||
<script src='js/id/id.js'></script>
|
||||
<script src='js/id/util.js'></script>
|
||||
<script src='js/id/oauth.js'></script>
|
||||
<script src='js/id/taginfo.js'></script>
|
||||
<script src='js/id/renderer/style.js'></script>
|
||||
<script src='js/id/renderer/background.js'></script>
|
||||
<script src='js/id/renderer/map.js'></script>
|
||||
<script src='js/id/renderer/hash.js'></script>
|
||||
<script src='js/id/renderer/markers.js'></script>
|
||||
<script src='js/id/ui/inspector.js'></script>
|
||||
<script src='js/id/ui/commit.js'></script>
|
||||
<script src='js/id/ui/loading.js'></script>
|
||||
<script src='js/id/ui/userpanel.js'></script>
|
||||
|
||||
<script src='js/id/actions/modes.js'></script>
|
||||
<script src='js/id/actions/actions.js'></script>
|
||||
|
||||
<script src='js/id/controller/controller.js'></script>
|
||||
|
||||
<script src='js/id/format/format.js'></script>
|
||||
<script src='js/id/format/geojson.js'></script>
|
||||
<script src='js/id/format/xml.js'></script>
|
||||
|
||||
<script src='js/id/graph/entity.js'></script>
|
||||
<script src='js/id/graph/graph.js'></script>
|
||||
<script src='js/id/graph/history.js'></script>
|
||||
<script src='js/id/connection.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="iD"></div><script>
|
||||
var id = iD(document.getElementById('iD'));
|
||||
</script></body>
|
||||
</html>
|
||||
@@ -27,11 +27,11 @@ 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');
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
</script>
|
||||
|
||||
<!-- include spec files here... -->
|
||||
<script src="spec/actions/add_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,7 @@
|
||||
</script>
|
||||
|
||||
<!-- include spec files here... -->
|
||||
<script src="spec/actions/add_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>
|
||||
|
||||
15
test/spec/actions/add_way_node.js
Normal file
15
test/spec/actions/add_way_node.js
Normal file
@@ -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"]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user