Remember dimming/sharpening preferences
authorRichard Fairhurst <richard@systemed.net>
Tue, 30 Nov 2010 21:35:59 +0000 (21:35 +0000)
committerRichard Fairhurst <richard@systemed.net>
Tue, 30 Nov 2010 21:35:59 +0000 (21:35 +0000)
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/TileSet.as
net/systemeD/potlatch2/BackgroundSelector.mxml
net/systemeD/potlatch2/collections/Imagery.as
potlatch2.mxml

index 8a95181..59f93e6 100644 (file)
@@ -116,7 +116,7 @@ package net.systemeD.halcyon {
                // ------------------------------------------------------------------------------------------
                // Initialise map at a given lat/lon
 
-        public function init(startlat:Number,startlon:Number,startscale:uint=0):void {
+        public function init(startlat:Number, startlon:Number, startscale:uint=0):void {
                        while (numChildren) { removeChildAt(0); }
 
                        tileset=new TileSet(this);                                      // 0 - 900913 background
@@ -124,7 +124,9 @@ package net.systemeD.halcyon {
                                tileset.blocks=initparams['tileblocks'];//   |
                        }                                                                                       //   |
                        addChild(tileset);                                                      //   |
-                       tileset.init(tileparams);                                       //   |
+                       tileset.init(tileparams, false, 
+                                    initparams['background_dim']    ==null ? true  : initparams['background_dim'],
+                                    initparams['background_sharpen']==null ? false : initparams['background_sharpen']);
 
                        vectorbg = new Sprite();                                        // 1 - vector background layers
                        addChild(vectorbg);                                                     //   |
@@ -384,10 +386,18 @@ package net.systemeD.halcyon {
                public function setDimming(dim:Boolean):void {
                        if (tileset) { tileset.setDimming(dim); }
                }
+               public function getDimming():Boolean {
+                       if (tileset) { return tileset.getDimming(); }
+                       return true;
+               }
 
                public function setSharpen(sharpen:Boolean):void {
                        if (tileset) { tileset.setSharpen(sharpen); }
                }
+               public function getSharpen():Boolean {
+                       if (tileset) { return tileset.getSharpen(); }
+                       return false;
+               }
 
                // ------------------------------------------------------------------------------------------
                // Export (experimental)
index fe631d2..9890926 100644 (file)
@@ -36,12 +36,13 @@ package net.systemeD.halcyon {
 
         public function TileSet(map:Map) {
                        this.map=map;
-                       alpha=0.5;
                        createSprites();
                        map.addEventListener(MapEvent.NUDGE_BACKGROUND, nudgeHandler);
                }
        
-               public function init(params:Object, update:Boolean=false):void {
+               public function init(params:Object, update:Boolean=false, dim:Boolean=true, sharpen:Boolean=false):void {
+                       setDimming(dim);
+                       sharpening=sharpen;
                        baseurl=params.url;
                        scheme =params.scheme ? params.scheme : '900913';
                        tiles={};
@@ -60,6 +61,9 @@ package net.systemeD.halcyon {
                public function setDimming(dim:Boolean):void {
                        alpha=dim ? 0.5 : 1;
                }
+               public function getDimming():Boolean {
+                       return (alpha<1);
+               }
 
                public function setSharpen(sharpen:Boolean):void {
                        var f:Array=[]; if (sharpen) { f=[sharpenFilter]; }
@@ -71,6 +75,9 @@ package net.systemeD.halcyon {
                        }
                        sharpening=sharpen;
                }
+               public function getSharpen():Boolean {
+                       return sharpening;
+               }
 
                public function changeScale(scale:uint):void {
                        for (var i:uint=map.MINSCALE; i<=map.MAXSCALE; i++) {
index c06a952..fc65178 100644 (file)
@@ -9,10 +9,10 @@
                        change="Application.application.bgButton.close(); Imagery.instance().setBackground(background.selectedItem);"                   
                dataProvider="{Imagery.instance().getAvailableImagery()}" />
        <mx:HBox>
-       <mx:CheckBox width="100%" label="Dim" selected="true" id="dim"
-           change="Application.application.theMap.setDimming(dim.selected); Application.application.yahoo.alpha = dim.selected ? 0.5 : 1" />
-       <mx:CheckBox width="100%" label="Sharpen" selected="false" id="sharpen"
-           change="Application.application.theMap.setSharpen(sharpen.selected);" />
+       <mx:CheckBox width="100%" label="Dim" selected="{Application.application.theMap.getDimming()}" id="dim"
+           change="setDimming(dim.selected)" />
+       <mx:CheckBox width="100%" label="Sharpen" selected="{Application.application.theMap.getSharpen()}" id="sharpen"
+           change="setSharpen(sharpen.selected)" />
        </mx:HBox>
 
        <mx:HBox>
                import mx.collections.ArrayCollection;
                import mx.managers.PopUpManager;
                import net.systemeD.halcyon.Globals;
+
+               public function setDimming(v:Boolean):void {
+                       Application.application.theMap.setDimming(dim.selected);
+                       Application.application.yahoo.alpha = dim.selected ? 0.5 : 1;
+                       var obj:SharedObject=SharedObject.getLocal("user_state");
+                       obj.setProperty('background_dim',v);
+                       obj.flush();
+               }
+               public function setSharpen(v:Boolean):void {
+                       Application.application.theMap.setSharpen(sharpen.selected);
+                       var obj:SharedObject=SharedObject.getLocal("user_state");
+                       obj.setProperty('background_sharpen',v);
+                       obj.flush();
+               }
     ]]></mx:Script>    
 </mx:VBox>
 
index d27445a..c74421c 100644 (file)
@@ -50,13 +50,11 @@ package net.systemeD.potlatch2.collections {
 
         private function onImageryLoad(event:Event):void {
                        var xml:XML = new XML(URLLoader(event.target).data);
-                       var saved:Object;
+                       var saved:Object = {};
                        var bg: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={ url: ''};
                        }
 
                        var isSet:Boolean=false;
@@ -72,8 +70,8 @@ package net.systemeD.potlatch2.collections {
                                for each (a in set.@*) { obj[a.name().localName]=a.toString(); }
                                for each (a in set.* ) { obj[a.name()          ]=a.toString(); }
                 collection.push(obj);
-                               if ((obj.url ==saved.url) ||
-                                   (obj.name==saved.name && obj.name!='Custom')) { isSet=true; }
+                               if ((saved.url  && obj.url ==saved.url) ||
+                                   (saved.name && obj.name==saved.name && obj.name!='Custom')) { isSet=true; }
                        }
 
                        // Add user's previous preference (from SharedObject) if we didn't find it in the XML file
index 9d4d0e8..2ddcd40 100644 (file)
             b.graphics.endFill();
                        _root.addChild(b);
 
-                       // hard-coded block on Google tiles
-                       var params:Object={};
-                       for (var k:String in this.loaderInfo.parameters) {
+                       // pass additional parameters to map
+                       var params:Object={}; var k:String;
+                       for (k in this.loaderInfo.parameters) {
                                params[k]=this.loaderInfo.parameters[k];
                        }
-                       params['tileblocks']=[new RegExp("google","i")];
+                       for (k in SharedObject.getLocal('user_state').data) {
+                               params[k]=SharedObject.getLocal('user_state').data[k];
+                       }
+                       params['tileblocks']=[new RegExp("google","i")];        // hard-coded block on Google tiles
 
                        // create map and Yahoo
                        theMap=new Map(params);