Prevent single-node ways from being created by undo.
[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         horizontalScrollPolicy="off"
8         verticalScrollPolicy="off"
9         horizontalAlign="center" 
10         addedToStage="startInit()"
11         preloader="net.systemeD.potlatch2.Preloader">
12
13     <map:LocalizationMap xmlns:map="l10n.map.*" />
14
15         <mx:Style source="styles/Application.css"/>
16
17     <mx:Glow id="glowImage" duration="100" 
18         alphaFrom="0.3" alphaTo="1.0" 
19         blurXFrom="0.0" blurXTo="5.0" 
20         blurYFrom="0.0" blurYTo="5.0" 
21         color="0xFF8000"/>
22     <mx:Glow id="unglowImage" duration="100" 
23         alphaFrom="1.0" alphaTo="0.3" 
24         blurXFrom="5.0" blurXTo="0.0" 
25         blurYFrom="5.0" blurYTo="0.0" 
26         color="0xFF8000"/>
27     <mx:WipeLeft id="wipeOut" duration="250"/>
28     <mx:WipeRight id="wipeIn" duration="250"/>
29
30     <mx:ApplicationControlBar dock="true">
31         <mx:PopUpButton id="bgButton" label="Background" openAlways="true" styleName="appBarButton"
32             creationComplete="bgButton.popUp = new BackgroundSelector();"/>
33         <mx:PopUpButton id="styleButton" label="Map Style" openAlways="true" styleName="appBarButton"
34             creationComplete="styleButton.popUp = new StyleSelector();"/>
35                 <mx:PopUpMenuButton id="gpsButton" styleName="appBarButton"
36                     itemClick="if (event.index==0) { trackLoader.load(); } 
37                           else if (event.index==1) { new MyGpxDialog().init(); } 
38                                               else { mx.controls.Menu(gpsButton.popUp).selectedIndex=0; 
39                                                      mx.controls.Menu(gpsButton.popUp).selectedIndex=0; /* Yes, we do need to call it twice */
40                                                      theMap.removeLayerByName('GPS tracks'); }">
41                         <mx:dataProvider>
42                                 <mx:Array>
43                                         <mx:Object label="GPS data" id="gpsData" />
44                                         <mx:Object label="My tracks" id="myTracks" />
45                                         <mx:Object label="Clear" id="clearGps" />
46                                 </mx:Array>
47                         </mx:dataProvider>
48                 </mx:PopUpMenuButton>
49         <mx:Spacer width="100%"/>
50         <mx:Button id="undo" label="Undo" click="MainUndoStack.getGlobalStack().undo();" styleName="appBarButton"
51             enabled="{MainUndoStack.getGlobalStack().canUndo()}"
52             toolTip="{MainUndoStack.getGlobalStack().getUndoDescription() ? 'Undo '+MainUndoStack.getGlobalStack().getUndoDescription() : 'Undo last action'}" />
53         <mx:Button id="redo" label="Redo" click="MainUndoStack.getGlobalStack().redo();" styleName="appBarButton"
54             enabled="{MainUndoStack.getGlobalStack().canRedo()}"
55             toolTip="{MainUndoStack.getGlobalStack().getRedoDescription() ? 'Redo '+MainUndoStack.getGlobalStack().getRedoDescription() : 'Redo last action'}" />
56         <mx:Spacer width="100%"/>
57         <mx:Button id="helpButton" label="Help" click="new HelpDialog().init();" styleName="appBarButton" />
58         <mx:Button id="optionsButton" label="Options" click="new OptionsDialog().init();" styleName="appBarButton" />
59         <mx:Button label="Save" icon="@Embed('embedded/upload.svg')" disabledIcon="@Embed('embedded/upload_disabled.svg')" styleName="appBarButton"
60                         click="SaveManager.saveChanges(theMap.editableLayer.connection);" id="saveButton" enabled="false"/>
61     </mx:ApplicationControlBar>
62     
63     <mx:HDividedBox width="100%" height="100%">
64
65           <!-- Tag viewer -->
66           <potlatch2:TagViewer width="25%" height="100%" id="tagViewer"/>
67
68       <mx:Canvas width="75%" height="100%">
69         <mx:Canvas id="map_area" resize="onResizeMap()"
70             top="0" left="0" width="100%" height="100%" dragEnter="dragEnterHandler(event);" dragDrop="dragDropHandler(event);">
71         </mx:Canvas>
72         <mx:Image source="@Embed('embedded/zoomIn.svg')" right="3" top="3" click="theMap.zoomIn();"
73             rollOverEffect="glowImage" rollOutEffect="unglowImage" toolTip="{'Zoom in - currently z'+getScale()}" />
74         <mx:Image source="@Embed('embedded/zoomOut.svg')" right="3" top="20" click="theMap.zoomOut();"
75             rollOverEffect="glowImage" rollOutEffect="unglowImage" toolTip="{'Zoom out - currently z'+getScale()}" />
76         <mx:Image source="@Embed('embedded/search.svg')" right="3" top="40" click="new FindDialog().init();"
77             rollOverEffect="glowImage" rollOutEffect="unglowImage" toolTip="Find place" />
78         <mx:TextArea id="dataWorking" text="" right="20" top="3" disabledColor="black" backgroundDisabledColor="0xFFFFEA" height="18"
79             enabled="false" borderThickness="0"
80             showEffect="{wipeIn}" hideEffect="{wipeOut}"/>
81         <mx:TextArea id="coordsbox" left="0" top="0" disabledColor="black" backgroundDisabledColor="0xFFFFEA" height="33"
82             width="57" enabled="false" borderThickness="0" visible="false"/>
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.find.*;
94                 import net.systemeD.potlatch2.collections.*;
95                 import net.systemeD.potlatch2.controller.*;
96                 import net.systemeD.potlatch2.help.*;
97                 import net.systemeD.potlatch2.options.*;
98                 import net.systemeD.potlatch2.utils.*;
99         import net.systemeD.potlatch2.mygpx.*;
100                 import net.systemeD.controls.FloatingAlert;
101                 import mx.managers.PopUpManager;
102                 import flash.system.Security;
103                 import flash.net.*;
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 mx.events.DragEvent;
110         import mx.events.CloseEvent;
111         import mx.managers.DragManager;
112         import mx.core.DragSource;
113         import mx.controls.Alert;
114         import com.mindspace.l10n.events.LocaleEvent;
115
116         public var theMap:Map;
117         public var theController:EditController;
118                 public var yahoo:Yahoo;
119                 public var trackLoader:TrackLoader;
120                 public var toolbox:Toolbox;
121         public var bugLoader:BugLoader;
122         public var bikeShopLoader:BikeShopLoader;
123
124                 private var savecount:uint=0;
125                 private var loadcount:uint=0;
126
127         include "version.as";
128
129                 private function startInit():void {
130             /* For reasons that I don't yet understand, the en_US locale is the default and doesn't work at all. */
131             /* Change this to another locale (e.g. fr_FR) to see the differences. */
132             if (loaderInfo.parameters['locale']) {
133               dispatchEvent(new LocaleEvent(LocaleEvent.LOAD_LOCALE,loaderInfo.parameters['locale']));
134             }
135
136                         // Load font and don't do anything until that's done
137                         var loader:Loader = new Loader();
138                         loader.contentLoaderInfo.addEventListener(Event.COMPLETE, continueInit);
139                         loader.load(new URLRequest("FontLibrary.swf"));
140                 }
141                 
142                 private function continueInit(r:Event):void {
143                         // Set font
144                         var FontLibrary:Class = r.target.applicationDomain.getDefinition("FontLibrary") as Class;
145                         Font.registerFont(FontLibrary.DejaVu);
146
147                         Globals.vars.map_area = map_area;
148                         Globals.vars.root = map_area.rawChildren;                       // set up global reference to root level
149                         var _root:IChildList = map_area.rawChildren;            // convenient local shorthand
150                         Globals.vars.nocache = loaderInfo.parameters['nocache'] == 'true';
151                         Globals.vars.flashvars = loaderInfo.parameters;
152
153                         // populate sharedObject with loaderInfo parameters if supplied
154                         var obj:SharedObject = SharedObject.getLocal("user_state");
155                         var objChanged:Boolean = false;
156                         if (loaderInfo.parameters['tileurl']) {
157                                 obj.setProperty('background_url',loaderInfo.parameters['tileurl']); 
158                                 obj.setProperty('background_name','Custom'); 
159                                 objChanged=true;
160                         }
161                         if (loaderInfo.parameters['style']) { 
162                                 obj.setProperty('stylesheet_url',loaderInfo.parameters['style']);
163                                 obj.setProperty('stylesheet_name','Custom');
164                                 objChanged=true; 
165                         }
166                         if (objChanged) { obj.flush(); }
167
168                         // map backdrop object
169             var w:uint = map_area.width;
170             var h:uint = map_area.height;
171             var b:Sprite = new Sprite();
172             b.height=h; b.width=w;
173             b.graphics.beginFill(0xFFFFEA,100); 
174             b.graphics.drawRect(0,0,w,h); 
175             b.graphics.endFill();
176                         _root.addChild(b);
177
178                         // pass additional parameters to map
179                         var params:Object={}; var k:String;
180                         for (k in this.loaderInfo.parameters) params[k]=this.loaderInfo.parameters[k];
181                         for (k in SharedObject.getLocal('user_state').data) params[k]=SharedObject.getLocal('user_state').data[k];
182
183                         // Create map
184                         theMap=new Map();
185                         theMap.backdrop=b;
186             theMap.updateSize(w,h);
187                         theMap.addEventListener(MapEvent.SCALE, scaleHandler);
188
189                         yahoo=new Yahoo(theMap);
190                         yahoo.hide();
191                         _root.addChild(yahoo);
192                         _root.addChild(theMap);
193
194                         // Initialise stylesheets
195                         Stylesheets.instance().init();
196                         Stylesheets.instance().addEventListener(CollectionEvent.SELECT,
197                                 function(e:CollectionEvent):void { theMap.editableLayer.setStyle(String(e.data)); }
198                         );
199
200                         // Add core data layer
201                         var conn:Connection = new XMLConnection("Main", params['api'], params['policy'], params);
202             conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
203             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
204             conn.addEventListener(Connection.SAVE_STARTED, onDataStart);
205             conn.addEventListener(Connection.SAVE_COMPLETED, onDataComplete);
206             conn.addEventListener(Connection.DATA_DIRTY, onDataDirty);
207             conn.addEventListener(Connection.DATA_CLEAN, onDataClean);
208                         conn.addEventListener(MapEvent.ERROR, onMapError);
209                         conn.addEventListener(AttentionEvent.ATTENTION, onAttention);
210                         conn.addEventListener(AttentionEvent.ALERT, onAlert);
211                         theMap.addLayer(conn, Stylesheets.instance().selected, false, true);
212
213             // Auto-load vector backgrounds from config
214             theMap.addEventListener(MapEvent.INITIALISED, function(e:Event):void { VectorBackgrounds.instance().init(theMap); });
215
216                         // Set start position of map
217                         // ** FIXME: if lat/lon/zoom aren't supplied, we need to keep the map in a non-loading state 
218                         //           until the user has decided where to start editing (e.g. when the first GPX loads)
219                         theMap.init(params['lat'], params['lon'], params['zoom']);
220
221                         // add attribution/logo sprite
222                         var overlay:Sprite=new Sprite();
223                         var attribution:TextField=new TextField();
224                         attribution.width=220; attribution.height=300;
225                         attribution.multiline=true;
226                         attribution.wordWrap=true;
227                         attribution.selectable=false;
228                         attribution.defaultTextFormat=new TextFormat("_sans", 9, 0, false, false, false);
229                         overlay.addChild(attribution);
230                         var terms:TextField=new TextField();
231                         terms.width=200; terms.height=15;
232                         terms.selectable=false;
233                         terms.defaultTextFormat=new TextFormat("_sans", 9, 0, false, false, true);
234                         overlay.addChild(terms);
235                         _root.addChild(overlay);
236
237                         // mouse-up handler attached to stage, so the user can release outside the map
238                         stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
239                         Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
240                         Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
241
242                         // initialise imagery
243                         theMap.tileset.blocks=[new RegExp("google","i")];       // hard-coded block on Google tiles
244                         theMap.tileset.setDimming(params['background_dim']    ==null ? true  : params['background_dim']);
245                         theMap.tileset.setSharpen(params['background_sharpen']==null ? false : params['background_sharpen']);
246                         Imagery.instance().init(theMap, overlay, yahoo);
247                         Imagery.instance().addEventListener(MapEvent.BUMP, bumpHandler);
248                         Imagery.instance().addEventListener(CollectionEvent.SELECT,
249                                 function(e:CollectionEvent):void { theMap.tileset.init(e.data, e.data!=''); }
250                         );
251
252                         // keyboard event attached to stage
253                         stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
254             
255                         // mouse-position listener for co-ordinate display
256             theMap.addEventListener(MapEvent.MOUSE_MOVE, mouseoverHandler);
257
258                         // position toolbox
259                         toolbox=Toolbox(PopUpManager.createPopUp(this,Toolbox,false));
260                         toolbox.init(theController);
261                         toolbox.x=stage.stageWidth-toolbox.width-5;
262                         toolbox.y=stage.stageHeight-toolbox.height-5;
263
264                         // add debug field
265                         var t:TextField=new TextField();
266                         t.width=500; t.height=150; t.border=true;
267                         t.multiline=true;
268                         _root.addChild(t);
269                         Globals.vars.debug=t;
270             t.visible = loaderInfo.parameters["show_debug"] == 'true';
271                         Globals.vars.root=theMap;       // just for the addDebug function
272
273                         // create controller
274             theController = new EditController(theMap, tagViewer, toolbox);
275             theController.setActive();
276                         theController.addEventListener(AttentionEvent.ATTENTION, onAttention);
277                         theController.addEventListener(AttentionEvent.ALERT, onAlert);
278             
279             // set the access token from saved cookie
280             var tokenObject:SharedObject = SharedObject.getLocal("access_token");
281             conn.setAccessToken(tokenObject.data["oauth_token"], tokenObject.data["oauth_token_secret"]);
282
283             // Load any requested GPX track
284             if (loaderInfo.parameters['gpx']) {
285                 var id:Number = loaderInfo.parameters['gpx'];
286                 if (conn.hasAccessToken()) { 
287                     loadTrace(id);
288                 } else {
289                     SaveManager.ensureAccess(function ():void { loadTrace(id); }, conn);
290                 }
291             }
292
293                         // Load arbitrary GPX from provided URL
294                         if (loaderInfo.parameters['gpx_url']) {
295
296                 var gpx_url:String = loaderInfo.parameters['gpx_url'];
297
298                 var connection:Connection = new Connection(name, gpx_url, null, null);
299                 var gpx:GpxImporter=new GpxImporter(connection, theMap, [gpx_url],
300                                                 function(success:Boolean,message:String=null):void {
301                                                     if (!success) return;
302                                                     var paint:MapPaint = theMap.addLayer(connection, "stylesheets/gpx.css");
303                                                     paint.updateEntityUIs(false, false);
304                                                     dispatchEvent(new Event("layers_changed"));
305                                                 }, false);
306                         }
307
308                         // create GPS trackloader
309                         trackLoader=new TrackLoader(theMap,conn.apiBase);
310
311             // Force authentication on startup, if required
312             // force_auth == force => checks for access token, and displays OAuth panel if needed
313             var force_auth:String = loaderInfo.parameters["force_auth"];
314             if (!conn.hasAccessToken() && force_auth == 'force') {
315               SaveManager.ensureAccess(onAccessChecked, conn);
316             }
317
318             // show help dialog on startup, if required
319             // show_help == always => on every startup
320             // show_help == once => show on first startup only
321             var show_help:String = loaderInfo.parameters["show_help"];
322
323             if (show_help == 'always' || (show_help == 'once' && obj.data["help_shown"] != "true")) {
324               new HelpDialog().init();
325             }
326
327             // Check if Tiger highlighting should be enabled from saved object
328             Globals.vars.highlightTiger = obj.data['tiger_highlighted'];
329                 }
330                 
331                 public function onMapError(mapEvent:MapEvent):void {
332                         var buttons:uint=0;
333                         if (mapEvent.params.no) { trace("no is set"); }
334                         if (mapEvent.params.yes             ) buttons|=mx.controls.Alert.YES;
335                         if (mapEvent.params.no              ) buttons|=mx.controls.Alert.NO;
336                         if (mapEvent.params.cancel          ) buttons|=mx.controls.Alert.CANCEL;
337                         if (mapEvent.params.ok || buttons==0) buttons|=mx.controls.Alert.OK;
338                         trace("showing alert with "+buttons);
339                         Alert.show(mapEvent.params.message, 'Error', buttons, null, function(closeEvent:CloseEvent):void { 
340                                 switch (closeEvent.detail) {
341                                         case mx.controls.Alert.CANCEL:  mapEvent.params.cancel(); break; //fixme? this gets called if user presses escape, even if there's no cancel button.
342                                         case mx.controls.Alert.YES:             mapEvent.params.yes(); break;
343                                         case mx.controls.Alert.NO:              mapEvent.params.no(); break;
344                                         default:                                                if (mapEvent.params.ok) mapEvent.params.ok();
345                                 }
346                         });
347                 }
348
349                 /** Highlight an entity in response to an 'attention' event */
350
351                 public function onAttention(event:AttentionEvent):void {
352                         var entity:Entity=event.entity;
353                         if (entity is Relation) {
354                                 // If it's a relation, just bring up the editor panel
355                                 var panel:RelationEditorPanel = RelationEditorPanel(
356                                         PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
357                                 panel.setRelation(entity as Relation);
358                                 PopUpManager.centerPopUp(panel);
359                                 return;
360                         }
361
362                         var lat:Number, lon:Number;
363                         var panTo:Boolean=true;
364                         if (entity is Way) {
365                                 // If it's a way, find if it's on-screen
366                                 for (var i:uint=0; i<Way(entity).length; i++) {
367                                         var node:Node=Way(entity).getNode(i)
368                                         if (node.within(theMap.edge_l,theMap.edge_r,theMap.edge_t,theMap.edge_b)) { panTo=false; }
369                                         lat=node.lat; lon=node.lon;
370                                 }
371                         } else if (entity is Node) {
372                                 // If it's a node, check if it's on-screen
373                                 if (entity.within(theMap.edge_l,theMap.edge_r,theMap.edge_t,theMap.edge_b)) { panTo=false; }
374                                 lat=Node(entity).lat; lon=Node(entity).lon;
375                         }
376                         // Pan if required, and select the object
377                         if (panTo) { theMap.moveMapFromLatLon(lat,lon); }
378                         theController.setState(theController.findStateForSelection([entity]));
379                 }
380
381                 /** Display floating warning in response to an 'alert' event */
382
383                 public function onAlert(event:AttentionEvent):void {
384                         var alert:FloatingAlert=new FloatingAlert(event.message);
385                         stage.addChild(alert);
386                 }
387
388         public function onResizeMap():void {
389             if ( theMap != null )
390                 theMap.updateSize(map_area.width, map_area.height);
391
392                         if (toolbox) {
393                                 toolbox.x=Math.min(toolbox.x,stage.stageWidth-toolbox.width-5);
394                                 toolbox.y=Math.min(toolbox.y,stage.stageHeight-toolbox.height-5);
395                         }
396         }
397                 private function bumpHandler(e:MapEvent):void {
398                         if (toolbox) {
399                                 toolbox.y=Math.min(toolbox.y,stage.stageHeight-toolbox.height-10-e.params.y);
400                         }
401                 }
402
403         private function mouseoverHandler(e:MapEvent):void {
404             if (coordsbox.visible) {
405                 coordsbox.text= Number(e.params.x).toFixed(5) + "\n " + Number(e.params.y).toFixed(5); // Not sure if 5 dp's really required.
406             }
407         }
408
409         private function onDataStart(event:Event):void {
410                         switch (event.type) {
411                                 case Connection.LOAD_STARTED:   loadcount++; break;
412                                 case Connection.SAVE_STARTED:   savecount++; break;
413                         }
414                         updateDataWorking();
415         }
416         private function onDataComplete(event:Event):void {
417                         switch (event.type) {
418                                 case Connection.LOAD_COMPLETED: loadcount--; break;
419                                 case Connection.SAVE_COMPLETED: savecount--; break;
420                         }
421             updateDataWorking();
422         }
423                 private function updateDataWorking():void {
424                         if (loadcount>0 && savecount>0) { dataWorking.text="Loading/saving..."; }
425                         else if (loadcount>0)           { dataWorking.text="Loading data..."; }
426                         else if (savecount>0)           { dataWorking.text="Saving data..."; }
427                         else                            { dataWorking.text=""; }
428                         dataWorking.visible=(dataWorking.text!="");
429                 }
430         private function onDataDirty(event:Event):void {
431                         saveButton.enabled=true;
432             if (ExternalInterface.available) {
433               ExternalInterface.call("markChanged", false);
434             }
435                 }
436                 private function onDataClean(event:Event):void {
437                         saveButton.enabled=false;
438             if (ExternalInterface.available) {
439               ExternalInterface.call("markChanged", true);
440             }
441                 }
442                 
443
444
445                 private function scaleHandler(event:MapEvent):void {
446                         dispatchEvent(new Event("rescale"));
447                 }
448                 
449                 [Bindable(event="rescale")]
450                 private function getScale():String {
451                         return String(theMap.scale);
452                 }
453
454         private function dragEnterHandler(event:DragEvent):void {
455             // Get the drop target component from the event object.
456             var dropTarget:Canvas=event.currentTarget as Canvas;
457             // Accept the drag only if the user is dragging poi with tags
458             if (event.dragSource.hasFormat('tags')) 
459             {
460                 DragManager.acceptDragDrop(dropTarget);
461             }
462         }
463         
464         private function dragDropHandler(event:DragEvent):void {
465                         // Deselect the dragged icon
466                         if (event.dragSource.dataForFormat('container')) {
467                                 event.dragSource.dataForFormat('container').selectedItem=-1;
468                         }
469
470                         // Get the tags
471             var tags:Array = event.dragSource.dataForFormat('tags') as Array;
472
473             // If you dnd quick enough, this exposes a flex bug and event.stageX/Y become negative.
474             // Take the mouse positions from a displayObject's stage for consistent results.
475             var mapLoc:Point = Globals.vars.root.globalToLocal(new Point(event.target.stage.mouseX, event.target.stage.mouseY));
476             var lat:Number = Globals.vars.root.coord2lat(mapLoc.y);
477             var lon:Number = Globals.vars.root.coord2lon(mapLoc.x);
478             
479             var createAction:CompositeUndoableAction = new CompositeUndoableAction("Create POI");
480             
481                         var conn:Connection = theMap.editableLayer.connection;
482             var node:Node = conn.createNode({}, lat, lon, createAction.push);
483             for each ( var tag:Object in tags ) {
484                 node.setTag(tag.k, tag.v, createAction.push);
485             }
486                         conn.registerPOI(node);
487                         MainUndoStack.getGlobalStack().addAction(createAction);
488             theController.setState(new SelectedPOINode(node));
489         }
490
491         /* Called when forcing an initial access token check. */
492         private function onAccessChecked():void {
493             // Floaty panel message "You now have access";
494         }
495
496         private function loadTrace(id:Number):void {
497             var conn:Connection = theMap.editableLayer.connection;
498             conn.addEventListener(Connection.TRACES_LOADED, function (e:Event):void {
499                 for each (var trace:Trace in conn.getTraces()) {
500                     if (trace.id == id) { trace.addToMap(); }
501                 }
502             });
503             conn.fetchUserTraces();
504         }
505
506         ]]></mx:Script>
507
508 </mx:Application>
509