Current working version

This commit is contained in:
Richard Fairhurst
2012-07-11 14:27:30 +01:00
parent 790d71bba4
commit 22fab3eb1d
48 changed files with 4088 additions and 2 deletions
+165
View File
@@ -0,0 +1,165 @@
// iD/controller/shape/DrawWay.js
/*
Add road or shape -> DrawWay
The user is drawing a way.
Goes to:
-> click empty area: adds point, continues
-> click way: adds junction, continues
-> click node: adds to way, continues
-> double-click, or click this way: goes to Edit/SelectedWay
*/
define(['dojo/_base/declare','dojo/_base/lang','dojox/gfx/shape','iD/controller/ControllerState'], function(declare,lang,shape){
// ----------------------------------------------------------------------
// DrawWay class
declare("iD.controller.shape.DrawWay", [iD.controller.ControllerState], {
way: null,
wayUI: null,
editEnd: false,
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.highlight(2);
},
exitState:function() {
this.controller.map.clearElastic();
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;
var map=this.controller.map;
if (event.type=='mouseover' && entityType=='way' && entityUI!=this.wayUI) {
// Mouse over way, show hover highlight
entityUI.setStateClass('shownodeshover');
entityUI.redraw();
this.wayUI.redraw();
this.updateElastic(event);
return this;
} else if (event.type=='mouseout' && entityType=='way' && entityUI!=this.wayUI) {
// Mouse left way, remove hover highlight
// Find what object we're moving into
var into=shape.byId((event.hasOwnProperty('toElement') ? event.toElement : event.relatedTarget).__gfxObject__);
// If it's a nodeUI that belongs to a hovering way, don't deselect
if (into && into.hasOwnProperty('source') && into.source.hasStateClass('hoverway') && into.source.entity.hasParent(entity)) { return this; }
entityUI.resetStateClass('shownodeshover');
entityUI.redraw();
this.wayUI.redraw();
this.updateElastic(event);
return this;
} else if (event.type=='mouseout' && entityType=='node') {
// Mouse left node, remove hover highlight from parent way too
var ways=entity.parentWays();
for (var i in ways) {
var ui=this.controller.map.getUI(ways[i]);
if (ui && ui.hasStateClass('shownodeshover')) {
ui.resetStateClass('shownodeshover');
ui.redraw();
}
}
this.updateElastic(event);
this.wayUI.redraw();
return this;
} else if (event.type=='mousemove') {
// Mouse moved, update elastic
this.updateElastic(event);
return this;
} else if (event.type=='mousedown') {
switch (entityType) {
case 'node':
// Click on node
if (entity==this.getDrawingNode()) {
// Double-click, so complete drawing
return new iD.controller.edit.SelectedWay(this.way);
} else if (entity==this.getStartNode()) {
// Start of this way, so complete drawing
this.appendNode(entity, this.undoAdder() );
return new iD.controller.edit.SelectedWay(this.way);
} else {
// Add to way
this.appendNode(entity, this.undoAdder() );
return this;
}
case 'way':
// Click on way, add new junction node to way
console.log("clicked a way, add new junction to way");
var ways=[entity]; // ** needs to find all the ways under the mouse
var undo=new iD.actions.CompositeUndoableAction();
var node=this.appendNewNode(event, undo);
// array.forEach(ways, function(w) { w.insertNodeAtClosestPosition(node, true, undo.push); } );
var action=this.undoAdder(); action(undo);
return this;
}
} else if (event.type=='click') {
// Click on empty space, add new node to way
console.log("clicked empty space, add a new node to way");
var undo=new iD.actions.CompositeUndoableAction();
this.appendNewNode(event, undo);
var action=this.undoAdder(); action(undo);
return this;
}
return this;
},
updateElastic:function(event) {
var map=this.controller.map;
map.drawElastic(
map.lon2coord(this.getDrawingNode().lon),
map.lat2coord(this.getDrawingNode().lat),
map.mouseX(event), map.mouseY(event)
);
},
getDrawingNode:function() {
return (this.editEnd ? this.way.nodes[this.way.length()-1] : this.way.nodes[0]);
},
getStartNode:function() {
return (this.editEnd ? this.way.nodes[0] : this.way.nodes[this.way.length()-1]);
},
appendNode:function(node, performAction) {
if (this.editEnd) { this.way.doAppendNode(node, performAction); }
else { this.way.doPrependNode(node, performAction); }
},
appendNewNode:function(event, undo) {
var map=this.controller.map;
var node=this.getConnection().createNode(
{},
map.coord2lat(map.mouseY(event)),
map.coord2lon(map.mouseX(event)), lang.hitch(undo,undo.push) );
this.appendNode(node, lang.hitch(undo,undo.push));
return node;
},
});
// ----------------------------------------------------------------------
// End of module
});
+78
View File
@@ -0,0 +1,78 @@
// iD/controller/shape/NoSelection.js
/*
Add road or shape -> NoSelection
The user has clicked 'Add road or shape', but hasn't yet started drawing.
Goes to:
-> click empty area: goes to shape/DrawWay
-> click way: goes to shape/SelectedWay
-> click way-node: goes to shape/SelectedWayNode
-> click POI: ** not done yet, needs to ask "convert to shape"?
*/
define(['dojo/_base/declare','dojo/_base/lang',
'iD/actions/UndoableAction',
'iD/controller/ControllerState',
'iD/controller/shape/DrawWay',
'iD/controller/shape/SelectedWay',
'iD/controller/shape/SelectedWayNode',
'iD/controller/shape/SelectedPOINode',
], function(declare,lang){
// ----------------------------------------------------------------------
// ControllerState base class
declare("iD.controller.shape.NoSelection", [iD.controller.ControllerState], {
constructor:function() {
},
enterState:function() {
this.controller.stepper.setSteps([
"Click anywhere on the map to start drawing there",
"Keep clicking to add each point, and press Enter or double-click when you're done",
"Set the type of the road or shape"
]).highlight(1);
},
processMouseEvent:function(event,entityUI) {
var entity=entityUI ? entityUI.entity : null;
var entityType=entity ? entity.entityType : null;
var map=this.controller.map;
if (event.type=='click') {
switch (entityType) {
case 'node':
// Click to select a node
var ways=entity.parentWays();
if (ways.length==0) { return new iD.controller.shape.SelectedPOINode(entity); }
else { return new iD.controller.shape.SelectedWayNode(entity,ways[0]); }
case 'way':
// Click to select a way
return new iD.controller.shape.SelectedWay(entityUI.entity);
default:
// Click to start a new way
var undo = new iD.actions.CompositeUndoableAction();
console.log("Event is ",event.type);
var startNode = this.getConnection().createNode(
{},
map.coord2lat(map.mouseY(event)),
map.coord2lon(map.mouseX(event)), 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);
console.log("Started new way");
return new iD.controller.shape.DrawWay(way);
}
}
return this;
},
});
// ----------------------------------------------------------------------
// End of module
});
+34
View File
@@ -0,0 +1,34 @@
// iD/controller/shape/SelectedPOINode.js
/*
Add road or shape -> SelectedPOINode
The user has clicked 'Add road or shape', then a POI node to be converted to a way.
*/
define(['dojo/_base/declare',
'iD/actions/UndoableAction',
'iD/controller/ControllerState',
], function(declare){
// ----------------------------------------------------------------------
// SelectedPOINode class
declare("iD.controller.shape.SelectedPOINode", [iD.controller.ControllerState], {
constructor:function() {
},
processMouseEvent:function(event,entityUI) {
var entity=entityUI ? entityUI.entity : null;
var entityType=entity ? entity.entityType : null;
return this;
},
});
// ----------------------------------------------------------------------
// End of module
});
+34
View File
@@ -0,0 +1,34 @@
// iD/controller/shape/SelectedWay.js
/*
Add road or shape -> SelectedWay
The user has clicked 'Add road or shape', then a way to start the new way at.
*/
define(['dojo/_base/declare',
'iD/actions/UndoableAction',
'iD/controller/ControllerState',
], function(declare){
// ----------------------------------------------------------------------
// SelectedWayNode class
declare("iD.controller.shape.SelectedWay", [iD.controller.ControllerState], {
constructor:function() {
},
processMouseEvent:function(event,entityUI) {
var entity=entityUI ? entityUI.entity : null;
var entityType=entity ? entity.entityType : null;
return this;
},
});
// ----------------------------------------------------------------------
// End of module
});
+34
View File
@@ -0,0 +1,34 @@
// iD/controller/shape/SelectedWayNode.js
/*
Add road or shape -> SelectedWayNode
The user has clicked 'Add road or shape', then a way-node to start the way at.
*/
define(['dojo/_base/declare',
'iD/actions/UndoableAction',
'iD/controller/ControllerState',
], function(declare){
// ----------------------------------------------------------------------
// SelectedWayNode class
declare("iD.controller.shape.SelectedWayNode", [iD.controller.ControllerState], {
constructor:function() {
},
processMouseEvent:function(event,entityUI) {
var entity=entityUI ? entityUI.entity : null;
var entityType=entity ? entity.entityType : null;
return this;
},
});
// ----------------------------------------------------------------------
// End of module
});