one-way arrows
authorRichard Fairhurst <richard@systemed.net>
Sun, 28 Mar 2010 23:27:17 +0000 (23:27 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sun, 28 Mar 2010 23:27:17 +0000 (23:27 +0000)
TODO.txt
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/styleparser/ShapeStyle.as
resources/potlatch.css

index 87ca3b0be3fe640604c22423de4d021ed1cccc17..99b2d7d03a80f11a935899e3bd97ec1f6fb9f0b9 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -55,7 +55,7 @@ Potlatch 2: main outstanding issues
 == Rendering (Halcyon) ==
 
 * Shields
-* Arrows (dash-style or something) for oneway et al
+* More line decoration (cliffs etc.), and implied values for 'dashes' if not supplied
 * Complete MapCSS support
 * Don't redraw stuff that's offscreen
 * 'Light' version without vectorlayer support etc.
index 59b8a41d55d3ab8ae86c9af6d11999f29a757821..ab69170ceedf2aa86bc8b27c827690ec295035f5 100755 (executable)
@@ -173,8 +173,10 @@ package net.systemeD.halcyon {
                                                stroke=new Shape(); addToLayer(stroke,STROKESPRITE,sublayer);
                                                stroke.graphics.moveTo(x0,y0);
                                                s.applyStrokeStyle(stroke.graphics);
-                                               if (s.dashes && s.dashes.length>0) { dashedLine(stroke.graphics,s.dashes); }
-                                                                                                         else { solidLine(stroke.graphics); }
+                                               if (s.dashes && s.dashes.length>0) {
+                                                       var segments:Array=dashedLine(stroke.graphics,s.dashes); 
+                                                       if (s.line_style) { lineDecoration(stroke.graphics,s,segments); }
+                                               } else { solidLine(stroke.graphics); }
                                                drawn=true;
                                        }
 
@@ -275,7 +277,8 @@ package net.systemeD.halcyon {
 
                // Draw dashed polyline
                
-               private function dashedLine(g:Graphics,dashes:Array):void {
+               private function dashedLine(g:Graphics,dashes:Array):Array {
+                       var segments:Array=[];
                        var draw:Boolean=false, dashleft:Number=0, dc:Array=new Array();
                        var a:Number, xc:Number, yc:Number;
                        var curx:Number, cury:Number;
@@ -289,6 +292,7 @@ package net.systemeD.halcyon {
                                if (dashleft<=0) {      // should be ==0
                                        if (dc.length==0) { dc=dashes.slice(0); }
                                        dashleft=dc.shift();
+                                       if (draw) { segments.push([curx,cury,dx,dy]); }
                                        draw=!draw;
                                }
                                if (segleft<=0) {       // should be ==0
@@ -316,6 +320,7 @@ package net.systemeD.halcyon {
                                        segleft-=dashleft; dashleft=0;
                                }
                        }
+                       return segments;
                }
 
                private function moveLine(g:Graphics,x:Number,y:Number,draw:Boolean):void {
@@ -323,6 +328,34 @@ package net.systemeD.halcyon {
                                 else { g.moveTo(x,y); }
                }
 
+               // Draw decoration (arrows etc.)
+               
+               private function lineDecoration(g:Graphics,s:ShapeStyle,segments:Array):void {
+                       var c:int=s.color ? s.color : 0;
+                       switch (s.line_style.toLowerCase()) {
+
+                               case 'arrows':
+                                       var w:Number=s.width*1.5;       // width of arrow
+                                       var l:Number=s.width*2;         // length of arrow
+                                       var angle0:Number, angle1:Number, angle2:Number;
+                                       g.lineStyle(1,c);
+                                       for each (var seg:Array in segments) {
+                                               g.beginFill(c);
+                                               angle0= Math.atan2(seg[3],seg[2]);
+                                               angle1=-Math.atan2(seg[3],seg[2]);
+                                               angle2=-Math.atan2(seg[3],seg[2])-Math.PI;
+                                               g.moveTo(seg[0]+l*Math.cos(angle0),
+                                                        seg[1]+l*Math.sin(angle0));
+                                               g.lineTo(seg[0]+w*Math.sin(angle1),
+                                                        seg[1]+w*Math.cos(angle1));
+                                               g.lineTo(seg[0]+w*Math.sin(angle2),
+                                                        seg[1]+w*Math.cos(angle2));
+                                               g.endFill();
+                                       }
+                                       break;
+                               }
+               }
+
                
                // Find point partway (0-1) along a path
                // returns (x,y,angle)
index dad6d4f9e26645501c9d233df0a29183c79cc459..fe83ea1e2cd16f36be5016355a5c24ea6319d2bb 100644 (file)
@@ -10,6 +10,7 @@ package net.systemeD.halcyon.styleparser {
                public var dashes:Array=[];
                public var linecap:String;
                public var linejoin:String;
+               public var line_style:String;
                
                public var fill_color:Number;
                public var fill_opacity:Number;
@@ -22,7 +23,7 @@ package net.systemeD.halcyon.styleparser {
                
                override public function get properties():Array {
                        return [
-                               'width','color','opacity','dashes','linecap','linejoin',
+                               'width','color','opacity','dashes','linecap','linejoin','line_style',
                                'fill_color','fill_opacity','fill_image',
                                'casing_width','casing_color','casing_opacity','casing_dashes'
                        ];
@@ -54,6 +55,7 @@ package net.systemeD.halcyon.styleparser {
                        g.beginFill(fill_color,
                                                fill_opacity ? fill_opacity : 1);
                }
+               
        }
 
 }
index 296f1ad975cc4c0e4bd328586af33148dbf2a03f..abd144b1a0a860de524fece53b85b5d8160f6b10 100644 (file)
@@ -122,6 +122,10 @@ way[tunnel=yes]
     { z-index: 4; color: white; width: eval('_width+2'); }
     { z-index: 3; color: black; width: eval('_width+6'); dashes: 4,4; }
 
+/* Oneway */
+way[oneway=yes] { z-index: 10; color: #444444; width: 3; dashes: 15,25; line-style: arrows; }
+
+
 /* Change the road colour based on dynamically set "highlighted" tag (see earlier) */
 
 way .highlighted { color: pink; }