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:Object;
if (SharedObject.getLocal("user_state").data['background_url']) {
saved={ name: SharedObject.getLocal("user_state").data['background_name'],
url: SharedObject.getLocal("user_state").data['background_url' ] };
} else {
saved={};
}
var isSet:Boolean=false;
var backgroundSet:Boolean = false;
theController.imagery=new Array(
{ name: "None", url: "" },
{ name: "Yahoo", url: "yahoo", sourcetag: "Yahoo" } );
for each(var set:XML in xml.set) {
var obj:Object={};
for (var a:String in set.children()) {
obj[set.child(a).name()]=set.child(a);
}
theController.imagery.push(obj);
if ((obj.url ==saved.url) ||
(obj.name==saved.name && obj.name!='Custom')) { isSet=true; }
}
if (!isSet && saved.name && saved.url && saved.url!='' && saved.url!='yahoo') {
theController.imagery.push(saved);
isSet=true;
}
for each (var bg:Object in theController.imagery) {
if (bg.name==saved.name || bg.url==saved.url) {
setBackground(bg);
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(theController.imagery[1]);
}
}
public function setBackground(bg:Object):void {
if (bg.url=='yahoo') { theMap.setBackground('' ); yahoo.show(); }
else { theMap.setBackground(bg.url); yahoo.hide(); }
theController.imagerySelected=bg;
var obj:SharedObject = SharedObject.getLocal("user_state");
obj.setProperty('background_url' ,String(bg.url));
obj.setProperty('background_name',String(bg.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 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) {
var obj:Object={};
for (var a:String in set.children()) {
obj[set.child(a).name()]=set.child(a);
}
theController.stylesheets.push(obj);
if (obj.url==saved_url || (obj.name==saved_name && obj.name!='Custom')) { isInMenu=true; }
}
if (saved_url && !isInMenu) { theController.stylesheets.push({ name:saved_name, url: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.name==saved_nameĀ || ss.url==saved_url) {
setStylesheet(ss.name, ss.url);
isSet = true;
break;
}
}
if (!isSet) {
if(theController.stylesheets.length > 0) {
var s:Object = theController.stylesheets[0];
setStylesheet(s.name, s.url);
} else {
//hit and hope. FIXME should this be an error state?
theController.stylesheets.push({ name:'Potlatch', url:'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";
}
]]>