1 package net.systemeD.halcyon.connection {
3 import flash.events.EventDispatcher;
4 import flash.utils.Dictionary;
6 public class Entity extends EventDispatcher {
7 private var _id:Number;
8 private var _version:uint;
9 private var tags:Object = {};
10 private var modified:Boolean = false;
11 private var _loaded:Boolean = true;
12 private var parents:Dictionary = new Dictionary();
13 private var locked:Boolean = false;
14 protected var deleted:Boolean = false;
16 public function Entity(id:Number, version:uint, tags:Object, loaded:Boolean) {
18 this._version = version;
20 this._loaded = loaded;
24 public function get id():Number {
28 public function get version():uint {
32 public function get loaded():Boolean {
36 public function updateEntityProperties(version:uint, tags:Object, loaded:Boolean):void {
37 _version=version; this.tags=tags; _loaded=loaded;
40 // Tag-handling methods
42 public function hasTags():Boolean {
43 for (var key:String in tags)
48 // ** we could do with hasInterestingTags - don't bother with source, created_by, any TIGER tags, etc.
50 public function getTag(key:String):String {
54 public function setTag(key:String, value:String):void {
55 var old:String = tags[key];
57 if ( value == null || value == "" )
62 dispatchEvent(new TagEvent(Connection.TAG_CHANGED, this, key, key, old, value));
66 public function renameTag(oldKey:String, newKey:String):void {
67 var value:String = tags[oldKey];
68 if ( oldKey != newKey ) {
72 dispatchEvent(new TagEvent(Connection.TAG_CHANGED, this, oldKey, newKey, value, value));
76 public function getTagList():TagList {
77 return new TagList(tags);
80 public function getTagsCopy():Object {
82 for (var key:String in tags )
83 copy[key] = tags[key];
87 public function getTagsHash():Object {
88 // hm, not sure we should be doing this, but for read-only purposes
89 // it's faster than using getTagsCopy
93 public function getTagArray():Array {
95 for (var key:String in tags )
96 copy.push(new Tag(this, key, tags[key]));
100 // Clean/dirty methods
102 public function get isDirty():Boolean {
106 public function markClean(newID:Number, newVersion:uint):void {
108 this._version = newVersion;
112 protected function markDirty():void {
118 public function remove():void {
122 internal function isEmpty():Boolean {
123 return false; // to be overridden
126 protected function removeFromParents():void {
127 for (var o:Object in parents) {
128 if (o is Relation) { Relation(o).removeMember(this); }
129 else if (o is Way) { Way(o).removeNode(Node(this)); }
130 if (o.isEmpty()) { o.remove(); }
136 public function addParent(parent:Entity):void {
137 parents[parent]=true;
139 if ( parent is Relation )
140 dispatchEvent(new RelationMemberEvent(Connection.ADDED_TO_RELATION, this, parent as Relation, -1));
143 public function removeParent(parent:Entity):void {
144 delete parents[parent];
146 if ( parent is Relation )
147 dispatchEvent(new RelationMemberEvent(Connection.REMOVED_FROM_RELATION, this, parent as Relation, -1));
150 public function get parentWays():Array {
152 for (var o:Object in parents) {
153 if (o is Way) { a.push(o); }
158 public function get hasParents():Boolean {
159 for (var o:Object in parents) { return true; }
163 public function get hasParentWays():Boolean {
164 for (var o:Object in parents) {
165 if (o is Way) { return true; }
170 public function get numParentWays():uint {
172 for (var o:Object in parents) {
173 if (o is Way) { i++; }
178 public function get parentRelations():Array {
180 for (var o:Object in parents) {
181 if (o is Relation) { a.push(o); }
186 public function get parentObjects():Array {
188 for (var o:Object in parents) { a.push(o); }
192 public function hasParent(entity:Entity):Boolean {
193 return parents[entity] == true;
196 // Resume/suspend redraw
198 public function suspend():void {
199 dispatchEvent(new EntityEvent(Connection.SUSPEND_REDRAW, this));
202 public function resume():void {
203 dispatchEvent(new EntityEvent(Connection.RESUME_REDRAW, this));
208 public function getType():String {