POI stuff
authorRichard Fairhurst <richard@systemed.net>
Mon, 1 Jun 2009 12:13:30 +0000 (12:13 +0000)
committerRichard Fairhurst <richard@systemed.net>
Mon, 1 Jun 2009 12:13:30 +0000 (12:13 +0000)
33 files changed:
LICENCE.txt [new file with mode: 0644]
README.txt
halcyon.mxml
halcyon.tmproj
icons/airport.png [new file with mode: 0755]
icons/atm.png [new file with mode: 0755]
icons/bar.png [new file with mode: 0755]
icons/bus_stop.png [new file with mode: 0755]
icons/cafe.png [new file with mode: 0755]
icons/convenience.png [new file with mode: 0755]
icons/fast_food.png [new file with mode: 0755]
icons/fire_station.png [new file with mode: 0755]
icons/hospital.png [new file with mode: 0755]
icons/hotel.png [new file with mode: 0755]
icons/icons_grid.png [new file with mode: 0755]
icons/parking.png [new file with mode: 0755]
icons/pharmacy.png [new file with mode: 0755]
icons/pharmacy_dispensing.png [new file with mode: 0755]
icons/police.png [new file with mode: 0755]
icons/post_box.png [new file with mode: 0755]
icons/pub.png [new file with mode: 0755]
icons/recycling.png [new file with mode: 0755]
icons/restaurant.png [new file with mode: 0755]
icons/school.png [new file with mode: 0755]
icons/station.png [new file with mode: 0755]
icons/taxi.png [new file with mode: 0755]
icons/telephone.png [new file with mode: 0755]
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/POI.as
net/systemeD/halcyon/connection/AMFConnection.as
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/styleparser/ImageLoader.as
net/systemeD/halcyon/styleparser/RuleSet.as

diff --git a/LICENCE.txt b/LICENCE.txt
new file mode 100644 (file)
index 0000000..90107a0
--- /dev/null
@@ -0,0 +1,13 @@
+            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+                    Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar
+  14 rue de Plaisance, 75014 Paris, France
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. You just DO WHAT THE FUCK YOU WANT TO.
index 7e94cd393857da902f7f5a68250e4c65cfbb9d98..58f1c29fd8b71b8d02d0a024232ae05cacb8b4a6 100644 (file)
@@ -2,7 +2,7 @@
 
 Here's some embryonic unfinished stuff to play with.
 
-This is a live OSM renderer written in AS3 which will one day grow into a beautiful map editor.
+This is a live OSM renderer written in AS3 which will one day grow into a beautiful map editor. It's rules-based (like, say, Mapnik) and does dotted lines, text on a path, casing, icons for POIs, all of that.
 
 === What you'll need ===
 
@@ -15,10 +15,15 @@ This is a live OSM renderer written in AS3 which will one day grow into a beauti
 === How to compile and run ===
 
 Compiling:
-mxmlc -managers=flash.fonts.AFEFontManager -output=/path/to/halcyon.swf /path/to/halcyon.mxml
+* fcsh
+  - launches the Flex Compiler SHell
+* mxmlc -managers=flash.fonts.AFEFontManager -output=/path/to/halcyon.swf /path/to/halcyon.mxml 
+  - compile for the first time
+* compile 1 
+  - compile each subsequent time (_much_ faster than using mxmlc every time)
 
 Running:
-* Make sure test.yaml is in the same directory as halcyon.swf
+* Make sure test.yaml and icons/ are in the same directory as halcyon.swf
 * Open halcyon.swf in your browser
 
 === Some other stuff you might need to know ===
index ec1c18ca3be54a22fe5b1afa82f4e6ded82f6276..3b96573b24dcc020e9963c9ee0e78b6890eae9a9 100755 (executable)
@@ -79,9 +79,9 @@
 
                        // add debug field
                        var t:TextField=new TextField();
-                       //t.width=400; t.height=100; t.border=true; 
-                       //t.multiline=true;
-                       //_root.addChild(t);
+                       t.width=400; t.height=100; t.border=true; 
+                       t.multiline=true;
+                       _root.addChild(t);
                        Globals.vars.debug=t;
                }
 
