remember background imagery; infinite sublayers; bugfixes
authorRichard Fairhurst <richard@systemed.net>
Wed, 16 Jun 2010 09:21:03 +0000 (09:21 +0000)
committerRichard Fairhurst <richard@systemed.net>
Wed, 16 Jun 2010 09:21:03 +0000 (09:21 +0000)
TODO.txt
net/systemeD/halcyon/Elastic.as
net/systemeD/halcyon/EntityUI.as
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/MapPaint.as
net/systemeD/halcyon/TileSet.as
net/systemeD/potlatch2/BackgroundSelector.mxml
net/systemeD/potlatch2/Yahoo.as
net/systemeD/potlatch2/controller/DrawWay.as
potlatch2.mxml

index 43c1567..583a57a 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -28,6 +28,7 @@ Potlatch 2: main outstanding issues
 
 == Tag editing ==
 
+** limitChanged bug causing very slow deselects etc.
 * Dynamic reloading of stylesheet/map_features, so that you don't need to reload the full page when editing them
 * If a select name is too long then, the select menu seems to give a horizontal scrollbar instead of the name of the item e.g. cuisine#Coffee Shop
 * If you have both inputSets names and buildingAddress, and name= key is filled in then the basic tab will get both, surely only name should be shown and building name should be ignored e.g. cafes. [Actually this was an issue of addr: being missing from one of them, however this may still be a problem for other overlapping inputSets]
@@ -41,7 +42,6 @@ Potlatch 2: main outstanding issues
 == UI ==
 
 ** Potlatch 1-style "floaty warnings"
-** Should remember which background imagery layer you had previously selected
 * Custom imagery dialog fixes
 * Ctrl-clicking two areas (one inside the other) should create a multipolygon
 * B keypress for background source tag
@@ -59,7 +59,7 @@ Potlatch 2: main outstanding issues
 
 == Rendering (Halcyon) ==
 
-** Infinite z-indexes
+* halcyon_viewer needs updating for new tileurl stuff
 * { interactive: no; } - stop items being clicked on (and their maxwidth being taken into account)
 * Shields
 * More line decoration (cliffs etc.), and implied values for 'dashes' if not supplied
index 6417168..a3b6190 100755 (executable)
@@ -61,8 +61,15 @@ package net.systemeD.halcyon {
                        // Create stroke object
                        var stroke:Shape = new Shape();
             stroke.graphics.lineStyle(1, 0xff0000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND);
-                       addToLayer(stroke,3);
+
+                       var l:DisplayObject=map.paint.getChildAt(map.paint.maxlayer-map.paint.minlayer);
+                       var o:DisplayObject=Sprite(l).getChildAt(3);    // names layer
+                       (o as Sprite).addChild(stroke);
+                       sprites.push(stroke);
+
                        dashedLine(stroke.graphics, [2,2]);
+
+
                }
                
                // ------------------------------------------------------------------------------------------
@@ -116,19 +123,5 @@ package net.systemeD.halcyon {
                                 else { g.moveTo(x,y); }
                }
 
-               
-               // Add object (stroke/fill/roadname) to layer sprite
-               
-               private function addToLayer(s:DisplayObject,t:uint,sublayer:int=-1):void {
-                       var l:DisplayObject=Map(map).paint.getChildAt(map.paint.maxlayer-map.paint.minlayer);
-                       var o:DisplayObject=Sprite(l).getChildAt(t);
-                       if (sublayer!=-1) { o=Sprite(o).getChildAt(sublayer); }
-                       Sprite(o).addChild(s);
-                       sprites.push(s);
-            if ( s is Sprite ) {
-                Sprite(s).mouseEnabled = false;
-                Sprite(s).mouseChildren = false;
-            }
-               }
        }
 }
