Start branching ways

This commit is contained in:
Richard Fairhurst
2012-07-11 23:12:41 +01:00
parent 45cca3b8ed
commit 3cee46eac3
3 changed files with 67 additions and 10 deletions

View File

@@ -1,10 +1,9 @@
DrawWay to do:
* make junctions
* start from a POI node ("convert into way?")
* still allow dragging the map
Drag and drop to do:
* icon grid
* improve 'avatar'
* presentation
* cope with dragging onto anything, not just blank areas of the map
Next to do:
@@ -34,9 +33,6 @@ Events
- the Controller gets the message and invokes a redraw
- no need for anything else to listen
General code
* Do the ***doSetLatLon*** and ***_setLatLon*** naming convention
------------------------------------------------
Modes:

View File

@@ -34,9 +34,10 @@ declare("iD.actions.AddNodeToWayAction", [iD.actions.UndoableEntityAction], {
// add the node
if (this.index==-1) this.index=this.nodeList.length;
this.node.addParent(way);
this.node.connection.unregisterPOI(this.node);
this.nodeList.splice(this.index, 0, this.node);
this.markDirty();
// way.expandBbox(this.node);
way.expandBbox(this.node);
way.refresh();
return this.SUCCESS;

View File

@@ -7,23 +7,83 @@
*/
define(['dojo/_base/declare',
define(['dojo/_base/declare','dojo/_base/lang',
'iD/actions/UndoableAction',
'iD/controller/ControllerState',
], function(declare){
], function(declare,lang){
// ----------------------------------------------------------------------
// SelectedWayNode class
declare("iD.controller.shape.SelectedWay", [iD.controller.ControllerState], {
constructor:function() {
way: null,
wayUI: null,
constructor:function(_way) {
this.way=_way;
},
enterState:function() {
this.wayUI=this.controller.map.getUI(this.way);
this.wayUI.setStateClass('selected');
this.wayUI.setStateClass('shownodes');
this.wayUI.redraw();
this.controller.stepper.setSteps({
begin: "Click anywhere on the map to start drawing there",
startpoint: "Click the point on the way where you want to start your new way",
draw: "Keep clicking to add each point, and press Enter or double-click when you're done",
tag: "Set the type of the road or shape"
},['begin','startpoint','draw','tag']).highlight('startpoint');
},
exitState:function() {
this.wayUI.resetStateClass('selected');
this.wayUI.resetStateClass('shownodes');
this.wayUI.redraw();
},
processMouseEvent:function(event,entityUI) {
var entity=entityUI ? entityUI.entity : null;
var entityType=entity ? entity.entityType : null;
if (event.type=='click') {
switch (entityType) {
case null:
return new iD.controller.shape.NoSelection();
case 'node':
var ways=entity.parentWays();
if (entity.hasParent(this.way)) {
// start a branching way from an existing point
var way = this.getConnection().createWay({}, [entity], lang.hitch(this,this.undoAdder) );
this.controller.map.createUI(way);
return new iD.controller.shape.DrawWay(way);
} else if (ways.length==0) {
// convert POI into way
return this;
} else {
// select another way
return new iD.controller.shape.SelectedWay(entity.getParents()[0]);
}
case 'way':
if (entity==this.way) {
// start a branching way from a new point
var map = this.controller.map;
var undo = new iD.actions.CompositeUndoableAction();
var startNode = this.getConnection().createNode(
{},
map.coord2lat(map.mouseY(event)),
map.coord2lon(map.mouseX(event)), lang.hitch(undo,undo.push) );
entity.doInsertNodeAtClosestPosition(startNode, true, lang.hitch(undo,undo.push));
var way = this.getConnection().createWay({}, [startNode], lang.hitch(undo,undo.push) );
this.controller.undoStack.addAction(undo);
this.controller.map.createUI(way);
return new iD.controller.shape.DrawWay(way);
} else {
// select another way
return new iD.controller.shape.SelectedWay(entity);
}
}
} else {
}
return this;
},