1 <?xml version="1.0" encoding="utf-8"?>
3 xmlns:mx="http://www.adobe.com/2006/mxml"
4 xmlns:halcyon="net.systemeD.halcyon.*"
5 xmlns:potlatch2="net.systemeD.potlatch2.*"
7 horizontalAlign="center"
8 addedToStage="initApp()">
10 <mx:Style source="styles/Application.css"/>
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"
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"
22 <mx:WipeLeft id="wipeOut" duration="250"/>
23 <mx:WipeRight id="wipeIn" duration="250"/>
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>
41 <mx:HDividedBox width="100%" height="100%">
44 <potlatch2:TagViewer width="25%" height="100%" id="tagViewer"/>
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);">
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}"/>
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"
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 width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
93 import net.systemeD.halcyon.*;
94 import net.systemeD.halcyon.connection.*;
95 import net.systemeD.potlatch2.*;
96 import net.systemeD.potlatch2.save.SaveManager;
97 import net.systemeD.potlatch2.controller.*;
98 import net.systemeD.potlatch2.help.*;
99 import net.systemeD.potlatch2.options.*;
100 import net.systemeD.potlatch2.utils.*;
101 import mx.managers.PopUpManager;
102 import flash.system.Security;
104 import flash.events.MouseEvent;
105 import flash.display.Sprite;
106 import mx.core.IChildList;
107 import mx.containers.Canvas;
108 import mx.core.Application;
109 import com.yahoo.maps.api.YahooMap;
110 import com.yahoo.maps.api.YahooMapEvent;
111 import com.yahoo.maps.api.core.location.LatLon;
112 import mx.events.DragEvent;
113 import mx.managers.DragManager;
114 import mx.core.DragSource;
116 public var theMap:Map;
117 public var theController:EditController;
118 public var yahooListener:Object = new Object();
119 public var yahoo:YahooMap = new YahooMap();
121 private function initApp():void {
123 Globals.vars.map_area = map_area;
124 Globals.vars.yahoo = yahoo;
125 Globals.vars.root = map_area.rawChildren; // set up global reference to root level
126 var _root:IChildList = map_area.rawChildren; // convenient local shorthand
128 // map backdrop object
129 var w:uint = map_area.width;
130 var h:uint = map_area.height;
131 var b:Sprite = new Sprite();
132 b.height=h; b.width=w;
133 b.graphics.beginFill(0xFFFFEA,100);
134 b.graphics.drawRect(0,0,w,h);
135 b.graphics.endFill();
138 // Add Yahoo! background
139 yahoo.init("f0a.sejV34HnhgIbNSmVHmndXFpijgGeun0fSIMG9428hW_ifF3pYKwbV6r9iaXojl1lU_dakekR", w, h);
140 yahoo.mapType="satellite";
141 _root.addChild(yahoo);
146 yahooListener.yahooInit=function(event:YahooMapEvent):void {
147 yahoo.zoomLevel = 18-theMap.scale;
148 yahoo.centerLatLon = new LatLon(theMap.centre_lat, theMap.centre_lon);
150 yahooListener.moveHandler=function(event:MapEvent):void {
151 if (!yahoo.visible) { return; }
152 yahoo.zoomLevel=18-event.params.scale;
153 yahoo.centerLatLon=new LatLon(event.params.lat, event.params.lon);
155 theMap.addEventListener(MapEvent.MOVE, yahooListener.moveHandler);
157 yahooListener.resizeHandler=function(event:MapEvent):void {
158 yahoo.setSize(event.params.width, event.params.height);
160 theMap.addEventListener(MapEvent.RESIZE, yahooListener.resizeHandler);
162 yahoo.addEventListener(YahooMapEvent.MAP_INITIALIZE, yahooListener.yahooInit);
165 theMap=new Map(this.loaderInfo.parameters);
167 _root.addChild(theMap);
168 theMap.updateSize(w, h);
171 var s:Sprite=new Sprite();
172 s.graphics.beginFill(0xFFFFFF,100);
173 s.graphics.drawRect(0,0,w,h);
174 s.graphics.endFill();
180 s.graphics.lineStyle(2,0);
181 s.graphics.moveTo(stage.stageWidth/2-20,stage.stageHeight/2);
182 s.graphics.lineTo(stage.stageWidth/2+20,stage.stageHeight/2);
183 s.graphics.moveTo(stage.stageWidth/2,stage.stageHeight/2-20);
184 s.graphics.lineTo(stage.stageWidth/2,stage.stageHeight/2+20);
187 // mouse-up handler attached to stage, so the user can release outside the map
188 stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
189 Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
190 Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
192 // keyboard event attached to stage
193 stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
195 // example listener event
196 var myListenerObj:Object = new Object();
197 myListenerObj.mapHandler=function(event:MapEvent):void {
198 Globals.vars.debug.appendText("Download event fired - "+event.params.minlat+","+event.params.minlon+"\n");
200 theMap.addEventListener(MapEvent.DOWNLOAD, myListenerObj.mapHandler);
203 var t:TextField=new TextField();
204 t.width=500; t.height=150; t.border=true;
207 Globals.vars.debug=t;
208 t.visible = loaderInfo.parameters["show_debug"] == 'true';
209 Globals.vars.root=theMap; // just for the addDebug function
211 theController = new EditController(theMap, tagViewer, toolbox);
212 theController.setActive();
214 var conn:Connection = Connection.getConnectionInstance();
215 conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
216 conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
218 // and to import a shapefile...
219 // 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"]);
222 public function onResizeMap():void {
223 if ( theMap != null )
224 theMap.updateSize(map_area.width, map_area.height);
227 private function onDataStart(event:Event):void {
228 dataWorking.text = event.type == Connection.LOAD_STARTED ? "Loading data..." : "Saving Data...";
229 dataWorking.visible = true;
231 private function onDataComplete(event:Event):void {
232 dataWorking.visible = false;
237 private function dragEnterHandler(event:DragEvent):void {
238 // Get the drop target component from the event object.
239 var dropTarget:Canvas=event.currentTarget as Canvas;
240 // Accept the drag only if the user is dragging poi with tags
241 if (event.dragSource.hasFormat('tags'))
243 DragManager.acceptDragDrop(dropTarget);
247 private function dragDropHandler(event:DragEvent):void {
248 // Get the data identified by the color format from the drag source.
249 // Blame http://www.adobe.com/devnet/flex/quickstart/adding_drag_and_drop/#manual
250 // for whatever horrid abuse of "color format" this is doing
251 var tags:Array = event.dragSource.dataForFormat('tags') as Array;
252 var mapLoc:Point = Globals.vars.root.globalToLocal(new Point(event.stageX, event.stageY));
253 var lat:Number = Globals.vars.root.coord2lat(mapLoc.y);
254 var lon:Number = Globals.vars.root.coord2lon(mapLoc.x);
256 var createAction:CompositeUndoableAction = new CompositeUndoableAction("Create POI");
258 var node:Node = Connection.getConnectionInstance().createNode({}, lat, lon, createAction.push);
259 for each ( var tag:Object in tags ) {
260 node.setTag(tag.k, tag.v, createAction.push);
262 Connection.getConnectionInstance().registerPOI(node);
263 MainUndoStack.getGlobalStack().addAction(createAction);
264 theController.setState(new SelectedPOINode(node));