move bg and style selection to top bar, and give a choice of styles
[potlatch2.git] / potlatch2.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:Style source="styles/Application.css"/>
11
12     <mx:Glow id="glowImage" duration="100" 
13         alphaFrom="0.3" alphaTo="1.0" 
14         blurXFrom="0.0" blurXTo="5.0" 
15         blurYFrom="0.0" blurYTo="5.0" 
16         color="0xFF8000"/>
17     <mx:Glow id="unglowImage" duration="100" 
18         alphaFrom="1.0" alphaTo="0.3" 
19         blurXFrom="5.0" blurXTo="0.0" 
20         blurYFrom="5.0" blurYTo="0.0" 
21         color="0xFF8000"/>
22     <mx:WipeLeft id="wipeOut" duration="250"/>
23     <mx:WipeRight id="wipeIn" duration="250"/>
24
25     <mx:ApplicationControlBar dock="true">
26         <mx:PopUpButton id="bgButton" label="Background" openAlways="true"
27             creationComplete="bgButton.popUp = new BackgroundSelector();"/>
28         <mx:PopUpButton id="styleButton" label="Map Style" openAlways="true"
29             creationComplete="styleButton.popUp = new StyleSelector();"/>
30         <mx:Spacer width="100%"/>
31         <mx:Button label="Help" click="new HelpDialog().init();" />
32         <mx:Button label="Options" click="new OptionsDialog().init();" />
33         <mx:Button label="Save" icon="@Embed('embedded/save.svg')" click="SaveManager.saveChanges();"/>
34     </mx:ApplicationControlBar>
35     
36     <mx:HDividedBox width="100%" height="100%">
37
38           <!-- Tag viewer -->
39           <potlatch2:TagViewer width="25%" height="100%" id="tagViewer"/>
40
41       <mx:Canvas width="75%" height="100%">
42         <mx:Canvas id="map_area" resize="onResizeMap()"
43             top="0" left="0" width="100%" height="100%">
44         </mx:Canvas>
45         <mx:Image source="@Embed('embedded/zoomIn.svg')" right="3" top="3" click="theMap.zoomIn();"
46             rollOverEffect="glowImage" rollOutEffect="unglowImage"/>
47         <mx:Image source="@Embed('embedded/zoomOut.svg')" right="3" top="20" click="theMap.zoomOut();"
48             rollOverEffect="glowImage" rollOutEffect="unglowImage"/>
49         <mx:TextArea id="dataWorking" text="" right="20" top="3" disabledColor="black" backgroundDisabledColor="0xFFFFEA" height="18"
50             enabled="false" borderThickness="0"
51             showEffect="{wipeIn}" hideEffect="{wipeOut}"/>
52       </mx:Canvas>
53     </mx:HDividedBox>
54
55         <mx:Script><![CDATA[
56                 import net.systemeD.halcyon.*;
57                 import net.systemeD.halcyon.connection.*;
58                 import net.systemeD.potlatch2.*;
59                 import net.systemeD.potlatch2.save.SaveManager;
60                 import net.systemeD.potlatch2.help.*;
61                 import net.systemeD.potlatch2.options.*;
62                 import net.systemeD.potlatch2.utils.*;
63                 import mx.managers.PopUpManager;
64                 import flash.system.Security;
65                 import flash.net.*;
66                 import flash.events.MouseEvent;
67                 import flash.display.Sprite;
68                 import mx.core.IChildList;
69         import mx.containers.Canvas;
70                 import mx.core.Application;
71                 import com.yahoo.maps.api.YahooMap;
72                 import com.yahoo.maps.api.YahooMapEvent;
73                 import com.yahoo.maps.api.core.location.LatLon;
74
75         public var theMap:Map;
76                 public var yahooListener:Object = new Object();
77                 public var yahoo:YahooMap = new YahooMap(); 
78
79                 private function initApp():void {
80
81                         Globals.vars.map_area = map_area;
82                         Globals.vars.yahoo = yahoo;
83                         Globals.vars.root = map_area.rawChildren;                       // set up global reference to root level
84                         var _root:IChildList = map_area.rawChildren;            // convenient local shorthand
85
86                         // map backdrop object
87             var w:uint = map_area.width;
88             var h:uint = map_area.height;
89             var b:Sprite = new Sprite();
90             b.height=h; b.width=w;
91             b.graphics.beginFill(0xFFFFEA,100); 
92             b.graphics.drawRect(0,0,w,h); 
93             b.graphics.endFill();
94                         _root.addChild(b);
95
96                         // Add Yahoo! background
97                         yahoo.init("f0a.sejV34HnhgIbNSmVHmndXFpijgGeun0fSIMG9428hW_ifF3pYKwbV6r9iaXojl1lU_dakekR", w, h);  
98                         yahoo.mapType="satellite";
99                         _root.addChild(yahoo);
100                         yahoo.visible=false;
101                         yahoo.alpha=0.5;
102
103                         // Yahoo! listeners
104                         yahooListener.yahooInit=function(event:YahooMapEvent):void {
105                                 yahoo.zoomLevel = 18-theMap.scale;
106                                 yahoo.centerLatLon = new LatLon(theMap.centre_lat, theMap.centre_lon);
107
108                                 yahooListener.moveHandler=function(event:MapEvent):void {
109                                         if (!yahoo.visible) { return; }
110                                         yahoo.zoomLevel=18-event.params.scale;
111                                         yahoo.centerLatLon=new LatLon(event.params.lat, event.params.lon);
112                                 };
113                                 theMap.addEventListener(MapEvent.MOVE, yahooListener.moveHandler);
114
115                                 yahooListener.resizeHandler=function(event:MapEvent):void {
116                                         yahoo.setSize(event.params.width, event.params.height);
117                                 };
118                                 theMap.addEventListener(MapEvent.RESIZE, yahooListener.resizeHandler);
119                         }
120                         yahoo.addEventListener(YahooMapEvent.MAP_INITIALIZE, yahooListener.yahooInit);
121
122                         // add map
123                         theMap=new Map(this.loaderInfo.parameters);
124                         theMap.backdrop=b;
125                         _root.addChild(theMap);
126             theMap.updateSize(w, h);
127
128                         // add mask for map
129                         var s:Sprite=new Sprite();
130                         s.graphics.beginFill(0xFFFFFF,100);
131                         s.graphics.drawRect(0,0,w,h);
132                         s.graphics.endFill();
133                         _root.addChild(s);
134                         theMap.mask=s;
135
136                         // add crosshair
137                         /*s=new Sprite();
138                         s.graphics.lineStyle(2,0);
139                         s.graphics.moveTo(stage.stageWidth/2-20,stage.stageHeight/2);
140                         s.graphics.lineTo(stage.stageWidth/2+20,stage.stageHeight/2);
141                         s.graphics.moveTo(stage.stageWidth/2,stage.stageHeight/2-20);
142                         s.graphics.lineTo(stage.stageWidth/2,stage.stageHeight/2+20);
143                         _root.addChild(s);*/
144
145                         // mouse-up handler attached to stage, so the user can release outside the map
146                         stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
147                         Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
148                         Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
149
150                         // keyboard event attached to stage
151                         stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
152
153                         // example listener event
154                         var myListenerObj:Object = new Object();
155                         myListenerObj.mapHandler=function(event:MapEvent):void {
156                                 Globals.vars.debug.appendText("Download event fired - "+event.params.minlat+","+event.params.minlon+"\n");
157                         };
158                         theMap.addEventListener(MapEvent.DOWNLOAD, myListenerObj.mapHandler);
159
160                         // add debug field
161                         var t:TextField=new TextField();
162                         t.width=500; t.height=150; t.border=true;
163                         t.multiline=true;
164                         _root.addChild(t);
165                         Globals.vars.debug=t;
166             t.visible = loaderInfo.parameters["show_debug"] == 'true';
167                         Globals.vars.root=theMap;       // just for the addDebug function
168
169             var controller:EditController = new EditController(theMap, tagViewer);
170             controller.setActive();
171             
172             var conn:Connection = Connection.getConnectionInstance();
173             conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
174             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
175
176                         // and to import a shapefile...
177 //                      var importer:ShpImporter = new ShpImporter(theMap, ["http://127.0.0.1/~richard/shp/wildrnp020.shp","http://127.0.0.1/~richard/shp/wildrnp020.shx","http://127.0.0.1/~richard/shp/wildrnp020.dbf"]);
178                 }
179
180         public function onResizeMap():void {
181             if ( theMap != null )
182                 theMap.updateSize(map_area.width, map_area.height);
183         }
184
185         private function onDataStart(event:Event):void {
186             dataWorking.text = event.type == Connection.LOAD_STARTED ? "Loading data..." : "Saving Data...";
187             dataWorking.visible = true;
188         }
189         private function onDataComplete(event:Event):void {
190             dataWorking.visible = false;
191         }
192         ]]></mx:Script>
193
194 </mx:Application>
195