Draw multiple strokes, label POIs, and much much more fun.
[potlatch2.git] / net / systemeD / halcyon / POI.as
index e5b999122c0b19bd23c0e6d8df8058f13588bea3..9deecba794879e274f3fc8eabf9e55f30e34a934 100644 (file)
@@ -1,24 +1,29 @@
 package net.systemeD.halcyon {
 
+       import flash.display.*;
+       import flash.events.*;
+       import flash.text.AntiAliasType;
+       import flash.text.GridFitType;
+       import flash.text.TextField;
+       import flash.text.TextFormat;
     import net.systemeD.halcyon.connection.Node;
-
+       import net.systemeD.halcyon.styleparser.*;
+       
        public class POI extends Object {
-
-               import flash.display.*;
-               import flash.events.*;
-               import flash.text.TextField;
-               import flash.text.TextFormat;
-               import net.systemeD.halcyon.styleparser.*;
-
+               
         private var node:Node;
                public var map:Map;                                                     // reference to parent map
                public var icon:Bitmap;                                         // instance in display list
                public var name:Sprite;                                         //  |
                private var iconname:String='';                         // name of icon
 
+               public static const DEFAULT_TEXTFIELD_PARAMS:Object = {
+                       embedFonts: true,
+                       antiAliasType: AntiAliasType.ADVANCED,
+                       gridFitType: GridFitType.NONE
+               };
                [Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")]
                public static var DejaVu:Class;
-               public var nameformat:TextFormat;
 
                public function POI(node:Node, map:Map) {
                        this.map = map;
@@ -28,24 +33,35 @@ package net.systemeD.halcyon {
                
                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 && 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;
+                       var styles:Array=map.ruleset.getStyles(true,tags,map.scale);
+                       var r:Boolean=false;    // ** rendered
+                       for each (var s:* in styles) {
+                               if ((s is PointStyle) && s.icon && s.icon!="") {
+                                       r=true;
+                                       if (s.icon!=iconname) {
+                                               // 'load' icon (actually just from library)
+                                               if (map.ruleset.images[s.icon]) {
+                                                       var loader:Loader = new Loader();
+                                                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
+                                                       loader.loadBytes(map.ruleset.images[s.icon]);
+                                                       iconname=s.icon;
+                                               }
+                                       } else {
+                                               // already loaded, so just reposition
+                                               updatePosition();
+                                               iconname=s.icon;
+                                       }
+                               } else if ((s is TextStyle) && s.tag && tags[s.tag]) {
+                                       // create name sprite
+                                       if (!name) {
+                                               name=new Sprite();
+                                               var c:DisplayObject=map.getChildAt(12);
+                                               Sprite(c).addChild(name);
                                        }
-                               } else {
-                                       // already loaded, so just reposition
-                                       updatePosition();
-                                       iconname=ps.icon;
+                                       s.writeNameLabel(name,tags[s.tag],map.lon2coord(node.lon),map.latp2coord(node.latp));
                                }
-                       } else if (iconname!='') {
+                       }
+                       if (!r && iconname!='') {
                                // not rendered any more, so remove
                                var l:DisplayObject=map.getChildAt(11);
                                Sprite(l).removeChild(icon);
@@ -61,8 +77,9 @@ package net.systemeD.halcyon {
                }
 
                private function updatePosition():void {
-                       icon.x=map.lon2coord(node.lon);
-                       icon.y=map.latp2coord(node.latp);
+                       icon.x=map.lon2coord(node.lon)-icon.width/2;
+                       icon.y=map.latp2coord(node.latp)-icon.height/2;
                }
+
        }
 }