From b23ce19b1f0f934d164f3de726cc6d78c075c636 Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Wed, 11 Jul 2012 18:23:13 +0100 Subject: [PATCH] Create junctions when drawing a way --- js/iD/Entity.js | 67 ++++++++++++++++++++++++++++--- js/iD/actions/MoveNodeAction.js | 58 ++++++++++++++++++++++++++ js/iD/controller/shape/DrawWay.js | 5 ++- potlatch.css | 2 +- 4 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 js/iD/actions/MoveNodeAction.js diff --git a/js/iD/Entity.js b/js/iD/Entity.js index a29bf15eb..553ab0234 100755 --- a/js/iD/Entity.js +++ b/js/iD/Entity.js @@ -1,9 +1,9 @@ // iD/Entity.js // Entity classes for iD -define(['dojo/_base/declare','dojo/_base/array', - 'iD/actions/AddNodeToWayAction' - ], function(declare,array){ +define(['dojo/_base/declare','dojo/_base/array','dojo/_base/lang', + 'iD/actions/AddNodeToWayAction','iD/actions/MoveNodeAction' + ], function(declare,array,lang){ // ---------------------------------------------------------------------- // Entity base class @@ -117,11 +117,29 @@ declare("iD.Node", [iD.Entity], { this.modified=this.id<0; }, - project:function() { - this.latp=180/Math.PI * Math.log(Math.tan(Math.PI/4+this.lat*(Math.PI/180)/2)); - }, + project:function() { this.latp=180/Math.PI * Math.log(Math.tan(Math.PI/4+this.lat*(Math.PI/180)/2)); }, + latp2lat:function(a) { return 180/Math.PI * (2 * Math.atan(Math.exp(a*Math.PI/180)) - Math.PI/2); }, within:function(left,right,top,bottom) { return (this.lon>=left) && (this.lon<=right) && (this.lat>=bottom) && (this.lat<=top) && !this.deleted; }, + + refresh:function() { + var ways=this.parentWays(); + var conn=this.connection; + array.forEach(ways,function(way) { conn.refreshEntity(way); }); + this.connection.refreshEntity(this); + }, + + doSetLonLatp:function(lon,latproj,performAction) { + performAction(new iD.actions.MoveNodeAction(this, this.latp2lat(latproj), lon, lang.hitch(this,this._setLatLonImmediate) )); + }, + + _setLatLonImmediate:function(lat,lon) { + this.lat = lat; + this.lon = lon; + this.project(); + var ways = this.parentWays(); + for (var i=0; i0 && this.getNode(index-1)==node) return; + if (indexthis.createTime) { + this.oldLat = prev.oldLat; + this.oldLon = prev.oldLon; + return true; + } + return false; + }, + +}); + +// ---------------------------------------------------------------------- +// End of module +}); diff --git a/js/iD/controller/shape/DrawWay.js b/js/iD/controller/shape/DrawWay.js index f0dcc60e3..21d211d5a 100644 --- a/js/iD/controller/shape/DrawWay.js +++ b/js/iD/controller/shape/DrawWay.js @@ -14,7 +14,8 @@ */ -define(['dojo/_base/declare','dojo/_base/lang','dojox/gfx/shape','iD/controller/ControllerState'], function(declare,lang,shape){ +define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/array','dojox/gfx/shape','iD/controller/ControllerState'], + function(declare,lang,array,shape){ // ---------------------------------------------------------------------- // DrawWay class @@ -111,7 +112,7 @@ declare("iD.controller.shape.DrawWay", [iD.controller.ControllerState], { 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); } ); + array.forEach(ways, function(w) { w.doInsertNodeAtClosestPosition(node, true, lang.hitch(undo,undo.push)); } ); var action=this.undoAdder(); action(undo); return this; } diff --git a/potlatch.css b/potlatch.css index c012df349..ac8ddf93c 100755 --- a/potlatch.css +++ b/potlatch.css @@ -132,7 +132,7 @@ way::highlight :hover { z-index: 2; width: eval('_width+10'); color: #ffff99; } way::highlight :selected { z-index: 2; width: eval('_width+10'); color: yellow; opacity: 0.7;} node :selectedway { z-index: 9; icon-image: square; icon-width: 8; color: red; layer: 5; } -node::junction :junction :selectedway { z-index: 8; icon-image: square; icon-width: 11; casing-color: black; casing-width: 1; layer: 5; } +node::junction :junction :selectedway, node::junction :junction :hoverway { z-index: 8; icon-image: square; icon-width: 11; casing-color: black; casing-width: 1; layer: 5; } node !:drawn :poi { z-index: 2; icon-image: circle; icon-width: 4; color: green; casing-color: black; casing-width: 1; }