Very basic map event support, plus calculate area centroids correctly.
authorRichard Fairhurst <richard@systemed.net>
Mon, 8 Jun 2009 17:05:09 +0000 (17:05 +0000)
committerRichard Fairhurst <richard@systemed.net>
Mon, 8 Jun 2009 17:05:09 +0000 (17:05 +0000)
halcyon.mxml
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/MapEvent.as [new file with mode: 0644]
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/connection/Way.as

index dd09029..23d8a72 100755 (executable)
@@ -8,7 +8,7 @@
 
     <mx:HDividedBox width="100%" height="100%">
 
-      <mx:VBox height="100%">
+      <mx:VBox height="50%">
         <mx:Button label="+" click="theMap.zoomIn();"/>
         <mx:Button label="-" click="theMap.zoomOut();"/>
       </mx:VBox>
@@ -23,6 +23,7 @@
                import flash.display.Sprite;
                import mx.core.IChildList;
         import mx.containers.Canvas;
+               import mx.core.Application;
 
         public var theMap:Map;
 
             var b:Canvas = new Canvas();
             b.height=200; b.width=200;
             b.setStyle("backgroundColor", 0xFFFFEA);
-                       //var b:Sprite=new Sprite();
-                       //b.graphics.beginFill(0xFFFFEA,100);
-                       //b.graphics.drawRect(0,0,200,200);
-                       //b.graphics.endFill();
                        _root.addChild(b);
 
                        // add map
                        // keyboard event attached to stage
                        stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
 
+                       // example listener event
+                       var myListenerObj:Object = new Object();
+                       myListenerObj.mapHandler=function(event:MapEvent):void {
+                               Globals.vars.debug.appendText("Download event fired - "+event.minlat+","+event.minlon+"\n");
+                       };
+                       theMap.addEventListener(MapEvent.DOWNLOAD, myListenerObj.mapHandler);
+
                        // add debug field
                        var t:TextField=new TextField();
                        t.width=400; t.height=100; t.border=true; 
index d6a1413..e202306 100755 (executable)
@@ -168,8 +168,7 @@ package net.systemeD.halcyon {
                // (typically from whichways, but will want to add more connections)
 
                public function download():void {
-                       var e:MapEvent = new MapEvent("download",edge_l,edge_r,edge_t,edge_b);
-                       this.dispatchEvent(e);
+                       this.dispatchEvent(new MapEvent(MapEvent.DOWNLOAD,edge_l,edge_r,edge_t,edge_b));
                        
                        if (edge_l>=bigedge_l && edge_r<=bigedge_r &&
                                edge_b>=bigedge_b && edge_t<=bigedge_t) { return; }     // we have already loaded this area, so ignore
diff --git a/net/systemeD/halcyon/MapEvent.as b/net/systemeD/halcyon/MapEvent.as
new file mode 100644 (file)
index 0000000..87262d3
--- /dev/null
@@ -0,0 +1,19 @@
+package net.systemeD.halcyon {
+
+    import flash.events.Event;
+
+    public class MapEvent extends Event {
+
+               public static const DOWNLOAD:String = "download";
+               public var minlon:Number, maxlon:Number, maxlat:Number, minlat:Number;
+
+        public function MapEvent(eventname:String, minlon:Number, maxlon:Number, maxlat:Number, minlat:Number) {
+            super(eventname);
+            this.minlat = minlat;
+            this.minlon = minlon;
+            this.maxlat = maxlat;
+            this.maxlon = maxlon;
+        }
+    }
+
+}
index 15490bd..e1f20d1 100755 (executable)
@@ -55,23 +55,23 @@ package net.systemeD.halcyon {
                        pathlength=0;
                        patharea=0;
                        
+                       lx = way.getNode(way.length-1).lon;
+                       ly = way.getNode(way.length-1).latp;
                        for ( var i:uint = 0; i < way.length; i++ ) {
                 var node:Node = way.getNode(i);
                 var latp:Number = node.latp;
                 var lon:Number  = node.lon;
-                               if ( !isNaN(lx) ) {
-                    pathlength += Math.sqrt( Math.pow(lon-lx,2)+Math.pow(latp-ly,2) );
-                                       patharea += lx*latp-lon*ly;
-                                       sc = (lx*latp-lon*ly); 
-                                       cx += (lx+lon)*sc;
-                                       cy += (ly+latp)*sc;
-                }
+                               if ( i>0 ) { pathlength += Math.sqrt( Math.pow(lon-lx,2)+Math.pow(latp-ly,2) ); }
+                               sc = (lx*latp-lon*ly)*map.scalefactor;
+                               cx += (lx+lon)*sc;
+                               cy += (ly+latp)*sc;
+                               patharea += sc;
                                lx=lon; ly=latp;
                        }
 
                        pathlength*=map.scalefactor;
-                       patharea*=map.scalefactor/2;
-                       if (patharea>0 && way.isArea()) {
+                       patharea/=2;
+                       if (patharea!=0 && way.isArea()) {
                                centroid_x=map.lon2coord(cx/patharea/6);
                                centroid_y=map.latp2coord(cy/patharea/6);
                        } else if (pathlength>0) {
index f26d5b6..ec37b0f 100644 (file)
@@ -35,7 +35,7 @@ package net.systemeD.halcyon.connection {
         }
 
                public function isArea():Boolean {
-                       return nodes[0]==nodes[nodes.length-1] && nodes.length>2;
+                       return (nodes[0].id==nodes[nodes.length-1].id  && nodes.length>2);
                }
     }