refactor the potlatch 2 code to look more MVC wrt the API parts
[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:Sprite;                                         // instance in display list
16                 public var name:Sprite;                                         //  |
17
18                 [Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")]
19                 public static var DejaVu:Class;
20                 public var nameformat:TextFormat;
21
22                 public function POI(node:Node, map:Map) {
23                         this.map = map;
24                         this.node = node;
25
26 map.addDebug("POI "+node.id);
27
28                         // place icon on map
29             var tags:Object = node.getTagsCopy();
30                         var styles:Array=map.ruleset.getStyle(true,tags,map.scale);
31                         var ps:PointStyle=styles[1];
32
33                         if (ps) {
34 map.addDebug("pointstyle found");
35                                 if (ps.icon && ps.icon!='') {
36 map.addDebug("placing "+ps.icon);
37                                         var loader:Loader = new Loader();
38                                         loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
39                                         loader.loadBytes(map.ruleset.images[ps.icon]);
40                                 }
41                         }
42                 }
43
44                 private function loadedIcon(event:Event):void {
45 map.addDebug("loadedIcon");
46                         var bitmap:Bitmap = Bitmap(event.target.content);
47                         var l:DisplayObject=map.getChildAt(11);
48                         bitmap.x=map.lon2coord(node.lon);
49                         bitmap.y=map.latp2coord(node.latp);
50                         Sprite(l).addChild(bitmap);
51                 }
52                 
53                 // redraw
54         }
55 }