Add rudimentary measurement function (press E)
authorRichard Fairhurst <richard@systemeD.net>
Sun, 7 Feb 2016 14:18:41 +0000 (14:18 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Sun, 7 Feb 2016 14:18:41 +0000 (14:18 +0000)
net/systemeD/halcyon/connection/Trace.as
net/systemeD/potlatch2/controller/ControllerState.as
net/systemeD/potlatch2/controller/Measurement.as [new file with mode: 0644]

index bf785de..7ef528d 100644 (file)
@@ -182,7 +182,7 @@ package net.systemeD.halcyon.connection {
                                     Math.cos(lat1*Math.PI/180) * 
                                     Math.cos(lat2*Math.PI/180) * 
                                     Math.pow(Math.sin(dlon / 2),2);
-                       a=Math.atan2(Math.sqrt(a),Math.sqrt(1-a));
+                       a=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));
                        return a*3958.75*1609;
                }
                
index eebb743..f769e3f 100644 (file)
@@ -84,6 +84,7 @@ package net.systemeD.potlatch2.controller {
                                case 66:        setSourceTag(); break;                                                                                                  // B - set source tag for current object
                                case 67:        editableLayer.connection.closeChangeset(); break;                                               // C - close changeset
                                case 68:        editableLayer.alpha=1.3-editableLayer.alpha; return null;                               // D - dim
+                               case 69:        return new Measurement(this);                                                                                   // E - measurement
                                case 71:        FlexGlobals.topLevelApplication.trackLoader.load(); break;                              // G - GPS tracks **FIXME: move from Application to Map
                 case 72:    showHistory(); break;                                                   // H - History
                                case 83:        SaveManager.saveChanges(editableLayer.connection); break;                               // S - save
diff --git a/net/systemeD/potlatch2/controller/Measurement.as b/net/systemeD/potlatch2/controller/Measurement.as
new file mode 100644 (file)
index 0000000..9189a1b
--- /dev/null
@@ -0,0 +1,55 @@
+package net.systemeD.potlatch2.controller {
+       import flash.events.*;
+       import flash.geom.Point;
+       import net.systemeD.potlatch2.EditController;
+       import net.systemeD.halcyon.connection.*;
+       import net.systemeD.halcyon.Elastic;
+       import net.systemeD.halcyon.AttentionEvent;
+
+       public class Measurement extends ControllerState {
+
+               private var elastic:Elastic;
+               protected var previousState:ControllerState;
+        
+               public function Measurement(previousState:ControllerState) {
+                       this.previousState = previousState;
+               }
+               override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
+
+                       if (event.type==MouseEvent.MOUSE_UP && !elastic) {
+                               // click to start
+                               var start:Point = new Point(controller.map.coord2lon(event.localX),
+                                                           controller.map.coord2latp(event.localY));
+                               elastic = new Elastic(controller.map, start, start);
+                               return this;
+
+                       } else if (event.type==MouseEvent.MOUSE_UP) {
+                               // click to exit
+                               controller.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, "Distance "+Math.round(getDistance()*10)/10+"m"));
+                               elastic.removeSprites();
+                               elastic = null;
+                               return previousState;
+
+                       } else if (event.type==MouseEvent.MOUSE_MOVE && elastic) {
+                               // update elastic line
+                               var point:Point = new Point(controller.map.coord2lon(event.localX),
+                                                           controller.map.coord2latp(event.localY));
+                               elastic.end = point;
+                               return this;
+
+                       }
+                       // event not handled
+                       return this;
+               }
+
+               private function getDistance():Number {
+                       return Trace.greatCircle(controller.map.latp2lat(elastic.start.y), elastic.start.x,
+                                                    controller.map.latp2lat(elastic.end.y  ), elastic.end.x);
+               }
+
+               override public function toString():String {
+                       return "Measurement";
+               }
+       }
+}