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, conn);
}
// 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(mapEvent:MapEvent):void {
var buttons:uint=0;
if (mapEvent.params.yes ) buttons|=mx.controls.Alert.YES;
if (mapEvent.params.no ) buttons|=mx.controls.Alert.NO;
if (mapEvent.params.cancel ) buttons|=mx.controls.Alert.CANCEL;
if (mapEvent.params.ok || buttons==0) buttons|=mx.controls.Alert.OK;
Alert.show(mapEvent.params.message, 'Error', buttons, null, function(closeEvent:CloseEvent):void {
switch (closeEvent.detail) {
case mx.controls.Alert.CANCEL: mapEvent.params.cancel(); break; //fixme? this gets called if user presses escape, even if there's no cancel button.
case mx.controls.Alert.YES: mapEvent.params.yes(); break;
case mx.controls.Alert.NO: mapEvent.params.no(); break;
default: if (mapEvent.params.ok) mapEvent.params.ok();
}
});
}
/** Highlight an entity in response to an 'attention' event */
public function onAttention(event:AttentionEvent):void {
var entity:Entity=event.entity;
if (entity is Relation) {
// If it's a relation, just bring up the editor panel
var panel:RelationEditorPanel = RelationEditorPanel(
PopUpManager.createPopUp(Application(FlexGlobals.topLevelApplication), RelationEditorPanel, true));
panel.setRelation(entity as Relation);
PopUpManager.centerPopUp(panel);
return;
}
var lat:Number, lon:Number;
var panTo:Boolean=true;
if (entity is Way) {
// If it's a way, find if it's on-screen
for (var i:uint=0; i0 && savecount>0) { t="Loading/saving#..."; }
else if (loadcount>0) { t="Loading data#..."; }
else if (savecount>0) { t="Saving data..."; }
else { t=""; }
dataWorking.text=t.replace("#",(loadcount>1) ? (" ("+loadcount+")") : "");
var previousState:Boolean=dataWorking.visible;
var newState:Boolean=(dataWorking.text!="");
if (!previousState && newState) spinner.start();
if (previousState && !newState) spinner.stop();
dataWorking.visible=newState;
}
private function onDataDirty(event:Event):void {
saveButton.enabled=true;
if (ExternalInterface.available) {
ExternalInterface.call("markChanged", false);
}
if (!saveTimer || !saveTimer.running) {
saveTimer=new Timer(60*1000,0);
saveTimer.addEventListener(TimerEvent.TIMER,saveTimeUpdate);
saveTimer.start();
}
}
private function onDataClean(event:Event):void {
saveButton.enabled=false;
if (ExternalInterface.available) {
ExternalInterface.call("markChanged", true);
}
if (saveTimer && saveTimer.running) {
saveTimer.stop();
saveTimer.removeEventListener(TimerEvent.TIMER,saveTimeUpdate);
saveTimeWrite(0);
}
}
private function saveTimeUpdate(event:TimerEvent):void {
var timer:Timer=Timer(event.target);
saveTimeWrite(uint(timer.delay*timer.currentCount/1000/60));
}
private function saveTimeWrite(minutes:uint):void {
if (minutes<5) {
saveButton.label=saveLabel;
} else {
saveButton.label=saveLabel+" ("+minutes+"m"+")";
if (minutes>=20 && minutes/5==int(minutes/5)) {
theController.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, minutes+"m since last save - please save regularly"));
}
}
}
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;
// If you dnd quick enough, this exposes a flex bug and event.stageX/Y become negative.
// Take the mouse positions from a displayObject's stage for consistent results.
var mapLoc:Point = Globals.vars.root.globalToLocal(new Point(event.target.stage.mouseX, event.target.stage.mouseY));
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 conn:Connection = theMap.editableLayer.connection;
var node:Node = conn.createNode({}, lat, lon, createAction.push);
for each ( var tag:Object in tags ) {
node.setTag(tag.k, tag.v, createAction.push);
}
conn.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";
}
private function loadTrace(id:Number):void {
var conn:Connection = theMap.editableLayer.connection;
conn.addEventListener(Connection.TRACES_LOADED, function (e:Event):void {
var t:Trace = conn.findTrace(id);
if (!t) { t=new Trace(conn,id); conn.addTrace(t); }
t.addToMap();
conn.removeEventListener(Connection.TRACES_LOADED, arguments.callee);
});
conn.fetchUserTraces();
}
]]>