can now change tags in the 'Advanced' mode
[potlatch2.git] / net / systemeD / halcyon / connection / Connection.as
1 package net.systemeD.halcyon.connection {
2
3     import flash.net.*;
4
5     import flash.events.EventDispatcher;
6     import flash.events.Event;
7
8         public class Connection extends EventDispatcher {
9
10         private static var CONNECTION_TYPE:String = "AMF";
11         private static var connectionInstance:Connection = null;
12
13         protected static var policyURL:String = "http://127.0.0.1:3000/api/crossdomain.xml";
14         protected static var apiBaseURL:String = "http://127.0.0.1:3000/api/0.6/";
15
16         public static function getConnection():Connection {
17             if ( connectionInstance == null ) {
18                 if ( CONNECTION_TYPE == "XML" )
19                     connectionInstance = new XMLConnection();
20                 else
21                     connectionInstance = new AMFConnection();
22             }
23             return connectionInstance;
24         }
25
26                 public function getEnvironment(responder:Responder):void {}
27
28         // connection events
29         public static var NEW_NODE:String = "new_node";
30         public static var NEW_WAY:String = "new_way";
31         public static var NEW_RELATION:String = "new_relation";
32         public static var NEW_POI:String = "new_poi";
33         public static var TAG_CHANGE:String = "tag_change";
34
35         // store the data we download
36         private var negativeID:Number = -1;
37         private var nodes:Object = {};
38         private var ways:Object = {};
39         private var relations:Object = {};
40         private var pois:Array = [];
41
42         protected function get nextNegative():Number {
43             return negativeID--;
44         }
45
46         protected function setNode(node:Node):void {
47             nodes[node.id] = node;
48             dispatchEvent(new EntityEvent(NEW_NODE, node));
49         }
50
51         protected function setWay(way:Way):void {
52             ways[way.id] = way;
53             dispatchEvent(new EntityEvent(NEW_WAY, way));
54         }
55
56         protected function setRelation(relation:Relation):void {
57             relations[relation.id] = relation;
58             dispatchEvent(new EntityEvent(NEW_RELATION, relation));
59         }
60
61         protected function registerPOI(node:Node):void {
62             if ( pois.indexOf(node) < 0 ) {
63                 pois.push(node);
64                 dispatchEvent(new EntityEvent(NEW_POI, node));
65             }
66         }
67
68         protected function unregisterPOI(node:Node):void {
69             var index:uint = pois.indexOf(node);
70             if ( index >= 0 ) {
71                 pois.splice(index,1);
72             }
73         }
74
75         public function getNode(id:Number):Node {
76             return nodes[id];
77         }
78
79         public function getWay(id:Number):Way {
80             return ways[id];
81         }
82
83         public function getRelation(id:Number):Relation {
84             return relations[id];
85         }
86
87         public function createNode(tags:Object, lat:Number, lon:Number):Node {
88             var node:Node = new Node(nextNegative, 0, tags, lat, lon);
89             setNode(node);
90             return node;
91         }
92
93         public function createWay(tags:Object, nodes:Array):Way {
94             var way:Way = new Way(nextNegative, 0, tags, nodes.concat());
95             setWay(way);
96             return way;
97         }
98
99         public function createRelation(tags:Object, members:Array):Relation {
100             var relation:Relation = new Relation(nextNegative, 0, tags, members.concat());
101             setRelation(relation);
102             return relation;
103         }
104
105         public function getAllNodeIDs():Array {
106             var list:Array = [];
107             for each (var node:Node in nodes)
108                 list.push(node.id);
109             return list;
110         }
111
112         public function getAllWayIDs():Array {
113             var list:Array = [];
114             for each (var way:Way in ways)
115                 list.push(way.id);
116             return list;
117         }
118
119         public function getAllRelationIDs():Array {
120             var list:Array = [];
121             for each (var relation:Relation in relations)
122                 list.push(relation.id);
123             return list;
124         }
125
126         // these are functions that the Connection implementation is expected to
127         // provide. This class has some generic helpers for the implementation.
128                 public function loadBbox(left:Number, right:Number,
129                                                                 top:Number, bottom:Number):void {
130             }
131     }
132
133 }
134
135