mirror of
https://github.com/FoggedLens/iD.git
synced 2026-06-03 21:48:03 +02:00
Merge branch 'master' of github.com:systemed/iD
This commit is contained in:
@@ -1,25 +1,17 @@
|
||||
iD.behavior.AddWay = function(mode) {
|
||||
var map = mode.map,
|
||||
history = mode.history,
|
||||
controller = mode.controller,
|
||||
event = d3.dispatch('startFromNode', 'startFromWay', 'start'),
|
||||
draw;
|
||||
|
||||
function add(datum) {
|
||||
if (datum.type === 'node') {
|
||||
event.startFromNode(datum);
|
||||
} else if (datum.type === 'way') {
|
||||
var choice = iD.geo.chooseIndex(datum, d3.mouse(map.surface.node()), map);
|
||||
event.startFromWay(datum, choice.loc, choice.index);
|
||||
} else if (datum.midpoint) {
|
||||
var way = history.graph().entity(datum.way);
|
||||
event.startFromWay(way, datum.loc, datum.index);
|
||||
} else {
|
||||
event.start(map.mouseCoordinates());
|
||||
}
|
||||
}
|
||||
event = d3.dispatch('start', 'startFromWay', 'startFromNode', 'startFromMidpoint'),
|
||||
draw = iD.behavior.Draw(map);
|
||||
|
||||
var addWay = function(surface) {
|
||||
draw.on('click', event.start)
|
||||
.on('clickWay', event.startFromWay)
|
||||
.on('clickNode', event.startFromNode)
|
||||
.on('clickMidpoint', event.startFromMidpoint)
|
||||
.on('cancel', addWay.cancel)
|
||||
.on('finish', addWay.cancel);
|
||||
|
||||
map.fastEnable(false)
|
||||
.minzoom(16)
|
||||
.dblclickEnable(false);
|
||||
@@ -43,10 +35,5 @@ iD.behavior.AddWay = function(mode) {
|
||||
controller.exit();
|
||||
};
|
||||
|
||||
draw = iD.behavior.Draw()
|
||||
.on('add', add)
|
||||
.on('cancel', addWay.cancel)
|
||||
.on('finish', addWay.cancel);
|
||||
|
||||
return d3.rebind(addWay, event, 'on');
|
||||
};
|
||||
|
||||
+16
-3
@@ -1,5 +1,5 @@
|
||||
iD.behavior.Draw = function () {
|
||||
var event = d3.dispatch('move', 'add', 'undo', 'cancel', 'finish'),
|
||||
iD.behavior.Draw = function(map) {
|
||||
var event = d3.dispatch('move', 'click', 'clickWay', 'clickNode', 'clickMidpoint', 'undo', 'cancel', 'finish'),
|
||||
keybinding = d3.keybinding('draw'),
|
||||
down, surface, hover;
|
||||
|
||||
@@ -26,7 +26,20 @@ iD.behavior.Draw = function () {
|
||||
}
|
||||
|
||||
function click() {
|
||||
event.add(datum());
|
||||
var d = datum();
|
||||
if (d.type === 'way') {
|
||||
var choice = iD.geo.chooseIndex(d, d3.mouse(map.surface.node()), map);
|
||||
event.clickWay(d, choice.loc, choice.index);
|
||||
|
||||
} else if (d.type === 'node') {
|
||||
event.clickNode(d);
|
||||
|
||||
} else if (d.type === 'midpoint') {
|
||||
event.clickMidpoint(d);
|
||||
|
||||
} else {
|
||||
event.click(map.mouseCoordinates());
|
||||
}
|
||||
}
|
||||
|
||||
function keydown() {
|
||||
|
||||
+43
-40
@@ -1,11 +1,11 @@
|
||||
iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) {
|
||||
iD.behavior.DrawWay = function(wayId, index, mode, baseGraph) {
|
||||
var map = mode.map,
|
||||
history = mode.history,
|
||||
controller = mode.controller,
|
||||
event = d3.dispatch('add', 'addHead', 'addTail', 'addNode', 'addWay'),
|
||||
way = mode.history.graph().entity(wayId),
|
||||
finished = false,
|
||||
draw;
|
||||
annotation = 'added to a way',
|
||||
draw = iD.behavior.Draw(map);
|
||||
|
||||
var node = iD.Node({loc: map.mouseCoordinates()}),
|
||||
nodeId = node.id;
|
||||
@@ -17,7 +17,7 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) {
|
||||
function move(datum) {
|
||||
var loc = map.mouseCoordinates();
|
||||
|
||||
if (datum.type === 'node' || datum.midpoint) {
|
||||
if (datum.type === 'node' || datum.type === 'midpoint') {
|
||||
loc = datum.loc;
|
||||
} else if (datum.type === 'way') {
|
||||
loc = iD.geo.chooseIndex(datum, d3.mouse(map.surface.node()), map).loc;
|
||||
@@ -26,29 +26,20 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) {
|
||||
history.replace(iD.actions.MoveNode(nodeId, loc));
|
||||
}
|
||||
|
||||
function add(datum) {
|
||||
if (datum.id === headId) {
|
||||
event.addHead(datum);
|
||||
} else if (datum.id === tailId) {
|
||||
event.addTail(datum);
|
||||
} else if (datum.type === 'node' && datum.id !== nodeId) {
|
||||
event.addNode(datum);
|
||||
} else if (datum.type === 'way') {
|
||||
var choice = iD.geo.chooseIndex(datum, d3.mouse(map.surface.node()), map);
|
||||
event.addWay(datum, choice.loc, choice.index);
|
||||
} else if (datum.midpoint) {
|
||||
var way = history.graph().entity(datum.way);
|
||||
event.addWay(way, datum.loc, datum.index);
|
||||
} else {
|
||||
event.add(map.mouseCoordinates());
|
||||
}
|
||||
}
|
||||
|
||||
function undone() {
|
||||
controller.enter(iD.modes.Browse());
|
||||
}
|
||||
|
||||
var drawWay = function(surface) {
|
||||
draw.on('move', move)
|
||||
.on('click', drawWay.add)
|
||||
.on('clickWay', drawWay.addWay)
|
||||
.on('clickNode', drawWay.addNode)
|
||||
.on('clickMidpoint', drawWay.addMidpoint)
|
||||
.on('undo', history.undo)
|
||||
.on('cancel', drawWay.cancel)
|
||||
.on('finish', drawWay.finish);
|
||||
|
||||
map.fastEnable(false)
|
||||
.minzoom(16)
|
||||
.dblclickEnable(false);
|
||||
@@ -80,6 +71,12 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) {
|
||||
history.on('undone.draw', null);
|
||||
};
|
||||
|
||||
drawWay.annotation = function(_) {
|
||||
if (!arguments.length) return annotation;
|
||||
annotation = _;
|
||||
return drawWay;
|
||||
};
|
||||
|
||||
function ReplaceTemporaryNode(newNode) {
|
||||
return function(graph) {
|
||||
return graph
|
||||
@@ -88,10 +85,13 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) {
|
||||
}
|
||||
}
|
||||
|
||||
// Connect the way to an existing node and continue drawing.
|
||||
drawWay.addNode = function(node, annotation) {
|
||||
history.perform(
|
||||
ReplaceTemporaryNode(node),
|
||||
// Accept the current position of the temporary node and continue drawing.
|
||||
drawWay.add = function(loc) {
|
||||
var newNode = iD.Node({loc: loc});
|
||||
|
||||
history.replace(
|
||||
iD.actions.AddNode(newNode),
|
||||
ReplaceTemporaryNode(newNode),
|
||||
annotation);
|
||||
|
||||
finished = true;
|
||||
@@ -99,7 +99,7 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) {
|
||||
};
|
||||
|
||||
// Connect the way to an existing way.
|
||||
drawWay.addWay = function(way, loc, wayIndex, annotation) {
|
||||
drawWay.addWay = function(way, loc, wayIndex) {
|
||||
var newNode = iD.Node({loc: loc});
|
||||
|
||||
history.perform(
|
||||
@@ -112,13 +112,23 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) {
|
||||
controller.enter(mode);
|
||||
};
|
||||
|
||||
// Accept the current position of the temporary node and continue drawing.
|
||||
drawWay.add = function(loc, annotation) {
|
||||
var newNode = iD.Node({loc: loc});
|
||||
// Connect the way to an existing node and continue drawing.
|
||||
drawWay.addNode = function(node) {
|
||||
history.perform(
|
||||
ReplaceTemporaryNode(node),
|
||||
annotation);
|
||||
|
||||
history.replace(
|
||||
iD.actions.AddNode(newNode),
|
||||
ReplaceTemporaryNode(newNode),
|
||||
finished = true;
|
||||
controller.enter(mode);
|
||||
};
|
||||
|
||||
// Add a midpoint, connect the way to it, and continue drawing.
|
||||
drawWay.addMidpoint = function(midpoint) {
|
||||
var node = iD.Node();
|
||||
|
||||
history.perform(
|
||||
iD.actions.AddMidpoint(midpoint, node),
|
||||
ReplaceTemporaryNode(node),
|
||||
annotation);
|
||||
|
||||
finished = true;
|
||||
@@ -149,12 +159,5 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) {
|
||||
controller.enter(iD.modes.Browse());
|
||||
};
|
||||
|
||||
draw = iD.behavior.Draw()
|
||||
.on('move', move)
|
||||
.on('add', add)
|
||||
.on('undo', history.undo)
|
||||
.on('cancel', drawWay.cancel)
|
||||
.on('finish', drawWay.finish);
|
||||
|
||||
return d3.rebind(drawWay, event, 'on');
|
||||
};
|
||||
|
||||
+21
-6
@@ -15,11 +15,13 @@ iD.modes.AddArea = function() {
|
||||
history = mode.history,
|
||||
controller = mode.controller;
|
||||
|
||||
function startFromNode(node) {
|
||||
function start(loc) {
|
||||
var graph = history.graph(),
|
||||
node = iD.Node({loc: loc}),
|
||||
way = iD.Way({tags: defaultTags});
|
||||
|
||||
history.perform(
|
||||
iD.actions.AddNode(node),
|
||||
iD.actions.AddWay(way),
|
||||
iD.actions.AddWayNode(way.id, node.id),
|
||||
iD.actions.AddWayNode(way.id, node.id));
|
||||
@@ -42,13 +44,25 @@ iD.modes.AddArea = function() {
|
||||
controller.enter(iD.modes.DrawArea(way.id, graph));
|
||||
}
|
||||
|
||||
function start(loc) {
|
||||
function startFromNode(node) {
|
||||
var graph = history.graph(),
|
||||
node = iD.Node({loc: loc}),
|
||||
way = iD.Way({tags: defaultTags});
|
||||
|
||||
history.perform(
|
||||
iD.actions.AddNode(node),
|
||||
iD.actions.AddWay(way),
|
||||
iD.actions.AddWayNode(way.id, node.id),
|
||||
iD.actions.AddWayNode(way.id, node.id));
|
||||
|
||||
controller.enter(iD.modes.DrawArea(way.id, graph));
|
||||
}
|
||||
|
||||
function startFromMidpoint(midpoint) {
|
||||
var graph = history.graph(),
|
||||
node = iD.Node(),
|
||||
way = iD.Way({tags: defaultTags});
|
||||
|
||||
history.perform(
|
||||
iD.actions.AddMidpoint(midpoint, node),
|
||||
iD.actions.AddWay(way),
|
||||
iD.actions.AddWayNode(way.id, node.id),
|
||||
iD.actions.AddWayNode(way.id, node.id));
|
||||
@@ -57,9 +71,10 @@ iD.modes.AddArea = function() {
|
||||
}
|
||||
|
||||
behavior = iD.behavior.AddWay(mode)
|
||||
.on('startFromNode', startFromNode)
|
||||
.on('start', start)
|
||||
.on('startFromWay', startFromWay)
|
||||
.on('start', start);
|
||||
.on('startFromNode', startFromNode)
|
||||
.on('startFromMidpoint', startFromMidpoint);
|
||||
|
||||
mode.map.surface.call(behavior);
|
||||
mode.map.tail('Click on the map to start drawing an area, like a park, lake, or building.', true);
|
||||
|
||||
+33
-19
@@ -15,6 +15,33 @@ iD.modes.AddLine = function() {
|
||||
history = mode.history,
|
||||
controller = mode.controller;
|
||||
|
||||
function start(loc) {
|
||||
var graph = history.graph(),
|
||||
node = iD.Node({loc: loc}),
|
||||
way = iD.Way({tags: defaultTags});
|
||||
|
||||
history.perform(
|
||||
iD.actions.AddNode(node),
|
||||
iD.actions.AddWay(way),
|
||||
iD.actions.AddWayNode(way.id, node.id));
|
||||
|
||||
controller.enter(iD.modes.DrawLine(way.id, 'forward', graph));
|
||||
}
|
||||
|
||||
function startFromWay(other, loc, index) {
|
||||
var graph = history.graph(),
|
||||
node = iD.Node({loc: loc}),
|
||||
way = iD.Way({tags: defaultTags});
|
||||
|
||||
history.perform(
|
||||
iD.actions.AddNode(node),
|
||||
iD.actions.AddWay(way),
|
||||
iD.actions.AddWayNode(way.id, node.id),
|
||||
iD.actions.AddWayNode(other.id, node.id, index));
|
||||
|
||||
controller.enter(iD.modes.DrawLine(way.id, 'forward', graph));
|
||||
}
|
||||
|
||||
function startFromNode(node) {
|
||||
var graph = history.graph(),
|
||||
parent = graph.parentWays(node)[0],
|
||||
@@ -37,27 +64,13 @@ iD.modes.AddLine = function() {
|
||||
}
|
||||
}
|
||||
|
||||
function startFromWay(other, loc, index) {
|
||||
function startFromMidpoint(midpoint) {
|
||||
var graph = history.graph(),
|
||||
node = iD.Node({loc: loc}),
|
||||
node = iD.Node(),
|
||||
way = iD.Way({tags: defaultTags});
|
||||
|
||||
history.perform(
|
||||
iD.actions.AddNode(node),
|
||||
iD.actions.AddWay(way),
|
||||
iD.actions.AddWayNode(way.id, node.id),
|
||||
iD.actions.AddWayNode(other.id, node.id, index));
|
||||
|
||||
controller.enter(iD.modes.DrawLine(way.id, 'forward', graph));
|
||||
}
|
||||
|
||||
function start(loc) {
|
||||
var graph = history.graph(),
|
||||
node = iD.Node({loc: loc}),
|
||||
way = iD.Way({tags: defaultTags});
|
||||
|
||||
history.perform(
|
||||
iD.actions.AddNode(node),
|
||||
iD.actions.AddMidpoint(midpoint, node),
|
||||
iD.actions.AddWay(way),
|
||||
iD.actions.AddWayNode(way.id, node.id));
|
||||
|
||||
@@ -65,9 +78,10 @@ iD.modes.AddLine = function() {
|
||||
}
|
||||
|
||||
behavior = iD.behavior.AddWay(mode)
|
||||
.on('startFromNode', startFromNode)
|
||||
.on('start', start)
|
||||
.on('startFromWay', startFromWay)
|
||||
.on('start', start);
|
||||
.on('startFromNode', startFromNode)
|
||||
.on('startFromMidpoint', startFromMidpoint);
|
||||
|
||||
mode.map.surface.call(behavior);
|
||||
mode.map.tail('Click on the map to start drawing an road, path, or route.', true);
|
||||
|
||||
@@ -16,8 +16,8 @@ iD.modes.AddPoint = function() {
|
||||
|
||||
map.tail('Click on the map to add a point.', true);
|
||||
|
||||
function add() {
|
||||
var node = iD.Node({loc: map.mouseCoordinates()});
|
||||
function add(loc) {
|
||||
var node = iD.Node({loc: loc});
|
||||
|
||||
history.perform(
|
||||
iD.actions.AddNode(node),
|
||||
@@ -26,12 +26,23 @@ iD.modes.AddPoint = function() {
|
||||
controller.enter(iD.modes.Select(node, true));
|
||||
}
|
||||
|
||||
function addWay(way, loc, index) {
|
||||
add(loc);
|
||||
}
|
||||
|
||||
function addNode(node) {
|
||||
add(node.loc);
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
controller.exit();
|
||||
}
|
||||
|
||||
behavior = iD.behavior.Draw()
|
||||
.on('add', add)
|
||||
behavior = iD.behavior.Draw(map)
|
||||
.on('click', add)
|
||||
.on('clickWay', addWay)
|
||||
.on('clickNode', addNode)
|
||||
.on('clickMidpoint', addNode)
|
||||
.on('cancel', cancel)
|
||||
.on('finish', cancel)
|
||||
(surface);
|
||||
|
||||
+11
-23
@@ -8,33 +8,21 @@ iD.modes.DrawArea = function(wayId, baseGraph) {
|
||||
|
||||
mode.enter = function() {
|
||||
var way = mode.history.graph().entity(wayId),
|
||||
index = -1,
|
||||
headId = way.nodes[way.nodes.length - 2],
|
||||
tailId = way.first(),
|
||||
annotation = way.isDegenerate() ? 'started an area' : 'continued an area';
|
||||
tailId = way.first();
|
||||
|
||||
function addHeadTail() {
|
||||
behavior.finish();
|
||||
}
|
||||
behavior = iD.behavior.DrawWay(wayId, -1, mode, baseGraph)
|
||||
.annotation(way.isDegenerate() ? 'started an area' : 'continued an area');
|
||||
|
||||
function addNode(node) {
|
||||
behavior.addNode(node, annotation);
|
||||
}
|
||||
var addNode = behavior.addNode;
|
||||
|
||||
function addWay(way, loc, index) {
|
||||
behavior.addWay(way, loc, index, annotation);
|
||||
}
|
||||
|
||||
function add(loc) {
|
||||
behavior.add(loc, annotation);
|
||||
}
|
||||
|
||||
behavior = iD.behavior.DrawWay(wayId, headId, tailId, index, mode, baseGraph)
|
||||
.on('addHead', addHeadTail)
|
||||
.on('addTail', addHeadTail)
|
||||
.on('addNode', addNode)
|
||||
.on('addWay', addWay)
|
||||
.on('add', add);
|
||||
behavior.addNode = function(node) {
|
||||
if (node.id === headId || node.id === tailId) {
|
||||
behavior.finish();
|
||||
} else {
|
||||
addNode(node);
|
||||
}
|
||||
};
|
||||
|
||||
mode.map.surface.call(behavior);
|
||||
mode.map.tail('Click to add points to your area. Click the first point to finish the area.', true);
|
||||
|
||||
+10
-31
@@ -9,41 +9,20 @@ iD.modes.DrawLine = function(wayId, direction, baseGraph) {
|
||||
mode.enter = function() {
|
||||
var way = mode.history.graph().entity(wayId),
|
||||
index = (direction === 'forward') ? undefined : 0,
|
||||
headId = (direction === 'forward') ? way.last() : way.first(),
|
||||
tailId = (direction === 'forward') ? way.first() : way.last(),
|
||||
annotation = way.isDegenerate() ? 'started a line' : 'continued a line';
|
||||
headId = (direction === 'forward') ? way.last() : way.first();
|
||||
|
||||
function addHead() {
|
||||
behavior.finish();
|
||||
}
|
||||
behavior = iD.behavior.DrawWay(wayId, index, mode, baseGraph)
|
||||
.annotation(way.isDegenerate() ? 'started a line' : 'continued a line');
|
||||
|
||||
function addTail(node) {
|
||||
// connect the way in a loop
|
||||
if (way.nodes.length > 2) {
|
||||
behavior.addNode(node, annotation);
|
||||
var addNode = behavior.addNode;
|
||||
|
||||
behavior.addNode = function(node) {
|
||||
if (node.id === headId) {
|
||||
behavior.finish();
|
||||
} else {
|
||||
behavior.cancel();
|
||||
addNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
function addNode(node) {
|
||||
behavior.addNode(node, annotation);
|
||||
}
|
||||
|
||||
function addWay(way, loc, index) {
|
||||
behavior.addWay(way, loc, index, annotation);
|
||||
}
|
||||
|
||||
function add(loc) {
|
||||
behavior.add(loc, annotation);
|
||||
}
|
||||
|
||||
behavior = iD.behavior.DrawWay(wayId, headId, tailId, index, mode, baseGraph)
|
||||
.on('addHead', addHead)
|
||||
.on('addTail', addTail)
|
||||
.on('addNode', addNode)
|
||||
.on('addWay', addWay)
|
||||
.on('add', add);
|
||||
};
|
||||
|
||||
mode.map.surface.call(behavior);
|
||||
mode.map.tail('Click to add more points to the line. ' +
|
||||
|
||||
@@ -92,7 +92,7 @@ iD.Map = function() {
|
||||
|
||||
all = _.compact(_.values(only));
|
||||
filter = function(d) {
|
||||
if (d.midpoint) {
|
||||
if (d.type === 'midpoint') {
|
||||
for (var i = 0; i < d.ways.length; i++) {
|
||||
if (d.ways[i].id in only) return true;
|
||||
}
|
||||
|
||||
@@ -20,11 +20,9 @@ iD.svg.Midpoints = function(projection) {
|
||||
|
||||
} else if (iD.geo.dist(projection(a.loc), projection(b.loc)) > 40) {
|
||||
midpoints[id] = {
|
||||
midpoint: true,
|
||||
type: 'midpoint',
|
||||
id: id,
|
||||
loc: iD.geo.interp(a.loc, b.loc, 0.5),
|
||||
a: a.id,
|
||||
b: b.id,
|
||||
ways: [{id: entity.id, index: j + 1}]
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user