Merge branch 'master' of github.com:systemed/iD

This commit is contained in:
Tom MacWright
2012-12-06 19:27:01 -05:00
17 changed files with 111 additions and 34 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
iD.actions.ReverseWay = function(wayId) {
return function(graph) {
var way = graph.entity(wayId),
nodes = way.nodes.slice();
nodes = way.nodes.slice().reverse();
return graph.replace(way.update({nodes: nodes}), 'changed way direction');
};
};
+1 -1
View File
@@ -70,7 +70,7 @@ iD.Graph.prototype = {
// Resolve the id references in a way, replacing them with actual objects.
fetch: function(id) {
var entity = this.entities[id], nodes = [];
if (!entity.nodes || !entity.nodes.length) return iD.Entity(entity); // TODO: shouldn't be necessary
if (!entity.nodes || !entity.nodes.length) return entity;
for (var i = 0, l = entity.nodes.length; i < l; i++) {
nodes[i] = this.fetch(entity.nodes[i]);
}
+15 -10
View File
@@ -7,31 +7,36 @@ iD.modes.AddArea = function() {
};
mode.enter = function() {
mode.map.dblclickEnable(false);
mode.map.hint('Click on the map to start drawing an area, like a park, lake, or building.');
var map = mode.map,
history = mode.history,
controller = mode.controller;
mode.map.surface.on('click.addarea', function() {
map.dblclickEnable(false)
.hint('Click on the map to start drawing an area, like a park, lake, or building.');
map.surface.on('click.addarea', function() {
var datum = d3.select(d3.event.target).datum() || {},
way = iD.Way({tags: { building: 'yes', area: 'yes' }});
// connect a way to an existing way
if (datum.type === 'node') {
mode.history.perform(
// start from an existing node
history.perform(
iD.actions.AddWay(way),
iD.actions.AddWayNode(way.id, datum.id));
} else {
var node = iD.Node({loc: mode.map.mouseCoordinates()});
mode.history.perform(
// start from a new node
var node = iD.Node({loc: map.mouseCoordinates()});
history.perform(
iD.actions.AddWay(way),
iD.actions.AddNode(node),
iD.actions.AddWayNode(way.id, node.id));
}
mode.controller.enter(iD.modes.DrawArea(way.id));
controller.enter(iD.modes.DrawArea(way.id));
});
mode.map.keybinding().on('⎋.addarea', function() {
mode.controller.exit();
map.keybinding().on('⎋.addarea', function() {
controller.exit();
});
};
+11 -7
View File
@@ -6,16 +6,20 @@ iD.modes.AddPlace = function() {
};
mode.enter = function() {
mode.map.hint('Click on the map to add a place.');
var map = mode.map,
history = mode.history,
controller = mode.controller;
mode.map.surface.on('click.addplace', function() {
var node = iD.Node({loc: mode.map.mouseCoordinates(), _poi: true});
mode.history.perform(iD.actions.AddNode(node));
mode.controller.enter(iD.modes.Select(node));
map.hint('Click on the map to add a place.');
map.surface.on('click.addplace', function() {
var node = iD.Node({loc: map.mouseCoordinates(), _poi: true});
history.perform(iD.actions.AddNode(node));
controller.enter(iD.modes.Select(node));
});
mode.map.keybinding().on('⎋.addplace', function() {
mode.controller.exit();
map.keybinding().on('⎋.addplace', function() {
controller.exit();
});
};
+11 -9
View File
@@ -7,27 +7,29 @@ iD.modes.AddRoad = function() {
};
mode.enter = function() {
var map = mode.map;
var map = mode.map,
history = mode.history,
controller = mode.controller;
map.dblclickEnable(false)
.hint('Click on the map to start drawing an road, path, or route.');
map.surface.on('click.addroad', function() {
var datum = d3.select(d3.event.target).datum() || {},
direction = 'forward',
way = iD.Way({ tags: { highway: 'residential' } });
way = iD.Way({ tags: { highway: 'residential' } }),
direction = 'forward';
if (datum.type === 'node') {
// continue an existing way
var id = datum.id;
var parents = mode.history.graph().parentWays(id);
var parents = history.graph().parentWays(id);
if (parents.length && parents[0].nodes[0] === id) {
way = parents[0];
direction = 'backward';
} else if (parents.length && _.last(parents[0].nodes) === id) {
way = parents[0];
} else {
mode.history.perform(
history.perform(
iD.actions.AddWay(way),
iD.actions.AddWayNode(way.id, datum.id));
}
@@ -36,7 +38,7 @@ iD.modes.AddRoad = function() {
var node = iD.Node({loc: map.mouseCoordinates()}),
index = iD.util.geo.chooseIndex(datum, d3.mouse(map.surface.node()), map);
mode.history.perform(
history.perform(
iD.actions.AddWay(way),
iD.actions.AddWayNode(datum.id, node, index),
iD.actions.AddWayNode(way.id, node.id));
@@ -44,17 +46,17 @@ iD.modes.AddRoad = function() {
// begin a new way
var node = iD.Node({loc: map.mouseCoordinates()});
mode.history.perform(
history.perform(
iD.actions.AddWay(way),
iD.actions.AddNode(node),
iD.actions.AddWayNode(way.id, node.id));
}
mode.controller.enter(iD.modes.DrawRoad(way.id, direction));
controller.enter(iD.modes.DrawRoad(way.id, direction));
});
map.keybinding().on('⎋.addroad', function() {
mode.controller.exit();
controller.exit();
});
};
-2
View File
@@ -14,7 +14,6 @@ iD.modes.DrawRoad = function(wayId, direction) {
tailId = (direction === 'forward') ? _.first(way.nodes) : _.last(way.nodes);
map.dblclickEnable(false)
.dragEnable(false)
.fastEnable(false)
.hint('Click to add more points to the road. ' +
'Click on other roads to connect to them, and double-click to ' +
@@ -90,7 +89,6 @@ iD.modes.DrawRoad = function(wayId, direction) {
.on('⌫.drawroad', null);
window.setTimeout(function() {
mode.map.dblclickEnable(true);
mode.map.dragEnable(true);
}, 1000);
};
+1 -3
View File
@@ -12,8 +12,6 @@ iD.modes.Select = function (entity) {
return { x: p[0], y: p[1] };
})
.on('drag', function(entity) {
if (!mode.map.dragEnable()) return;
d3.event.sourceEvent.stopPropagation();
if (!dragging) {
@@ -31,7 +29,7 @@ iD.modes.Select = function (entity) {
});
})
.on('dragend', function () {
if (!mode.map.dragEnable() || !dragging) return;
if (!dragging) return;
dragging = undefined;
mode.map.redraw();
});
+8
View File
@@ -83,10 +83,18 @@
</script>
<!-- include spec files here... -->
<script src="spec/actions/add_node.js"></script>
<script src="spec/actions/add_way.js"></script>
<script src="spec/actions/add_way_node.js"></script>
<script src="spec/actions/change_entity_tags.js"></script>
<script src="spec/actions/delete_node.js"></script>
<script src="spec/actions/delete_way.js"></script>
<script src="spec/actions/move.js"></script>
<script src="spec/actions/noop.js"></script>
<script src="spec/actions/remove_way_node.js"></script>
<script src="spec/actions/remove_relation_member.js"></script>
<script src="spec/actions/reverse_way.js"></script>
<script src="spec/format/geojson.js"></script>
<script src="spec/format/xml.js"></script>
<script src="spec/graph/graph.js"></script>
+8
View File
@@ -25,10 +25,18 @@
</script>
<!-- include spec files here... -->
<script src="spec/actions/add_node.js"></script>
<script src="spec/actions/add_way.js"></script>
<script src="spec/actions/add_way_node.js"></script>
<script src="spec/actions/change_entity_tags.js"></script>
<script src="spec/actions/delete_node.js"></script>
<script src="spec/actions/delete_way.js"></script>
<script src="spec/actions/move.js"></script>
<script src="spec/actions/noop.js"></script>
<script src="spec/actions/remove_way_node.js"></script>
<script src="spec/actions/remove_relation_member.js"></script>
<script src="spec/actions/reverse_way.js"></script>
<script src="spec/format/geojson.js"></script>
<script src="spec/format/xml.js"></script>
<script src="spec/graph/graph.js"></script>
+7
View File
@@ -0,0 +1,7 @@
describe("iD.actions.AddNode", function () {
it("adds a node to the graph", function () {
var node = iD.Node(),
graph = iD.actions.AddNode(node)(iD.Graph());
expect(graph.entity(node.id)).to.equal(node);
});
});
+7
View File
@@ -0,0 +1,7 @@
describe("iD.actions.AddWay", function () {
it("adds a way to the graph", function () {
var way = iD.Way(),
graph = iD.actions.AddWay(way)(iD.Graph());
expect(graph.entity(way.id)).to.equal(way);
});
});
+8
View File
@@ -0,0 +1,8 @@
describe("iD.actions.ChangeEntityTags", function () {
it("changes an entity's tags", function () {
var entity = iD.Entity(),
tags = {foo: 'bar'},
graph = iD.actions.ChangeEntityTags(entity.id, tags)(iD.Graph([entity]));
expect(graph.entity(entity.id).tags).to.eql(tags);
});
});
+8
View File
@@ -0,0 +1,8 @@
describe("iD.actions.Move", function () {
it("changes an entity's location", function () {
var entity = iD.Entity(),
loc = [2, 3],
graph = iD.actions.Move(entity.id, loc)(iD.Graph([entity]));
expect(graph.entity(entity.id).loc).to.eql(loc);
});
});
+7
View File
@@ -0,0 +1,7 @@
describe("iD.actions.Noop", function () {
it("does nothing", function () {
var graph = iD.Graph(),
action = iD.actions.Noop(graph);
expect(action(graph)).to.equal(graph);
});
});
@@ -0,0 +1,8 @@
describe("iD.actions.RemoveRelationMember", function () {
it("removes a member from a relation", function () {
var node = iD.Node(),
relation = iD.Way({members: [node.id]}),
graph = iD.actions.RemoveRelationMember(relation.id, node.id)(iD.Graph([node, relation]));
expect(graph.entity(relation.id).members).to.eql([]);
});
});
+9
View File
@@ -0,0 +1,9 @@
describe("iD.actions.ReverseWay", function () {
it("reverses the order of nodes in the way", function () {
var node1 = iD.Node(),
node2 = iD.Node(),
way = iD.Way({nodes: [node1.id, node2.id]}),
graph = iD.actions.ReverseWay(way.id)(iD.Graph([node1, node2, way]));
expect(graph.entity(way.id).nodes).to.eql([node2.id, node1.id]);
});
});
+1 -1
View File
@@ -83,7 +83,7 @@ describe('iD.Graph', function() {
var node = iD.Node({id: "n1"}),
way = iD.Way({id: "w1", nodes: ["n1"]}),
graph = iD.Graph({n1: node, w1: way});
expect(graph.fetch("w1").nodes[0].id).to.equal("n1");
expect(graph.fetch("w1").nodes).to.eql([node]);
});
});