width can be defined based on maximum width so far
authorRichard Fairhurst <richard@systemed.net>
Sun, 10 Jan 2010 16:15:30 +0000 (16:15 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sun, 10 Jan 2010 16:15:30 +0000 (16:15 +0000)
12 files changed:
net/systemeD/halcyon/EntityUI.as
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/styleparser/PointStyle.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/StyleList.as
net/systemeD/potlatch2/controller/SelectedWay.as
net/systemeD/potlatch2/controller/SelectedWayNode.as
resources/potlatch.css

index ca7cc1f567f2e933f5d56f1fa491237b0afd0aa5..b652fbf579f9b7d600d7f12e50e0d75a7d862796 100644 (file)
@@ -50,6 +50,7 @@ package net.systemeD.halcyon {
                                var d:DisplayObject=sprites.pop();
                                if (d.parent) { d.parent.removeChild(d); }
                        }
+                       listenSprite=null;
                }
 
                protected function createListenSprite(hitzone:Sprite):void {
index 3f1f22b950736aff4d0e1d72cf2f1eee63f80356..db22e5860b962b35ce7425dbb7f8700d1d1accf6 100755 (executable)
@@ -59,7 +59,6 @@ package net.systemeD.halcyon {
             redraw();
         }
                private function wayDeleted(event:EntityEvent):void {
-                       Globals.vars.root.addDebug("waydeleted fired on "+way.length+":"+event.entity);
                        redraw();
                }
 
@@ -210,13 +209,13 @@ package net.systemeD.halcyon {
                                if (node.id==nodeSelected) { nodetags[':selected']='yes'; }
                                sl=map.ruleset.getStyles(node,nodetags);
                                if (sl.hasStyles()) {
-                                       if (!map.pois[node.id]) { map.pois[node.id]=new NodeUI(node,map,r); }
+                                       if (!map.pois[node.id]) {
+                                               map.pois[node.id]=new NodeUI(node,map,r);
+                                       }
                                        map.pois[node.id].redraw(sl);
-                                       // ** 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)
                                } else if (map.pois[node.id]) {
                                        map.pois[node.id].removeSprites();
+                                       delete map.pois[node.id];
                                }
                        }
                        if (!drawn) { return false; }
index e41104ed63d37ebb601477626b4962a6c33fb667..78742f558b601a2dc0f4f8b69e912108d6528cab 100644 (file)
@@ -124,7 +124,7 @@ package net.systemeD.halcyon.connection {
                }
 
                protected function removeFromParents():void {
-                       for each (var o:Entity in parents) {
+                       for (var o:Object in parents) {
                                if (o is Relation) { Relation(o).removeMember(this); }
                                else if (o is Way) { Way(o).removeNode(Node(this)); }
                                if (o.isEmpty()) { o.remove(); }
index e95d2ddb81a00bcb17daf3045097950f282c34ad..aac8c65c2a08fe6114aff4ed408a3e0af3a4d7e6 100644 (file)
@@ -3,7 +3,7 @@ package net.systemeD.halcyon.styleparser {
        public class PointStyle extends Style {
 
                public var icon_image:String;
-               public var icon_width:uint;
+               public var icon_width:uint=0;
                public var icon_height:uint;
                public var rotation:Number;
 
index 68fbc00447895ed2ba5cbcaaa6223653c82883a4..1840e2f2cba3825c4db1031010001de845a444f8 100644 (file)
@@ -3,6 +3,7 @@ package net.systemeD.halcyon.styleparser {
        import flash.events.*;
        import flash.net.*;
        import net.systemeD.halcyon.Map;
+       import net.systemeD.halcyon.ExtendedLoader;
        import net.systemeD.halcyon.ExtendedURLLoader;
     import net.systemeD.halcyon.connection.Entity;
 
@@ -13,10 +14,11 @@ package net.systemeD.halcyon.styleparser {
        public class RuleSet {
 
                private var map:Map;
-               public var choosers:Array=new Array();  // list of StyleChoosers
-               public var images:Object=new Object();  // loaded images
-               private var iconCallback:Function=null; // function to call when all icons loaded
-               private var iconsToLoad:uint=0;                 // number of icons left to load (fire callback when ==0)
+               public var choosers:Array=new Array();          // list of StyleChoosers
+               public var images:Object=new Object();          // loaded images
+               public var imageWidths:Object=new Object();     // width of each bitmap image
+               private var iconCallback:Function=null;         // function to call when all icons loaded
+               private var iconsToLoad:uint=0;                         // number of icons left to load (fire callback when ==0)
 
                // variables for name, author etc.
 
@@ -30,7 +32,7 @@ package net.systemeD.halcyon.styleparser {
                public function getStyles(obj:Entity,tags:Object):StyleList {
                        var sl:StyleList=new StyleList();
                        for each (var sc:StyleChooser in choosers) {
-                               sc.updateStyles(obj,tags,sl);
+                               sc.updateStyles(obj,tags,sl,imageWidths);
                        }
                        return sl;
                }
@@ -98,7 +100,20 @@ package net.systemeD.halcyon.styleparser {
                // data handler
 
                private function loadedImage(event:Event):void {
-                       images[event.target.info['filename']]=event.target.data;
+                       var fn:String=event.target.info['filename'];
+                       images[fn]=event.target.data;
+
+                       var loader:ExtendedLoader = new ExtendedLoader();
+                       loader.info['filename']=fn;
+                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, measureWidth);
+                       loader.loadBytes(map.ruleset.images[fn]);
+               }
+               
+               private function measureWidth(event:Event):void {
+                       var fn:String=event.target.loader.info['filename'];
+                       imageWidths[fn]=event.target.width;
+                       // ** do we need to explicitly remove the loader object now?
+
                        iconsToLoad--;
                        if (iconsToLoad==0 && iconCallback!=null) { iconCallback(); }
                }
index 4f5358603df9e8b6ed38549dc3aa58f61c5e3e92..dad6d4f9e26645501c9d233df0a29183c79cc459 100644 (file)
@@ -4,7 +4,7 @@ package net.systemeD.halcyon.styleparser {
        
        public class ShapeStyle extends Style {
 
-               public var width:Number;
+               public var width:Number=0;
                public var color:Number;
                public var opacity:Number;
                public var dashes:Array=[];
index 72fdc1f67b379017186f9449734f8180f1fd687c..d35f136d7485b4462f726fecdf6580b8104b6654 100755 (executable)
@@ -58,6 +58,9 @@ package net.systemeD.halcyon.styleparser {
                        for (var k:String in evals) {
                                // ** Do we need to do typing here?
                                this[k]=evals[k].exec(tags);
+                               
+                               // ** If the stylesheet has width=eval('_width+2'), then this will set Style.width to 7 (say).
+                               //    
                        }
                }
 
index 3586212d964126c5910a3eb72a5f0f805b9f0024..10503b10b2b4bc05f0d8fa14ff51742db0736f96 100755 (executable)
@@ -31,9 +31,10 @@ package net.systemeD.halcyon.styleparser {
 
                // Update the current StyleList from this StyleChooser
 
-               public function updateStyles(obj:Entity, tags:Object, sl:StyleList):void {
+               public function updateStyles(obj:Entity, tags:Object, sl:StyleList, imageWidths:Object):void {
                        // Are any of the ruleChains fulfilled?
                        // ** needs to cope with min/max zoom
+                       var w:Number;
                        var fulfilled:Boolean=false;
                        for each (var c:Array in ruleChains) {
                                if (testChain(c,-1,obj,tags)) {
@@ -45,11 +46,23 @@ package net.systemeD.halcyon.styleparser {
                        // Update StyleList
                        for each (var r:Style in styles) {
                                var a:*;
-                               if      (r is ShapeStyle ) { a=sl.shapeStyles; }
-                               else if (r is ShieldStyle) { a=sl.shieldStyles; }
-                               else if (r is TextStyle  ) { a=sl.textStyles;  }
-                               else if (r is PointStyle ) { a=sl.pointStyles; }
-                               else if (r is InstructionStyle) {
+                               if (r is ShapeStyle) {
+                                       a=sl.shapeStyles;
+                                       if (ShapeStyle(r).width>sl.maxwidth && !r.evals['width']) { sl.maxwidth=ShapeStyle(r).width; }
+                               } else if (r is ShieldStyle) {
+                                       a=sl.shieldStyles;
+                               } else if (r is TextStyle) { 
+                                       a=sl.textStyles;
+                               } else if (r is PointStyle) { 
+                                       a=sl.pointStyles;
+                                       w=0;
+                                       if (PointStyle(r).icon_width && !PointStyle(r).evals['icon_width']) {
+                                               w=PointStyle(r).icon_width;
+                                       } else if (PointStyle(r).icon_image && imageWidths[PointStyle(r).icon_image]) {
+                                               w=imageWidths[PointStyle(r).icon_image];
+                                       }
+                                       if (w>sl.maxwidth) { sl.maxwidth=w; }
+                               } else if (r is InstructionStyle) {
                                        if (InstructionStyle(r).breaker) { return; }
                                        if (InstructionStyle(r).set_tags) {
                                                for (var k:String in InstructionStyle(r).set_tags) { tags[k]=InstructionStyle(r).set_tags[k]; }
@@ -57,6 +70,7 @@ package net.systemeD.halcyon.styleparser {
                                        continue;
                                }
                                if (r.drawn) { tags[':drawn']='yes'; }
+                               tags['_width']=sl.maxwidth;
                                
                                r.runEvals(tags);
                                if (a[r.sublayer]) {
index e2496e278d138e5e7fb9e7e3edca7cee59e95b90..f00715f64855621d6e7eba6613abc4f9309ac4c0 100755 (executable)
@@ -15,6 +15,7 @@ package net.systemeD.halcyon.styleparser {
                public var textStyles:Array=[];
                public var pointStyles:Array=[];
                public var shieldStyles:Array=[];
+               public var maxwidth:Number=0;
 
                public function hasStyles():Boolean {
                        return ( (shapeStyles.length + textStyles.length + pointStyles.length + shieldStyles.length) > 0 );
index b4c5c94755d480ee74e9b5f09041c1d363ea16fc..ab8321c2bf36947b2c1675cba76fa91ada5dc723 100644 (file)
@@ -92,8 +92,6 @@ package net.systemeD.potlatch2.controller {
         }
 
                protected function mergeWith(way:Way):Boolean {
-                       Globals.vars.root.addDebug("merge with "+way.id);
-
                        // ** needs to prefer positive to negative IDs
                        // find common point
                        if (way==selectedWay) { return false; }
index fc151859c467a10c47ffee0cf53763c1035eb4e0..822cfb8e8b03325058b3b647e61319fa7895ec8a 100644 (file)
@@ -102,7 +102,6 @@ package net.systemeD.potlatch2.controller {
                        // abort if start or end
                        if (selectedWay.getNode(0                   ) == selectedNode) { return this; }
                        if (selectedWay.getNode(selectedWay.length-1) == selectedNode) { return this; }
-                       Globals.vars.root.addDebug("splitting way at "+selectedWay.indexOfNode(selectedNode));
 
                        // create new way
                        var newWay:Way = controller.connection.createWay(
index e5c3edc474b6c7aa876e2494d5c79e70a25f8e4b..14e734c056831f312dff96694d4ae4f81a855a1c 100644 (file)
@@ -113,14 +113,14 @@ way .highlighted { color: pink; }
 /* Interactive editors may choose different behaviour when a user mouses-over or selects
    an object. Potlatch 2 supports these but the stand-alone Halcyon viewer does not */
 
-way :hover     { z-index: 2; width: 8; color: #ffff99; }
-way :selected { z-index: 2; width: 8; color: yellow; }
+way :hover     { z-index: 2; width: eval('_width+10'); color: #ffff99; }
+way :selected { z-index: 2; width: eval('_width+10'); color: yellow; opacity: 0.7;}
 way !:drawn { z-index:10; width: 0.5; color: gray; } 
 
 node :selectedway { z-index: 9; icon-image: square; icon-width: 7; color: red; }
 node :hoverway { z-index: 9; icon-image: square; icon-width: 7; color: blue; }
 node !:drawn :poi { z-index: 2; icon-image: circle; icon-width: 4; color: green; casing-color: black; casing-width: 1; }
-node :selected { z-index: 1; icon-image: square; icon-width: 15; color: yellow; }
+node :selected { z-index: 1; icon-image: square; icon-width: eval('_width+10'); color: yellow; }
 
 /* Descendant selectors provide an easy way to style relations: this example means "any way
    which is part of a relation whose type=route". */