mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 05:30:35 +02:00
Extract Entity#isUsed
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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({});
|
||||
|
||||
Reference in New Issue
Block a user