Extract Entity#isUsed

This commit is contained in:
John Firebaugh
2013-05-24 15:42:55 -07:00
parent 8f272f2508
commit 16e5f5e2ce
3 changed files with 36 additions and 8 deletions
+5
View File
@@ -99,6 +99,11 @@ iD.Entity.prototype = {
return this.extent(resolver).intersects(extent);
},
isUsed: function(resolver) {
return _.without(Object.keys(this.tags), 'area').length > 0 ||
resolver.parentRelations(this).length > 0;
},
// Returns the (possibly negative) area of the entity in square pixels at an
// arbitrary unspecified zoom level -- so basically, only useful for relative
// comparisons.
+4 -8
View File
@@ -53,16 +53,12 @@ iD.ui.Inspector = function(context) {
presetLayer.call(presetList);
});
var unused =
_.without(Object.keys(entity.tags), 'area').length === 0 &&
context.graph().parentRelations(entity).length === 0;
if (unused) {
panewrap.style('right', '-100%');
presetLayer.call(presetList);
} else {
if (entity.isUsed(context.graph())) {
panewrap.style('right', '-0%');
tagLayer.call(entityEditor);
} else {
panewrap.style('right', '-100%');
presetLayer.call(presetList);
}
}
+27
View File
@@ -144,6 +144,33 @@ describe('iD.Entity', function () {
});
});
describe("#isUsed", function () {
it("returns false for an entity without tags", function () {
var node = iD.Node(),
graph = iD.Graph([node]);
expect(node.isUsed(graph)).to.equal(false);
});
it("returns true for an entity with tags", function () {
var node = iD.Node({tags: {foo: 'bar'}}),
graph = iD.Graph([node]);
expect(node.isUsed(graph)).to.equal(true);
});
it("returns false for an entity with only an area=yes tag", function () {
var node = iD.Node({tags: {area: 'yes'}}),
graph = iD.Graph([node]);
expect(node.isUsed(graph)).to.equal(false);
});
it("returns true for an entity that is a relation member", function () {
var node = iD.Node(),
relation = iD.Relation({members: [{id: node.id}]}),
graph = iD.Graph([node, relation]);
expect(node.isUsed(graph)).to.equal(true);
});
});
describe("#hasDeprecatedTags", function () {
it("returns false if entity has no tags", function () {
expect(iD.Entity().deprecatedTags()).to.eql({});