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