X-Git-Url: https://git.openstreetmap.org/potlatch2.git/blobdiff_plain/02181a891ed738bfc58397df7e41daf0b880a5bd..66908183701a850864ba489ca462d14e521b805e:/net/systemeD/halcyon/styleparser/Style.as?ds=sidebyside diff --git a/net/systemeD/halcyon/styleparser/Style.as b/net/systemeD/halcyon/styleparser/Style.as old mode 100755 new mode 100644 index 8f8e22ee..a28ece13 --- a/net/systemeD/halcyon/styleparser/Style.as +++ b/net/systemeD/halcyon/styleparser/Style.as @@ -3,18 +3,43 @@ package net.systemeD.halcyon.styleparser { import flash.utils.ByteArray; import flash.net.*; + /** A Style is a set of graphic properties (e.g. stroke colour and width, casing colour and width, + font and text size), typically derived from a MapCSS descriptor. This is the base class + for particular style groupings such as ShapeStyle and PointStyle. + + @see net.systemeD.halcyon.styleparser.StyleList + @see net.systemeD.halcyon.styleparser.StyleChooser + */ + public class Style { + /** Has this style had another style merged into it? + (When styles cascade, then we need to merge the first style with any subsequent styles that apply.) */ public var merged:Boolean=false; - public var edited:Boolean=false; // true once a property has been set from a string + + /** Is the style active (properties have been set)? */ + public var edited:Boolean=false; + + /** The sublayer is the z-index property _within_ an OSM layer. + It enables (for example) trunk roads to be rendered above primary roads within that OSM layer, + and so on. "OSM layer 1 / sublayer 5" will render above "OSM layer 1 / sublayer 4", but below + "OSM layer 2 / sublayer 4". */ public var sublayer:Number=5; - public var interactive:Boolean=true; - public var evals:Object={}; // compiled SWFs for each eval. We keep it here, not in the property - // | itself, so that we can retain typing for each property - // Return an exact copy of this object - // ** this needs some benchmarking - may be quicker to iterate over .properties, copying each one + /** Does this style permit mouse interaction? + (Some styling, such as P2's back-level yellow highlight for selected ways, should not respond + to mouse events.) */ + public var interactive:Boolean=true; + /** Compiled SWFs for each eval. We keep it here, not in the property itself, so that we can retain typing for each property. */ + public var evals:Object={}; + + /** TagValue assignments, e.g. { width: tag('lanes'); } */ + public var tagvalues:Object={}; + + /** Make an exact copy of an object. + Used when merging cascading styles. (FIXME: this needs some benchmarking - it may be quicker to simply iterate over .properties, + copying each one. */ public function deepCopy():* { registerClassAlias("net.systemeD.halcyon.styleparser.ShapeStyle",ShapeStyle); registerClassAlias("net.systemeD.halcyon.styleparser.TextStyle",TextStyle); @@ -27,49 +52,44 @@ package net.systemeD.halcyon.styleparser { return (a.readObject()); } - // Add properties from another object - + /** Merge two Style objects. */ public function mergeWith(additional:Style):void { for each (var prop:String in properties) { - if (additional[prop]) { + // Note extra check for empty arrays, which we use to mean 'undefined' (see setPropertyFromString below) + if (additional[prop] != undefined && !((additional[prop] is Array) && additional[prop].length==0)) { this[prop]=additional[prop]; } } this.merged=true; } - // Getters (to be overridden) - + /** Properties getter, to be overridden. */ public function get properties():Array { return []; } + /** Does this style require anything to be drawn? (To be overridden.) */ public function get drawn():Boolean { return false; } - // Eval handling - + /** Are there any eval functions defined? (This isn't used.) */ public function hasEvals():Boolean { for (var k:String in evals) { return true; } return false; } + /** Run all evals for this Style over the supplied tags. + If, for example, the stylesheet contains width=eval('_width+2'), then this will set Style.width to 7. */ public function runEvals(tags:Object):void { - 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). - // - } + for (var k:String in evals) this[k]=evals[k].exec(tags); } - - // Set property and cast as correct type (used in stylesheet imports) + /** Set a property, casting as correct type. */ public function setPropertyFromString(k:String,v:*):Boolean { if (!this.hasOwnProperty(k)) { return false; } if (v is Eval) { evals[k]=v; v=1; } + else if (v is TagValue) { tagvalues[k]=v; v=1; } // Arrays don't return a proper typeof, so check manually // Note that undefined class variables always have typeof=object, @@ -92,11 +112,13 @@ package net.systemeD.halcyon.styleparser { return false; } + /** Summarise Style as String - for debugging. */ public function toString():String { var str:String=''; for each (var k:String in this.properties) { if (this.hasOwnProperty(k)) { str+=k+"="+this[k]+"; "; } } + for each (k in tagvalues) str+=k+";"; return str; } }