some more footling around with POI nodes in ways
authorRichard Fairhurst <richard@systemed.net>
Fri, 9 Oct 2009 15:00:05 +0000 (15:00 +0000)
committerRichard Fairhurst <richard@systemed.net>
Fri, 9 Oct 2009 15:00:05 +0000 (15:00 +0000)
net/systemeD/halcyon/POI.as
net/systemeD/halcyon/TileSet.as
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/styleparser/RuleSet.as
net/systemeD/halcyon/styleparser/Style.as
net/systemeD/halcyon/styleparser/StyleList.as

index be01436da347c94906441268cba396f6229fd256..31ddd536e646accea0fc2514d01981701d2ce2ea 100644 (file)
@@ -13,9 +13,10 @@ package net.systemeD.halcyon {
                
         private var node:Node;
                public var map:Map;                                                     // reference to parent map
-               public var icon:Bitmap;                                         // instance in display list
+               public var icon:Sprite;                                         // instance in display list
                public var name:Sprite;                                         //  |
                private var iconname:String='';                         // name of icon
+               public var loaded:Boolean=false;
 
                public static const DEFAULT_TEXTFIELD_PARAMS:Object = {
 //                     embedFonts: true,
@@ -25,16 +26,18 @@ package net.systemeD.halcyon {
 //             [Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")]
 //             public static var DejaVu:Class;
 
-               public function POI(node:Node, map:Map) {
+               public function POI(node:Node, map:Map, sl:StyleList=null) {
                        this.map = map;
                        this.node = node;
-                       redraw();
+                       redraw(sl);
                }
                
-               public function redraw():void {
+               public function redraw(sl:StyleList=null):Boolean {
                        var tags:Object = node.getTagsCopy();
                        // ** apply :hover etc.
-                       var sl:StyleList=map.ruleset.getStyles(this.node,tags);
+                       if (!sl) { sl=map.ruleset.getStyles(this.node,tags); }
+                       if (!sl.hasStyles()) { return false; }
+                       
                        var r:Boolean=false;    // ** rendered
                        var l:DisplayObject;
                        for (var sublayer:uint=0; sublayer<10; sublayer++) {
@@ -53,7 +56,6 @@ package net.systemeD.halcyon {
                                        } else {
                                                // already loaded, so just reposition
                                                updatePosition();
-                                               iconname=s.icon_image;
                                        }
                                }
 
@@ -74,15 +76,27 @@ package net.systemeD.halcyon {
                                Sprite(l).removeChild(icon);
                                iconname='';
                        }
+                       return true;
                }
 
                private function loadedIcon(event:Event):void {
-                       icon = Bitmap(event.target.content);
+                       icon = new Sprite();
+                       icon.addChild(Bitmap(event.target.content));
                        var l:DisplayObject=map.getChildAt(map.POISPRITE);
                        Sprite(l).addChild(icon);
                        updatePosition();
+
+            icon.addEventListener(MouseEvent.CLICK, mouseEvent);
+            icon.buttonMode = true;
+            icon.mouseEnabled = true;
+
+                       loaded=true;
                }
 
+        private function mouseEvent(event:MouseEvent):void {
+                       map.entityMouseEvent(event, node);
+        }
+
                private function updatePosition():void {
                        icon.x=map.lon2coord(node.lon)-icon.width/2;
                        icon.y=map.latp2coord(node.latp)-icon.height/2;
index d71013d535b052b12613eec1a53aae604bea91cc..0786e08e73aaae82c8a52b9da934b5aa4c8c9432 100755 (executable)
@@ -10,7 +10,6 @@ package net.systemeD.halcyon {
        import flash.net.*;
        
        import net.systemeD.halcyon.ImageURLLoader;
-       import net.systemeD.halcyon.Globals;
        import flash.system.LoaderContext;
        
     public class TileSet extends Sprite {
@@ -70,8 +69,10 @@ package net.systemeD.halcyon {
                                r=requests.shift(); tz=r[0]; tx=r[1]; ty=r[2];
                                if (tx>=tile_l && tx<=tile_r && ty>=tile_t && ty<=tile_b) {
                                        // Tile is on-screen, so load
+                                       waiting++;
                                        var loader:Loader = new Loader();
                                        loader.contentLoaderInfo.addEventListener(Event.INIT, doImgInit);
+                       loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, missingTileError);
                                        loader.load(new URLRequest(tileURL(tx,ty)), 
                                                    new LoaderContext(true));
                                        this.addChild(loader);
@@ -82,7 +83,12 @@ package net.systemeD.halcyon {
                        }
                }
 
-               protected function doImgInit(evt:Event):void {
+        private function missingTileError(event:Event):void {
+                       waiting--;
+                       return;
+               }
+
+               protected function doImgInit(event:Event):void {
                        waiting--;
                        return;
                }
index 8ca965cd4766b652dcc8054f1c4aeddc6c4640fe..929b25c8272b5c6a8f8d71dc1d71e40fe322a889 100755 (executable)
@@ -196,17 +196,28 @@ package net.systemeD.halcyon {
                                        }
                                }
                                
-                               // ** draw icons
-                               for (var i:uint = 0; i < way.length; i++) {
-                       var node:Node = way.getNode(i);
-                                       if (node.hasTags()) {
-                                               map.connection.registerPOI(node);
+                               // ** ShieldStyle to do
+                       }
+
+                       // ** draw icons
+                       for (var i:uint = 0; i < way.length; i++) {
+                var node:Node = way.getNode(i);
+                   if (map.pois[node.id]) {
+                                       if (map.pois[node.id].loaded) {
+                                               map.pois[node.id].redraw();
+                                       }
+                               } else if (node.hasTags()) {
+                                       sl=map.ruleset.getStyles(node,node.getTagsHash());
+                                       if (sl.hasStyles()) {
+                                               map.pois[node.id]=new POI(node,map,sl);
+                                               // ** this should be done via the registerPOI/event listener mechanism,
+                                               //    but that needs a bit of reworking so we can pass in a styleList
+                                               //    (otherwise we end up computing the styles twice which is expensive)
                                        }
                                }
-                               
-                               
-                               // ** ShieldStyle to do
                        }
+                       
+                       
 
                        // No styles, so add a thin trace
             if (!drawn && map.showall) {
index de2983a087f24a3870d057fa15cfcc019a290c6c..5708328092c383a6bd2faf7bbe207fd20c661d56 100644 (file)
@@ -43,6 +43,8 @@ package net.systemeD.halcyon.connection {
             return false;
         }
 
+               // ** we could do with hasInterestingTags - don't bother with source, created_by, any TIGER tags, etc.
+
         public function getTag(key:String):String {
             return tags[key];
         }
index 517856f37a11f3a5662ee2f27a3a275233f87168..42d6179ecf39813f74dc25bca9a8585998336a91 100644 (file)
@@ -88,7 +88,6 @@ package net.systemeD.halcyon.styleparser {
                // data handler
 
                private function loadedImage(event:Event):void {
-Globals.vars.root.addDebug("adding image at "+event.target.filename);
                        images[event.target.filename]=event.target.data;
                        iconsToLoad--;
                        if (iconsToLoad==0 && iconCallback!=null) { iconCallback(); }
index d0708239805c84f102d0c130252911c8471eecf6..cd5b608adb989665221ac03acee85df7f7f901a0 100755 (executable)
@@ -2,7 +2,6 @@ package net.systemeD.halcyon.styleparser {
 
        import flash.utils.ByteArray;
        import flash.net.*;
-       import net.systemeD.halcyon.Globals;
 
        public class Style {
 
index 5ee42bca4a39b420a62389b780a9fe2a529c3f28..e2496e278d138e5e7fb9e7e3edca7cee59e95b90 100755 (executable)
@@ -16,5 +16,8 @@ package net.systemeD.halcyon.styleparser {
                public var pointStyles:Array=[];
                public var shieldStyles:Array=[];
 
+               public function hasStyles():Boolean {
+                       return ( (shapeStyles.length + textStyles.length + pointStyles.length + shieldStyles.length) > 0 );
+               }
        }
 }
\ No newline at end of file