replace old Yahoo cruft with shinier code
[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="253" 
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                 click='toolbox.doReverseDirection();'
70                                 width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
71                 <mx:Button icon="@Embed('embedded/cut.svg')" 
72                 click='toolbox.doSplit();'
73                                 width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
74                 <mx:Button icon="@Embed('embedded/straighten.svg')" 
75                                 click='toolbox.doStraighten();' 
76                                 width="28" height="28" textAlign="left" paddingLeft="5" paddingRight="0" />
77                 <mx:Button icon="@Embed('embedded/circle.svg')" 
78                                 click='toolbox.doCircularise();' 
79                                 width="28" height="28" textAlign="left" paddingLeft="4" paddingRight="0" />
80                 <mx:Button icon="@Embed('embedded/quadrilateralise.svg')" 
81                                 click='toolbox.doQuadrilateralise();' 
82                                 width="28" height="28" textAlign="left" paddingLeft="6" paddingRight="0" />
83                 <mx:Button icon="@Embed('embedded/parallel.svg')" 
84                                 click='toolbox.doParallelise();' 
85                                 width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
86
87                 </potlatch2:Toolbox>
88
89     </mx:Canvas>
90
91     </mx:HDividedBox>
92
93         <mx:Script><![CDATA[
94                 import net.systemeD.halcyon.*;
95                 import net.systemeD.halcyon.connection.*;
96                 import net.systemeD.potlatch2.*;
97                 import net.systemeD.potlatch2.save.SaveManager;
98                 import net.systemeD.potlatch2.controller.*;
99                 import net.systemeD.potlatch2.help.*;
100                 import net.systemeD.potlatch2.options.*;
101                 import net.systemeD.potlatch2.utils.*;
102                 import mx.managers.PopUpManager;
103                 import flash.system.Security;
104                 import flash.net.*;
105                 import flash.events.MouseEvent;
106                 import flash.display.Sprite;
107                 import mx.core.IChildList;
108         import mx.containers.Canvas;
109                 import mx.core.Application;
110         import mx.events.DragEvent;
111         import mx.managers.DragManager;
112         import mx.core.DragSource;
113
114         public var theMap:Map;
115         public var theController:EditController;
116
117                 private function initApp():void {
118
119                         Globals.vars.map_area = map_area;
120                         Globals.vars.root = map_area.rawChildren;                       // set up global reference to root level
121                         var _root:IChildList = map_area.rawChildren;            // convenient local shorthand
122
123                         // map backdrop object
124             var w:uint = map_area.width;
125             var h:uint = map_area.height;
126             var b:Sprite = new Sprite();
127             b.height=h; b.width=w;
128             b.graphics.beginFill(0xFFFFEA,100); 
129             b.graphics.drawRect(0,0,w,h); 
130             b.graphics.endFill();
131                         _root.addChild(b);
132
133                         // create map and Yahoo
134                         theMap=new Map(this.loaderInfo.parameters);
135                         theMap.backdrop=b;
136                         var yahoo:Yahoo=new Yahoo(w,h,theMap);
137                         yahoo.hide();
138                         Globals.vars.yahoo = yahoo;
139                         _root.addChild(yahoo);
140                         _root.addChild(theMap);
141             theMap.updateSize(w,h);
142
143                         // add mask for map
144                         var s:Sprite=new Sprite();
145                         s.graphics.beginFill(0xFFFFFF,100);
146                         s.graphics.drawRect(0,0,w,h);
147                         s.graphics.endFill();
148                         _root.addChild(s);
149                         theMap.mask=s;
150
151                         // add crosshair
152                         /*s=new Sprite();
153                         s.graphics.lineStyle(2,0);
154                         s.graphics.moveTo(stage.stageWidth/2-20,stage.stageHeight/2);
155                         s.graphics.lineTo(stage.stageWidth/2+20,stage.stageHeight/2);
156                         s.graphics.moveTo(stage.stageWidth/2,stage.stageHeight/2-20);
157                         s.graphics.lineTo(stage.stageWidth/2,stage.stageHeight/2+20);
158                         _root.addChild(s);*/
159
160                         // mouse-up handler attached to stage, so the user can release outside the map
161                         stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
162                         Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
163                         Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
164
165                         // keyboard event attached to stage
166                         stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
167
168                         // example listener event
169                         var myListenerObj:Object = new Object();
170                         myListenerObj.mapHandler=function(event:MapEvent):void {
171                                 Globals.vars.debug.appendText("Download event fired - "+event.params.minlat+","+event.params.minlon+"\n");
172                         };
173                         theMap.addEventListener(MapEvent.DOWNLOAD, myListenerObj.mapHandler);
174
175                         // add debug field
176                         var t:TextField=new TextField();
177                         t.width=500; t.height=150; t.border=true;
178                         t.multiline=true;
179                         _root.addChild(t);
180                         Globals.vars.debug=t;
181             t.visible = loaderInfo.parameters["show_debug"] == 'true';
182                         Globals.vars.root=theMap;       // just for the addDebug function
183
184             theController = new EditController(theMap, tagViewer, toolbox);
185             theController.setActive();
186             
187             var conn:Connection = Connection.getConnectionInstance();
188             conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
189             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
190
191                         // and to import a shapefile...
192 //                      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"]);
193                 }
194
195         public function onResizeMap():void {
196             if ( theMap != null )
197                 theMap.updateSize(map_area.width, map_area.height);
198         }
199
200         private function onDataStart(event:Event):void {
201             dataWorking.text = event.type == Connection.LOAD_STARTED ? "Loading data..." : "Saving Data...";
202             dataWorking.visible = true;
203         }
204         private function onDataComplete(event:Event):void {
205             dataWorking.visible = false;
206         }
207         
208
209         
210         private function dragEnterHandler(event:DragEvent):void {
211             // Get the drop target component from the event object.
212             var dropTarget:Canvas=event.currentTarget as Canvas;
213             // Accept the drag only if the user is dragging poi with tags
214             if (event.dragSource.hasFormat('tags')) 
215             {
216                 DragManager.acceptDragDrop(dropTarget);
217             }
218         }
219         
220         private function dragDropHandler(event:DragEvent):void {
221             // Get the data identified by the color format from the drag source.
222             // Blame http://www.adobe.com/devnet/flex/quickstart/adding_drag_and_drop/#manual
223             // for whatever horrid abuse of "color format" this is doing
224             var tags:Array = event.dragSource.dataForFormat('tags') as Array;
225             var mapLoc:Point = Globals.vars.root.globalToLocal(new Point(event.stageX, event.stageY));
226             var lat:Number = Globals.vars.root.coord2lat(mapLoc.y);
227             var lon:Number = Globals.vars.root.coord2lon(mapLoc.x);
228             
229             var createAction:CompositeUndoableAction = new CompositeUndoableAction("Create POI");
230             
231             var node:Node = Connection.getConnectionInstance().createNode({}, lat, lon, createAction.push);
232             for each ( var tag:Object in tags ) {
233                 node.setTag(tag.k, tag.v, createAction.push);
234             }
235                         Connection.getConnectionInstance().registerPOI(node);
236                         MainUndoStack.getGlobalStack().addAction(createAction);
237             theController.setState(new SelectedPOINode(node));
238         }
239
240         ]]></mx:Script>
241
242 </mx:Application>
243