Files
iD/js/id/graph/entity.js
2012-12-04 17:23:09 -05:00

55 lines
1.2 KiB
JavaScript

iD.Entity = function(a, b, c) {
if (!(this instanceof iD.Entity)) return new iD.Entity(a, b, c);
_.extend(this, {tags: {}}, a, b, c);
if (!this.id) {
this.id = iD.util.id(this.type);
this._updated = true;
}
delete this._extent;
if (iD.debug) {
Object.freeze(this);
Object.freeze(this.tags);
}
};
iD.Entity.prototype = {
update: function(attrs) {
return iD.Entity(this, attrs, {_updated: true});
},
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({tags: {}}, attrs || {}, {type: 'node'});
};
iD.Way = function(attrs) {
return iD.Entity({tags: {}, nodes: []}, attrs || {}, {type: 'way'});
};
iD.Way.isOneWay = function(d) {
return !!(d.tags.oneway && d.tags.oneway === 'yes');
};
iD.Way.isClosed = function(d) {
return (!d.nodes.length) || d.nodes[d.nodes.length - 1].id === d.nodes[0].id;
};
iD.Way.isArea = function(d) {
return iD.Way.isClosed(d) || (d.tags.area && d.tags.area === 'yes');
};
iD.Relation = function(attrs) {
return iD.Entity({tags: {}}, attrs || {}, {type: 'relation'});
};