add a feature selector to the simple view
[potlatch2.git] / net / systemeD / halcyon / mapfeatures / Feature.as
1 package net.systemeD.halcyon.mapfeatures {
2
3     import flash.events.EventDispatcher;
4     import flash.events.Event;
5     import net.systemeD.halcyon.connection.Entity;
6
7         public class Feature extends EventDispatcher {
8         private var mapFeatures:MapFeatures;
9         private var _xml:XML;
10         private static var variablesPattern:RegExp = /[$][{]([^}]+)[}]/g;
11         private var _tags:Array;
12
13         public function Feature(_xml:XML) {
14             this._xml = _xml;
15             _tags = new Array();
16             
17             for each(var tag:XML in definition.tag) {
18                 var tagObj:Object = new Object();
19                 tagObj["k"] = tag.@k;
20                 tagObj["v"] = tag.@v;
21                 _tags.push(tagObj);
22             }
23
24         }
25         
26         public function get definition():XML {
27             return _xml;
28         }
29     
30         [Bindable(event="nameChanged")]
31         public function get name():String {
32             return _xml.@name;
33         }
34     
35         [Bindable(event="imageChanged")]
36         public function get image():String {
37             var icon:XMLList = _xml.icon;
38
39             if ( icon.length() > 0 && icon[0].hasOwnProperty("@image") )
40                 return icon[0].@image;
41             else
42                 return null;
43         }
44         
45         public function htmlDetails(entity:Entity):String {
46             var icon:XMLList = _xml.icon;
47             if ( icon == null )
48                 return "";
49
50             var txt:String = icon.children().toXMLString();
51             var replaceTag:Function = function():String {
52                 var value:String = entity.getTag(arguments[1]);
53                 return value == null ? "" : value;
54             };
55             txt = txt.replace(variablesPattern, replaceTag);
56             return txt;
57         }
58         
59         public function isInCategory(category:String):Boolean {
60             var cats:XMLList = _xml.category;
61             if ( cats.length() == 0 )
62                 return false;
63                 
64             for each( var cat:XML in cats )
65                 if ( cat.text()[0] == category )
66                     return true;
67             return false;
68         }
69         
70         public function get tags():Array {
71             return _tags;
72         }
73     }
74 }
75