diff --git a/js/id/core/tags.js b/js/id/core/tags.js index 50fe79dd4..ae4a87f27 100644 --- a/js/id/core/tags.js +++ b/js/id/core/tags.js @@ -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' && diff --git a/js/id/svg/tag_classes.js b/js/id/svg/tag_classes.js index e9c3fcafc..abffe1220 100644 --- a/js/id/svg/tag_classes.js +++ b/js/id/svg/tag_classes.js @@ -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) { diff --git a/test/spec/svg/tag_classes.js b/test/spec/svg/tag_classes.js index 752a4b094..1b5ff1429 100644 --- a/test/spec/svg/tag_classes.js +++ b/test/spec/svg/tag_classes.js @@ -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())