checks for access token, and displays OAuth panel if needed var force_auth:String = loaderInfo.parameters["force_auth"]; if (!conn.hasAccessToken() && force_auth == 'force') { SaveManager.ensureAccess(onAccessChecked); } // show help dialog on startup, if required // show_help == always => on every startup // show_help == once => show on first startup only var show_help:String = loaderInfo.parameters["show_help"]; if (show_help == 'always' || (show_help == 'once' && obj.data["help_shown"] != "true")) { new HelpDialog().init(); } // Check if Tiger highlighting should be enabled from saved object Globals.vars.highlightTiger = obj.data['tiger_highlighted']; } public function onMapError(event:MapEvent):void { Alert.show(event.params.message, 'Error', mx.controls.Alert.OK); } public function onResizeMap():void { if ( theMap != null ) theMap.updateSize(map_area.width, map_area.height); if (toolbox) { toolbox.x=Math.min(toolbox.x,stage.stageWidth-toolbox.width-15); toolbox.y=Math.min(toolbox.y,stage.stageHeight-toolbox.height-15); } } private function onDataStart(event:Event):void { switch (event.type) { case Connection.LOAD_STARTED: loadcount++; break; case Connection.SAVE_STARTED: savecount++; break; } updateDataWorking(); } private function onDataComplete(event:Event):void { switch (event.type) { case Connection.LOAD_COMPLETED: loadcount--; break; case Connection.SAVE_COMPLETED: savecount--; break; } updateDataWorking(); } private function updateDataWorking():void { if (loadcount>0 && savecount>0) { dataWorking.text="Loading/saving..."; } else if (loadcount>0) { dataWorking.text="Loading data..."; } else if (savecount>0) { dataWorking.text="Saving data..."; } else { dataWorking.text=""; } dataWorking.visible=(dataWorking.text!=""); } private function onDataDirty(event:Event):void { saveButton.enabled=true; if (ExternalInterface.available) { ExternalInterface.call("markChanged", false); } } private function onDataClean(event:Event):void { saveButton.enabled=false; if (ExternalInterface.available) { ExternalInterface.call("markChanged", true); } } private function onImageryLoad(event:Event):void { var xml:XML = new XML(URLLoader(event.target).data); var saved_url:String = SharedObject.getLocal("user_state").data['background_url']; var saved_name:String= SharedObject.getLocal("user_state").data['background_name']; var xml_url:String, xml_name:String, isSet:Boolean=false; var backgroundSet:Boolean = false; theController.imagery=new Array( { label: "None", data: "" }, { label: "Yahoo", data: "yahoo" } ); for each(var set:XML in xml.set) { xml_url= set.child("url"); xml_name=set.child("name"); theController.imagery.push({ label:xml_name, data:xml_url }); if (xml_url==saved_url || (xml_name==saved_name && xml_name!='Custom')) { isSet=true; } } if (!isSet && saved_name != null && saved_url != null && saved_url != '' && saved_url != 'yahoo') { theController.imagery.push({ label:saved_name, data:saved_url }); isSet=true; } for each (var bg:Object in theController.imagery) { if (bg['label']==saved_nameĀ || bg['data']==saved_url) { setBackground(bg['label'], bg['data']); backgroundSet = true; } } // For most contributors it's useful to set the background to yahoo by default, I reckon, but lets make it a config if (!backgroundSet && loaderInfo.parameters['yahoo_default'] == 'true') { setBackground("Yahoo", "yahoo"); } } public function setBackground(name:String,url:String):void { // ** this should take an object with all parameters (source tag, etc.) if (url=='yahoo') { theMap.setBackground('') ; yahoo.show(); } else { theMap.setBackground(url); yahoo.hide(); } var obj:SharedObject = SharedObject.getLocal("user_state"); obj.setProperty("background_url",url ); obj.setProperty("background_name",name); obj.flush(); } private function onStylesheetsLoad(event:Event):void { var xml:XML = new XML(URLLoader(event.target).data); var saved_url:String = SharedObject.getLocal("user_state").data['stylesheet_url']; var saved_name:String= SharedObject.getLocal("user_state").data['stylesheet_name']; var xml_url:String, xml_name:String, isInMenu:Boolean=false, isSet:Boolean=false; // first, build the menu from the stylesheet list. // Also ensure the saved_url is in the menu (might be either saved from before, or supplied via loaderInfo) theController.stylesheets=new Array(); for each(var set:XML in xml.stylesheet) { xml_url= set.child("url"); xml_name=set.child("name"); theController.stylesheets.push({ label:xml_name, data:xml_url }); if (xml_url==saved_url || (xml_name==saved_name && xml_name!='Custom')) { isInMenu=true; } } if (saved_url && !isInMenu) { theController.stylesheets.push({ label:saved_name, data:saved_url }); } // pick a stylesheet to be set. It should be the saved one, if it is in the menu // or alternatively the first one on the menu, // or finally try 'potlatch.css' for each (var ss:Object in theController.stylesheets) { if (ss['label']==saved_nameĀ || ss['data']==saved_url) { setStylesheet(ss['label'], ss['data']); isSet = true; break; } } if (!isSet) { if(theController.stylesheets.length > 0) { var s:Object = theController.stylesheets[0]; setStylesheet(s['label'], s['data']); } else { //hit and hope. FIXME should this be an error state? theController.stylesheets.push({ label:'Potlatch', data:'potlatch.css'}); setStylesheet('Potlatch','potlatch.css'); } } } public function setStylesheet(name:String,url:String):void { theMap.setStyle(url); var obj:SharedObject = SharedObject.getLocal("user_state"); obj.setProperty("stylesheet_url",url); obj.setProperty("stylesheet_name",name); obj.flush(); } private function scaleHandler(event:MapEvent):void { dispatchEvent(new Event("rescale")); } [Bindable(event="rescale")] private function getScale():String { return String(theMap.scale); } private function dragEnterHandler(event:DragEvent):void { // Get the drop target component from the event object. var dropTarget:Canvas=event.currentTarget as Canvas; // Accept the drag only if the user is dragging poi with tags if (event.dragSource.hasFormat('tags')) { DragManager.acceptDragDrop(dropTarget); } } private function dragDropHandler(event:DragEvent):void { // Deselect the dragged icon if (event.dragSource.dataForFormat('container')) { event.dragSource.dataForFormat('container').selectedItem=-1; } // Get the tags var tags:Array = event.dragSource.dataForFormat('tags') as Array; var mapLoc:Point = Globals.vars.root.globalToLocal(new Point(event.stageX, event.stageY)); var lat:Number = Globals.vars.root.coord2lat(mapLoc.y); var lon:Number = Globals.vars.root.coord2lon(mapLoc.x); var createAction:CompositeUndoableAction = new CompositeUndoableAction("Create POI"); var node:Node = Connection.getConnectionInstance().createNode({}, lat, lon, createAction.push); for each ( var tag:Object in tags ) { node.setTag(tag.k, tag.v, createAction.push); } Connection.getConnectionInstance().registerPOI(node); MainUndoStack.getGlobalStack().addAction(createAction); theController.setState(new SelectedPOINode(node)); } /* Called when forcing an initial access token check. */ private function onAccessChecked():void { // Floaty panel message "You now have access"; } ]]>