POI stuff
[potlatch2.git] / net / systemeD / halcyon / POI.as
1 package net.systemeD.halcyon {
2
3     import net.systemeD.halcyon.connection.Node;
4
5         public class POI extends Object {
6
7                 import flash.display.*;
8                 import flash.events.*;
9                 import flash.text.TextField;
10                 import flash.text.TextFormat;
11                 import net.systemeD.halcyon.styleparser.*;
12
13         private var node:Node;
14                 public var map:Map;                                                     // reference to parent map
15                 public var icon:Bitmap;                                         // instance in display list
16                 public var name:Sprite;                                         //  |
17                 private var iconname:String='';                         // name of icon
18
19                 [Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")]
20                 public static var DejaVu:Class;
21                 public var nameformat:TextFormat;
22
23                 public function POI(node:Node, map:Map) {
24                         this.map = map;
25                         this.node = node;
26                         redraw();
27                 }
28                 
29                 public function redraw():void {
30                         var tags:Object = node.getTagsCopy();
31                         var styles:Array=map.ruleset.getStyle(true,tags,map.scale);
32                         var ps:PointStyle=styles[1];
33
34                         if (ps && ps.icon && ps.icon!='') {
35                                 if (ps.icon!=iconname) {
36                                         // 'load' icon (actually just from library)
37                                         if (map.ruleset.images[ps.icon]) {
38                                                 var loader:Loader = new Loader();
39                                                 loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
40                                                 loader.loadBytes(map.ruleset.images[ps.icon]);
41                                                 iconname=ps.icon;
42                                         }
43                                 } else {
44                                         // already loaded, so just reposition
45                                         updatePosition();
46                                         iconname=ps.icon;
47                                 }
48                         } else if (iconname!='') {
49                                 // not rendered any more, so remove
50                                 var l:DisplayObject=map.getChildAt(11);
51                                 Sprite(l).removeChild(icon);
52                                 iconname='';
53                         }
54                 }
55
56                 private function loadedIcon(event:Event):void {
57                         icon = Bitmap(event.target.content);
58                         var l:DisplayObject=map.getChildAt(11);
59                         Sprite(l).addChild(icon);
60                         updatePosition();
61                 }
62
63                 private function updatePosition():void {
64                         icon.x=map.lon2coord(node.lon);
65                         icon.y=map.latp2coord(node.latp);
66                 }
67         }
68 }