d5dfc98e619b947352e02cc0756d6951630eb6de
[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="Undo" click="MainUndoStack.getGlobalStack().undo();"
32             enabled="{MainUndoStack.getGlobalStack().canUndo()}"/>
33         <mx:Button label="Redo" click="MainUndoStack.getGlobalStack().redo();"
34             enabled="{MainUndoStack.getGlobalStack().canRedo()}"/>
35         <mx:Spacer width="100%"/>
36         <mx:Button label="Help" click="new HelpDialog().init();" />
37         <mx:Button label="Options" click="new OptionsDialog().init();" />
38         <mx:Button label="Save" icon="@Embed('embedded/save.svg')" click="SaveManager.saveChanges();"/>
39     </mx:ApplicationControlBar>
40     
41     <mx:HDividedBox width="100%" height="100%">
42
43           <!-- Tag viewer -->
44           <potlatch2:TagViewer width="25%" height="100%" id="tagViewer"/>
45
46       <mx:Canvas width="75%" height="100%">
47         <mx:Canvas id="map_area" resize="onResizeMap()"
48             top="0" left="0" width="100%" height="100%" dragEnter="dragEnterHandler(event);" dragDrop="dragDropHandler(event);">
49         </mx:Canvas>
50         <mx:Image source="@Embed('embedded/zoomIn.svg')" right="3" top="3" click="theMap.zoomIn();"
51             rollOverEffect="glowImage" rollOutEffect="unglowImage"/>
52         <mx:Image source="@Embed('embedded/zoomOut.svg')" right="3" top="20" click="theMap.zoomOut();"
53             rollOverEffect="glowImage" rollOutEffect="unglowImage"/>
54         <mx:TextArea id="dataWorking" text="" right="20" top="3" disabledColor="black" backgroundDisabledColor="0xFFFFEA" height="18"
55             enabled="false" borderThickness="0"
56             showEffect="{wipeIn}" hideEffect="{wipeOut}"/>
57
58                 <potlatch2:Toolbox id="toolbox" 
59                         height="46" width="217" 
60                         headerHeight="6" headerColors="[black, gray]" 
61                         borderThicknessRight="0" borderThicknessLeft="0" borderThicknessBottom="0" 
62                         paddingLeft="4" paddingTop="4" layout="horizontal"
63                         x="10" y="300">
64
65                 <mx:Button icon="@Embed('embedded/delete.svg')"
66                                 click='toolbox.doDelete();' 
67                                 width="28" height="28" textAlign="left" paddingLeft="6" paddingRight="0" />
68                 <mx:Button icon="@Embed('embedded/direction.svg')" 
69                                 width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
70                 <mx:Button icon="@Embed('embedded/straighten.svg')" 
71                                 click='toolbox.doStraighten();' 
72                                 width="28" height="28" textAlign="left" paddingLeft="5" paddingRight="0" />
73                 <mx:Button icon="@Embed('embedded/circle.svg')" 
74                                 click='toolbox.doCircularise();' 
75                                 width="28" height="28" textAlign="left" paddingLeft="4" paddingRight="0" />
76                 <mx:Button icon="@Embed('embedded/quadrilateralise.svg')" 
77                                 click='toolbox.doQuadrilateralise();' 
78                                 width="28" height="28" textAlign="left" paddingLeft="6" paddingRight="0" />
79                 <mx:Button icon="@Embed('embedded/parallel.svg')" 
80                                 width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
81
82                 </potlatch2:Toolbox>
83
84     </mx:Canvas>
85
86     </mx:HDividedBox>
87
88         <mx:Script><![CDATA[
89                 import net.systemeD.halcyon.*;
90                 import net.systemeD.halcyon.connection.*;
91                 import net.systemeD.potlatch2.*;
92                 import net.systemeD.potlatch2.save.SaveManager;
93                 import net.systemeD.potlatch2.controller.*;
94                 import net.systemeD.potlatch2.help.*;
95                 import net.systemeD.potlatch2.options.*;
96                 import net.systemeD.potlatch2.utils.*;
97                 import mx.managers.PopUpManager;
98                 import flash.system.Security;
99                 import flash.net.*;
100                 import flash.events.MouseEvent;
101                 import flash.display.Sprite;
102                 import mx.core.IChildList;
103         import mx.containers.Canvas;
104                 import mx.core.Application;
105                 import com.yahoo.maps.api.YahooMap;
106                 import com.yahoo.maps.api.YahooMapEvent;
107                 import com.yahoo.maps.api.core.location.LatLon;
108         import mx.events.DragEvent;
109         import mx.managers.DragManager;
110         import mx.core.DragSource;
111
112         public var theMap:Map;
113         public var theController:EditController;
114                 public var yahooListener:Object = new Object();
115                 public var yahoo:YahooMap = new YahooMap(); 
116
117                 private function initApp():void {
118
119                         Globals.vars.map_area = map_area;
120                         Globals.vars.yahoo = yahoo;
121                         Globals.vars.root = map_area.rawChildren;                       // set up global reference to root level
122                         var _root:IChildList = map_area.rawChildren;            // convenient local shorthand
123
124                         // map backdrop object
125             var w:uint = map_area.width;
126             var h:uint = map_area.height;
127             var b:Sprite = new Sprite();
128             b.height=h; b.width=w;
129             b.graphics.beginFill(0xFFFFEA,100); 
130             b.graphics.drawRect(0,0,w,h); 
131             b.graphics.endFill();
132                         _root.addChild(b);
133
134                         // Add Yahoo! background
135                         yahoo.init("f0a.sejV34HnhgIbNSmVHmndXFpijgGeun0fSIMG9428hW_ifF3pYKwbV6r9iaXojl1lU_dakekR", w, h);  
136                         yahoo.mapType="satellite";
137                         _root.addChild(yahoo);
138                         yahoo.visible=false;
139                         yahoo.alpha=0.5;
140
141                         // Yahoo! listeners
142                         yahooListener.yahooInit=function(event:YahooMapEvent):void {
143                                 yahoo.zoomLevel = 18-theMap.scale;
144                                 yahoo.centerLatLon = new LatLon(theMap.centre_lat, theMap.centre_lon);
145
146                                 yahooListener.moveHandler=function(event:MapEvent):void {
147                                         if (!yahoo.visible) { return; }
148                                         yahoo.zoomLevel=18-event.params.scale;
149                                         yahoo.centerLatLon=new LatLon(event.params.lat, event.params.lon);
150                                 };
151                                 theMap.addEventListener(MapEvent.MOVE, yahooListener.moveHandler);
152
153                                 yahooListener.resizeHandler=function(event:MapEvent):void {
154                                         yahoo.setSize(event.params.width, event.params.height);
155                                 };
156                                 theMap.addEventListener(MapEvent.RESIZE, yahooListener.resizeHandler);
157                         }
158                         yahoo.addEventListener(YahooMapEvent.MAP_INITIALIZE, yahooListener.yahooInit);
159
160                         // add map
161                         theMap=new Map(this.loaderInfo.parameters);
162                         theMap.backdrop=b;
163                         _root.addChild(theMap);
164             theMap.updateSize(w, h);
165
166                         // add mask for map
167                         var s:Sprite=new Sprite();
168                         s.graphics.beginFill(0xFFFFFF,100);
169                         s.graphics.drawRect(0,0,w,h);
170                         s.graphics.endFill();
171                         _root.addChild(s);
172                         theMap.mask=s;
173
174                         // add crosshair
175                         /*s=new Sprite();
176                         s.graphics.lineStyle(2,0);
177                         s.graphics.moveTo(stage.stageWidth/2-20,stage.stageHeight/2);
178                         s.graphics.lineTo(stage.stageWidth/2+20,stage.stageHeight/2);
179                         s.graphics.moveTo(stage.stageWidth/2,stage.stageHeight/2-20);
180                         s.graphics.lineTo(stage.stageWidth/2,stage.stageHeight/2+20);
181                         _root.addChild(s);*/
182
183                         // mouse-up handler attached to stage, so the user can release outside the map
184                         stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
185                         Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
186                         Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
187
188                         // keyboard event attached to stage
189                         stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
190
191                         // example listener event
192                         var myListenerObj:Object = new Object();
193                         myListenerObj.mapHandler=function(event:MapEvent):void {
194                                 Globals.vars.debug.appendText("Download event fired - "+event.params.minlat+","+event.params.minlon+"\n");
195                         };
196                         theMap.addEventListener(MapEvent.DOWNLOAD, myListenerObj.mapHandler);
197
198                         // add debug field
199                         var t:TextField=new TextField();
200                         t.width=500; t.height=150; t.border=true;
201                         t.multiline=true;
202                         _root.addChild(t);
203                         Globals.vars.debug=t;
204             t.visible = loaderInfo.parameters["show_debug"] == 'true';
205                         Globals.vars.root=theMap;       // just for the addDebug function
206
207             theController = new EditController(theMap, tagViewer, toolbox);
208             theController.setActive();
209             
210             var conn:Connection = Connection.getConnectionInstance();
211             conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
212             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
213
214                         // and to import a shapefile...
215 //                      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"]);
216                 }
217
218         public function onResizeMap():void {
219             if ( theMap != null )
220                 theMap.updateSize(map_area.width, map_area.height);
221         }
222
223         private function onDataStart(event:Event):void {
224             dataWorking.text = event.type == Connection.LOAD_STARTED ? "Loading data..." : "Saving Data...";
225             dataWorking.visible = true;
226         }
227         private function onDataComplete(event:Event):void {
228             dataWorking.visible = false;
229         }
230         
231
232         
233         private function dragEnterHandler(event:DragEvent):void {
234             // Get the drop target component from the event object.
235             var dropTarget:Canvas=event.currentTarget as Canvas;
236             // Accept the drag only if the user is dragging poi with tags
237             if (event.dragSource.hasFormat('tags')) 
238             {
239                 DragManager.acceptDragDrop(dropTarget);
240             }
241         }
242         
243         private function dragDropHandler(event:DragEvent):void {
244             // Get the data identified by the color format from the drag source.
245             // Blame http://www.adobe.com/devnet/flex/quickstart/adding_drag_and_drop/#manual
246             // for whatever horrid abuse of "color format" this is doing
247             var tags:Array = event.dragSource.dataForFormat('tags') as Array;
248             var mapLoc:Point = Globals.vars.root.globalToLocal(new Point(event.stageX, event.stageY));
249             var lat:Number = Globals.vars.root.coord2lat(mapLoc.y);
250             var lon:Number = Globals.vars.root.coord2lon(mapLoc.x);
251             
252             var createAction:CompositeUndoableAction = new CompositeUndoableAction("Create POI");
253             
254             var node:Node = Connection.getConnectionInstance().createNode({}, lat, lon);
255             for each ( var tag:Object in tags ) {
256                 node.setTag(tag.k, tag.v, createAction.push);
257             }
258                         Connection.getConnectionInstance().registerPOI(node);
259                         MainUndoStack.getGlobalStack().addAction(createAction);
260             theController.setState(new SelectedPOINode(node));
261         }
262
263         ]]></mx:Script>
264
265 </mx:Application>
266