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 parents:Dictionary = new Dictionary();
13 public function Entity(id:Number, version:uint, tags:Object) {
15 this._version = version;
20 public function get id():Number {
24 public function get version():uint {
28 // Tag-handling methods
30 public function hasTags():Boolean {
31 for (var key:String in tags)
36 public function getTag(key:String):String {
40 public function setTag(key:String, value:String):void {
41 var old:String = tags[key];
43 if ( value == null || value == "" )
48 dispatchEvent(new TagEvent(Connection.TAG_CHANGE, this, key, key, old, value));
52 public function renameTag(oldKey:String, newKey:String):void {
53 var value:String = tags[oldKey];
54 if ( oldKey != newKey ) {
58 dispatchEvent(new TagEvent(Connection.TAG_CHANGE, this, oldKey, newKey, value, value));
62 public function getTagList():TagList {
63 return new TagList(tags);
66 public function getTagsCopy():Object {
68 for (var key:String in tags )
69 copy[key] = tags[key];
73 public function getTagsHash():Object {
74 // hm, not sure we should be doing this, but for read-only purposes
75 // it's faster than using getTagsCopy
79 public function getTagArray():Array {
81 for (var key:String in tags )
82 copy.push(new Tag(this, key, tags[key]));
86 // Clean/dirty methods
88 public function get isDirty():Boolean {
92 public function markClean(newID:Number, newVersion:uint):void {
94 this._version = newVersion;
98 protected function markDirty():void {
104 public function addParent(parent:Entity):void {
105 parents[parent]=true;
108 public function removeParent(parent:Entity):void {
109 delete parents[parent];
112 public function get parentWays():Array {
114 for (var o:Object in parents) {
115 if (o is Way) { a.push(o); }
120 public function get parentRelations():Array {
122 for (var o:Object in parents) {
123 if (o is Relation) { a.push(o); }
128 public function get parentObjects():Array {
130 for (var o:Object in parents) { a.push(o); }
136 public function getType():String {