Load all feature images from map features through the FileBank
authorTom Hughes <tom@compton.nu>
Sat, 24 Mar 2012 12:21:00 +0000 (12:21 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 24 Mar 2012 16:08:13 +0000 (16:08 +0000)
net/systemeD/potlatch2/mapfeatures/Feature.as
net/systemeD/potlatch2/mapfeatures/MapFeatures.as

index 38d2839..01dd585 100644 (file)
@@ -10,7 +10,6 @@ package net.systemeD.potlatch2.mapfeatures {
     
     import net.systemeD.halcyon.FileBank;
     import net.systemeD.halcyon.connection.Entity;
-    import net.systemeD.potlatch2.utils.CachedDataLoader;
 
         /** A "map feature" is sort of a template for a map entity. It consists of a few crucial key/value pairs that define the feature, so that
          * entities can be recognised. It also contains optional keys, with associated editing controls, that are defined as being appropriate
@@ -32,10 +31,23 @@ package net.systemeD.potlatch2.mapfeatures {
         public function Feature(mapFeatures:MapFeatures, _xml:XML) {
             this.mapFeatures = mapFeatures;
             this._xml = _xml;
+            loadImages();
             parseConditions();
             parseEditors();
         }
 
+        private function loadImages():void {
+            var icon:XMLList = _xml.icon;
+            if ( icon.length() > 0 ) {
+                if ( icon[0].hasOwnProperty("@dnd") ) {
+                    FileBank.getInstance().addFromFile(icon[0].@dnd);
+                }
+                if ( icon[0].hasOwnProperty("@image") ) {
+                    FileBank.getInstance().addFromFile(icon[0].@image);
+                }
+            }
+        }
+
         private function parseConditions():void {
             _tags = [];
            _withins = [];
@@ -147,12 +159,8 @@ package net.systemeD.potlatch2.mapfeatures {
                 imageURL = icon[0].@image;
             }
 
-            if ( imageURL ) {
-                               if (FileBank.getInstance().hasFile(imageURL)) {
-                                       return FileBank.getInstance().getAsByteArray(imageURL);
-                               } else {
-                       return CachedDataLoader.loadData(imageURL, imageLoaded);
-                               }
+            if ( imageURL && FileBank.getInstance().hasFile(imageURL) ) {
+                return FileBank.getInstance().getAsByteArray(imageURL);
             }
             var bitmap:BitmapAsset = new missingIconCls() as BitmapAsset;
             return new PNGEncoder().encode(bitmap.bitmapData);
@@ -166,10 +174,6 @@ package net.systemeD.potlatch2.mapfeatures {
                return point.length() > 0 && !(XML(point[0]).attribute("draganddrop")[0] == "no");
         }
 
-        private function imageLoaded(url:String, data:ByteArray):void {
-            dispatchEvent(new Event("imageChanged"));
-        }
-
         public function htmlDetails(entity:Entity):String {
             var icon:XMLList = _xml.icon;
             return makeHTMLIcon(icon, entity);
index 5dc5b02..a8048ee 100644 (file)
@@ -4,6 +4,7 @@ package net.systemeD.potlatch2.mapfeatures {
     import flash.events.EventDispatcher;
     import flash.net.*;
     
+    import net.systemeD.halcyon.FileBank;
     import net.systemeD.halcyon.NestedXMLLoader;
     import net.systemeD.halcyon.connection.*;
 
@@ -71,7 +72,9 @@ package net.systemeD.potlatch2.mapfeatures {
                 if ( catXML.child("category").length() == 0 )
                   _categories.push(new Category(this, catXML.@name, catXML.@id, _categories.length));
             }
-            dispatchEvent(new Event("featuresLoaded"));
+            FileBank.getInstance().onFilesLoaded(function():void {
+                dispatchEvent(new Event("featuresLoaded"));
+            });
         }
 
         private function tagsFromInputSet(inputSet:XMLList, f:Feature):void {