nice zoom buttons and a loading message
[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         xmlns:potlatch2="net.systemeD.potlatch2.*"
6         layout="vertical"
7         horizontalAlign="center" 
8         addedToStage="initApp()">
9
10     <mx:Glow id="glowImage" duration="100" 
11         alphaFrom="0.3" alphaTo="1.0" 
12         blurXFrom="0.0" blurXTo="5.0" 
13         blurYFrom="0.0" blurYTo="5.0" 
14         color="0xFF8000"/>
15     <mx:Glow id="unglowImage" duration="100" 
16         alphaFrom="1.0" alphaTo="0.3" 
17         blurXFrom="5.0" blurXTo="0.0" 
18         blurYFrom="5.0" blurYTo="0.0" 
19         color="0xFF8000"/>
20     <mx:WipeLeft id="wipeOut" duration="250"/>
21     <mx:WipeRight id="wipeIn" duration="250"/>
22
23     <mx:HDividedBox width="100%" height="100%">
24
25       <mx:VBox height="100%" width="25%" horizontalAlign="right">
26         <potlatch2:TagViewer width="100%" height="100%" id="tagViewer"/>
27       </mx:VBox>
28       <mx:Canvas width="75%" height="100%">
29         <mx:Canvas id="map_area" resize="onResizeMap()"
30             top="0" left="0" width="100%" height="100%">
31         </mx:Canvas>
32         <mx:Image source="@Embed('embedded/zoomIn.svg')" right="3" top="3" click="theMap.zoomIn();"
33             rollOverEffect="glowImage" rollOutEffect="unglowImage"/>
34         <mx:Image source="@Embed('embedded/zoomOut.svg')" right="3" top="20" click="theMap.zoomOut();"
35             rollOverEffect="glowImage" rollOutEffect="unglowImage"/>
36         <mx:Label id="dataWorking" text="" right="20" top="3"
37             showEffect="{wipeIn}" hideEffect="{wipeOut}"/>
38       </mx:Canvas>
39     </mx:HDividedBox>
40
41         <mx:Script><![CDATA[
42                 import net.systemeD.halcyon.*;
43                 import net.systemeD.halcyon.connection.*;
44                 import net.systemeD.potlatch2.*;
45                 import flash.system.Security;
46                 import flash.net.*;
47                 import flash.events.MouseEvent;
48                 import flash.display.Sprite;
49                 import mx.core.IChildList;
50         import mx.containers.Canvas;
51                 import mx.core.Application;
52
53         public var theMap:Map;
54
55                 private function initApp():void {
56
57                         Globals.vars.map_area=map_area;
58                         Globals.vars.root=map_area.rawChildren;                 // set up global reference to root level
59                         var _root:IChildList=map_area.rawChildren;              // convenient local shorthand
60
61                         // map backdrop object
62             var w:uint = map_area.width;
63             var h:uint = map_area.height;
64             var b:Sprite = new Sprite();
65             b.height=h; b.width=w;
66             b.graphics.beginFill(0xFFFFEA,100); 
67             b.graphics.drawRect(0,0,w,h); 
68             b.graphics.endFill();
69                         _root.addChild(b);
70
71                         // add map
72                         theMap=new Map(this.loaderInfo.parameters);
73                         theMap.backdrop=b;
74                         _root.addChild(theMap);
75             theMap.updateSize(w, h);
76
77                         // add mask for map
78                         var s:Sprite=new Sprite();
79                         s.graphics.beginFill(0xFFFFFF,100);
80                         s.graphics.drawRect(0,0,w,h);
81                         s.graphics.endFill();
82                         _root.addChild(s);
83                         theMap.mask=s;
84
85                         // add crosshair
86                         /*s=new Sprite();
87                         s.graphics.lineStyle(2,0);
88                         s.graphics.moveTo(stage.stageWidth/2-20,stage.stageHeight/2);
89                         s.graphics.lineTo(stage.stageWidth/2+20,stage.stageHeight/2);
90                         s.graphics.moveTo(stage.stageWidth/2,stage.stageHeight/2-20);
91                         s.graphics.lineTo(stage.stageWidth/2,stage.stageHeight/2+20);
92                         _root.addChild(s);*/
93
94                         // mouse-up handler attached to stage, so the user can release outside the map
95                         stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
96                         theMap.backdrop.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
97                         theMap.backdrop.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
98
99                         // keyboard event attached to stage
100                         stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
101
102                         // example listener event
103                         var myListenerObj:Object = new Object();
104                         myListenerObj.mapHandler=function(event:MapEvent):void {
105                                 Globals.vars.debug.appendText("Download event fired - "+event.minlat+","+event.minlon+"\n");
106                         };
107                         theMap.addEventListener(MapEvent.DOWNLOAD, myListenerObj.mapHandler);
108
109                         // add debug field
110                         var t:TextField=new TextField();
111                         t.width=400; t.height=100; t.border=true;
112                         t.multiline=true;
113                         _root.addChild(t);
114                         Globals.vars.debug=t;
115             t.visible = true;
116
117             var controller:EditController = new EditController(theMap, tagViewer);
118             controller.setActive();
119             
120             var conn:Connection = Connection.getConnectionInstance();
121             conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
122             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
123                 }
124
125         public function onResizeMap():void {
126             if ( theMap != null )
127                 theMap.updateSize(map_area.width, map_area.height);
128         }
129
130         private function onDataStart(event:Event):void {
131             dataWorking.text = event.type == Connection.LOAD_STARTED ? "Loading data..." : "Saving Data...";
132             dataWorking.visible = true;
133         }
134         private function onDataComplete(event:Event):void {
135             dataWorking.visible = false;
136         }
137         ]]></mx:Script>
138
139 </mx:Application>
140