Differentiate between paved/unpaved roads (closes #2564)

Now `iD.svg.TagClasses` will add the class 'tag-unpaved' for unpaved roads.
This commit is contained in:
Bryan Housel
2015-11-25 15:28:37 -05:00
parent 093b2a5a60
commit b4628298d9
3 changed files with 105 additions and 0 deletions

View File

@@ -30,6 +30,17 @@ iD.oneWayTags = {
}
};
iD.pavedTags = {
'surface': {
'paved': true,
'asphalt': true,
'concrete': true
},
'tracktype': {
'grade1': true
}
};
iD.interestingTag = function (key) {
return key !== 'attribution' &&
key !== 'created_by' &&

View File

@@ -79,6 +79,21 @@ iD.svg.TagClasses = function() {
classes += ' tag-' + k + ' tag-' + k + '-' + v;
}
// For highways, look for surface tagging..
if (primary === 'highway') {
var paved = (t.highway !== 'track');
for (k in t) {
v = t[k];
if (k in iD.pavedTags) {
paved = !!iD.pavedTags[k][v];
break;
}
}
if (!paved) {
classes += ' tag-unpaved';
}
}
classes = classes.trim();
if (classes !== value) {

View File

@@ -82,6 +82,85 @@ describe("iD.svg.TagClasses", function () {
expect(selection.attr('class')).to.equal(null);
});
it('adds tag-unpaved for highway=track with no surface tagging', function() {
selection
.datum(iD.Entity({tags: {highway: 'track'}}))
.call(iD.svg.TagClasses());
expect(selection).to.be.classed('tag-unpaved');
});
it('does not add tag-unpaved for highway=track with explicit paved surface tagging', function() {
selection
.datum(iD.Entity({tags: {highway: 'track', surface: 'asphalt'}}))
.call(iD.svg.TagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
selection
.datum(iD.Entity({tags: {highway: 'track', tracktype: 'grade1'}}))
.call(iD.svg.TagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
});
it('adds tag-unpaved for highway=track with explicit unpaved surface tagging', function() {
selection
.datum(iD.Entity({tags: {highway: 'track', surface: 'dirt'}}))
.call(iD.svg.TagClasses());
expect(selection).to.be.classed('tag-unpaved');
selection
.datum(iD.Entity({tags: {highway: 'track', tracktype: 'grade3'}}))
.call(iD.svg.TagClasses());
expect(selection).to.be.classed('tag-unpaved');
});
it('does not add tag-unpaved for other highway types with no surface tagging', function() {
selection
.datum(iD.Entity({tags: {highway: 'tertiary'}}))
.call(iD.svg.TagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
selection
.datum(iD.Entity({tags: {highway: 'foo'}}))
.call(iD.svg.TagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
});
it('does not add tag-unpaved for other highway types with explicit paved surface tagging', function() {
selection
.datum(iD.Entity({tags: {highway: 'tertiary', surface: 'asphalt'}}))
.call(iD.svg.TagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
selection
.datum(iD.Entity({tags: {highway: 'foo', tracktype: 'grade1'}}))
.call(iD.svg.TagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
});
it('adds tag-unpaved for other highway types with explicit unpaved surface tagging', function() {
selection
.datum(iD.Entity({tags: {highway: 'tertiary', surface: 'dirt'}}))
.call(iD.svg.TagClasses());
expect(selection).to.be.classed('tag-unpaved');
selection
.datum(iD.Entity({tags: {highway: 'foo', tracktype: 'grade3'}}))
.call(iD.svg.TagClasses());
expect(selection).to.be.classed('tag-unpaved');
});
it('does not add tag-unpaved for non-highways', function() {
selection
.datum(iD.Entity({tags: {railway: 'abandoned', surface: 'gravel'}}))
.call(iD.svg.TagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
selection
.datum(iD.Entity({tags: {amenity: 'parking', surface: 'dirt'}}))
.call(iD.svg.TagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
});
it('adds tags based on the result of the `tags` accessor', function() {
selection
.datum(iD.Entity())