add node drawing + dragging & highlight selected way using stylesheet
[potlatch2.git] / net / systemeD / halcyon / connection / Node.as
1 package net.systemeD.halcyon.connection {
2
3     public class Node extends Entity {
4         private var _lat:Number;
5         private var _latproj:Number;
6         private var _lon:Number;
7         private var _ways:Array = new Array();
8
9         public function Node(id:Number, version:uint, tags:Object, lat:Number, lon:Number) {
10             super(id, version, tags);
11             this.lat = lat;
12             this.lon = lon;
13         }
14
15         public function get lat():Number {
16             return _lat;
17         }
18
19         public function get latp():Number {
20             return _latproj;
21         }
22
23         public function get lon():Number {
24             return _lon;
25         }
26
27         public function set lat(lat:Number):void {
28             var oldLat:Number = this._lat;
29             this._lat = lat;
30             this._latproj = lat2latp(lat);
31             markDirty();
32             dispatchEvent(new NodeMovedEvent(Connection.NODE_MOVED, this, oldLat, _lon));
33         }
34
35         public function set latp(latproj:Number):void {
36             this._latproj = latproj;
37             this._lat = latp2lat(lat);
38         }
39
40         public function set lon(lon:Number):void {
41             this._lon = lon;
42         }
43
44         public override function toString():String {
45             return "Node("+id+"@"+version+"): "+lat+","+lon+" "+getTagList();
46         }
47
48         public static function lat2latp(lat:Number):Number {
49             return 180/Math.PI * Math.log(Math.tan(Math.PI/4+lat*(Math.PI/180)/2));
50         }
51
52                 public function latp2lat(a:Number):Number {
53                     return 180/Math.PI * (2 * Math.atan(Math.exp(a*Math.PI/180)) - Math.PI/2);
54                 }
55                 
56                 public function get ways():Array {
57                     return _ways;
58                 }
59
60         public function registerAddedToWay(way:Way):void {
61             if ( _ways.indexOf(way) < 0 )
62                 _ways.push(way);
63         }
64         
65         public function registerRemovedFromWay(way:Way):void {
66             var i:int = _ways.indexOf(way);
67             if ( i >= 0 )
68                 _ways.splice(i, 1);
69         }
70         
71                 public override function getType():String {
72                         return 'node';
73                 }
74     }
75
76 }