Fix dragging while drawing, fix delete binding. Fixes #184

This commit is contained in:
Tom MacWright
2012-12-06 15:51:48 -05:00
parent a94eb35ddd
commit dc37eb99b4
3 changed files with 21 additions and 9 deletions

View File

@@ -57,7 +57,7 @@ iD.modes.DrawArea = function(way_id) {
mode.map.keybinding().on('⌫.drawarea', function() {
d3.event.preventDefault();
var lastNode = _.last(way.nodes);
mode.history.replace(iD.actions.removeWayNode(way,
mode.history.replace(iD.actions.RemoveWayNode(way,
mode.history.graph().entity(lastNode)));
mode.history.replace(iD.actions.DeleteNode(
mode.history.graph().entity(lastNode)));

View File

@@ -9,9 +9,10 @@ iD.modes.DrawRoad = function(way_id, direction) {
'Click on other roads to connect to them, and double-click to ' +
'end the road.');
mode.map.dragEnable(false);
mode.map.fastEnable(false);
var index = (direction === 'forward') ? undefined : -1,
node = iD.Node({loc: mode.map.mouseCoordinates()}),
node = iD.Node({loc: mode.map.mouseCoordinates(), tags: { elastic: true } }),
way = mode.history.graph().entity(way_id),
firstNode = way.nodes[0],
lastNode = _.last(way.nodes);
@@ -26,11 +27,11 @@ iD.modes.DrawRoad = function(way_id, direction) {
mode.map.surface.on('mousemove.drawroad', function() {
mode.history.replace(iD.actions.AddWayNode(way,
node.update({loc: mode.map.mouseCoordinates()}), index));
node.update({ loc: mode.map.mouseCoordinates() }), index));
});
mode.map.surface.on('click.drawroad', function() {
d3.event.stopPropagation();
// d3.event.stopPropagation();
var datum = d3.select(d3.event.target).datum() || {};
@@ -52,7 +53,7 @@ iD.modes.DrawRoad = function(way_id, direction) {
mode.history.replace(iD.actions.AddWayNode(way, datum, index));
}
} else if (datum.type === 'way') {
node = node.update({loc: mode.map.mouseCoordinates()});
node = node.update({loc: mode.map.mouseCoordinates(), tags: {} });
mode.history.replace(iD.actions.AddWayNode(way, node, index));
var connectedWay = mode.history.graph().entity(datum.id);
@@ -63,7 +64,7 @@ iD.modes.DrawRoad = function(way_id, direction) {
node,
connectedIndex));
} else {
node = node.update({loc: mode.map.mouseCoordinates()});
node = node.update({loc: mode.map.mouseCoordinates(), tags: {} });
mode.history.replace(iD.actions.AddWayNode(way, node, index));
}
@@ -76,7 +77,7 @@ iD.modes.DrawRoad = function(way_id, direction) {
mode.map.keybinding().on('⌫.drawroad', function() {
d3.event.preventDefault();
mode.history.replace(iD.actions.removeWayNode(way,
mode.history.replace(iD.actions.RemoveWayNode(way,
mode.history.graph().entity(lastNode)));
mode.history.replace(iD.actions.DeleteNode(
mode.history.graph().entity(lastNode)));
@@ -87,6 +88,7 @@ iD.modes.DrawRoad = function(way_id, direction) {
mode.exit = function() {
mode.map.hint(false);
mode.map.fastEnable(true);
mode.map.surface
.on('mousemove.drawroad', null)
.on('click.drawroad', null);

View File

@@ -13,6 +13,7 @@ iD.Map = function() {
.on('zoom', zoomPan),
dblclickEnabled = true,
dragEnabled = true,
fastEnabled = true,
dragging,
dragbehavior = d3.behavior.drag()
.origin(function(entity) {
@@ -176,7 +177,10 @@ iD.Map = function() {
handles.exit().remove();
handles.enter().append('image')
.attr({ width: 6, height: 6, 'class': 'handle', 'xlink:href': 'css/handle.png' })
.call(dragbehavior);
.each(function(d) {
if (d.tags && d.tags.elastic) return;
d3.select(this).call(dragbehavior);
});
handles.attr('transform', function(entity) {
var p = projection(entity.loc);
return 'translate(' + [~~p[0], ~~p[1]] + ') translate(-3, -3) rotate(45, 3, 3)';
@@ -304,7 +308,7 @@ iD.Map = function() {
if (d3.event && d3.event.sourceEvent.type === 'dblclick') {
if (!dblclickEnabled) return;
}
var fast = (d3.event.scale === projection.scale());
var fast = (d3.event.scale === projection.scale() && fastEnabled);
projection
.translate(d3.event.translate)
.scale(d3.event.scale);
@@ -379,6 +383,12 @@ iD.Map = function() {
return map;
};
map.fastEnable = function(_) {
if (!arguments.length) return fastEnabled;
fastEnabled = _;
return map;
};
map.zoom = function(z) {
if (!arguments.length) {
return Math.max(Math.log(projection.scale()) / Math.LN2 - 8, 0);