Make primary and troads wider so they aren't narrower than secondary roads.
[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       </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         import mx.events.DragEvent;
75         import mx.managers.DragManager;
76         import mx.core.DragSource;
77
78         public var theMap:Map;
79                 public var yahooListener:Object = new Object();
80                 public var yahoo:YahooMap = new YahooMap(); 
81
82                 private function initApp():void {
83
84                         Globals.vars.map_area = map_area;
85                         Globals.vars.yahoo = yahoo;
86                         Globals.vars.root = map_area.rawChildren;                       // set up global reference to root level
87                         var _root:IChildList = map_area.rawChildren;            // convenient local shorthand
88
89                         // map backdrop object
90             var w:uint = map_area.width;
91             var h:uint = map_area.height;
92             var b:Sprite = new Sprite();
93             b.height=h; b.width=w;
94             b.graphics.beginFill(0xFFFFEA,100); 
95             b.graphics.drawRect(0,0,w,h); 
96             b.graphics.endFill();
97                         _root.addChild(b);
98
99                         // Add Yahoo! background
100                         yahoo.init("f0a.sejV34HnhgIbNSmVHmndXFpijgGeun0fSIMG9428hW_ifF3pYKwbV6r9iaXojl1lU_dakekR", w, h);  
101                         yahoo.mapType="satellite";
102                         _root.addChild(yahoo);
103                         yahoo.visible=false;
104                         yahoo.alpha=0.5;
105
106                         // Yahoo! listeners
107                         yahooListener.yahooInit=function(event:YahooMapEvent):void {
108                                 yahoo.zoomLevel = 18-theMap.scale;
109                                 yahoo.centerLatLon = new LatLon(theMap.centre_lat, theMap.centre_lon);
110
111                                 yahooListener.moveHandler=function(event:MapEvent):void {
112                                         if (!yahoo.visible) { return; }
113                                         yahoo.zoomLevel=18-event.params.scale;
114                                         yahoo.centerLatLon=new LatLon(event.params.lat, event.params.lon);
115                                 };
116                                 theMap.addEventListener(MapEvent.MOVE, yahooListener.moveHandler);
117
118                                 yahooListener.resizeHandler=function(event:MapEvent):void {
119                                         yahoo.setSize(event.params.width, event.params.height);
120                                 };
121                                 theMap.addEventListener(MapEvent.RESIZE, yahooListener.resizeHandler);
122                         }
123                         yahoo.addEventListener(YahooMapEvent.MAP_INITIALIZE, yahooListener.yahooInit);
124
125                         // add map
126                         theMap=new Map(this.loaderInfo.parameters);
127                         theMap.backdrop=b;
128                         _root.addChild(theMap);
129             theMap.updateSize(w, h);
130
131                         // add mask for map
132                         var s:Sprite=new Sprite();
133                         s.graphics.beginFill(0xFFFFFF,100);
134                         s.graphics.drawRect(0,0,w,h);
135                         s.graphics.endFill();
136                         _root.addChild(s);
137                         theMap.mask=s;
138
139                         // add crosshair
140                         /*s=new Sprite();
141                         s.graphics.lineStyle(2,0);
142                         s.graphics.moveTo(stage.stageWidth/2-20,stage.stageHeight/2);
143                         s.graphics.lineTo(stage.stageWidth/2+20,stage.stageHeight/2);
144                         s.graphics.moveTo(stage.stageWidth/2,stage.stageHeight/2-20);
145                         s.graphics.lineTo(stage.stageWidth/2,stage.stageHeight/2+20);
146                         _root.addChild(s);*/
147
148                         // mouse-up handler attached to stage, so the user can release outside the map
149                         stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
150                         Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
151                         Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
152
153                         // keyboard event attached to stage
154                         stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
155
156                         // example listener event
157                         var myListenerObj:Object = new Object();
158                         myListenerObj.mapHandler=function(event:MapEvent):void {
159                                 Globals.vars.debug.appendText("Download event fired - "+event.params.minlat+","+event.params.minlon+"\n");
160                         };
161                         theMap.addEventListener(MapEvent.DOWNLOAD, myListenerObj.mapHandler);
162
163                         // add debug field
164                         var t:TextField=new TextField();
165                         t.width=500; t.height=150; t.border=true;
166                         t.multiline=true;
167                         _root.addChild(t);
168                         Globals.vars.debug=t;
169             t.visible = loaderInfo.parameters["show_debug"] == 'true';
170                         Globals.vars.root=theMap;       // just for the addDebug function
171
172             var controller:EditController = new EditController(theMap, tagViewer);
173             controller.setActive();
174             
175             var conn:Connection = Connection.getConnectionInstance();
176             conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
177             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
178
179                         // and to import a shapefile...
180 //                      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"]);
181                 }
182
183         public function onResizeMap():void {
184             if ( theMap != null )
185                 theMap.updateSize(map_area.width, map_area.height);
186         }
187
188         private function onDataStart(event:Event):void {
189             dataWorking.text = event.type == Connection.LOAD_STARTED ? "Loading data..." : "Saving Data...";
190             dataWorking.visible = true;
191         }
192         private function onDataComplete(event:Event):void {
193             dataWorking.visible = false;
194         }
195         
196
197         
198         private function dragEnterHandler(event:DragEvent):void {
199             // Get the drop target component from the event object.
200             var dropTarget:Canvas=event.currentTarget as Canvas;
201             // Accept the drag only if the user is dragging poi with tags
202             if (event.dragSource.hasFormat('tags')) 
203             {
204                 DragManager.acceptDragDrop(dropTarget);
205             }
206         }
207         
208         private function dragDropHandler(event:DragEvent):void {
209             // Get the data identified by the color format from the drag source.
210             // Blame http://www.adobe.com/devnet/flex/quickstart/adding_drag_and_drop/#manual
211             // for whatever horrid abuse of "color format" this is doing
212             var tags:Array = event.dragSource.dataForFormat('tags') as Array;
213             var mapLoc:Point = Globals.vars.root.globalToLocal(new Point(event.stageX, event.stageY));
214             var lat:Number = Globals.vars.root.coord2lat(mapLoc.y);
215             var lon:Number = Globals.vars.root.coord2lon(mapLoc.x);
216             var node:Node = Connection.getConnectionInstance().createNode({}, lat, lon);
217             for each ( var tag:Object in tags ) {
218               node.setTag(tag.k, tag.v);
219             }
220                         Connection.getConnectionInstance().registerPOI(node);
221         }
222
223         ]]></mx:Script>
224
225 </mx:Application>
226