delete objects (possibly not complete)
[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
8         public function Node(id:Number, version:uint, tags:Object, loaded:Boolean, lat:Number, lon:Number) {
9             super(id, version, tags, loaded);
10             this._lat = lat;
11             this._latproj = lat2latp(lat);
12             this._lon = lon;
13         }
14
15                 public function update(version:uint, tags:Object, loaded:Boolean, lat:Number, lon:Number):void {
16                         updateEntityProperties(version,tags,loaded); this.lat=lat; this.lon=lon;
17                 }
18
19         public function get lat():Number {
20             return _lat;
21         }
22
23         public function get latp():Number {
24             return _latproj;
25         }
26
27         public function get lon():Number {
28             return _lon;
29         }
30
31         public function set lat(lat:Number):void {
32             var oldLat:Number = this._lat;
33             this._lat = lat;
34             this._latproj = lat2latp(lat);
35             markDirty();
36             dispatchEvent(new NodeMovedEvent(Connection.NODE_MOVED, this, oldLat, _lon));
37         }
38
39         public function set latp(latproj:Number):void {
40             var oldLat:Number = this._lat;
41             this._latproj = latproj;
42             this._lat = latp2lat(latproj);
43             markDirty();
44             dispatchEvent(new NodeMovedEvent(Connection.NODE_MOVED, this, oldLat, _lon));
45          }
46
47         public function set lon(lon:Number):void {
48             var oldLon:Number = this._lon;
49             this._lon = lon;
50             markDirty();
51             dispatchEvent(new NodeMovedEvent(Connection.NODE_MOVED, this, _lat, oldLon));
52          }
53
54         public override function toString():String {
55             return "Node("+id+"@"+version+"): "+lat+","+lon+" "+getTagList();
56         }
57
58                 public override function remove():void {
59                         removeFromParents();
60                         deleted=true;
61             dispatchEvent(new EntityEvent(Connection.NODE_DELETED, this));
62                 }
63
64                 internal override function isEmpty():Boolean {
65                         return deleted;
66                 }
67
68         public static function lat2latp(lat:Number):Number {
69             return 180/Math.PI * Math.log(Math.tan(Math.PI/4+lat*(Math.PI/180)/2));
70         }
71
72                 public static function latp2lat(a:Number):Number {
73                     return 180/Math.PI * (2 * Math.atan(Math.exp(a*Math.PI/180)) - Math.PI/2);
74                 }
75                 
76                 public override function getType():String {
77                         return 'node';
78                 }
79     }
80
81 }