basic POI rendering support
authorRichard Fairhurst <richard@systemed.net>
Sat, 30 May 2009 17:24:08 +0000 (17:24 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sat, 30 May 2009 17:24:08 +0000 (17:24 +0000)
halcyon.tmproj
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/POI.as
net/systemeD/halcyon/styleparser/ImageLoader.as [new file with mode: 0644]
net/systemeD/halcyon/styleparser/RuleSet.as

index a01c864..8dc2963 100644 (file)
@@ -8,37 +8,43 @@
                        <key>filename</key>
                        <string>net/systemeD/halcyon/AMFConnection.as</string>
                        <key>lastUsed</key>
-                       <date>2009-05-30T10:52:22Z</date>
+                       <date>2009-05-30T13:59:09Z</date>
                </dict>
                <dict>
                        <key>filename</key>
                        <string>net/systemeD/halcyon/Connection.as</string>
+                       <key>lastUsed</key>
+                       <date>2009-05-30T13:59:04Z</date>
                </dict>
                <dict>
                        <key>filename</key>
                        <string>net/systemeD/halcyon/Globals.as</string>
+                       <key>lastUsed</key>
+                       <date>2009-05-30T15:21:19Z</date>
                </dict>
                <dict>
                        <key>filename</key>
                        <string>net/systemeD/halcyon/Map.as</string>
                        <key>lastUsed</key>
-                       <date>2009-05-30T10:43:34Z</date>
+                       <date>2009-05-30T15:21:19Z</date>
                </dict>
                <dict>
                        <key>filename</key>
                        <string>net/systemeD/halcyon/Node.as</string>
                        <key>lastUsed</key>
-                       <date>2009-05-30T08:37:45Z</date>
+                       <date>2009-05-30T13:59:07Z</date>
                </dict>
                <dict>
                        <key>filename</key>
                        <string>net/systemeD/halcyon/POI.as</string>
+                       <key>lastUsed</key>
+                       <date>2009-05-30T15:09:53Z</date>
                </dict>
                <dict>
                        <key>filename</key>
                        <string>net/systemeD/halcyon/Way.as</string>
                        <key>lastUsed</key>
-                       <date>2009-05-30T10:43:35Z</date>
+                       <date>2009-05-30T15:16:50Z</date>
                </dict>
                <dict>
                        <key>expanded</key>
@@ -54,7 +60,7 @@
                        <key>filename</key>
                        <string>halcyon.mxml</string>
                        <key>lastUsed</key>
-                       <date>2009-05-30T10:52:25Z</date>
+                       <date>2009-05-30T15:21:19Z</date>
                        <key>selected</key>
                        <true/>
                </dict>
index 6aa469e..5caa1b5 100755 (executable)
@@ -63,13 +63,15 @@ package net.systemeD.halcyon {
 
         public function Map() {
 
-                       for (var l:int=0; l<11; l++) {                          // 11 layers (10 is +5, 0 is -5)
+                       for (var l:int=0; l<13; l++) {                          // 11 layers (10 is +5, 0 is -5)
                                var s:Sprite=new Sprite();
                                s.addChild(new Sprite());                               // [layer][0]=fill, [1]=stroke, [2]=names
                                s.addChild(new Sprite());
                                s.addChild(new Sprite());
                                addChild(s);
                        }
+                       s=new Sprite(); addChild(s);                            // 11 - POIs
+                       s=new Sprite(); addChild(s);                            // 12 - shields
 
                        connection=new AMFConnection(
                                "http://127.0.0.1:3000/api/0.6/amf/read",
@@ -177,9 +179,9 @@ package net.systemeD.halcyon {
                        }
 
                        for each (var p:Array in pointlist) {
-                               i=w[0]; v=w[4];
+                               i=p[0]; v=p[4];
                                if (pois[i] && pois[i].version==v) { continue; }
-                               pois[i]=new POI(i,v,w[1],w[2],w[3],this);
+                               pois[i]=new POI(i,v,p[1],p[2],p[3],this);
                        }
 
                        addDebug("waylist is "+waylist);
index 8907c86..fddb8b4 100644 (file)
@@ -3,6 +3,7 @@ package net.systemeD.halcyon {
        public class POI extends Object {
 
                import flash.display.*;
+               import flash.events.*;
                import flash.text.TextField;
                import flash.text.TextFormat;
                import net.systemeD.halcyon.styleparser.*;
@@ -25,12 +26,37 @@ package net.systemeD.halcyon {
                        this.id=id;
                        this.version=version;
                        this.map=map;
+                       if (tags==null) { tags=new Object(); }
                        this.tags=tags;
+map.addDebug("POI "+id);
                        if (map.nodes[id]) {
                                // ** already exists - do stuff if it's moved, or in a way
                        } else {
                                map.nodes[id]=new Node(id,lon,map.lat2latp(lat),tags,version);
                        }
+
+                       // place icon on map
+                       var styles:Array=map.ruleset.getStyle(true,tags,map.scale);
+                       var ps:PointStyle=styles[1];
+
+                       if (ps) {
+map.addDebug("pointstyle found");
+                               if (ps.icon && ps.icon!='') {
+map.addDebug("placing "+ps.icon);
+                                       var loader:Loader = new Loader();
+                                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
+                                       loader.loadBytes(map.ruleset.images[ps.icon]);
+                               }
+                       }
+               }
+
+               private function loadedIcon(event:Event):void {
+map.addDebug("loadedIcon");
+                       var bitmap:Bitmap = Bitmap(event.target.content);
+                       var l:DisplayObject=map.getChildAt(11);
+                       bitmap.x=map.lon2coord(map.nodes[id].lon);
+                       bitmap.y=map.latp2coord(map.nodes[id].latp);
+                       Sprite(l).addChild(bitmap);
                }
                
                // redraw
diff --git a/net/systemeD/halcyon/styleparser/ImageLoader.as b/net/systemeD/halcyon/styleparser/ImageLoader.as
new file mode 100644 (file)
index 0000000..35ac41d
--- /dev/null
@@ -0,0 +1,9 @@
+package net.systemeD.halcyon.styleparser {
+
+       import flash.events.*;
+       import flash.net.*;
+
+       public class ImageLoader extends URLLoader {
+               public var filename:String;
+       }
+}
\ No newline at end of file
index 131f195..3e85a17 100644 (file)
@@ -3,10 +3,12 @@ package net.systemeD.halcyon.styleparser {
        import org.as3yaml.*;
        import flash.events.*;
        import flash.net.*;
+       import net.systemeD.halcyon.Globals;
 
        public class RuleSet {
 
                public var rules:Array=new Array();             // list of rules
+               public var images:Object=new Object();  // loaded images
 
                // variables for name, author etc.
 
@@ -19,8 +21,8 @@ package net.systemeD.halcyon.styleparser {
                        for each (var rule:* in rules) {
                                if ( isPoint && rule is ShapeRule) { continue; }
                                if (!isPoint && rule is PointRule) { continue; }
-                               if (scale>rule.minScale) { continue; }
-                               if (scale<rule.maxScale) { continue; }
+                               if (scale>rule.minScale && !isPoint) { continue; }
+                               if (scale<rule.maxScale && !isPoint) { continue; }
                                if (rule.test(tags)) {
                                        if (rule is ShapeRule && rule.shapeStyle)  { ss=rule.shapeStyle; }
                                        if (rule is PointRule && rule.pointStyle)  { ps=rule.pointStyle; }
@@ -76,7 +78,8 @@ package net.systemeD.halcyon.styleparser {
                private function loadedRuleSet(event:Event):void {
                        var loader:URLLoader = URLLoader(event.target);  
                        rules=YAML.decode(event.target.data) as Array;
-                       // fire some event or other to tell map to redraw
+                       // ** fire some event or other to tell map to redraw
+                       loadImages();
                }
 
                private function httpStatusHandler( event:HTTPStatusEvent ):void { }
@@ -84,5 +87,38 @@ package net.systemeD.halcyon.styleparser {
                private function ioErrorHandler( event:IOErrorEvent ):void { }
                
                // serialise/deserialise methods
+
+
+               // ------------------------------------------------------------------------------------------------
+               // Load all referenced images
+               // ** currently only looks in PointRules
+               // ** will duplicate if referenced twice, shouldn't
+               
+               public function loadImages():void {
+                       var ps:PointStyle;
+                       for each (var rule:* in rules) {
+                               if (!(rule is PointRule)) { continue; }
+                               if (!(rule.pointStyle)) { continue; }
+                               if (!(rule.pointStyle.icon)) { continue; }
+                               
+                               var request:URLRequest=new URLRequest(rule.pointStyle.icon);
+                               var loader:ImageLoader=new ImageLoader();
+                               loader.dataFormat=URLLoaderDataFormat.BINARY;
+                               loader.filename=rule.pointStyle.icon;
+                               loader.addEventListener(Event.COMPLETE,                                         loadedImage,                    false, 0, true);
+                               loader.addEventListener(HTTPStatusEvent.HTTP_STATUS,            httpStatusHandler,              false, 0, true);
+                               loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler,   false, 0, true);
+                               loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler,                 false, 0, true);
+                               loader.load(request);
+                       }
+               }
+
+               // data handler
+
+               private function loadedImage(event:Event):void {
+                       Globals.vars.debug.appendText("Target is "+event.target+", name"+event.target.filename+"\n");
+                       images[event.target.filename]=event.target.data;
+               }
+
        }
 }