diff --git a/js/id/modes/add_area.js b/js/id/modes/add_area.js index 7a76a98db..d9ecdbcce 100644 --- a/js/id/modes/add_area.js +++ b/js/id/modes/add_area.js @@ -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(); }); }; diff --git a/js/id/modes/add_place.js b/js/id/modes/add_place.js index 780023e76..56e54959d 100644 --- a/js/id/modes/add_place.js +++ b/js/id/modes/add_place.js @@ -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(); }); }; diff --git a/js/id/modes/add_road.js b/js/id/modes/add_road.js index a194b3295..879f930c8 100644 --- a/js/id/modes/add_road.js +++ b/js/id/modes/add_road.js @@ -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(); }); };