bitmap fills FTW
authorRichard Fairhurst <richard@systemed.net>
Fri, 4 Sep 2009 16:36:18 +0000 (16:36 +0000)
committerRichard Fairhurst <richard@systemed.net>
Fri, 4 Sep 2009 16:36:18 +0000 (16:36 +0000)
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/styleparser/MapCSS.as
net/systemeD/halcyon/styleparser/ShapeStyle.as
resources/fills/grass.jpg [new file with mode: 0644]
resources/test.css

index 9d5e97e531b196a2cd9a702cb5bf91a166982175..4019008db211811aebd09f69e5ba44174fdf3015 100755 (executable)
@@ -116,58 +116,46 @@ package net.systemeD.halcyon {
 
                        // Iterate through each sublayer, drawing any styles on that layer
                        var sl:StyleList=map.ruleset.getStyles(this.way, tags);
-                       var drawn:Boolean=false;
+                       var drawn:Boolean;
                        for (var sublayer:uint=0; sublayer<11; sublayer++) {
                                if (sl.shapeStyles[sublayer]) {
                                        var s:ShapeStyle=sl.shapeStyles[sublayer];
-                                       var stroke:Shape, fill:Shape, roadname:Sprite, f:Graphics, g:Graphics;
+                                       var stroke:Shape, fill:Shape, roadname:Sprite, lower:Graphics, upper:Graphics;
+                                       var casedrawn:Boolean;
+                                       var x0:Number=map.lon2coord(way.getNode(0).lon);
+                                       var y0:Number=map.latp2coord(way.getNode(0).latp);
 
-                                       // Set stroke style
+                                       // Create stroke object
                                        if (s.width)  {
-                                               stroke=new Shape(); addToLayer(stroke,1,sublayer); g=stroke.graphics;
-                               g.moveTo(map.lon2coord(way.getNode(0).lon), map.latp2coord(way.getNode(0).latp));
-                                               g.lineStyle(s.width,
-                                                                       s.color ? s.color : 0,
-                                                                       s.opacity ? s.opacity : 1,
-                                                                       false, "normal",
-                                                                       s.linecap  ? s.linecap : "none",
-                                                                       s.linejoin ? s.linejoin : "round");
+                                               stroke=new Shape(); addToLayer(stroke,1,sublayer);
+                                               upper=stroke.graphics; upper.moveTo(x0,y0);
+                                               s.applyStrokeStyle(upper);
                                        }
 
                                        // Set fill and casing style
-                                       if (s.fill_color || s.casing_width) {
-                                               fill=new Shape(); addToLayer(fill,0); f=fill.graphics;
-                               f.moveTo(map.lon2coord(way.getNode(0).lon), map.latp2coord(way.getNode(0).latp));
-                                               if (s.casing_width)  {
-                                                       f.lineStyle(s.casing_width,
-                                                                               s.casing_color   ? s.casing_color : 0,
-                                                                               s.casing_opacity ? s.casing_opacity : 1,
-                                                                               false, "normal",
-                                                                               s.linecap  ? s.linecap : "none",
-                                                                               s.linejoin ? s.linejoin : "round");
-                                               }
-                                               if (s.fill_color) {
-                                                       f.beginFill(s.fill_color,
-                                                                               s.fill_opacity ? s.fill_opacity : 1);
-                                               }
+                                       if (s.fill_color || s.fill_image || s.casing_width) {
+                                               fill=new Shape(); addToLayer(fill,0);
+                                               lower=fill.graphics; lower.moveTo(x0,y0);
+                                               if (s.casing_width) { s.applyCasingStyle(lower); }
                                        }
 
-                                       // Draw stroke
-                                       if (s.dashes && s.dashes.length>0) {
-                                               dashedLine(g,s.dashes); drawn=true;
-                                       } else if (s.width) { 
-                                               solidLine(g); drawn=true;
-                                       }
-                       
-                                       // Draw fill and casing
+                                       // Draw stroke (dashed or solid)
+                                       if (s.dashes && s.dashes.length>0) { dashedLine(upper,s.dashes); drawn=true; }
+                                       else if (s.width) { solidLine(upper); drawn=true; }
+
+                                       // Draw dashed casing
                                        if (s.casing_dashes && s.casing_dashes.length>0) {
-                                               dashedLine(f,s.casing_dashes); f.lineStyle(); drawn=true;
+                                               dashedLine(lower,s.casing_dashes); lower.lineStyle(); drawn=true; casedrawn=true;
                                        }
-                                       if (s.fill_color) {
-                                               f.beginFill(s.fill_color,s.fill_opacity); 
-                                               solidLine(f); f.endFill(); drawn=true;
-                                       } else if (s.casing_width && (!s.casing_dashes || s.casing_dashes.length==0)) {
-                                               solidLine(f); drawn=true;
+
+                                       // Draw fill and solid casing
+                                       if (s.fill_image) {
+                                               new WayBitmapFiller(this,lower,s);
+                                       } else if (s.fill_color) {
+                                               s.applyFill(lower);
+                                               solidLine(lower); lower.endFill(); drawn=true;
+                                       } else if (s.casing_width && !casedrawn) {
+                                               solidLine(lower); drawn=true;
                                        }
 
 
@@ -252,7 +240,7 @@ package net.systemeD.halcyon {
 
                // Draw solid polyline
                
-               private function solidLine(g:Graphics):void {
+               public function solidLine(g:Graphics):void {
             var node:Node = way.getNode(0);
                        g.moveTo(map.lon2coord(node.lon), map.latp2coord(node.latp));
                        for (var i:uint = 1; i < way.length; i++) {
index 6babebda0aa3adbc58fd5a0260c46bc2cdc31a31..f4f142dcbedbd0322bcb6d7158b531e1f24fcc42 100755 (executable)
@@ -18,7 +18,7 @@ package net.systemeD.halcyon.styleparser {
                private var choosers:Array;
 
                private static const WHITESPACE:RegExp  =/^ \s+ /sx;
-               private static const COMMENT:RegExp             =/^ \/* .+? *\/ \s* /sx;        /* */
+               private static const COMMENT:RegExp             =/^ \/\* .+? \*\/ \s* /sx;      /* */
                private static const CLASS:RegExp               =/^ ([\.:]\w+) \s* /sx;
                private static const ZOOM:RegExp                =/^ \| \s* z([\d\-]+) \s* /isx;
                private static const GROUP:RegExp               =/^ , \s* /isx;
index 7df67b5ecc4625e9fde98a97a664111ee0942c8b..5efa7077bc0277ac564c452c5a40ea774d6d1377 100644 (file)
@@ -1,5 +1,7 @@
 package net.systemeD.halcyon.styleparser {
 
+       import flash.display.Graphics;
+       
        public class ShapeStyle extends Style {
 
                public var width:Number;
@@ -25,6 +27,29 @@ package net.systemeD.halcyon.styleparser {
                                'casing_width','casing_color','casing_opacity','casing_dashes'
                        ];
                }
+               
+               public function applyStrokeStyle(g:Graphics):void {
+                       g.lineStyle(width,
+                                               color ? color : 0,
+                                               opacity ? opacity : 1,
+                                               false, "normal",
+                                               linecap  ? linecap : "none",
+                                               linejoin ? linejoin : "round");
+               }
+               
+               public function applyCasingStyle(g:Graphics):void {
+                       g.lineStyle(casing_width,
+                                               casing_color   ? casing_color : 0,
+                                               casing_opacity ? casing_opacity : 1,
+                                               false, "normal",
+                                               linecap  ? linecap : "none",
+                                               linejoin ? linejoin : "round");
+               }
+               
+               public function applyFill(g:Graphics):void {
+                       g.beginFill(fill_color,
+                                               fill_opacity ? fill_opacity : 1);
+               }
        }
 
 }
diff --git a/resources/fills/grass.jpg b/resources/fills/grass.jpg
new file mode 100644 (file)
index 0000000..26dcd2f
Binary files /dev/null and b/resources/fills/grass.jpg differ
index 9d1ed6a5a4e8eeeed8115e92058770666f9f6593..a4ba5430c3eaaadba29aaea4a1bfc86351ecc4f1 100644 (file)
@@ -11,6 +11,9 @@ way .highlighted { color: pink; }
 way :hover     { z-index: 2; width: 8; color: gray; }
 way :selected { z-index: 2; width: 8; color: yellow; }
 
+way[leisure=pitch],way[leisure=park] { fill-image: fills/grass.jpg; }
+/* fill-color: forestgreen; */
+
 relation[type=route] way { z-index: 1; width: 17; color: blue; opacity: 0.4; }
 
 node[amenity=pub] { icon-image: icons/pub.png; font-family: DejaVu; text: name; font-size: 9; }