POIs, and relations, and stuff :)
authorRichard Fairhurst <richard@systemed.net>
Fri, 4 Sep 2009 13:50:53 +0000 (13:50 +0000)
committerRichard Fairhurst <richard@systemed.net>
Fri, 4 Sep 2009 13:50:53 +0000 (13:50 +0000)
21 files changed:
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/POI.as
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/connection/AMFConnection.as
net/systemeD/halcyon/connection/AMFCounter.as [new file with mode: 0644]
net/systemeD/halcyon/connection/Changeset.as
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/connection/Node.as
net/systemeD/halcyon/connection/Relation.as
net/systemeD/halcyon/connection/Way.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/halcyon/styleparser/InstructionStyle.as
net/systemeD/halcyon/styleparser/MapCSS.as
net/systemeD/halcyon/styleparser/Rule.as
net/systemeD/halcyon/styleparser/RuleSet.as
net/systemeD/halcyon/styleparser/ShapeStyle.as
net/systemeD/halcyon/styleparser/Style.as
net/systemeD/halcyon/styleparser/StyleChooser.as
net/systemeD/halcyon/styleparser/TextStyle.as
resources/test.css

index 43ce446..3cb31aa 100755 (executable)
@@ -232,6 +232,7 @@ package net.systemeD.halcyon {
 
         private function newWayCreated(event:EntityEvent):void {
             var way:Way = event.entity as Way;
+                       if (!way.loaded) { return; }
             ways[way.id] = new WayUI(way, this);
         }
 
index 2a39c71..92f2303 100644 (file)
@@ -33,7 +33,8 @@ package net.systemeD.halcyon {
                
                public function redraw():void {
                        var tags:Object = node.getTagsCopy();
-                       var sl:StyleList=map.ruleset.getStyles(this.node,map.scale);
+                       // ** apply :hover etc.
+                       var sl:StyleList=map.ruleset.getStyles(this.node,tags);
                        var r:Boolean=false;    // ** rendered
                        for (var sublayer:uint=0; sublayer<10; sublayer++) {
 
index 3a3c530..9d5e97e 100755 (executable)
@@ -119,7 +119,6 @@ package net.systemeD.halcyon {
                        var drawn:Boolean=false;
                        for (var sublayer:uint=0; sublayer<11; sublayer++) {
                                if (sl.shapeStyles[sublayer]) {
-Globals.vars.root.addDebug("adding shapestyle on "+sublayer); 
                                        var s:ShapeStyle=sl.shapeStyles[sublayer];
                                        var stroke:Shape, fill:Shape, roadname:Sprite, f:Graphics, g:Graphics;
 
@@ -178,15 +177,16 @@ Globals.vars.root.addDebug("adding shapestyle on "+sublayer);
                                        var t:TextStyle=sl.textStyles[sublayer];
                                        roadname=new Sprite(); addToLayer(roadname,2);
                                        nameformat = t.getTextFormat();
-                                       var a:String=tags[t.text]; if (t.font_caps) { a=a.toUpperCase(); }
-                                       if (t.text_onpath) {
-                                               writeNameOnPath(roadname,a,t.text_offset ? t.text_offset : 0);
+                                       var a:String=tags[t.text];
+                                       if (a) {
+                                               if (t.font_caps) { a=a.toUpperCase(); }
+                                               if (t.text_center && centroid_x) {
+                                                       t.writeNameLabel(roadname,tags[t.text],centroid_x,centroid_y);
+                                               } else {
+                                                       writeNameOnPath(roadname,a,t.text_offset ? t.text_offset : 0);
+                                               }
                                                if (t.text_halo_radius>0) { roadname.filters=t.getHaloFilter(); }
-                                       } else if (centroid_x) {
-                                               t.writeNameLabel(roadname,tags[t.text],centroid_x,centroid_y);
                                        }
-
-
                                }
                                
                                // ** ShieldStyle to do
index 0f75959..da4c4e8 100755 (executable)
@@ -13,6 +13,9 @@ package net.systemeD.halcyon.connection {
                public var writeConnection:NetConnection;
                private var mapLoader:URLLoader;
 
+               private var eventTarget:AMFCounter;
+               private var bboxrequests:Array=new Array();
+
                // ------------------------------------------------------------
                // Constructor for new AMFConnection
 
@@ -39,9 +42,13 @@ package net.systemeD.halcyon.connection {
                                                                top:Number,bottom:Number):void {
                        readConnection.call("whichways",new Responder(gotBbox, error),left,bottom,right,top);
                }
+               
+               override public function sendEvent(e:*):void {
+                       eventTarget.addEvent(e);
+               }
 
         private function gotBbox(r:Object):void {
-                       var code:uint         =r.shift();
+                       var code:uint=r.shift();
             if (code) {
                 error(new Array(r.shift()));
                 return;
@@ -52,6 +59,21 @@ package net.systemeD.halcyon.connection {
                        var pointlist:Array   =r[1];
                        var relationlist:Array=r[2];
                        var id:Number, version:uint;
+                       var requests:AMFCounter=new AMFCounter(this);
+                       eventTarget=requests;
+
+                       // Load relations
+
+                       for each (var a:Array in relationlist) {
+                               id=Number(a[0]);
+                version=uint(a[1]);
+
+                var relation:Relation = getRelation(id);
+                if ( relation == null || !relation.loaded  ) {
+                    loadRelation(id);
+                                       requests.addRelationRequest(id);
+                }
+                       }
 
                        // Load ways
 
@@ -60,8 +82,9 @@ package net.systemeD.halcyon.connection {
                 version=uint(w[1]);
 
                 var way:Way = getWay(id);
-                if ( way == null ) {
+                if ( way == null || !way.loaded ) {
                     loadWay(id);
+                                       requests.addWayRequest(id);
                 }
                        }
 
@@ -72,15 +95,17 @@ package net.systemeD.halcyon.connection {
                 version = uint(p[4]);
 
                 var node:Node = getNode(id);
-                if ( node == null ) {
+                if ( node == null || !node.loaded ) {
                     var lat:Number = Number(p[2]);
                     var lon:Number = Number(p[1]);
                     var tags:Object = p[3];
-                    node = new Node(id, version, tags, lat, lon);
+                    node = new Node(id, version, tags, true, lat, lon);
                     setNode(node);
                 }
                 registerPOI(node);
                        }
+
+                       bboxrequests.push(requests);
         }
 
         private function error(r:Object):void {}
@@ -101,8 +126,10 @@ package net.systemeD.halcyon.connection {
                        var version:uint = uint(r[3]);
 
             var way:Way = getWay(id);
-            if ( way != null )
+            if ( way != null && way.loaded ) {
+                               gotRequest(id+"way");
                 return;
+                       }
 
             var nodesAMF:Array = r[1];
                        var tags:Object = r[2];
@@ -117,15 +144,82 @@ package net.systemeD.halcyon.connection {
                     var lon:Number = Number(p[0]);
                     var lat:Number = Number(p[1]);
                     var nodeTags:Object = p[3];
-                    node = new Node(nodeID, nodeVersion, nodeTags, lat, lon);
+                    node = new Node(nodeID, nodeVersion, nodeTags, true, lat, lon);
                     setNode(node);
-                }
+                } else if (!node.loaded) {
+                                       node.update(nodeVersion, nodeTags, true, lat, lon);
+                               }
                 nodes.push(node);
                        }
 
-            way = new Way(id, version, tags, nodes);
-            setWay(way);
+                       if (way==null) {
+               way = new Way(id, version, tags, true, nodes);
+               setWay(way);
+                       } else {
+                               way.update(version, tags, true, nodes);
+                       }
+                       gotRequest(id+"way");
+               }
+
+
+               private function loadRelation(id:uint):void {
+                       readConnection.call("getrelation",new Responder(gotRelation, error),id);
                }
 
+               private function gotRelation(r:Object):void {
+                       var code:uint = r.shift();
+            if (code) { error(new Array(r.shift())); return; }
+                       var message:String=r.shift();
+
+            var id:Number = Number(r[0]);
+                       var version:uint = uint(r[3]);
+
+            var relation:Relation = getRelation(id);
+            if ( relation != null && relation.loaded ) {
+                               gotRequest(id+"rel");
+                               return;
+                       }
+
+                       var tags:Object = r[1];
+            var membersAMF:Array = r[2];
+                       var members:Array = [];
+                       for each (var p:Array in membersAMF) {
+                               var type:String=p[0];
+                               var memid:Number=p[1];
+                               var role:String=p[2];
+                               var e:Entity;
+                               switch (type) {
+                                       case 'Node':
+                                               e=getNode(memid);
+                                               if (e==null) { e=new Node(memid,0,{},false,0,0); setNode(Node(e)); }
+                                               break;
+                                       case 'Way':
+                                               e=getWay(memid);
+                                               if (e==null) { e=new Way(memid,0,{},false,[]); setWay(Way(e)); }
+                                               break;
+                                       case 'Relation':
+                                               e=getRelation(memid);
+                                               if (e==null) { e=new Relation(memid,0,{},false,[]); setRelation(Relation(e)); }
+                                               break;
+                               }
+                               members.push(new RelationMember(e,role));
+                       }
+                       if (relation==null) {
+                   relation = new Relation(id, version, tags, true, members);
+                   setRelation(relation);
+                       } else {
+                               relation.update(version,tags,true,members);
+                       }
+                       gotRequest(id+"rel");
+               }
+               
+               private function gotRequest(n:String):void {
+                       for each (var c:AMFCounter in bboxrequests) {
+                               if (c.removeRequest(n)) { break; }
+                       }
+                       while (bboxrequests.length>0 && bboxrequests[0].count==0) {
+                               bboxrequests.shift();
+                       }
+               }
        }
 }
diff --git a/net/systemeD/halcyon/connection/AMFCounter.as b/net/systemeD/halcyon/connection/AMFCounter.as
new file mode 100644 (file)
index 0000000..5106e95
--- /dev/null
@@ -0,0 +1,50 @@
+package net.systemeD.halcyon.connection {
+
+    import flash.events.EventDispatcher;
+    import flash.events.Event;
+       
+       public class AMFCounter extends EventDispatcher {
+               private var requests:Object;
+               public var count:uint;
+               public var eventList:Array;
+               private var connection:Connection;
+               
+               public function AMFCounter(conn:Connection) {
+                       requests={};
+                       count=0;
+                       eventList=[];
+                       connection=conn;
+               }
+               
+               public function addEvent(e:*):void {
+                       eventList.push(e);
+               }
+               
+               public function addRelationRequest(id:uint):void {
+                       addRequest(id+"rel");
+               }
+               public function addWayRequest(id:uint):void {
+                       addRequest(id+"way");
+               }
+               private function addRequest(n:String):Boolean {
+                       if (requests[n]) { return false; }
+                       requests[n]=true;
+                       count++;
+                       return true;
+               }
+               
+               public function removeRequest(n:String):Boolean {
+                       if (!requests[n]) { return false; }
+                       delete requests[n];
+                       count--; if (count==0) { sendEvents(); }
+                       return true;
+               }
+               
+               private function sendEvents():void {
+                       for each (var e:* in eventList) {
+                               connection.dispatchEvent(e);
+                       }
+                       this.eventList=[];
+               }
+       }
+}
\ No newline at end of file
index 29fc4b9..b82f6f8 100644 (file)
@@ -5,7 +5,7 @@ package net.systemeD.halcyon.connection {
                public static var entity_type:String = 'changeset';
 
         public function Changeset(id:Number, tags:Object) {
-            super(id, 0, tags);
+            super(id, 0, tags, true);
         }
 
         public override function toString():String {
index be31ca0..34c6943 100755 (executable)
@@ -76,23 +76,27 @@ package net.systemeD.halcyon.connection {
 
         protected function setNode(node:Node):void {
             nodes[node.id] = node;
-            dispatchEvent(new EntityEvent(NEW_NODE, node));
+            sendEvent(new EntityEvent(NEW_NODE, node));
         }
 
         protected function setWay(way:Way):void {
             ways[way.id] = way;
-            dispatchEvent(new EntityEvent(NEW_WAY, way));
+            sendEvent(new EntityEvent(NEW_WAY, way));
         }
 
         protected function setRelation(relation:Relation):void {
             relations[relation.id] = relation;
-            dispatchEvent(new EntityEvent(NEW_RELATION, relation));
+            sendEvent(new EntityEvent(NEW_RELATION, relation));
         }
 
+               public function sendEvent(e:*):void {
+                       dispatchEvent(e);
+               }
+
         protected function registerPOI(node:Node):void {
             if ( pois.indexOf(node) < 0 ) {
                 pois.push(node);
-                dispatchEvent(new EntityEvent(NEW_POI, node));
+                sendEvent(new EntityEvent(NEW_POI, node));
             }
         }
 
@@ -105,7 +109,7 @@ package net.systemeD.halcyon.connection {
 
         protected function setActiveChangeset(changeset:Changeset):void {
             this.changeset = changeset;
-            dispatchEvent(new EntityEvent(NEW_CHANGESET, changeset));
+            sendEvent(new EntityEvent(NEW_CHANGESET, changeset));
         }
         
         public function getNode(id:Number):Node {
@@ -121,19 +125,19 @@ package net.systemeD.halcyon.connection {
         }
 
         public function createNode(tags:Object, lat:Number, lon:Number):Node {
-            var node:Node = new Node(nextNegative, 0, tags, lat, lon);
+            var node:Node = new Node(nextNegative, 0, tags, true, lat, lon);
             setNode(node);
             return node;
         }
 
         public function createWay(tags:Object, nodes:Array):Way {
-            var way:Way = new Way(nextNegative, 0, tags, nodes.concat());
+            var way:Way = new Way(nextNegative, 0, tags, true, nodes.concat());
             setWay(way);
             return way;
         }
 
         public function createRelation(tags:Object, members:Array):Relation {
-            var relation:Relation = new Relation(nextNegative, 0, tags, members.concat());
+            var relation:Relation = new Relation(nextNegative, 0, tags, true, members.concat());
             setRelation(relation);
             return relation;
         }
index 7e5e8a6..1e77bd0 100644 (file)
@@ -8,12 +8,14 @@ package net.systemeD.halcyon.connection {
         private var _version:uint;
         private var tags:Object = {};
         private var modified:Boolean = false;
+               private var _loaded:Boolean = true;
                private var parents:Dictionary = new Dictionary();
 
-        public function Entity(id:Number, version:uint, tags:Object) {
+        public function Entity(id:Number, version:uint, tags:Object, loaded:Boolean) {
             this._id = id;
             this._version = version;
             this.tags = tags;
+                       this._loaded = loaded;
             modified = id < 0;
         }
 
@@ -25,6 +27,14 @@ package net.systemeD.halcyon.connection {
             return _version;
         }
 
+        public function get loaded():Boolean {
+            return _loaded;
+        }
+
+               public function updateEntityProperties(v:uint,t:Object,l:Boolean):void {
+                       _version=v; tags=t; _loaded=l;
+               }
+
                // Tag-handling methods
 
         public function hasTags():Boolean {
index b8aceb0..de78065 100644 (file)
@@ -5,12 +5,16 @@ package net.systemeD.halcyon.connection {
         private var _latproj:Number;
         private var _lon:Number;
 
-        public function Node(id:Number, version:uint, tags:Object, lat:Number, lon:Number) {
-            super(id, version, tags);
+        public function Node(id:Number, version:uint, tags:Object, loaded:Boolean, lat:Number, lon:Number) {
+            super(id, version, tags, loaded);
             this.lat = lat;
             this.lon = lon;
         }
 
+               public function update(version:uint, tags:Object, loaded:Boolean, lat:Number, lon:Number):void {
+                       updateEntityProperties(version,tags,loaded); this.lat=lat; this.lon=lon;
+               }
+
         public function get lat():Number {
             return _lat;
         }
index 475a95e..5739750 100644 (file)
@@ -4,12 +4,19 @@ package net.systemeD.halcyon.connection {
         private var members:Array;
                public static var entity_type:String = 'relation';
 
-        public function Relation(id:Number, version:uint, tags:Object, members:Array) {
-            super(id, version, tags);
+        public function Relation(id:Number, version:uint, tags:Object, loaded:Boolean, members:Array) {
+            super(id, version, tags, loaded);
             this.members = members;
                        for each (var member:RelationMember in members) { member.entity.addParent(this); }
         }
 
+        public function update(version:uint, tags:Object, loaded:Boolean, members:Array):void {
+                       var member:RelationMember;
+                       for each (member in this.members) { member.entity.removeParent(this); }
+                       updateEntityProperties(version,tags,loaded); this.members=members;
+                       for each (member in members) { member.entity.addParent(this); }
+               }
+               
         public function get length():uint {
             return members.length;
         }
index 56dad5f..69c62ee 100644 (file)
@@ -4,12 +4,19 @@ package net.systemeD.halcyon.connection {
         private var nodes:Array;
                public static var entity_type:String = 'way';
 
-        public function Way(id:Number, version:uint, tags:Object, nodes:Array) {
-            super(id, version, tags);
+        public function Way(id:Number, version:uint, tags:Object, loaded:Boolean, nodes:Array) {
+            super(id, version, tags, loaded);
             this.nodes = nodes;
                        for each (var node:Node in nodes) { node.addParent(this); }
         }
 
+               public function update(version:uint, tags:Object, loaded:Boolean, nodes:Array):void {
+                       var node:Node;
+                       for each (node in this.nodes) { node.removeParent(this); }
+                       updateEntityProperties(version,tags,loaded); this.nodes=nodes;
+                       for each (node in nodes) { node.addParent(this); }
+               }
+
         public function get length():uint {
             return nodes.length;
         }
index 9fd6d05..08c3d8e 100644 (file)
@@ -60,7 +60,7 @@ package net.systemeD.halcyon.connection {
                     var lat:Number = Number(nodeData.@lat);
                     var lon:Number = Number(nodeData.@lon);
                     tags = parseTags(nodeData.tag);
-                    setNode(new Node(id, version, tags, lat, lon));
+                    setNode(new Node(id, version, tags, true, lat, lon));
                 }
             }
 
@@ -74,7 +74,7 @@ package net.systemeD.halcyon.connection {
                     for each(var nd:XML in data.nd)
                         nodes.push(getNode(Number(nd.@ref)));
                     tags = parseTags(data.tag);
-                    setWay(new Way(id, version, tags, nodes));
+                    setWay(new Way(id, version, tags,true,  nodes));
                 }
             }
         }
index d73b43f..1dec03e 100755 (executable)
@@ -1,7 +1,5 @@
 package net.systemeD.halcyon.styleparser {
 
-       import net.systemeD.halcyon.Globals;
-
        public class InstructionStyle extends Style {
 
                public var set_tags:Object;
@@ -11,7 +9,6 @@ package net.systemeD.halcyon.styleparser {
                        edited=true;
                        if (!set_tags) { set_tags=new Object(); }
                        set_tags[k]=v;
-                       Globals.vars.root.addDebug("set "+k+" to "+v);
                }
 
        }
index 5eb6da5..6babebd 100755 (executable)
@@ -60,8 +60,9 @@ package net.systemeD.halcyon.styleparser {
                private static const BOLD:RegExp=/^bold$/i;
                private static const ITALIC:RegExp=/^italic|oblique$/i;
                private static const CAPS:RegExp=/^uppercase$/i;
-               private static const LINE:RegExp=/^line$/i;
+               private static const CENTER:RegExp=/^center$/i;
 
+               private static const HEX:RegExp=/^#([0-9a-f]+)$/i;
                private static const CSSCOLORS:Object = {
                        aliceblue:0xf0f8ff,
                        antiquewhite:0xfaebd7,
@@ -232,7 +233,6 @@ package net.systemeD.halcyon.styleparser {
                                        css=css.replace(CLASS,'');
                                        sc.addCondition(new Condition('set',o[1]));
                                        previous=oCONDITION;
-                                       Globals.vars.root.addDebug("class: "+o[1]);
 
                                // Zoom
                                } else if ((o=ZOOM.exec(css))) {
@@ -241,14 +241,12 @@ package net.systemeD.halcyon.styleparser {
                                        css=css.replace(ZOOM,'');
                                        var z:Array=parseZoom(o[1]);
                                        sc.addZoom(z[0],z[1]);
-                                       Globals.vars.root.addDebug("zoom: "+o[1]+"->"+parseZoom(o[1]));
                                        previous=oZOOM;
 
                                // Grouping - just a comma
                                } else if ((o=GROUP.exec(css))) {
                                        css=css.replace(GROUP,'');
                                        sc.newGroup();
-                                       Globals.vars.root.addDebug("group");
                                        previous=oGROUP;
 
                                // Condition - [highway=primary]
@@ -258,7 +256,6 @@ package net.systemeD.halcyon.styleparser {
 
                                        css=css.replace(CONDITION,'');
                                        sc.addCondition(parseCondition(o[1]) as Condition);
-                                       Globals.vars.root.addDebug("condition: "+o[1]+'->'+parseCondition(o[1]));
                                        previous=oCONDITION;
 
                                // Object - way, node, relation
@@ -267,13 +264,11 @@ package net.systemeD.halcyon.styleparser {
 
                                        css=css.replace(OBJECT,'');
                                        sc.newObject(o[1]);
-                                       Globals.vars.root.addDebug("object: "+o[1]);
                                        previous=oOBJECT;
 
                                // Declaration - {...}
                                } else if ((o=DECLARATION.exec(css))) {
                                        css=css.replace(DECLARATION,'');
-                                       Globals.vars.root.addDebug("declaration: "+o[1]);
                                        sc.addStyles(parseDeclaration(o[1]));
                                        previous=oDECLARATION;
                                
@@ -293,14 +288,12 @@ package net.systemeD.halcyon.styleparser {
                }
                
                private function saveChooser(sc:StyleChooser):void {
-Globals.vars.root.addDebug("+ saveChooser [rc="+sc.ruleChains[0][0]+"]");
                        choosers.push(sc);
                };
 
                // Parse declaration string into list of styles
 
                private function parseDeclaration(s:String):Array {
-                       Globals.vars.root.addDebug("entering parseDeclaration with "+s); 
                        var styles:Array=[];
                        var t:Object=new Object();
                        var o:Object=new Object();
@@ -319,7 +312,6 @@ Globals.vars.root.addDebug("+ saveChooser [rc="+sc.ruleChains[0][0]+"]");
                                else if ((o=SET_TAG_TRUE.exec(a))) { xs.addSetTag(o[1],true); }
                                else if ((o=EXIT.exec(a))) { xs.setPropertyFromString('breaker',true); }
                        }
-if (xs.edited) { Globals.vars.root.addDebug("xs.set_tags is *"+xs.set_tags+"*");  }
 
                        // Find sublayer
                        var sub:uint=5;
@@ -328,10 +320,13 @@ if (xs.edited) { Globals.vars.root.addDebug("xs.set_tags is *"+xs.set_tags+"*");
                        xs.sublayer=10;
 
                        // Munge special values
-                       if (t['font_weight']   ) { if (t['font_weight'].match(BOLD)   ) { t['font_bold']=true;   } else { t['font_bold']=false;   } }
-                       if (t['font_style']    ) { if (t['font_style'].match(ITALIC)  ) { t['font_italic']=true; } else { t['font_italic']=false; } }
-                       if (t['text_transform']) { if (t['text_transform'].match(CAPS)) { t['font_caps']=true;   } else { t['font_caps']=false;   } }
-                       if (t['text_position'] ) { if (t['text_position'].match(LINE) ) { t['text_onpath']=true; } else { t['text_onpath']=false; } }
+                       if (t['font_weight']   ) { t['font_bold'  ] = t['font_weight'  ].match(BOLD  ) ? true : false; }
+                       if (t['font_style']    ) { t['font_italic'] = t['font_style'   ].match(ITALIC) ? true : false; }
+                       if (t['text_position'] ) { t['text_center'] = t['text_position'].match(CENTER) ? true : false; }
+                       if (t['text_transform']) {
+                               // ** needs other transformations, e.g. lower-case, sentence-case
+                               if (t['text_transform'].match(CAPS)) { t['font_caps']=true; } else { t['font_caps']=false; }
+                       }
 
                        // ** Do compound settings (e.g. line: 5px dotted blue;)
 
@@ -339,20 +334,21 @@ if (xs.edited) { Globals.vars.root.addDebug("xs.set_tags is *"+xs.set_tags+"*");
                        for (a in t) {
                                // Parse properties
                                // ** also do units, e.g. px/pt
-                               // ** convert # colours to 0x numbers
-Globals.vars.root.addDebug("looking at property *"+a+"*"); 
-                               if (a.match(COLOR) && CSSCOLORS[t[a].toLowerCase()]) { t[a]=CSSCOLORS[t[a].toLowerCase()]; }
+                               if (a.match(COLOR)) {
+                                       if (CSSCOLORS[t[a].toLowerCase()]) { t[a]=CSSCOLORS[t[a].toLowerCase()]; }
+                                       else if ((o=HEX.exec(t[a]))) { t[a]=Number("0x"+o[1]); }
+                               }
                                
                                // Set in styles
-                               if      (ss.hasOwnProperty(a)) { ss.setPropertyFromString(a,t[a]); Globals.vars.root.addDebug("added "+a+" to ShapeStyle"); }
-                               else if (ps.hasOwnProperty(a)) { ps.setPropertyFromString(a,t[a]); Globals.vars.root.addDebug("added "+a+" to PointStyle"); }
-                               else if (ts.hasOwnProperty(a)) { ts.setPropertyFromString(a,t[a]); Globals.vars.root.addDebug("added "+a+" to TextStyle"); }
-                               else if (hs.hasOwnProperty(a)) { hs.setPropertyFromString(a,t[a]); Globals.vars.root.addDebug("added "+a+" to ShieldStyle"); }
+                               if      (ss.hasOwnProperty(a)) { ss.setPropertyFromString(a,t[a]); }
+                               else if (ps.hasOwnProperty(a)) { ps.setPropertyFromString(a,t[a]); }
+                               else if (ts.hasOwnProperty(a)) { ts.setPropertyFromString(a,t[a]); }
+                               else if (hs.hasOwnProperty(a)) { hs.setPropertyFromString(a,t[a]); }
                        }
 
                        // Add each style to list
-                       if (ss.edited) { styles.push(ss); Globals.vars.root.addDebug("added ShapeStyle"); }
-                       if (ps.edited) { styles.push(ps); Globals.vars.root.addDebug("added PointStyle"); }
+                       if (ss.edited) { styles.push(ss); }
+                       if (ps.edited) { styles.push(ps); }
                        if (ts.edited) { styles.push(ts); }
                        if (hs.edited) { styles.push(hs); }
                        if (xs.edited) { styles.push(xs); }
index 061d1dd..c3d0bb2 100644 (file)
@@ -17,7 +17,7 @@ package net.systemeD.halcyon.styleparser {
                public function test(obj:Entity,tags:Object):Boolean {
                        if (subject!='' && obj.getType()!=subject) { return false; }
                        
-                       var v:Boolean; var i:uint=0;
+                       var v:Boolean=true; var i:uint=0;
                        for each (var condition:Condition in conditions) {
                                var r:Boolean=condition.test(tags);
                                if (i==0) { v=r; }
index 1d52f05..e17b69c 100644 (file)
@@ -6,7 +6,7 @@ package net.systemeD.halcyon.styleparser {
        import net.systemeD.halcyon.Globals;
        import net.systemeD.halcyon.Map;
     import net.systemeD.halcyon.connection.Entity;
-//     import bustin.dev.Inspector;
+       import bustin.dev.Inspector;
        
        public class RuleSet {
 
@@ -52,8 +52,9 @@ package net.systemeD.halcyon.styleparser {
                private function loadedCSS(event:Event):void {
                        var css:MapCSS=new MapCSS(map);
                        choosers=css.parse(event.target.data);
-//                     Inspector.getInstance().show();
-//                     Inspector.getInstance().shelf('Choosers', choosers);
+                       Inspector.getInstance().show();
+                       Inspector.getInstance().shelf('Choosers', choosers);
+                       loadImages();
                }
 
                private function httpStatusHandler( event:HTTPStatusEvent ):void { }
@@ -63,27 +64,30 @@ package net.systemeD.halcyon.styleparser {
 
                // ------------------------------------------------------------------------------------------------
                // 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 choosers) {
-                               // if (!(rule is PointRule)) { continue; }
-                               if (!(rule.pointStyle)) { continue; }
-                               if (!(rule.pointStyle.icon_image)) { continue; }
+Globals.vars.root.addDebug("entering loadImages");
+                       var filename:String;
+                       for each (var chooser:StyleChooser in choosers) {
+                               for each (var style:Style in chooser.styles) {
+                                       if      (style is PointStyle  && PointStyle(style).icon_image   ) { filename=PointStyle(style).icon_image; }
+                                       else if (style is ShapeStyle  && ShapeStyle(style).fill_image   ) { filename=ShapeStyle(style).fill_image; }
+                                       else if (style is ShieldStyle && ShieldStyle(style).shield_image) { filename=ShieldStyle(style).shield_image; }
+                                       else { continue; }
+Globals.vars.root.addDebug("need "+filename);
                                
-                               iconsToLoad++;
-                               var request:URLRequest=new URLRequest(rule.pointStyle.icon_image);
-                               var loader:ImageLoader=new ImageLoader();
-                               loader.dataFormat=URLLoaderDataFormat.BINARY;
-                               loader.filename=rule.pointStyle.icon_image;
-                               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);
+                                       iconsToLoad++;
+                                       var request:URLRequest=new URLRequest(filename);
+                                       var loader:ImageLoader=new ImageLoader();
+                                       loader.dataFormat=URLLoaderDataFormat.BINARY;
+                                       loader.filename=filename;
+                                       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);
+                               }
                        }
                }
 
index 59a13f0..7df67b5 100644 (file)
@@ -11,7 +11,7 @@ package net.systemeD.halcyon.styleparser {
                
                public var fill_color:Number;
                public var fill_opacity:Number;
-               public var fill_pattern:String;
+               public var fill_image:String;
                
                public var casing_width:Number;
                public var casing_color:Number;
@@ -21,7 +21,7 @@ package net.systemeD.halcyon.styleparser {
                override public function get properties():Array {
                        return [
                                'width','color','opacity','dashes','linecap','linejoin',
-                               'fill_color','fill_opacity','fill_pattern',
+                               'fill_color','fill_opacity','fill_image',
                                'casing_width','casing_color','casing_opacity','casing_dashes'
                        ];
                }
index 7fce3dd..e02794d 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 {
 
@@ -49,6 +48,9 @@ package net.systemeD.halcyon.styleparser {
                        // ** almost certainly need to do more here, e.g. true|1|yes=Boolean true
                        switch (typeof(this[k])) {
                                case "number":  this[k]=Number(v) ; edited=true; return true;
+                               case "object":  // **for some reason, typeof(string class variables) returns "object".
+                                                               // We'll probably need to fix this in future if we have more complex
+                                                               // properties
                                case "string":  this[k]=String(v) ; edited=true; return true;
                                case "boolean": this[k]=Boolean(v); edited=true; return true;
                        }
index 46f5aff..527002e 100755 (executable)
@@ -1,7 +1,6 @@
 package net.systemeD.halcyon.styleparser {
 
        import net.systemeD.halcyon.connection.Entity;
-       import net.systemeD.halcyon.Globals;
 
        public class StyleChooser {
 
@@ -38,7 +37,6 @@ package net.systemeD.halcyon.styleparser {
                        var fulfilled:Boolean=false;
                        for each (var c:Array in ruleChains) {
                                if (testChain(c,-1,obj,tags)) {
-Globals.vars.root.addDebug("object "+obj+", testChain "+c+" returned true"); 
                                        fulfilled=true; break;
                                }
                        }
@@ -59,17 +57,14 @@ Globals.vars.root.addDebug("object "+obj+", testChain "+c+" returned true");
                                        continue;
                                }
 
-Globals.vars.root.addDebug("style on "+r.sublayer); 
                                if (a[r.sublayer]) {
                                        // If there's already a style on this sublayer, then merge them
                                        // (making a deep copy if necessary to avoid altering the root style)
                                        if (!a[r.sublayer].merged) { a[r.sublayer]=a[r.sublayer].deepCopy(); }
                                        a[r.sublayer].mergeWith(r);
-Globals.vars.root.addDebug("merging style on sl"+r.sublayer); 
                                } else {
                                        // Otherwise, just assign it
                                        a[r.sublayer]=r;
-Globals.vars.root.addDebug("assigning style on sl"+r.sublayer); 
                                }
                        }
                }
@@ -90,8 +85,9 @@ Globals.vars.root.addDebug("assigning style on sl"+r.sublayer);
                        if (!r.test(obj, tags)) { return false; }
                        if (pos==0) { return true; }
                        
-                       for each (var p:Entity in obj.parentObjects) {
-                               if (testChain(chain.slice(0), pos-1, p, p.getTagsHash() )) { return true; }
+                       var o:Array=obj.parentObjects;
+                       for each (var p:Entity in o) {
+                               if (testChain(chain, pos-1, p, p.getTagsHash() )) { return true; }
                        }
                        return false;
                }
@@ -102,7 +98,6 @@ Globals.vars.root.addDebug("assigning style on sl"+r.sublayer);
                
                // newGroup             <- starts a new ruleChain in this.ruleChains
                public function newGroup():void {
-Globals.vars.root.addDebug("* newGroup");
                        if (ruleChains[rcpos].length>0) {
                                ruleChains[++rcpos]=[];
                        }
@@ -110,27 +105,22 @@ Globals.vars.root.addDebug("* newGroup");
 
                // newObject    <- adds into the current ruleChain (starting a new Rule)
                public function newObject(e:String=''):void {
-Globals.vars.root.addDebug("* newObject");
                        ruleChains[rcpos].push(new Rule(e));
                }
 
                // addZoom              <- adds into the current ruleChain (existing Rule)
                public function addZoom(z1:uint,z2:uint):void {
-Globals.vars.root.addDebug("* addZoom");
                        ruleChains[rcpos][ruleChains[rcpos].length-1].minZoom=z1;
                        ruleChains[rcpos][ruleChains[rcpos].length-1].minZoom=z2;
                }
                
                // addCondition <- adds into the current ruleChain (existing Rule)
                public function addCondition(c:Condition):void {
-Globals.vars.root.addDebug("* addCondition");
                        ruleChains[rcpos][ruleChains[rcpos].length-1].conditions.push(c);
-Globals.vars.root.addDebug("    now "+ruleChains[rcpos][ruleChains[rcpos].length-1].conditions);
                }
 
                // addStyles    <- adds to this.styles
                public function addStyles(a:Array):void {
-Globals.vars.root.addDebug("* Styles ("+ruleChains[0][0].conditions+")");
                        styles=styles.concat(a);
                }
                
index 2eeb9d9..ba772b4 100644 (file)
@@ -19,13 +19,13 @@ package net.systemeD.halcyon.styleparser {
                public var text:String;
                public var text_halo_color:uint;
                public var text_halo_radius:uint=0;
-               public var text_onpath:Boolean;         // true if on line
+               public var text_center:Boolean;
 
                override public function get properties():Array {
                        return [
                                'font_family','font_bold','font_italic','font_caps','font_size',
                                'text_color','text_offset','max_width',
-                               'text','text_halo_color','text_halo_radius','text_onpath'
+                               'text','text_halo_color','text_halo_radius','text_center'
                        ];
                }
 
index 6f09121..9d1ed6a 100644 (file)
@@ -1,9 +1,16 @@
 way[name=~/Brown/] { set .highlighted; }
-way[highway=secondary] { color: green; width: 5; }
-way[highway=unclassified] { color: blue; width: 3; }
-way[highway=residential] { color: blue; width: 2; }
+
+way[highway=secondary] { color: orange; width: 9; casing-width: 11; text: name; text-color: black; font-size: 9; text-position: line; }
+way[highway=tertiary],way[highway=unclassified] { color: yellow; width: 7; casing-width: 9; text: name; text-color: black; font-size: 7; text-position: line; }
+way[highway=residential] { color: #DDDDDD; casing-color: gray; width: 5; casing-width: 7; }
 way[highway=primary] { color: red; width: 5; }
 way[highway=trunk] { color: green; width: 7; }
+
 way .highlighted { color: pink; }
+
 way :hover     { z-index: 2; width: 8; color: gray; }
 way :selected { z-index: 2; width: 8; color: yellow; }
+
+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; }