gah
[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="100%" width="25%" horizontalAlign="right">
12         <mx:HBox>
13           <mx:Button label="Export" click="theMap.export();"/>
14           <mx:Button label="-" click="theMap.zoomOut();"/>
15           <mx:Button label="+" click="theMap.zoomIn();"/>
16         </mx:HBox>
17         <halcyon:TagViewer width="100%" height="100%" id="tagViewer"/>
18       </mx:VBox>
19       <mx:Canvas id="map_area" width="75%" height="100%" resize="onResizeMap()"/>
20     </mx:HDividedBox>
21
22         <mx:Script><![CDATA[
23                 import net.systemeD.halcyon.*;
24                 import flash.system.Security;
25                 import flash.net.*;
26                 import flash.events.MouseEvent;
27                 import flash.display.Sprite;
28                 import mx.core.IChildList;
29         import mx.containers.Canvas;
30                 import mx.core.Application;
31
32         public var theMap:Map;
33
34                 private function initApp():void {
35
36                         Globals.vars.map_area=map_area;
37                         Globals.vars.root=map_area.rawChildren;                 // set up global reference to root level
38                         var _root:IChildList=map_area.rawChildren;              // convenient local shorthand
39
40                         // map backdrop object
41             var w:uint = map_area.width;
42             var h:uint = map_area.height;
43             var b:Sprite = new Sprite();
44             b.height=h; b.width=w;
45             b.graphics.beginFill(0xFFFFEA,100); 
46             b.graphics.drawRect(0,0,w,h); 
47             b.graphics.endFill();
48                         _root.addChild(b);
49
50                         // add map
51                         theMap=new Map();
52                         theMap.backdrop=b;
53                         _root.addChild(theMap);
54             theMap.updateSize(w, h);
55
56                         // add mask for map
57                         var s:Sprite=new Sprite();
58                         s.graphics.beginFill(0xFFFFFF,100);
59                         s.graphics.drawRect(0,0,w,h);
60                         s.graphics.endFill();
61                         _root.addChild(s);
62                         theMap.mask=s;
63
64                         // add crosshair
65                         /*s=new Sprite();
66                         s.graphics.lineStyle(2,0);
67                         s.graphics.moveTo(stage.stageWidth/2-20,stage.stageHeight/2);
68                         s.graphics.lineTo(stage.stageWidth/2+20,stage.stageHeight/2);
69                         s.graphics.moveTo(stage.stageWidth/2,stage.stageHeight/2-20);
70                         s.graphics.lineTo(stage.stageWidth/2,stage.stageHeight/2+20);
71                         _root.addChild(s);*/
72
73                         // mouse-up handler attached to stage, so the user can release outside the map
74                         stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
75                         theMap.backdrop.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
76                         theMap.backdrop.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
77
78                         // keyboard event attached to stage
79                         stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
80
81                         // example listener event
82                         var myListenerObj:Object = new Object();
83                         myListenerObj.mapHandler=function(event:MapEvent):void {
84                                 Globals.vars.debug.appendText("Download event fired - "+event.minlat+","+event.minlon+"\n");
85                         };
86                         theMap.addEventListener(MapEvent.DOWNLOAD, myListenerObj.mapHandler);
87
88                         // add debug field
89                         var t:TextField=new TextField();
90                         t.width=400; t.height=100; t.border=true; 
91                         t.multiline=true;
92                         _root.addChild(t);
93                         Globals.vars.debug=t;
94             t.visible = true;
95
96             var controller:EditController = new EditController(theMap, tagViewer);
97             controller.setActive();
98                 }
99
100         public function onResizeMap():void {
101             if ( theMap != null )
102                 theMap.updateSize(map_area.width, map_area.height);
103         }
104
105         ]]></mx:Script>
106
107 </mx:Application>
108