mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 09:42:56 +00:00
47 lines
996 B
JavaScript
47 lines
996 B
JavaScript
iD.Entity = function(a, b) {
|
|
if (!(this instanceof iD.Entity)) return new iD.Entity(a, b);
|
|
|
|
_.extend(this, {tags: {}}, a, b);
|
|
|
|
if (b) {
|
|
this._updated = true;
|
|
}
|
|
|
|
if (!this.id) {
|
|
this.id = iD.Util.id(this.type);
|
|
this._updated = true;
|
|
}
|
|
|
|
if (iD.debug) {
|
|
Object.freeze(this);
|
|
Object.freeze(this.tags);
|
|
}
|
|
};
|
|
|
|
iD.Entity.prototype = {
|
|
update: function(attrs) {
|
|
attrs._updated = true;
|
|
return iD.Entity(this, attrs);
|
|
},
|
|
|
|
created: function() {
|
|
return this._updated && +this.id.slice(1) < 0;
|
|
},
|
|
|
|
modified: function() {
|
|
return this._updated && +this.id.slice(1) > 0;
|
|
}
|
|
};
|
|
|
|
iD.Node = function(attrs) {
|
|
return iD.Entity(_.extend({}, attrs || {}, {type: 'node'}));
|
|
};
|
|
|
|
iD.Way = function(attrs) {
|
|
return iD.Entity(_.extend({}, attrs || {}, {type: 'way', nodes: []}));
|
|
};
|
|
|
|
iD.Relation = function(attrs) {
|
|
return iD.Entity(_.extend({}, attrs || {}, {type: 'relation'}));
|
|
};
|