Prefer to render highway=* styles over railway=*

Fixes #1880
This commit is contained in:
John Firebaugh
2013-10-09 14:02:55 -07:00
parent d8567dcc43
commit 411db160fe
2 changed files with 46 additions and 10 deletions

View File

@@ -1,9 +1,13 @@
iD.svg.TagClasses = function() {
var keys = d3.set([
'highway', 'railway', 'waterway', 'power', 'motorway', 'amenity',
'natural', 'landuse', 'building', 'oneway', 'bridge', 'boundary',
'tunnel', 'leisure', 'construction', 'place', 'aeroway'
]), tagClassRe = /^tag-/,
var primary = [
'highway', 'railway', 'waterway', 'aeroway', 'motorway',
'power', 'amenity', 'natural', 'landuse', 'building', 'leisure',
'place', 'boundary'
],
secondary = [
'oneway', 'bridge', 'tunnel', 'construction'
],
tagClassRe = /^tag-/,
tags = function(entity) { return entity.tags; };
var tagClasses = function(selection) {
@@ -16,10 +20,21 @@ iD.svg.TagClasses = function() {
return name.length && !tagClassRe.test(name);
}).join(' ');
var t = tags(entity);
for (var k in t) {
if (!keys.has(k) || t[k] === 'no') continue;
classes += ' tag-' + k + ' tag-' + k + '-' + t[k];
var t = tags(entity), i, k, v;
for (i = 0; i < primary.length; i++) {
k = primary[i];
v = t[k];
if (!v || v === 'no') continue;
classes += ' tag-' + k + ' tag-' + k + '-' + v;
break;
}
for (i = 0; i < secondary.length; i++) {
k = secondary[i];
v = t[k];
if (!v || v === 'no') continue;
classes += ' tag-' + k + ' tag-' + k + '-' + v;
}
classes = classes.trim();

View File

@@ -12,13 +12,34 @@ describe("iD.svg.TagClasses", function () {
expect(selection.attr('class')).to.equal(null);
});
it('adds classes for highway tags', function() {
it('adds classes for primary tag key and key-value', function() {
selection
.datum(iD.Entity({tags: {highway: 'primary'}}))
.call(iD.svg.TagClasses());
expect(selection.attr('class')).to.equal('tag-highway tag-highway-primary');
});
it('adds only one primary tag', function() {
selection
.datum(iD.Entity({tags: {highway: 'primary', railway: 'abandoned'}}))
.call(iD.svg.TagClasses());
expect(selection.attr('class')).to.equal('tag-highway tag-highway-primary');
});
it('orders primary tags', function() {
selection
.datum(iD.Entity({tags: {railway: 'abandoned', highway: 'primary'}}))
.call(iD.svg.TagClasses());
expect(selection.attr('class')).to.equal('tag-highway tag-highway-primary');
});
it('adds secondary tags', function() {
selection
.datum(iD.Entity({tags: {highway: 'primary', bridge: 'yes'}}))
.call(iD.svg.TagClasses());
expect(selection.attr('class')).to.equal('tag-highway tag-highway-primary tag-bridge tag-bridge-yes');
});
it('adds no bridge=no tags', function() {
selection
.datum(iD.Entity({tags: {bridge: 'no'}}))