index 8dc29637b1dab7bf0010819cb210876106ea9542..e987b4084220cacca22e24f2232a3f17a8a84410 100644 (file)
@@ -4,47 +4,35 @@
 <dict>
        <key>documents</key>
        <array>
-               <dict>
-                       <key>filename</key>
-                       <string>net/systemeD/halcyon/AMFConnection.as</string>
-                       <key>lastUsed</key>
-                       <date>2009-05-30T13:59:09Z</date>
-               </dict>
-               <dict>
-                       <key>filename</key>
-                       <string>net/systemeD/halcyon/Connection.as</string>
-                       <key>lastUsed</key>
-                       <date>2009-05-30T13:59:04Z</date>
-               </dict>
-               <dict>
-                       <key>filename</key>
-                       <string>net/systemeD/halcyon/Globals.as</string>
-                       <key>lastUsed</key>
-                       <date>2009-05-30T15:21:19Z</date>
-               </dict>
                <dict>
                        <key>filename</key>
                        <string>net/systemeD/halcyon/Map.as</string>
                        <key>lastUsed</key>
-                       <date>2009-05-30T15:21:19Z</date>
+                       <date>2009-06-01T11:58:41Z</date>
                </dict>
                <dict>
                        <key>filename</key>
-                       <string>net/systemeD/halcyon/Node.as</string>
+                       <string>net/systemeD/halcyon/POI.as</string>
                        <key>lastUsed</key>
-                       <date>2009-05-30T13:59:07Z</date>
+                       <date>2009-06-01T12:11:15Z</date>
+                       <key>selected</key>
+                       <true/>
                </dict>
                <dict>
                        <key>filename</key>
-                       <string>net/systemeD/halcyon/POI.as</string>
+                       <string>net/systemeD/halcyon/WayUI.as</string>
                        <key>lastUsed</key>
-                       <date>2009-05-30T15:09:53Z</date>
+                       <date>2009-06-01T11:58:42Z</date>
                </dict>
                <dict>
-                       <key>filename</key>
-                       <string>net/systemeD/halcyon/Way.as</string>
-                       <key>lastUsed</key>
-                       <date>2009-05-30T15:16:50Z</date>
+                       <key>expanded</key>
+                       <true/>
+                       <key>name</key>
+                       <string>connection</string>
+                       <key>regexFolderFilter</key>
+                       <string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
+                       <key>sourceDirectory</key>
+                       <string>net/systemeD/halcyon/connection</string>
                </dict>
                <dict>
                        <key>expanded</key>
                        <key>sourceDirectory</key>
                        <string>net/systemeD/halcyon/styleparser</string>
                </dict>
+               <dict>
+                       <key>filename</key>
+                       <string>net/systemeD/halcyon/Globals.as</string>
+               </dict>
                <dict>
                        <key>filename</key>
                        <string>halcyon.mxml</string>
                        <key>lastUsed</key>
-                       <date>2009-05-30T15:21:19Z</date>
-                       <key>selected</key>
-                       <true/>
+                       <date>2009-06-01T11:49:17Z</date>
                </dict>
        </array>
        <key>fileHierarchyDrawerWidth</key>
@@ -72,6 +62,6 @@
        <key>showFileHierarchyDrawer</key>
        <true/>
        <key>windowFrame</key>
-       <string>{{272, 182}, {710, 564}}</string>
+       <string>{{268, 182}, {710, 564}}</string>
 </dict>
 </plist>
