Merge branch 'master' into snapshotserver
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / Category.as
1 package net.systemeD.potlatch2.mapfeatures {
2
3     import flash.events.EventDispatcher;
4
5         /** A Category is a (non-exclusive) grouping of related Features used to help the user find the map feature they are interested in using. */
6         public class Category extends EventDispatcher {
7         private var mapFeatures:MapFeatures;
8         /** The human-meaningful name of the category (eg, "Roads") */
9         private var _name:String;
10         private var _id:String;
11         /** The features that belong to this category. */
12         private var _features:Array;
13         private var _index:uint;
14
15         public function Category(mapFeatures:MapFeatures, name:String, id:String, globalIndex:uint) {
16             this.mapFeatures = mapFeatures;
17             this._name = name;
18             this._id = id;
19             this._index = globalIndex;
20
21             _features = new Array();
22             for each( var feature:Feature in mapFeatures.features ) {
23                 if ( feature.isInCategory(id) )
24                     _features.push(feature);
25             }
26         }
27
28         public function get id():String {
29             return _id;
30         }
31
32         public function get index():uint {
33             return _index;
34         }
35
36         [Bindable(event="categoryChange")]
37         public function get name():String {
38             return _name;
39         }
40
41         [Bindable(event="featuresChanged")]
42         public function get features():Array {
43             return _features;
44         }
45
46         [Bindable(event="featuresChanged")]
47         /** Get an array of all features in this category that have the requested type, or possibly empty list. */
48         public function getFeaturesForType(type:String, onlydnd:Boolean=false):Array {
49             if ( type == null || type == "" )
50                 return []; //_features;
51
52             var filteredFeatures:Array = new Array();
53             for each( var feature:Feature in _features ) {
54                 if ( feature.isType(type) )
55                     if (!onlydnd || feature.canDND()) {
56                         filteredFeatures.push(feature);
57                     }
58             }
59             return filteredFeatures;
60         }
61
62     }
63 }
64
65