Removed executable flag from files which don't need it.
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / Feature.as
index 77fa3bbbbdf8a639a558eb2061a420f0103606e5..0ad71358eeab6050181ffff3ced5bed50e1a5c01 100644 (file)
@@ -4,6 +4,8 @@ package net.systemeD.potlatch2.mapfeatures {
     import flash.events.Event;
     import flash.net.*;
     import flash.utils.ByteArray;
+    import mx.core.BitmapAsset;
+    import mx.graphics.codec.PNGEncoder;
     
     import net.systemeD.halcyon.connection.Entity;
     import net.systemeD.potlatch2.utils.CachedDataLoader;
@@ -13,23 +15,37 @@ package net.systemeD.potlatch2.mapfeatures {
         private var _xml:XML;
         private static var variablesPattern:RegExp = /[$][{]([^}]+)[}]/g;
         private var _tags:Array;
+               private var _withins:Array;
         private var _editors:Array;
 
+        [Embed(source="../../../../embedded/missing_icon.png")]
+        [Bindable]
+        public var missingIconCls:Class;
+
+
         public function Feature(mapFeatures:MapFeatures, _xml:XML) {
             this.mapFeatures = mapFeatures;
             this._xml = _xml;
-            parseTags();
+            parseConditions();
             parseEditors();
         }
         
-        private function parseTags():void {
-            _tags = new Array();
+        private function parseConditions():void {
+            _tags = [];
+                       _withins = [];
             
+                       // parse tags
             for each(var tag:XML in definition.tag) {
-                var tagObj:Object = new Object();
-                tagObj["k"] = tag.@k;
-                tagObj["v"] = tag.@v;
-                _tags.push(tagObj);
+                _tags.push( { k:tag.@k, v:tag.@v} );
+            }
+
+                       // parse 'within'
+            for each(var within:XML in definition.within) {
+                               var obj:Object= { entity:within.@entity, k:within.@k };
+                               if (within.attribute('v'      ).length()>0) { obj['v'      ]=within.@v;       }
+                               if (within.attribute('minimum').length()>0) { obj['minimum']=within.@minimum; }
+                               if (within.attribute('role'   ).length()>0) { obj['role'   ]=within.@role;    }
+                _withins.push(obj);
             }
         }
         
@@ -78,21 +94,27 @@ package net.systemeD.potlatch2.mapfeatures {
     
         [Bindable(event="nameChanged")]
         public function get name():String {
-            return _xml.@name;
+                       if (_xml.attribute('name').length()>0) { return _xml.@name; }
+                       return null;
         }
     
         [Bindable(event="imageChanged")]
         public function get image():ByteArray {
             var icon:XMLList = _xml.icon;
             var imageURL:String = null;
+            var img:ByteArray;
 
             if ( icon.length() > 0 && icon[0].hasOwnProperty("@image") )
                 imageURL = icon[0].@image;
-            
+
             if ( imageURL != null ) {
-                return CachedDataLoader.loadData(imageURL, imageLoaded);
+                img = CachedDataLoader.loadData(imageURL, imageLoaded);
             }
-            return null;
+            if (img) {
+              return img;
+            }
+            var bitmap:BitmapAsset = new missingIconCls() as BitmapAsset;
+            return new PNGEncoder().encode(bitmap.bitmapData);
         }
         
         private function imageLoaded(url:String, data:ByteArray):void {
@@ -121,8 +143,8 @@ package net.systemeD.potlatch2.mapfeatures {
             var newStr:String = str.replace(/&/g, "&");
             newStr = newStr.replace(/</g, "&lt;");
             newStr = newStr.replace(/>/g, "&gt;");
-            newStr = newStr.replace(/"/g, "&quot;");
-            newStr = newStr.replace(/'/g, "&apos;");
+            newStr = newStr.replace(/"/g, "&quot;");   // "
+            newStr = newStr.replace(/'/g, "&apos;");   // '
             return newStr;
         }
       
@@ -141,6 +163,10 @@ package net.systemeD.potlatch2.mapfeatures {
         public function get tags():Array {
             return _tags;
         }
+
+        public function get withins():Array {
+            return _withins;
+        }
         
         public function findFirstCategory():Category {
             for each( var cat:Category in mapFeatures.categories ) {
@@ -151,7 +177,11 @@ package net.systemeD.potlatch2.mapfeatures {
         }
         
         public function isType(type:String):Boolean {
-            return _xml.elements(type).length() > 0;
+            if (type=='area') {
+                           return (_xml.elements(type).length() > 0) || (_xml.elements('line').length() > 0);
+            } else {
+                           return _xml.elements(type).length() > 0;
+                       }
         }
         
         public function hasHelpURL():Boolean {