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