basic POI rendering support
[potlatch2.git] / net / systemeD / halcyon / POI.as
1 package net.systemeD.halcyon {
2
3         public class POI extends Object {
4
5                 import flash.display.*;
6                 import flash.events.*;
7                 import flash.text.TextField;
8                 import flash.text.TextFormat;
9                 import net.systemeD.halcyon.styleparser.*;
10
11                 public var id:int;
12                 public var tags:Object;
13                 public var clean:Boolean=true;                          // altered since last upload?
14                 public var uploading:Boolean=false;                     // currently uploading?
15                 public var locked:Boolean=false;                        // locked against upload?
16                 public var version:uint=0;                                      // version number?
17                 public var map:Map;                                                     // reference to parent map
18                 public var icon:Sprite;                                         // instance in display list
19                 public var name:Sprite;                                         //  |
20
21                 [Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")]
22                 public static var DejaVu:Class;
23                 public var nameformat:TextFormat;
24
25                 public function POI(id:int,version:int,lon:Number,lat:Number,tags:Object,map:Map) {
26                         this.id=id;
27                         this.version=version;
28                         this.map=map;
29                         if (tags==null) { tags=new Object(); }
30                         this.tags=tags;
31 map.addDebug("POI "+id);
32                         if (map.nodes[id]) {
33                                 // ** already exists - do stuff if it's moved, or in a way
34                         } else {
35                                 map.nodes[id]=new Node(id,lon,map.lat2latp(lat),tags,version);
36                         }
37
38                         // place icon on map
39                         var styles:Array=map.ruleset.getStyle(true,tags,map.scale);
40                         var ps:PointStyle=styles[1];
41
42                         if (ps) {
43 map.addDebug("pointstyle found");
44                                 if (ps.icon && ps.icon!='') {
45 map.addDebug("placing "+ps.icon);
46                                         var loader:Loader = new Loader();
47                                         loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
48                                         loader.loadBytes(map.ruleset.images[ps.icon]);
49                                 }
50                         }
51                 }
52
53                 private function loadedIcon(event:Event):void {
54 map.addDebug("loadedIcon");
55                         var bitmap:Bitmap = Bitmap(event.target.content);
56                         var l:DisplayObject=map.getChildAt(11);
57                         bitmap.x=map.lon2coord(map.nodes[id].lon);
58                         bitmap.y=map.latp2coord(map.nodes[id].latp);
59                         Sprite(l).addChild(bitmap);
60                 }
61                 
62                 // redraw
63         }
64 }