mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Support special styling for wikidata-tagged features
This commit is contained in:
@@ -105,6 +105,7 @@ g.point .stroke {
|
||||
fill: #fff;
|
||||
}
|
||||
|
||||
|
||||
g.qa_error .shadow,
|
||||
g.point .shadow,
|
||||
g.note .shadow {
|
||||
@@ -282,6 +283,22 @@ text.point {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
|
||||
/* Wikidata-tagged */
|
||||
g.point.tag-wikidata .stroke {
|
||||
fill: #8e9;
|
||||
}
|
||||
.labels-group.halo text.tag-wikidata {
|
||||
stroke: #8e9;
|
||||
}
|
||||
.icon.areaicon-halo.tag-wikidata {
|
||||
stroke: #9e9;
|
||||
}
|
||||
.icon.areaicon.tag-wikidata {
|
||||
color: #050;
|
||||
}
|
||||
|
||||
|
||||
/* Highlighting */
|
||||
g.point.highlighted .shadow,
|
||||
path.shadow.highlighted {
|
||||
|
||||
@@ -174,6 +174,9 @@ osmEntity.prototype = {
|
||||
return Object.keys(this.tags).some(osmIsInterestingTag);
|
||||
},
|
||||
|
||||
hasWikidata: function() {
|
||||
return !!this.tags.wikidata || !!this.tags['brand:wikidata'];
|
||||
},
|
||||
|
||||
isHighwayIntersection: function() {
|
||||
return false;
|
||||
|
||||
@@ -156,7 +156,8 @@ export function svgLabels(projection, context) {
|
||||
texts.enter()
|
||||
.append('text')
|
||||
.attr('class', function(d, i) {
|
||||
return classes + ' ' + labels[i].classes + ' ' + d.id;
|
||||
var hasWd = d.hasWikidata() ? ' tag-wikidata' : '';
|
||||
return classes + ' ' + labels[i].classes + hasWd + ' ' + d.id;
|
||||
})
|
||||
.merge(texts)
|
||||
.attr('x', get(labels, 'x'))
|
||||
@@ -192,7 +193,10 @@ export function svgLabels(projection, context) {
|
||||
// enter/update
|
||||
icons.enter()
|
||||
.append('use')
|
||||
.attr('class', 'icon ' + classes)
|
||||
.attr('class', function(d) {
|
||||
var hasWd = d.hasWikidata() ? ' tag-wikidata' : '';
|
||||
return 'icon ' + classes + hasWd;
|
||||
})
|
||||
.attr('width', '17px')
|
||||
.attr('height', '17px')
|
||||
.merge(icons)
|
||||
|
||||
@@ -127,11 +127,9 @@ export function svgPoints(projection, context) {
|
||||
.attr('transform', svgPointTransform(projection))
|
||||
.call(svgTagClasses());
|
||||
|
||||
// Selecting the following implicitly
|
||||
// sets the data (point entity) on the element
|
||||
groups.select('.shadow');
|
||||
groups.select('.stroke');
|
||||
groups.select('.icon')
|
||||
groups.select('.shadow'); // propagate bound data
|
||||
groups.select('.stroke'); // propagate bound data
|
||||
groups.select('.icon') // propagate bound data
|
||||
.attr('xlink:href', function(entity) {
|
||||
var preset = context.presets().match(entity, graph);
|
||||
var picon = preset && preset.icon;
|
||||
|
||||
@@ -139,6 +139,11 @@ export function svgTagClasses() {
|
||||
}
|
||||
}
|
||||
|
||||
// If this is a wikidata-tagged item, add a class for that..
|
||||
if (t.wikidata || t['brand:wikidata']) {
|
||||
classes.push('tag-wikidata');
|
||||
}
|
||||
|
||||
return classes.join(' ').trim();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
describe('iD.osmEntity', function () {
|
||||
it('returns a subclass of the appropriate type', function () {
|
||||
expect(iD.Entity({type: 'node'})).be.an.instanceOf(iD.osmNode);
|
||||
expect(iD.Entity({type: 'way'})).be.an.instanceOf(iD.osmWay);
|
||||
expect(iD.Entity({type: 'relation'})).be.an.instanceOf(iD.osmRelation);
|
||||
expect(iD.Entity({id: 'n1'})).be.an.instanceOf(iD.osmNode);
|
||||
expect(iD.Entity({id: 'w1'})).be.an.instanceOf(iD.osmWay);
|
||||
expect(iD.Entity({id: 'r1'})).be.an.instanceOf(iD.osmRelation);
|
||||
expect(iD.osmEntity({type: 'node'})).be.an.instanceOf(iD.osmNode);
|
||||
expect(iD.osmEntity({type: 'way'})).be.an.instanceOf(iD.osmWay);
|
||||
expect(iD.osmEntity({type: 'relation'})).be.an.instanceOf(iD.osmRelation);
|
||||
expect(iD.osmEntity({id: 'n1'})).be.an.instanceOf(iD.osmNode);
|
||||
expect(iD.osmEntity({id: 'w1'})).be.an.instanceOf(iD.osmWay);
|
||||
expect(iD.osmEntity({id: 'r1'})).be.an.instanceOf(iD.osmRelation);
|
||||
});
|
||||
|
||||
if (iD.debug) {
|
||||
it('is frozen', function () {
|
||||
expect(Object.isFrozen(iD.Entity())).to.be.true;
|
||||
expect(Object.isFrozen(iD.osmEntity())).to.be.true;
|
||||
});
|
||||
|
||||
it('freezes tags', function () {
|
||||
expect(Object.isFrozen(iD.Entity().tags)).to.be.true;
|
||||
expect(Object.isFrozen(iD.osmEntity().tags)).to.be.true;
|
||||
});
|
||||
}
|
||||
|
||||
describe('.id', function () {
|
||||
it('generates unique IDs', function () {
|
||||
expect(iD.Entity.id('node')).not.to.equal(iD.Entity.id('node'));
|
||||
expect(iD.osmEntity.id('node')).not.to.equal(iD.osmEntity.id('node'));
|
||||
});
|
||||
|
||||
describe('.fromOSM', function () {
|
||||
it('returns a ID string unique across entity types', function () {
|
||||
expect(iD.Entity.id.fromOSM('node', '1')).to.equal('n1');
|
||||
expect(iD.osmEntity.id.fromOSM('node', '1')).to.equal('n1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.toOSM', function () {
|
||||
it('reverses fromOSM', function () {
|
||||
expect(iD.Entity.id.toOSM(iD.Entity.id.fromOSM('node', '1'))).to.equal('1');
|
||||
expect(iD.osmEntity.id.toOSM(iD.osmEntity.id.fromOSM('node', '1'))).to.equal('1');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#copy', function () {
|
||||
it('returns a new Entity', function () {
|
||||
var n = iD.Entity({id: 'n'}),
|
||||
result = n.copy(null, {});
|
||||
expect(result).to.be.an.instanceof(iD.Entity);
|
||||
var n = iD.osmEntity({id: 'n'});
|
||||
var result = n.copy(null, {});
|
||||
expect(result).to.be.an.instanceof(iD.osmEntity);
|
||||
expect(result).not.to.equal(n);
|
||||
});
|
||||
|
||||
it('adds the new Entity to input object', function () {
|
||||
var n = iD.Entity({id: 'n'}),
|
||||
copies = {},
|
||||
result = n.copy(null, copies);
|
||||
var n = iD.osmEntity({id: 'n'});
|
||||
var copies = {};
|
||||
var result = n.copy(null, copies);
|
||||
expect(Object.keys(copies)).to.have.length(1);
|
||||
expect(copies.n).to.equal(result);
|
||||
});
|
||||
|
||||
it('returns an existing copy in input object', function () {
|
||||
var n = iD.Entity({id: 'n'}),
|
||||
copies = {},
|
||||
result1 = n.copy(null, copies),
|
||||
result2 = n.copy(null, copies);
|
||||
var n = iD.osmEntity({id: 'n'});
|
||||
var copies = {};
|
||||
var result1 = n.copy(null, copies);
|
||||
var result2 = n.copy(null, copies);
|
||||
expect(Object.keys(copies)).to.have.length(1);
|
||||
expect(result1).to.equal(result2);
|
||||
});
|
||||
|
||||
it('resets \'id\', \'user\', and \'version\' properties', function () {
|
||||
var n = iD.Entity({id: 'n', version: 10, user: 'user'}),
|
||||
copies = {};
|
||||
var n = iD.osmEntity({id: 'n', version: 10, user: 'user'});
|
||||
var copies = {};
|
||||
n.copy(null, copies);
|
||||
expect(copies.n.isNew()).to.be.ok;
|
||||
expect(copies.n.version).to.be.undefined;
|
||||
@@ -71,8 +71,8 @@ describe('iD.osmEntity', function () {
|
||||
});
|
||||
|
||||
it('copies tags', function () {
|
||||
var n = iD.Entity({id: 'n', tags: {foo: 'foo'}}),
|
||||
copies = {};
|
||||
var n = iD.osmEntity({id: 'n', tags: {foo: 'foo'}});
|
||||
var copies = {};
|
||||
n.copy(null, copies);
|
||||
expect(copies.n.tags).to.equal(n.tags);
|
||||
});
|
||||
@@ -80,85 +80,85 @@ describe('iD.osmEntity', function () {
|
||||
|
||||
describe('#update', function () {
|
||||
it('returns a new Entity', function () {
|
||||
var a = iD.Entity(),
|
||||
b = a.update({});
|
||||
expect(b instanceof iD.Entity).to.be.true;
|
||||
var a = iD.osmEntity();
|
||||
var b = a.update({});
|
||||
expect(b instanceof iD.osmEntity).to.be.true;
|
||||
expect(a).not.to.equal(b);
|
||||
});
|
||||
|
||||
it('updates the specified attributes', function () {
|
||||
var tags = {foo: 'bar'},
|
||||
e = iD.Entity().update({tags: tags});
|
||||
var tags = {foo: 'bar'};
|
||||
var e = iD.osmEntity().update({tags: tags});
|
||||
expect(e.tags).to.equal(tags);
|
||||
});
|
||||
|
||||
it('preserves existing attributes', function () {
|
||||
var e = iD.Entity({id: 'w1'}).update({});
|
||||
var e = iD.osmEntity({id: 'w1'}).update({});
|
||||
expect(e.id).to.equal('w1');
|
||||
});
|
||||
|
||||
it('doesn\'t modify the input', function () {
|
||||
var attrs = {tags: {foo: 'bar'}};
|
||||
iD.Entity().update(attrs);
|
||||
iD.osmEntity().update(attrs);
|
||||
expect(attrs).to.eql({tags: {foo: 'bar'}});
|
||||
});
|
||||
|
||||
it('doesn\'t copy prototype properties', function () {
|
||||
expect(iD.Entity().update({})).not.to.have.ownProperty('update');
|
||||
expect(iD.osmEntity().update({})).not.to.have.ownProperty('update');
|
||||
});
|
||||
|
||||
it('sets v to 1 if previously undefined', function() {
|
||||
expect(iD.Entity().update({}).v).to.equal(1);
|
||||
expect(iD.osmEntity().update({}).v).to.equal(1);
|
||||
});
|
||||
|
||||
it('increments v', function() {
|
||||
expect(iD.Entity({v: 1}).update({}).v).to.equal(2);
|
||||
expect(iD.osmEntity({v: 1}).update({}).v).to.equal(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#mergeTags', function () {
|
||||
it('returns self if unchanged', function () {
|
||||
var a = iD.Entity({tags: {a: 'a'}}),
|
||||
b = a.mergeTags({a: 'a'});
|
||||
var a = iD.osmEntity({tags: {a: 'a'}});
|
||||
var b = a.mergeTags({a: 'a'});
|
||||
expect(a).to.equal(b);
|
||||
});
|
||||
|
||||
it('returns a new Entity if changed', function () {
|
||||
var a = iD.Entity({tags: {a: 'a'}}),
|
||||
b = a.mergeTags({a: 'b'});
|
||||
expect(b instanceof iD.Entity).to.be.true;
|
||||
var a = iD.osmEntity({tags: {a: 'a'}});
|
||||
var b = a.mergeTags({a: 'b'});
|
||||
expect(b instanceof iD.osmEntity).to.be.true;
|
||||
expect(a).not.to.equal(b);
|
||||
});
|
||||
|
||||
it('merges tags', function () {
|
||||
var a = iD.Entity({tags: {a: 'a'}}),
|
||||
b = a.mergeTags({b: 'b'});
|
||||
var a = iD.osmEntity({tags: {a: 'a'}});
|
||||
var b = a.mergeTags({b: 'b'});
|
||||
expect(b.tags).to.eql({a: 'a', b: 'b'});
|
||||
});
|
||||
|
||||
it('combines non-conflicting tags', function () {
|
||||
var a = iD.Entity({tags: {a: 'a'}}),
|
||||
b = a.mergeTags({a: 'a'});
|
||||
var a = iD.osmEntity({tags: {a: 'a'}});
|
||||
var b = a.mergeTags({a: 'a'});
|
||||
expect(b.tags).to.eql({a: 'a'});
|
||||
});
|
||||
|
||||
it('combines conflicting tags with semicolons', function () {
|
||||
var a = iD.Entity({tags: {a: 'a'}}),
|
||||
b = a.mergeTags({a: 'b'});
|
||||
var a = iD.osmEntity({tags: {a: 'a'}});
|
||||
var b = a.mergeTags({a: 'b'});
|
||||
expect(b.tags).to.eql({a: 'a;b'});
|
||||
});
|
||||
|
||||
it('combines combined tags', function () {
|
||||
var a = iD.Entity({tags: {a: 'a;b'}}),
|
||||
b = iD.Entity({tags: {a: 'b'}});
|
||||
var a = iD.osmEntity({tags: {a: 'a;b'}});
|
||||
var b = iD.osmEntity({tags: {a: 'b'}});
|
||||
|
||||
expect(a.mergeTags(b.tags).tags).to.eql({a: 'a;b'});
|
||||
expect(b.mergeTags(a.tags).tags).to.eql({a: 'b;a'});
|
||||
});
|
||||
|
||||
it('combines combined tags with whitespace', function () {
|
||||
var a = iD.Entity({tags: {a: 'a; b'}}),
|
||||
b = iD.Entity({tags: {a: 'b'}});
|
||||
var a = iD.osmEntity({tags: {a: 'a; b'}});
|
||||
var b = iD.osmEntity({tags: {a: 'b'}});
|
||||
|
||||
expect(a.mergeTags(b.tags).tags).to.eql({a: 'a;b'});
|
||||
expect(b.mergeTags(a.tags).tags).to.eql({a: 'b;a'});
|
||||
@@ -167,24 +167,24 @@ describe('iD.osmEntity', function () {
|
||||
|
||||
describe('#osmId', function () {
|
||||
it('returns an OSM ID as a string', function () {
|
||||
expect(iD.Entity({id: 'w1234'}).osmId()).to.eql('1234');
|
||||
expect(iD.Entity({id: 'n1234'}).osmId()).to.eql('1234');
|
||||
expect(iD.Entity({id: 'r1234'}).osmId()).to.eql('1234');
|
||||
expect(iD.osmEntity({id: 'w1234'}).osmId()).to.eql('1234');
|
||||
expect(iD.osmEntity({id: 'n1234'}).osmId()).to.eql('1234');
|
||||
expect(iD.osmEntity({id: 'r1234'}).osmId()).to.eql('1234');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#intersects', function () {
|
||||
it('returns true for a way with a node within the given extent', function () {
|
||||
var node = iD.osmNode({loc: [0, 0]}),
|
||||
way = iD.osmWay({nodes: [node.id]}),
|
||||
graph = iD.coreGraph([node, way]);
|
||||
var node = iD.osmNode({loc: [0, 0]});
|
||||
var way = iD.osmWay({nodes: [node.id]});
|
||||
var graph = iD.coreGraph([node, way]);
|
||||
expect(way.intersects([[-5, -5], [5, 5]], graph)).to.equal(true);
|
||||
});
|
||||
|
||||
it('returns false for way with no nodes within the given extent', function () {
|
||||
var node = iD.osmNode({loc: [6, 6]}),
|
||||
way = iD.osmWay({nodes: [node.id]}),
|
||||
graph = iD.coreGraph([node, way]);
|
||||
var node = iD.osmNode({loc: [6, 6]});
|
||||
var way = iD.osmWay({nodes: [node.id]});
|
||||
var graph = iD.coreGraph([node, way]);
|
||||
expect(way.intersects([[-5, -5], [5, 5]], graph)).to.equal(false);
|
||||
});
|
||||
});
|
||||
@@ -208,59 +208,72 @@ describe('iD.osmEntity', function () {
|
||||
|
||||
describe('#hasParentRelations', function () {
|
||||
it('returns true for an entity that is a relation member', function () {
|
||||
var node = iD.osmNode(),
|
||||
relation = iD.osmRelation({members: [{id: node.id}]}),
|
||||
graph = iD.coreGraph([node, relation]);
|
||||
var node = iD.osmNode();
|
||||
var relation = iD.osmRelation({members: [{id: node.id}]});
|
||||
var graph = iD.coreGraph([node, relation]);
|
||||
expect(node.hasParentRelations(graph)).to.equal(true);
|
||||
});
|
||||
|
||||
it('returns false for an entity that is not a relation member', function () {
|
||||
var node = iD.osmNode(),
|
||||
graph = iD.coreGraph([node]);
|
||||
var node = iD.osmNode();
|
||||
var graph = iD.coreGraph([node]);
|
||||
expect(node.hasParentRelations(graph)).to.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#hasDeprecatedTags', function () {
|
||||
it('returns false if entity has no tags', function () {
|
||||
expect(iD.Entity().deprecatedTags()).to.eql([]);
|
||||
expect(iD.osmEntity().deprecatedTags()).to.eql([]);
|
||||
});
|
||||
|
||||
it('returns true if entity has deprecated tags', function () {
|
||||
expect(iD.Entity({ tags: { amenity: 'toilet' } }).deprecatedTags()).to.eql([{
|
||||
old: { amenity: 'toilet' },
|
||||
replace: { amenity: 'toilets' }
|
||||
}]);
|
||||
expect(iD.osmEntity({ tags: { amenity: 'toilet' } }).deprecatedTags()).to.eql(
|
||||
[{ old: { amenity: 'toilet' }, replace: { amenity: 'toilets' } }]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#hasWikidata', function () {
|
||||
it('returns false if entity has no tags', function () {
|
||||
expect(iD.osmEntity().hasWikidata()).to.be.not.ok;
|
||||
});
|
||||
|
||||
it('returns true if entity has a wikidata tag', function () {
|
||||
expect(iD.osmEntity({ tags: { wikidata: 'Q18275868' } }).hasWikidata()).to.be.ok;
|
||||
});
|
||||
|
||||
it('returns true if entity has a brand:wikidata tag', function () {
|
||||
expect(iD.osmEntity({ tags: { 'brand:wikidata': 'Q18275868' } }).hasWikidata()).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#hasInterestingTags', function () {
|
||||
it('returns false if the entity has no tags', function () {
|
||||
expect(iD.Entity().hasInterestingTags()).to.equal(false);
|
||||
expect(iD.osmEntity().hasInterestingTags()).to.equal(false);
|
||||
});
|
||||
|
||||
it('returns true if the entity has tags other than \'attribution\', \'created_by\', \'source\', \'odbl\' and tiger tags', function () {
|
||||
expect(iD.Entity({tags: {foo: 'bar'}}).hasInterestingTags()).to.equal(true);
|
||||
expect(iD.osmEntity({tags: {foo: 'bar'}}).hasInterestingTags()).to.equal(true);
|
||||
});
|
||||
|
||||
it('return false if the entity has only uninteresting tags', function () {
|
||||
expect(iD.Entity({tags: {source: 'Bing'}}).hasInterestingTags()).to.equal(false);
|
||||
expect(iD.osmEntity({tags: {source: 'Bing'}}).hasInterestingTags()).to.equal(false);
|
||||
});
|
||||
|
||||
it('return false if the entity has only tiger tags', function () {
|
||||
expect(iD.Entity({tags: {'tiger:source': 'blah', 'tiger:foo': 'bar'}}).hasInterestingTags()).to.equal(false);
|
||||
expect(iD.osmEntity({tags: {'tiger:source': 'blah', 'tiger:foo': 'bar'}}).hasInterestingTags()).to.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isHighwayIntersection', function () {
|
||||
it('returns false', function () {
|
||||
expect(iD.Entity().isHighwayIntersection()).to.be.false;
|
||||
expect(iD.osmEntity().isHighwayIntersection()).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isDegenerate', function () {
|
||||
it('returns true', function () {
|
||||
expect(iD.Entity().isDegenerate()).to.be.true;
|
||||
expect(iD.osmEntity().isDegenerate()).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -185,6 +185,27 @@ describe('iD.svgTagClasses', function () {
|
||||
expect(selection.classed('tag-unpaved')).to.be.false;
|
||||
});
|
||||
|
||||
it('does not add tag-wikidata if no wikidata tag', function() {
|
||||
selection
|
||||
.datum(iD.osmEntity())
|
||||
.call(iD.svgTagClasses());
|
||||
expect(selection.classed('tag-wikidata')).to.be.false;
|
||||
});
|
||||
|
||||
it('adds tag-wikidata if entity has a wikidata tag', function() {
|
||||
selection
|
||||
.datum(iD.osmEntity({ tags: { wikidata: 'Q18275868' } }))
|
||||
.call(iD.svgTagClasses());
|
||||
expect(selection.classed('tag-wikidata')).to.be.true;
|
||||
});
|
||||
|
||||
it('adds tag-wikidata if entity has a brand:wikidata tag', function() {
|
||||
selection
|
||||
.datum(iD.osmEntity({ tags: { 'brand:wikidata': 'Q18275868' } }))
|
||||
.call(iD.svgTagClasses());
|
||||
expect(selection.classed('tag-wikidata')).to.be.true;
|
||||
});
|
||||
|
||||
it('adds tags based on the result of the `tags` accessor', function() {
|
||||
var primary = function () { return { highway: 'primary'}; };
|
||||
selection
|
||||
|
||||
Reference in New Issue
Block a user