Very basic map event support, plus calculate area centroids correctly.
[potlatch2.git] / halcyon.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:Application 
3         xmlns:mx="http://www.adobe.com/2006/mxml" 
4         xmlns:halcyon="net.systemeD.halcyon.*"
5         layout="vertical"
6         horizontalAlign="center" 
7         addedToStage="initApp()">
8
9     <mx:HDividedBox width="100%" height="100%">
10
11       <mx:VBox height="50%">
12         <mx:Button label="+" click="theMap.zoomIn();"/>
13         <mx:Button label="-" click="theMap.zoomOut();"/>
14       </mx:VBox>
15       <mx:Canvas id="map_area" clipContent="true"/>
16     </mx:HDividedBox>
17
18         <mx:Script><![CDATA[
19                 import net.systemeD.halcyon.*;
20                 import flash.system.Security;
21                 import flash.net.*;
22                 import flash.events.MouseEvent;
23                 import flash.display.Sprite;
24                 import mx.core.IChildList;
25         import mx.containers.Canvas;
26                 import mx.core.Application;
27
28         public var theMap:Map;
29
30                 private function initApp():void {
31
32                         Globals.vars.root=map_area.rawChildren;                 // set up global reference to root level
33                         var _root:IChildList=map_area.rawChildren;              // convenient local shorthand
34
35                         // map backdrop object
36             var b:Canvas = new Canvas();
37             b.height=200; b.width=200;
38             b.setStyle("backgroundColor", 0xFFFFEA);
39                         _root.addChild(b);
40
41                         // add map
42                         theMap=new Map();
43                         theMap.backdrop=b;
44                         _root.addChild(theMap);
45
46                         // add mask for map
47                         var s:Sprite=new Sprite();
48                         s.graphics.beginFill(0xFFFFFF,100);
49                         s.graphics.drawRect(0,0,200,200);
50                         s.graphics.endFill();
51                         _root.addChild(s);
52                         theMap.mask=s;
53
54                         // add crosshair
55                         s=new Sprite();
56                         s.graphics.lineStyle(2,0);
57                         s.graphics.moveTo(stage.stageWidth/2-20,stage.stageHeight/2);
58                         s.graphics.lineTo(stage.stageWidth/2+20,stage.stageHeight/2);
59                         s.graphics.moveTo(stage.stageWidth/2,stage.stageHeight/2-20);
60                         s.graphics.lineTo(stage.stageWidth/2,stage.stageHeight/2+20);
61                         _root.addChild(s);
62
63                         // mouse-up handler attached to stage, so the user can release outside the map
64                         stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
65                         theMap.backdrop.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
66                         theMap.backdrop.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
67
68                         // keyboard event attached to stage
69                         stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
70
71                         // example listener event
72                         var myListenerObj:Object = new Object();
73                         myListenerObj.mapHandler=function(event:MapEvent):void {
74                                 Globals.vars.debug.appendText("Download event fired - "+event.minlat+","+event.minlon+"\n");
75                         };
76                         theMap.addEventListener(MapEvent.DOWNLOAD, myListenerObj.mapHandler);
77
78                         // add debug field
79                         var t:TextField=new TextField();
80                         t.width=400; t.height=100; t.border=true; 
81                         t.multiline=true;
82                         _root.addChild(t);
83                         Globals.vars.debug=t;
84                 }
85
86         ]]></mx:Script>
87
88 </mx:Application>
89