First cut at styling TIGER data via an option. Needs lots of propagation of uid and...
[potlatch2.git] / net / systemeD / halcyon / NodeUI.as
index fbce4631427d5292f7dc19011da33d1dd97f88fd..eb9e608bf8c380f1b97363f47475ec191a4a62fb 100644 (file)
@@ -15,20 +15,25 @@ package net.systemeD.halcyon {
        public class NodeUI extends EntityUI {
                
                public var loaded:Boolean=false;
-               private var iconname:String='';                         // name of icon
+               private var iconnames:Object={};                        // name of icon on each sublayer
                private var heading:Number=0;                           // heading within way
                private var rotation:Number=0;                          // rotation applied to this POI
                private static const NO_LAYER:int=-99999;
 
-               public function NodeUI(node:Node, paint:MapPaint, heading:Number=0, layer:int=NO_LAYER, sl:StyleList=null) {
+               public function NodeUI(node:Node, paint:MapPaint, heading:Number=0, layer:int=NO_LAYER, stateClasses:Object=null) {
                        super(node,paint);
                        if (layer==NO_LAYER) { this.layer=paint.maxlayer; } else { this.layer=layer; }
                        this.heading = heading;
+                       if (stateClasses) {
+                               for (var state:String in stateClasses) {
+                                       if (stateClasses[state]) { this.stateClasses[state]=stateClasses[state]; }
+                               }
+                       }
             entity.addEventListener(Connection.TAG_CHANGED, tagChanged);
                        entity.addEventListener(Connection.NODE_MOVED, nodeMoved);
                        entity.addEventListener(Connection.NODE_DELETED, nodeDeleted);
             attachRelationListeners();
-                       redraw(sl);
+                       redraw();
                }
                
                public function nodeMoved(event:Event):void {
@@ -38,71 +43,73 @@ package net.systemeD.halcyon {
                public function nodeDeleted(event:Event):void {
                        removeSprites();
                }
-               
-               override public function doRedraw(sl:StyleList):Boolean {
+
+               override public function doRedraw():Boolean {
                        if (!paint.ready) { return false; }
                        if (entity.deleted) { return false; }
 
                        var tags:Object = entity.getTagsCopy();
                        tags=applyStateClasses(tags);
                        if (!entity.hasParentWays) { tags[':poi']='yes'; }
-                       if (!sl) { sl=paint.ruleset.getStyles(entity,tags,paint.map.scale); }
+            if (entity.hasInterestingTags()) { tags[':hasTags']='yes'; }
+                       if (!styleList || !styleList.isValidAt(paint.map.scale)) {
+                               styleList=paint.ruleset.getStyles(entity,tags,paint.map.scale); 
+                       }
 
                        var inWay:Boolean=entity.hasParentWays;
-                       var hasStyles:Boolean=sl.hasStyles();
+                       var hasStyles:Boolean=styleList.hasStyles();
                        
-                       removeSprites(); iconname='';
-                       return renderFromStyle(sl,tags);
+                       removeSprites(); iconnames={};
+                       return renderFromStyle(tags);
                }
 
-               private function renderFromStyle(sl:StyleList,tags:Object):Boolean {
+               private function renderFromStyle(tags:Object):Boolean {
                        var r:Boolean=false;                    // ** rendered
                        var maxwidth:Number=4;                  // biggest width
                        var w:Number;
                        var icon:Sprite;
                        interactive=false;
-                       for each (var sublayer:Number in sl.sublayers) {
+                       for each (var sublayer:Number in styleList.sublayers) {
 
-                               if (sl.pointStyles[sublayer]) {
-                                       var s:PointStyle=sl.pointStyles[sublayer];
+                               if (styleList.pointStyles[sublayer]) {
+                                       var s:PointStyle=styleList.pointStyles[sublayer];
                                        interactive||=s.interactive;
                                        r=true;
                                        if (s.rotation) { rotation=s.rotation; }
-
-                                       if (s.icon_image!=iconname) {
+                                       if (s.icon_image!=iconnames[sublayer]) {
                                                if (s.icon_image=='square') {
                                                        // draw square
                                                        icon=new Sprite();
                                                        addToLayer(icon,STROKESPRITE,sublayer);
-                                                       w=styleIcon(icon,sl,sublayer);
+                                                       w=styleIcon(icon,sublayer);
                                                        icon.graphics.drawRect(0,0,w,w);
                                                        if (s.interactive) { maxwidth=Math.max(w,maxwidth); }
-                                                       iconname='_square';
+                                                       iconnames[sublayer]='_square';
 
                                                } else if (s.icon_image=='circle') {
                                                        // draw circle
                                                        icon=new Sprite();
                                                        addToLayer(icon,STROKESPRITE,sublayer);
-                                                       w=styleIcon(icon,sl,sublayer);
+                                                       w=styleIcon(icon,sublayer);
                                                        icon.graphics.drawCircle(w,w,w);
                                                        if (s.interactive) { maxwidth=Math.max(w,maxwidth); }
-                                                       iconname='_circle';
+                                                       iconnames[sublayer]='_circle';
 
                                                } else if (paint.ruleset.images[s.icon_image]) {
                                                        // 'load' icon (actually just from library)
-                                                       var loader:Loader = new Loader();
-                                                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void { 
-                                                               loadedIcon(e,sublayer); } );
+                                                       var loader:ExtendedLoader = new ExtendedLoader();
+                                                       loader.info['sublayer']=sublayer;
+                                                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
                                                        loader.loadBytes(paint.ruleset.images[s.icon_image]);
-                                                       iconname=s.icon_image;
+                                                       iconnames[sublayer]=s.icon_image;
                                                }
                                        }
                                }
 
                                // name sprite
                                var a:String='', t:TextStyle;
-                               if (sl.textStyles[sublayer]) {
-                                       t=sl.textStyles[sublayer];
+                               if (styleList.textStyles[sublayer]) {
+                                       t=styleList.textStyles[sublayer];
                                        interactive||=t.interactive;
                                        a=tags[t.text];
                                }
@@ -120,13 +127,13 @@ package net.systemeD.halcyon {
                }
 
 
-               private function styleIcon(icon:Sprite, sl:StyleList, sublayer:uint):Number {
+               private function styleIcon(icon:Sprite, sublayer:Number):Number {
                        loaded=true;
 
                        // get colours
-                       if (sl.shapeStyles[sublayer]) {
-                               var s:ShapeStyle=sl.shapeStyles[sublayer];
-                               if (s.color) { icon.graphics.beginFill(s.color); 
+                       if (styleList.shapeStyles[sublayer]) {
+                               var s:ShapeStyle=styleList.shapeStyles[sublayer];
+                               if (!isNaN(s.color)) { icon.graphics.beginFill(s.color);
                                        }
                                if (s.casing_width || !isNaN(s.casing_color)) {
                                        icon.graphics.lineStyle(s.casing_width ? s.casing_width : 1,
@@ -136,21 +143,21 @@ package net.systemeD.halcyon {
                        }
 
                        // return width
-                       return sl.pointStyles[sublayer].icon_width;
+                       return styleList.pointStyles[sublayer].icon_width;
                }
 
                private function addHitSprite(w:uint):void {
-            var hitzone:Sprite = new Sprite();
+            hitzone = new Sprite();
             hitzone.graphics.lineStyle(4, 0x000000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND);
                        hitzone.graphics.beginFill(0);
                        hitzone.graphics.drawRect(0,0,w,w);
-            addToLayer(hitzone, NODECLICKSPRITE);
-            hitzone.visible = false;
-                       setListenSprite(NODECLICKSPRITE, hitzone);
+                       hitzone.visible = false;
+                       setListenSprite();
                }
 
-               private function loadedIcon(event:Event,sublayer:uint):void {
+               private function loadedIcon(event:Event):void {
                        var icon:Sprite=new Sprite();
+                       var sublayer:Number=event.target.loader.info['sublayer'];
                        addToLayer(icon,STROKESPRITE,sublayer);
                        icon.addChild(Bitmap(event.target.content));
                        addHitSprite(icon.width);