diff --git a/icons/airport.png b/icons/airport.png
new file mode 100755 (executable)
index 0000000..b104403
Binary files /dev/null and b/icons/airport.png differ
diff --git a/icons/atm.png b/icons/atm.png
new file mode 100755 (executable)
index 0000000..6a953d3
Binary files /dev/null and b/icons/atm.png differ
diff --git a/icons/bar.png b/icons/bar.png
new file mode 100755 (executable)
index 0000000..13f97e3
Binary files /dev/null and b/icons/bar.png differ
diff --git a/icons/bus_stop.png b/icons/bus_stop.png
new file mode 100755 (executable)
index 0000000..989e9c3
Binary files /dev/null and b/icons/bus_stop.png differ
diff --git a/icons/cafe.png b/icons/cafe.png
new file mode 100755 (executable)
index 0000000..d9c1f77
Binary files /dev/null and b/icons/cafe.png differ
diff --git a/icons/convenience.png b/icons/convenience.png
new file mode 100755 (executable)
index 0000000..ad6cd2c
Binary files /dev/null and b/icons/convenience.png differ
diff --git a/icons/fast_food.png b/icons/fast_food.png
new file mode 100755 (executable)
index 0000000..ad2c39c
Binary files /dev/null and b/icons/fast_food.png differ
diff --git a/icons/fire_station.png b/icons/fire_station.png
new file mode 100755 (executable)
index 0000000..897c526
Binary files /dev/null and b/icons/fire_station.png differ
diff --git a/icons/hospital.png b/icons/hospital.png
new file mode 100755 (executable)
index 0000000..6cc0380
Binary files /dev/null and b/icons/hospital.png differ
diff --git a/icons/hotel.png b/icons/hotel.png
new file mode 100755 (executable)
index 0000000..f951247
Binary files /dev/null and b/icons/hotel.png differ
diff --git a/icons/icons_grid.png b/icons/icons_grid.png
new file mode 100755 (executable)
index 0000000..9b6d628
Binary files /dev/null and b/icons/icons_grid.png differ
diff --git a/icons/parking.png b/icons/parking.png
new file mode 100755 (executable)
index 0000000..a2675d0
Binary files /dev/null and b/icons/parking.png differ
diff --git a/icons/pharmacy.png b/icons/pharmacy.png
new file mode 100755 (executable)
index 0000000..5254d93
Binary files /dev/null and b/icons/pharmacy.png differ
diff --git a/icons/pharmacy_dispensing.png b/icons/pharmacy_dispensing.png
new file mode 100755 (executable)
index 0000000..9e3a4c5
Binary files /dev/null and b/icons/pharmacy_dispensing.png differ
diff --git a/icons/police.png b/icons/police.png
new file mode 100755 (executable)
index 0000000..da271d3
Binary files /dev/null and b/icons/police.png differ
diff --git a/icons/post_box.png b/icons/post_box.png
new file mode 100755 (executable)
index 0000000..8690ebb
Binary files /dev/null and b/icons/post_box.png differ
diff --git a/icons/pub.png b/icons/pub.png
new file mode 100755 (executable)
index 0000000..b03e915
Binary files /dev/null and b/icons/pub.png differ
diff --git a/icons/recycling.png b/icons/recycling.png
new file mode 100755 (executable)
index 0000000..aa613d5
Binary files /dev/null and b/icons/recycling.png differ
diff --git a/icons/restaurant.png b/icons/restaurant.png
new file mode 100755 (executable)
index 0000000..5b6da14
Binary files /dev/null and b/icons/restaurant.png differ
diff --git a/icons/school.png b/icons/school.png
new file mode 100755 (executable)
index 0000000..1067beb
Binary files /dev/null and b/icons/school.png differ
diff --git a/icons/station.png b/icons/station.png
new file mode 100755 (executable)
index 0000000..1e19825
Binary files /dev/null and b/icons/station.png differ
diff --git a/icons/taxi.png b/icons/taxi.png
new file mode 100755 (executable)
index 0000000..42c6f92
Binary files /dev/null and b/icons/taxi.png differ
diff --git a/icons/telephone.png b/icons/telephone.png
new file mode 100755 (executable)
index 0000000..c2a2d62
Binary files /dev/null and b/icons/telephone.png differ
index 8830de308b9f351b5bb66452d89cc70eab3808cd..36003a0b290c5edd1c5597414219fc29826a6572 100755 (executable)
@@ -19,7 +19,7 @@ package net.systemeD.halcyon {
                public const MINSCALE:uint=13;                                  // don't zoom out past this
                public const MAXSCALE:uint=19;                                  // don't zoom in past this
 
-               public var ruleset:RuleSet=new RuleSet();               // rules
+               public var ruleset:RuleSet=new RuleSet(redrawPOIs);     // rules
                
                public var ways:Object=new Object();                    // geodata
                public var nodes:Object=new Object();                   //  |
@@ -84,7 +84,7 @@ package net.systemeD.halcyon {
         }
 
                public function gotEnvironment(r:Object):void {
-                       init(51.45889,-0.21476);
+                       init(52.022,-1.2745);
                }
 
                // ------------------------------------------------------------------------------------------
@@ -205,14 +205,12 @@ package net.systemeD.halcyon {
                // Redraw all items, zoom in and out
                
                public function redraw():void {
-//                     addDebug("redrawing");
-//                     var s:String='';
-                       for each (var w:WayUI in ways) {
-                w.redraw();
-//                s+=w.id+",";
-            }
-//                     addDebug(s);
-                       // ** do POIs, etc.
+                       for each (var w:WayUI in ways) { w.redraw(); }
+                       for each (var p:POI in pois) { p.redraw(); }
+               }
+
+               public function redrawPOIs():void {
+                       for each (var p:POI in pois) { p.redraw(); }
                }
 
                public function zoomIn():void {
index 8b215b7d6d35d54b14ce6faa5db1f3d81295267b..e5b999122c0b19bd23c0e6d8df8058f13588bea3 100644 (file)
@@ -12,8 +12,9 @@ package net.systemeD.halcyon {
 
         private var node:Node;
                public var map:Map;                                                     // reference to parent map
-               public var icon:Sprite;                                         // instance in display list
+               public var icon:Bitmap;                                         // instance in display list
                public var name:Sprite;                                         //  |
+               private var iconname:String='';                         // name of icon
 
                [Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")]
                public static var DejaVu:Class;
@@ -22,34 +23,46 @@ package net.systemeD.halcyon {
                public function POI(node:Node, map:Map) {
                        this.map = map;
                        this.node = node;
-
-map.addDebug("POI "+node.id);
-
-                       // place icon on map
-            var tags:Object = node.getTagsCopy();
+                       redraw();
+               }
+               
+               public function redraw():void {
+                       var tags:Object = node.getTagsCopy();
                        var styles:Array=map.ruleset.getStyle(true,tags,map.scale);
                        var ps:PointStyle=styles[1];
 
-                       if (ps) {
-map.addDebug("pointstyle found");
-                               if (ps.icon && ps.icon!='') {
-map.addDebug("placing "+ps.icon);
-                                       var loader:Loader = new Loader();
-                                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
-                                       loader.loadBytes(map.ruleset.images[ps.icon]);
+                       if (ps && ps.icon && ps.icon!='') {
+                               if (ps.icon!=iconname) {
+                                       // 'load' icon (actually just from library)
+                                       if (map.ruleset.images[ps.icon]) {
+                                               var loader:Loader = new Loader();
+                                               loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
+                                               loader.loadBytes(map.ruleset.images[ps.icon]);
+                                               iconname=ps.icon;
+                                       }
+                               } else {
+                                       // already loaded, so just reposition
+                                       updatePosition();
+                                       iconname=ps.icon;
                                }
+                       } else if (iconname!='') {
+                               // not rendered any more, so remove
+                               var l:DisplayObject=map.getChildAt(11);
+                               Sprite(l).removeChild(icon);
+                               iconname='';
                        }
                }
 
                private function loadedIcon(event:Event):void {
-map.addDebug("loadedIcon");
-                       var bitmap:Bitmap = Bitmap(event.target.content);
+                       icon = Bitmap(event.target.content);
                        var l:DisplayObject=map.getChildAt(11);
-                       bitmap.x=map.lon2coord(node.lon);
-                       bitmap.y=map.latp2coord(node.latp);
-                       Sprite(l).addChild(bitmap);
+                       Sprite(l).addChild(icon);
+                       updatePosition();
+               }
+
+               private function updatePosition():void {
+                       icon.x=map.lon2coord(node.lon);
+                       icon.y=map.latp2coord(node.latp);
                }
-               
-               // redraw
        }
 }
index 7474c4113cb7253a13b5f3711187f9f5bf02d5db..837af4ac50d1c2892f23753d33c46ee453000db4 100755 (executable)
@@ -53,6 +53,8 @@ package net.systemeD.halcyon.connection {
                        var relationlist:Array=r[2];
                        var id:Number, version:uint;
 
+                       // Load ways
+
                        for each (var w:Array in waylist) {
                                id=Number(w[0]);
                 version=uint(w[1]);
@@ -63,15 +65,17 @@ package net.systemeD.halcyon.connection {
                 }
                        }
 
+                       // Create POIs
+
                        for each (var p:Array in pointlist) {
-                               id = Number(w[0]);
-                version = uint(w[4]);
+                               id = Number(p[0]);
+                version = uint(p[4]);
 
                 var node:Node = getNode(id);
                 if ( node == null ) {
-                    var lat:Number = Number(w[2]);
-                    var lon:Number = Number(w[1]);
-                    var tags:Object = w[3];
+                    var lat:Number = Number(p[2]);
+                    var lon:Number = Number(p[1]);
+                    var tags:Object = p[3];
                     node = new Node(id, version, tags, lat, lon);
                     setNode(node);
                 }
index 37bc8d544bf08b9e9ebae3b565052ea0a04f5001..b3caff77ffa076e67005604b02cda382952c8596 100755 (executable)
@@ -65,7 +65,7 @@ package net.systemeD.halcyon.connection {
         }
 
         protected function unregisterPOI(node:Node):void {
-            var index:uint = pois.indexOf(node)
+            var index:uint = pois.indexOf(node);
             if ( index >= 0 ) {
                 pois.splice(index,1);
             }
index 35ac41dada2cacc7acc290a0512c500836a5c866..1cbb7185d123df9be3b5f13da1aae32a108fe9e9 100644 (file)
@@ -1,5 +1,13 @@
 package net.systemeD.halcyon.styleparser {
 
+       /*
+               === ImageLoader ===
+
+               This simply allows us to store a filename in the URLLoader object,
+               so that the responder knows which image has just been loaded.
+
+       */
+
        import flash.events.*;
        import flash.net.*;
 
index 3e85a1728d6ddd8cb8e126b333f205380182fe97..15541ae31999b0be0a5b141f22945dd97eaf1dbd 100644 (file)
@@ -9,9 +9,15 @@ package net.systemeD.halcyon.styleparser {
 
                public var rules:Array=new Array();             // list of rules
                public var images:Object=new Object();  // loaded images
+               private var iconCallback:Function=null; // function to call when all icons loaded
+               private var iconsToLoad:uint=0;                 // number of icons left to load (fire callback when ==0)
 
                // variables for name, author etc.
 
+               public function RuleSet(f:Function=null):void {
+                       iconCallback=f;
+               }
+
                // returns array of ShapeStyle,PointStyle,TextStyle,ShieldStyle
                public function getStyle(isPoint:Boolean,tags:Object,scale:uint):Array {
                        var ss:ShapeStyle;
@@ -21,8 +27,8 @@ package net.systemeD.halcyon.styleparser {
                        for each (var rule:* in rules) {
                                if ( isPoint && rule is ShapeRule) { continue; }
                                if (!isPoint && rule is PointRule) { continue; }
-                               if (scale>rule.minScale && !isPoint) { continue; }
-                               if (scale<rule.maxScale && !isPoint) { continue; }
+                               if (scale>rule.minScale) { continue; }
+                               if (scale<rule.maxScale) { continue; }
                                if (rule.test(tags)) {
                                        if (rule is ShapeRule && rule.shapeStyle)  { ss=rule.shapeStyle; }
                                        if (rule is PointRule && rule.pointStyle)  { ps=rule.pointStyle; }
@@ -96,11 +102,13 @@ package net.systemeD.halcyon.styleparser {
                
                public function loadImages():void {
                        var ps:PointStyle;
+
                        for each (var rule:* in rules) {
                                if (!(rule is PointRule)) { continue; }
                                if (!(rule.pointStyle)) { continue; }
                                if (!(rule.pointStyle.icon)) { continue; }
                                
+                               iconsToLoad++;
                                var request:URLRequest=new URLRequest(rule.pointStyle.icon);
                                var loader:ImageLoader=new ImageLoader();
                                loader.dataFormat=URLLoaderDataFormat.BINARY;
@@ -116,9 +124,9 @@ package net.systemeD.halcyon.styleparser {
                // data handler
 
                private function loadedImage(event:Event):void {
-                       Globals.vars.debug.appendText("Target is "+event.target+", name"+event.target.filename+"\n");
                        images[event.target.filename]=event.target.data;
+                       iconsToLoad--;
+                       if (iconsToLoad==0 && iconCallback!=null) { iconCallback(); }
                }
-
        }
 }