index c50a0ad..38fc3c4 100644 (file)
@@ -48,10 +48,14 @@ package net.systemeD.halcyon {
                // Add object (stroke/fill/roadname) to layer sprite
                
                protected function addToLayer(s:DisplayObject,t:uint,sublayer:int=-1):void {
-                       var l:DisplayObject=paint.getChildAt(layer-paint.minlayer);
-                       var o:DisplayObject=Sprite(l).getChildAt(t);
-                       if (sublayer!=-1) { o=Sprite(o).getChildAt(sublayer); }
-                       Sprite(o).addChild(s);
+                       var l:DisplayObject, o:Sprite;
+                       if (sublayer!=-1) {
+                               o=paint.sublayer(layer,sublayer);
+                       } else {
+                               l=paint.getChildAt(layer-paint.minlayer);
+                               o=(l as Sprite).getChildAt(t) as Sprite;
+                       }
+                       o.addChild(s);
                        sprites.push(s);
             if ( s is Sprite ) {
                 Sprite(s).mouseChildren = false;
index d765bdd..19c701c 100755 (executable)
@@ -66,6 +66,8 @@ package net.systemeD.halcyon {
 
                public var backdrop:Object;                                             // reference to backdrop sprite
                public var tileset:TileSet;                                             // 900913 tile background
+               private var tileurl:String='';                                  // internal tile URL and priority - allows setting before tileset inited
+               private var tileprio:uint=0;                                    //  | 
                public var showall:Boolean=true;                                // show all objects, even if unstyled?
                
                public var connection:Connection;                               // server connection
@@ -107,24 +109,23 @@ package net.systemeD.halcyon {
                                init(initparams['lat'],
                                         initparams['lon'],
                                         initparams['zoom'],
-                                        initparams['style'],
-                                        initparams['tileurl']);
+                                        initparams['style']);
 
                        } else {
                                // somewhere innocuous
-                               init(53.09465,-2.56495,17,"test.css?d="+Math.random(),"");
+                               init(53.09465,-2.56495,17,"test.css?d="+Math.random());
                        }
                }
 
                // ------------------------------------------------------------------------------------------
                // Initialise map at a given lat/lon
 
-        public function init(startlat:Number,startlon:Number,startscale:uint=0,style:String=null,tileurl:String=''):void {
+        public function init(startlat:Number,startlon:Number,startscale:uint=0,style:String=null):void {
                        while (numChildren) { removeChildAt(0); }
 
                        tileset=new TileSet(this);                                      // 0 - 900913 background
                        addChild(tileset);                                                      //   |
-                       tileset.init(tileurl);
+                       tileset.init(tileurl);                                          //   |
 
                        vectorbg = new Sprite();                                        // 1 - vector background layers
                        addChild(vectorbg);                                                     //   |
@@ -329,6 +330,17 @@ package net.systemeD.halcyon {
                        }
         }
 
+               public function setBackground(url:String,priority:int):Boolean {
+                       if (priority<tileprio) { return false; }
+                       tileurl=url; tileprio=priority;
+                       if (tileset) { tileset.init(url, url!=''); }
+                       return true;
+               }
+
+               public function setDimming(dim:Boolean):void {
+                       if (tileset) { tileset.setDimming(dim); }
+               }
+
                // ------------------------------------------------------------------------------------------
                // Export (experimental)
                // ** just a bit of fun for now!
index 75a8f1b..e67d290 100644 (file)
@@ -19,6 +19,9 @@ package net.systemeD.halcyon {
                public var wayuis:Object=new Object();                  // sprites for ways and (POI/tagged) nodes
                public var nodeuis:Object=new Object();                 //  |
                public var isBackground:Boolean = true;                 // is it a background layer or the core paint object?
+               private var sublayerIndex:Object={};                    // hash of index->position
+
+               private const VERYBIG:Number=Math.pow(2,16);
 
                // Set up layering
                // [layer][3]                   - names
@@ -30,15 +33,14 @@ package net.systemeD.halcyon {
                        this.map=map;
                        this.minlayer=minlayer;
                        this.maxlayer=maxlayer;
+                       sublayerIndex[1]=0;
 
                        for (var l:int=minlayer; l<=maxlayer; l++) {    // each layer (10 is +5, 0 is -5)
                                var s:Sprite = getHitSprite();                  //  |
                                s.addChild(getPaintSprite());                           //      | 0 fill
                                s.addChild(getPaintSprite());                           //      | 1 casing
                                var t:Sprite = getPaintSprite();                        //  | 2 stroke
-                               for (var j:int=0; j<11; j++) {                          //      |  | ten sublayers
-                                       t.addChild(getPaintSprite());                   //  |  |  |
-                               }                                                                                       //  |  |  |
+                               t.addChild(getPaintSprite());                           //  |  | sublayer
                                s.addChild(t);                                                          //  |  |
                                s.addChild(getPaintSprite());                           //      | 3 names
                                s.addChild(getPaintSprite());                           //      | 4 nodes
@@ -54,18 +56,44 @@ package net.systemeD.halcyon {
                        return true;
                }
 
-/*             public function addToLayer(s:DisplayObject, layer:int, t:uint, sublayer:int=-1) {
-                       var l:DisplayObject=getChildAt(layer-minlayer);
-                       var o:DisplayObject=Sprite(l).getChildAt(t);
-                       if (sublayer!=-1) { o=Sprite(o).getChildAt(sublayer); }
-                       Sprite(o).addChild(s);
-                       sprites.push(s);
-            if ( s is Sprite ) {
-                Sprite(s).mouseEnabled = false;
-                Sprite(s).mouseChildren = false;
-            }
+               public function sublayer(layer:int,sublayer:Number):Sprite {
+                       var l:DisplayObject;
+                       var o:DisplayObject;
+                       var index:String, ix:Number;
+                       if (!sublayerIndex[sublayer]) {
+                               // work out which position to add at
+                               var lowestAbove:Number=VERYBIG;
+                               var lowestAbovePos:int=-1;
+                               var indexLength:uint=0;
+                               for (index in sublayerIndex) {
+                                       ix=Number(index);
+                                       if (ix>sublayer && ix<lowestAbove) {
+                                               lowestAbove=ix;
+                                               lowestAbovePos=sublayerIndex[index];
+                                       }
+                                       indexLength++;
+                               }
+                               if (lowestAbovePos==-1) { lowestAbovePos=indexLength; }
+                       
+                               // add sprites
+                               for (var i:int=minlayer; i<=maxlayer; i++) {
+                                       l=getChildAt(i-minlayer);
+                                       o=(l as Sprite).getChildAt(2);
+                                       (o as Sprite).addChildAt(getPaintSprite(),lowestAbovePos);
+                               }
+                       
+                               // update index
+                               for (index in sublayerIndex) {
+                                       ix=Number(index);
+                                       if (ix>sublayer) { sublayerIndex[index]++; }
+                               }
+                               sublayerIndex[sublayer]=lowestAbovePos;
+                       }
+
+                       l=getChildAt(layer-minlayer);
+                       o=(l as Sprite).getChildAt(2);
+                       return ((o as Sprite).getChildAt(sublayerIndex[sublayer]) as Sprite);
                }
-*/
 
                public function updateEntityUIs(o:Object, redraw:Boolean, remove:Boolean):void {
                        var way:Way, node:Node;
index 59eaaed..f91bc46 100755 (executable)
@@ -121,6 +121,10 @@ package net.systemeD.halcyon {
                private function tileURL(tx:int,ty:int):String {
                        return baseurl.replace('$z',map.scale).replace('$x',tx).replace('$y',ty);
                }
+               
+               public function get url():String {
+                       return baseurl ? baseurl : '';
+               }
 
 
                // Update offset
index 75e3847..fba2dd1 100644 (file)
@@ -4,10 +4,11 @@
        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"
        horizontalAlign="left" backgroundColor="white" borderStyle="inset">
        
-       <mx:List width="100%" height="100%" id="background" change="updateBackground();" verticalScrollPolicy="on" 
-                dataProvider="{Application.application.theController.imagery}" />
+       <mx:List width="100%" height="100%" id="background" verticalScrollPolicy="on" 
+                       change="Application.application.setBackground(background.selectedItem.label, background.selectedItem.data);"                    
+               dataProvider="{Application.application.theController.imagery}" />
        <mx:CheckBox width="100%" label="Dim background" selected="true" id="dim"
-           change="Globals.vars.root.tileset.setDimming(dim.selected); Globals.vars.yahoo.alpha = dim.selected ? 0.5 : 1" />
+           change="Application.application.theMap.setDimming(dim.selected); Application.application.yahoo.alpha = dim.selected ? 0.5 : 1" />
 
        <mx:HBox>
        <mx:Button label="Edit..." click="new BackgroundDialog().init(background);" />
                import mx.collections.ArrayCollection;
                import mx.managers.PopUpManager;
                import net.systemeD.halcyon.Globals;
-
-               private function updateBackground():void {
-            var theMap:Map = Globals.vars.root;
-                       var bg:String=background.selectedItem.data;
-                       if (bg=='yahoo') {
-                               theMap.tileset.init('',false);
-                               Globals.vars.yahoo.show();
-                       } else {
-                               theMap.tileset.init(background.selectedItem.data,true);
-                               Globals.vars.yahoo.hide();
-                       }
-               }
-
     ]]></mx:Script>    
 </mx:VBox>
 
index 942696d..e3111be 100644 (file)
@@ -18,6 +18,7 @@ package net.systemeD.potlatch2 {
                private var _scale:Number;
                private var offset_lat:Number=0;
                private var offset_lon:Number=0;
+               private var inited:Boolean=false;
 
                public function Yahoo(w:Number, h:Number, map:Map) {
                        super();
@@ -25,13 +26,17 @@ package net.systemeD.potlatch2 {
                        this.mapType="satellite";
                        this.alpha=0.5;
                        this.map=map;
+                       this.inited=false;
                }
                
                public function show():void {
                        this.visible=true;
-                       moveto(map.centre_lat, map.centre_lon, map.scale);
+                       if (inited) {
+                               moveto(map.centre_lat, map.centre_lon, map.scale);
+                       } else {
+                               this.addEventListener(YahooMapEvent.MAP_INITIALIZE, initHandler);
+                       }
 
-                       this.addEventListener(YahooMapEvent.MAP_INITIALIZE, initHandler);
                        map.addEventListener(MapEvent.MOVE, moveHandler);
                        map.addEventListener(MapEvent.RESIZE, resizeHandler);
                        map.addEventListener(MapEvent.NUDGE_BACKGROUND, nudgeHandler);
@@ -40,17 +45,19 @@ package net.systemeD.potlatch2 {
                public function hide():void {
                        this.visible=false;
 
-                       this.removeEventListener(YahooMapEvent.MAP_INITIALIZE, initHandler);
                        map.removeEventListener(MapEvent.MOVE, moveHandler);
                        map.removeEventListener(MapEvent.RESIZE, resizeHandler);
                        map.removeEventListener(MapEvent.NUDGE_BACKGROUND, nudgeHandler);
                }
                
                private function initHandler(event:YahooMapEvent):void {
+                       inited=true;
                        moveto(map.centre_lat, map.centre_lon, map.scale);
+                       this.removeEventListener(YahooMapEvent.MAP_INITIALIZE, initHandler);
                }
 
                private function moveHandler(event:MapEvent):void {
+                       if (!inited) { return; }
                        moveto(event.params.lat, event.params.lon, event.params.scale);
                }
 
index 4b7c7b4..bbcd7f6 100644 (file)
@@ -91,7 +91,7 @@ package net.systemeD.potlatch2.controller {
                                        controller.setCursor(controller.pen_plus);
                                }
                        } else if ( event.type == MouseEvent.MOUSE_OUT ) {
-                               if (focus!=selectedWay) {
+                               if (entity!=selectedWay) {
                                        hoverEntity=null;
                                        controller.map.setHighlight(focus, { showNodesHover: false });
                                        controller.map.setHighlight(selectedWay, { showNodes: true });
index 9aa18c6..4d4b842 100755 (executable)
 
         public var theMap:Map;
         public var theController:EditController;
+               public var yahoo:Yahoo;
 
                private var savecount:uint=0;
                private var loadcount:uint=0;
                        // create map and Yahoo
                        theMap=new Map(this.loaderInfo.parameters);
                        theMap.backdrop=b;
-                       var yahoo:Yahoo=new Yahoo(w,h,theMap);
+                       yahoo=new Yahoo(w,h,theMap);
                        yahoo.hide();
-                       Globals.vars.yahoo = yahoo;
                        _root.addChild(yahoo);
                        _root.addChild(theMap);
             theMap.updateSize(w,h);
+                       if (loaderInfo.parameters['tileurl']) {
+                               setBackground('custom',loaderInfo.parameters['tileurl'],2);
+                       }
 
                        // add mask for map
                        var s:Sprite=new Sprite();
                
         private function onImageryLoad(event:Event):void {
                        var xml:XML = new XML(URLLoader(event.target).data);
+
+                       // create menu
             theController.imagery=new Array(
                                { label: "None", data: "" },
                                { label: "Yahoo", data: "yahoo" } );
                        for each(var set:XML in xml.set) {
                 theController.imagery.push({ label:set.child("name"), data:set.child("url") });
                        }
+
+                       // set imagery from shared object
+                       var previous:String = SharedObject.getLocal("user_state").data['background'];
+                       for each (var bg:Object in theController.imagery) {
+                               if (bg['label']==previous) { 
+                                       setBackground(bg['label'], bg['data'], 1);
+                               }
+                       }
                }
-        
+
+               public function setBackground(name:String,url:String,priority:uint=2):void {
+                       // ** this should take an object with all parameters (source tag, etc.)
+                       var set:Boolean;
+                       if (url=='yahoo') {
+                               set=theMap.setBackground('',2);
+                               yahoo.show();
+                       } else {
+                               set=theMap.setBackground(url,priority)
+                               yahoo.hide();
+                       }
+                       if (set) {
+                               var obj:SharedObject = SharedObject.getLocal("user_state");
+                               obj.setProperty("background", name);
+                               obj.flush();
+                       }
+               }
+
         private function dragEnterHandler(event:DragEvent):void {
             // Get the drop target component from the event object.
             var dropTarget:Canvas=event.currentTarget as Canvas;