add rotation support and special _heading CSS variable
authorRichard Fairhurst <richard@systemed.net>
Sat, 17 Oct 2009 10:10:50 +0000 (10:10 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sat, 17 Oct 2009 10:10:50 +0000 (10:10 +0000)
net/systemeD/halcyon/POI.as
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/styleparser/PointStyle.as

index 32dfef0..fb52f6f 100644 (file)
@@ -6,6 +6,8 @@ package net.systemeD.halcyon {
        import flash.text.GridFitType;
        import flash.text.TextField;
        import flash.text.TextFormat;
+       import flash.geom.Matrix;
+       import flash.geom.Point;
     import net.systemeD.halcyon.connection.Node;
     import net.systemeD.halcyon.connection.Connection;
        import net.systemeD.halcyon.styleparser.*;
@@ -17,6 +19,8 @@ package net.systemeD.halcyon {
                public var icon:Sprite;                                         // instance in display list
                public var name:Sprite;                                         //  |
                private var iconname:String='';                         // name of icon
+               private var heading:Number=0;                           // heading within way
+               private var rotation:Number=0;                          // rotation applied to this POI
                public var loaded:Boolean=false;
 
                public static const DEFAULT_TEXTFIELD_PARAMS:Object = {
@@ -27,9 +31,10 @@ 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, sl:StyleList=null) {
+               public function POI(node:Node, map:Map, sl:StyleList=null, rotation:Number=0) {
                        this.map = map;
                        this.node = node;
+                       this.rotation = rotation;
                        redraw(sl);
                        node.addEventListener(Connection.NODE_MOVED, nodeMoved);
                }
@@ -40,6 +45,7 @@ package net.systemeD.halcyon {
                
                public function redraw(sl:StyleList=null):Boolean {
                        var tags:Object = node.getTagsCopy();
+                       tags['_heading']=heading;
                        // ** apply :hover etc.
                        if (!sl) { sl=map.ruleset.getStyles(this.node,tags); }
                        if (!sl.hasStyles() && iconname=='') { return false; }
@@ -51,6 +57,7 @@ package net.systemeD.halcyon {
                                if (sl.pointStyles[sublayer]) {
                                        var s:PointStyle=sl.pointStyles[sublayer];
                                        r=true;
+                                       if (s.rotation) { rotation=s.rotation; }
                                        if (s.icon_image!=iconname) {
                                                // 'load' icon (actually just from library)
                                                if (map.ruleset.images[s.icon_image]) {
@@ -116,8 +123,14 @@ package net.systemeD.halcyon {
 
                private function updatePosition():void {
                        if (!loaded) { return; }
-                       icon.x=map.lon2coord(node.lon)-icon.width/2;
-                       icon.y=map.latp2coord(node.latp)-icon.height/2;
+                       icon.x=0; icon.y=0; icon.rotation=0;
+
+                       var m:Matrix=new Matrix();
+//                     m.identity();
+                       m.translate(-icon.width/2,-icon.height/2);
+                       m.rotate(rotation);
+                       m.translate(map.lon2coord(node.lon),map.latp2coord(node.latp));
+                       icon.transform.matrix=m;
                }
 
        }
index bc5c165..2647ae6 100755 (executable)
@@ -22,6 +22,7 @@ package net.systemeD.halcyon {
                public var layer:int=0;                                         // map layer
                public var map:Map;                                                     // reference to parent map
                public var sprites:Array=new Array();           // instances in display list
+               public var heading:Array=new Array();           // angle at each node
                private var stateClasses:Object = new Object();
         private var hitzone:Sprite;
         private var listenSprite:Sprite;
@@ -87,6 +88,7 @@ package net.systemeD.halcyon {
                
                public function recalculate():void {
                        var lx:Number, ly:Number, sc:Number;
+                       var node:Node, latp:Number, lon:Number;
                        var cx:Number=0, cy:Number=0;
                        pathlength=0;
                        patharea=0;
@@ -94,16 +96,23 @@ package net.systemeD.halcyon {
                        lx = way.getNode(way.length-1).lon;
                        ly = way.getNode(way.length-1).latp;
                        for ( var i:uint = 0; i < way.length; i++ ) {
-                var node:Node = way.getNode(i);
-                var latp:Number = node.latp;
-                var lon:Number  = node.lon;
+                node = way.getNode(i);
+                latp = node.latp;
+                lon  = node.lon;
+
+                               // length and area
                                if ( i>0 ) { pathlength += Math.sqrt( Math.pow(lon-lx,2)+Math.pow(latp-ly,2) ); }
                                sc = (lx*latp-lon*ly)*map.scalefactor;
                                cx += (lx+lon)*sc;
                                cy += (ly+latp)*sc;
                                patharea += sc;
+                               
+                               // heading
+                               if (i>0) { heading[i-1]=Math.atan2((lon-lx),(latp-ly)); }
+
                                lx=lon; ly=latp;
                        }
+                       heading[way.length-1]=heading[way.length-2];
 
                        pathlength*=map.scalefactor;
                        patharea/=2;
@@ -200,6 +209,7 @@ package net.systemeD.halcyon {
                        }
 
                        // ** draw icons
+                       var r:Number;
                        for (var i:uint = 0; i < way.length; i++) {
                 var node:Node = way.getNode(i);
                    if (map.pois[node.id]) {
@@ -209,7 +219,9 @@ package net.systemeD.halcyon {
                                } else if (node.hasTags()) {
                                        sl=map.ruleset.getStyles(node,node.getTagsHash());
                                        if (sl.hasStyles()) {
-                                               map.pois[node.id]=new POI(node,map,sl);
+                                               if (i==0) { r= heading[i]; }
+                                                    else { r=(heading[i]+heading[i-1])/2; }
+                                               map.pois[node.id]=new POI(node,map,sl,r);
                                                // ** 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)
index e79916b..e426bdb 100644 (file)
@@ -5,10 +5,11 @@ package net.systemeD.halcyon.styleparser {
                public var icon_image:String;
                public var icon_width:uint;
                public var icon_height:uint;
+               public var rotation:Number;
 
                override public function get properties():Array {
                        return [
-                               'icon_image','icon_width','icon_height'
+                               'icon_image','icon_width','icon_height','rotation'
                        ];
                }
        }