add 'not found' cached image on failure
authorDave Stubbs <osm@randomjunk.co.uk>
Sun, 21 Mar 2010 12:21:01 +0000 (12:21 +0000)
committerDave Stubbs <osm@randomjunk.co.uk>
Sun, 21 Mar 2010 12:21:01 +0000 (12:21 +0000)
net/systemeD/potlatch2/utils/CachedDataLoader.as
resources/map_features.xml

index 3ed083491b1bec70a1b9a845b2da0ec2b987b8e4..c790cc685994ccdab2f206f29ca6f5bada4e47aa 100644 (file)
@@ -3,6 +3,8 @@ package net.systemeD.potlatch2.utils {
        import flash.events.*;
        import flash.net.*;
        import flash.utils.ByteArray;
+       import flash.display.BitmapData;
+       import mx.graphics.codec.PNGEncoder;
 
     import net.systemeD.halcyon.ExtendedURLLoader;
 
@@ -10,6 +12,7 @@ package net.systemeD.potlatch2.utils {
 
         private static var allData:Object = {};
         private static var requestsMade:Object = {};
+        private static var missingImage:ByteArray = null;
         
                public static function loadData(url:String, onLoadHandler:Function = null):ByteArray {
                    var data:ByteArray = allData[url];
@@ -24,6 +27,7 @@ package net.systemeD.potlatch2.utils {
                            var loader:ExtendedURLLoader = new ExtendedURLLoader();
                    loader.info = url;
                 loader.addEventListener(Event.COMPLETE, imageLoaded);
+                loader.addEventListener(IOErrorEvent.IO_ERROR, imageLoadFailed);
                 loader.dataFormat = URLLoaderDataFormat.BINARY;
                 loader.load(new URLRequest(url));
                    }
@@ -36,13 +40,36 @@ package net.systemeD.potlatch2.utils {
             var loader:ExtendedURLLoader = ExtendedURLLoader(event.target);
             var url:String = loader.info as String;
             allData[url] = loader.data;
+            dispatchEvents(url);
+        }
+        
+        private static function imageLoadFailed(event:Event):void {
+            var loader:ExtendedURLLoader = ExtendedURLLoader(event.target);
+            var url:String = loader.info as String;
             
+            allData[url] = getMissingImage();
+            dispatchEvents(url);
+        }
+        
+        private static function dispatchEvents(url:String):void {
             var requests:Array = requestsMade[url];
             for each ( var handler:Function in requests ) {
-                handler(url, loader.data);
+                handler(url, allData[url]);
             }
             
             delete requestsMade[url];
         }
+        
+        private static function getMissingImage():ByteArray {
+            if ( missingImage == null ) {
+                var bitmap:BitmapData = new BitmapData(16, 16, false);
+                for ( var i:uint = 0; i < 16; i++ ) {
+                    bitmap.setPixel(i, i, 0xff0000);
+                    bitmap.setPixel(15-i, i, 0xff0000);
+                }
+                missingImage = new PNGEncoder().encode(bitmap);
+            }
+            return missingImage;
+        }
        }
 }
index 0efaa867ace1991cb30007b30241f75c39d628e7..59e5e8c5ae2f0a20ebf29e091d961710b5500a9f 100644 (file)
   <category name="Buildings" id="buildings">
   </category>
 
+  <category name="Entertainment" id="entertainment">
+  </category>
+
+  <category name="Amenity" id="amenity">
+  </category>
+
   <!-- Roads -->
   
   <inputSet id="majorRoad">
   </feature>
   
   <feature name="Pub">
-    <category>transport</category>
+    <category>entertainment</category>
     <icon image="icons/pub.png">
       ${name}
     </icon>
     <point />
     <tag k="amenity" v="pub"/>
-    <inputSet ref="names" />
+    <inputSet ref="names"/>
+    <inputSet ref="buildingAddress" />
+  </feature>
+
+  <feature name="Bar">
+    <category>entertainment</category>
+    <icon image="icons/bar.png">
+      ${name}
+    </icon>
+    <point />
+    <tag k="amenity" v="bar"/>
+    <inputSet ref="names"/>
+    <inputSet ref="buildingAddress" />
+  </feature>
+
+  <feature name="Restaurant">
+    <category>entertainment</category>
+    <icon image="icons/restaurant.png">
+      ${name}
+    </icon>
+    <point />
+    <tag k="amenity" v="restaurant"/>
+    <inputSet ref="names"/>
+    <inputSet ref="buildingAddress" />
+  </feature>
+
+  <feature name="Post Box">
+    <category>amenity</category>
+    <icon image="icons/post_box.png">
+      ${ref}
+    </icon>
+    <point />
+    <tag k="amenity" v="post_box"/>
+    <input type="freetext" presence="always" category="Naming" name="Ref" key="ref" description="Reference number of the post box" />
+    <input type="freetext" presence="always" category="Naming" name="Operator" key="operator" description="The provider of the postal service" priority="low"/>
   </feature>
 
   <!-- cycle stuff -->