Very basic map event support, plus calculate area centroids correctly.
[potlatch2.git] / halcyon.mxml
index ab3f6d73448b0c2b63990d02c06b3148665ca47f..23d8a7290fe4b5eab433a5cd04b46be462ee69dc 100755 (executable)
@@ -6,11 +6,14 @@
        horizontalAlign="center" 
        addedToStage="initApp()">
 
-<!--    <halcyon:CountryComboBox /> -->
+    <mx:HDividedBox width="100%" height="100%">
 
-<!--   <halcyon:Map width="400" height="200" id="theMap" /> -->
-<!-- applicationComplete -->
-<!-- rawChildren -->
+      <mx:VBox height="50%">
+        <mx:Button label="+" click="theMap.zoomIn();"/>
+        <mx:Button label="-" click="theMap.zoomOut();"/>
+      </mx:VBox>
+      <mx:Canvas id="map_area" clipContent="true"/>
+    </mx:HDividedBox>
 
        <mx:Script><![CDATA[
                import net.systemeD.halcyon.*;
                import flash.events.MouseEvent;
                import flash.display.Sprite;
                import mx.core.IChildList;
+        import mx.containers.Canvas;
+               import mx.core.Application;
+
+        public var theMap:Map;
 
                private function initApp():void {
 
-                       Globals.vars.root=rawChildren;                  // set up global reference to root level
-                       var _root:IChildList=rawChildren;               // convenient local shorthand
+                       Globals.vars.root=map_area.rawChildren;                 // set up global reference to root level
+                       var _root:IChildList=map_area.rawChildren;              // convenient local shorthand
 
                        // map backdrop object
-                       var b:Sprite=new Sprite();
-                       b.graphics.beginFill(0xFFFFEA,100);
-                       b.graphics.drawRect(0,0,200,200);
-                       b.graphics.endFill();
+            var b:Canvas = new Canvas();
+            b.height=200; b.width=200;
+            b.setStyle("backgroundColor", 0xFFFFEA);
                        _root.addChild(b);
 
                        // add map
-                       var theMap:Map=new Map();
+                       theMap=new Map();
                        theMap.backdrop=b;
                        _root.addChild(theMap);
 
                        s.graphics.drawRect(0,0,200,200);
                        s.graphics.endFill();
                        _root.addChild(s);
-
                        theMap.mask=s;
 
+                       // add crosshair
+                       s=new Sprite();
+                       s.graphics.lineStyle(2,0);
+                       s.graphics.moveTo(stage.stageWidth/2-20,stage.stageHeight/2);
+                       s.graphics.lineTo(stage.stageWidth/2+20,stage.stageHeight/2);
+                       s.graphics.moveTo(stage.stageWidth/2,stage.stageHeight/2-20);
+                       s.graphics.lineTo(stage.stageWidth/2,stage.stageHeight/2+20);
+                       _root.addChild(s);
+
                        // mouse-up handler attached to stage, so the user can release outside the map
                        stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
                        theMap.backdrop.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
                        // 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;