make parallelise even moar awesome
authorRichard Fairhurst <richard@systemed.net>
Fri, 11 Jun 2010 07:13:51 +0000 (07:13 +0000)
committerRichard Fairhurst <richard@systemed.net>
Fri, 11 Jun 2010 07:13:51 +0000 (07:13 +0000)
TODO.txt
net/systemeD/halcyon/Map.as
net/systemeD/potlatch2/controller/SelectedParallelWay.as
net/systemeD/potlatch2/tools/Parallelise.as

index 42551c8..8108df3 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -44,7 +44,6 @@ Potlatch 2: main outstanding issues
 
 == UI ==
 
-** Parallelise should use the distance from the way, not from the first click (needs someone good at maths to fix this)
 ** Potlatch 1-style "floaty warnings"
 ** Toolbox fixes (see comments in file)
 ** Should remember which background imagery layer you had previously selected
@@ -72,3 +71,4 @@ Potlatch 2: main outstanding issues
 * More line decoration (cliffs etc.), and implied values for 'dashes' if not supplied
 * Complete MapCSS support
 * 'Light' version without vectorlayer support etc.
+* .gz support for OSMConnection
index 652a151..d765bdd 100755 (executable)
@@ -415,6 +415,11 @@ package net.systemeD.halcyon {
                // ------------------------------------------------------------------------------------------
                // Debugging
                
+               public function clearDebug():void {
+                       if (!Globals.vars.hasOwnProperty('debug')) return;
+                       Globals.vars.debug.text='';
+               }
+                       
                public function addDebug(text:String):void {
                        if (!Globals.vars.hasOwnProperty('debug')) return;
                        if (!Globals.vars.debug.visible) return;
index c1a15cf..50ce67b 100644 (file)
@@ -10,8 +10,10 @@ package net.systemeD.potlatch2.controller {
                private var startlon:Number;
                private var startlatp:Number;
                private var parallelise:Parallelise;
+               private var originalWay:Way;
 
         public function SelectedParallelWay(originalWay:Way) {
+                       this.originalWay = originalWay;
                        parallelise = new Parallelise(originalWay);
                        selectedWay=parallelise.parallelWay;
                        super (selectedWay);
@@ -21,21 +23,53 @@ package net.systemeD.potlatch2.controller {
                        if (event.type==MouseEvent.MOUSE_MOVE) {
                                var lon:Number =controller.map.coord2lon(controller.map.mouseX);
                                var latp:Number=controller.map.coord2latp(controller.map.mouseY);
-                               var offset:Number=Math.sqrt(Math.pow(lon-startlon,2)+
-                                                           Math.pow(latp-startlatp,2));
-                               if (lon<startlon) { offset=-offset; }   // ** this should be smarter than just lon<startlon
-                               parallelise.draw(offset);
+                               parallelise.draw(distanceFromWay(lon,latp));
                        } else if (event.type==MouseEvent.MOUSE_UP) {
                                return new SelectedWay(selectedWay);
                        }
                        return this;
         }
 
+               override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
+                       if (event.keyCode==27) {                        // Escape
+                               selectedWay.remove(MainUndoStack.getGlobalStack().addAction);
+                               return new NoSelection();
+                       }
+                       var cs:ControllerState = sharedKeyboardEvents(event);
+                       return cs ? cs : this;
+               }
+
                private function sgn(a:Number):Number {
                        if (a==0) return 0;
                        if (a<0) return -1;
                        return 1;
                }
+               
+               private function distanceFromWay(lon:Number,latp:Number):Number {
+                       var i:uint, ax:Number, ay:Number, bx:Number, by:Number, l:Number;
+                       var ad:Number, bd:Number;
+                       var r:Number, px:Number, py:Number;
+                       var furthdist:Number=-1; var furthsgn:int=1;
+                       for (i=0; i<originalWay.length-1; i++) {
+                               ax=originalWay.getNode(i).lon;
+                               ay=originalWay.getNode(i).latp;
+                               bx=originalWay.getNode(i+1).lon;
+                               by=originalWay.getNode(i+1).latp;
+
+                               ad=Math.sqrt(Math.pow(lon-ax,2)+Math.pow(latp-ay,2));   // distance to ax,ay
+                               bd=Math.sqrt(Math.pow(bx-lon,2)+Math.pow(by-latp,2));   // distance to bx,by
+                               l =Math.sqrt(Math.pow(bx-ax ,2)+Math.pow(by-ay  ,2));   // length of segment
+                               r =ad/(ad+bd);                                                                                  // proportion along segment
+                               px=ax+r*(bx-ax); py=ay+r*(by-ay);                                               // nearest point on line
+                               r=Math.sqrt(Math.pow(px-lon,2)+Math.pow(py-latp,2));    // distance from px,py to lon,latp
+
+                               if (furthdist<0 || furthdist>r) {
+                                       furthdist=r; 
+                                       furthsgn=sgn((bx-ax)*(latp-ay)-(by-ay)*(lon-ax));
+                               }
+                       }
+                       return furthdist*furthsgn;
+               }
 
                override public function enterState():void {
                        controller.map.paint.createWayUI(selectedWay);
index 8ba976e..51ea53d 100644 (file)
@@ -66,6 +66,7 @@ package net.systemeD.potlatch2.tools {
                                        parallelWay.appendNode(nodes[i], undo.push);
                                }
                        }
+                       if (originalWay.isArea()) { parallelWay.appendNode(nodes[0],undo.push); }
                        parallelWay.resume();
                        MainUndoStack.getGlobalStack().addAction(undo);
                }