Skip to content

Commit

Permalink
Add a disconnected highway validation
Browse files Browse the repository at this point in the history
(closes #3786)
  • Loading branch information
bhousel committed Jan 23, 2017
1 parent 2194ea2 commit e9e442e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ en:
on_wiki: "{tag} on wiki.osm.org"
used_with: "used with {type}"
validations:
disconnected_highway: Disconnected highway
disconnected_highway_tooltip: "Highways, such as roads and paths, should be connected to other highways."
untagged_point: Untagged point
untagged_line: Untagged line
untagged_area: Untagged area
Expand Down
2 changes: 2 additions & 0 deletions dist/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@
"used_with": "used with {type}"
},
"validations": {
"disconnected_highway": "Disconnected highway",
"disconnected_highway_tooltip": "Highways, such as roads and paths, should be connected to other highways.",
"untagged_point": "Untagged point",
"untagged_line": "Untagged line",
"untagged_area": "Untagged area",
Expand Down
42 changes: 42 additions & 0 deletions modules/validations/disconnected_highway.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { t } from '../util/locale';


export function validationDisconnectedHighway() {


function isDisconnectedHighway(entity, graph) {
if (!entity.tags.highway) return false;
if (entity.geometry(graph) !== 'line') return false;

return graph.childNodes(entity)
.every(function(vertex) {
return graph.parentWays(vertex)
.filter(function(parent) {
return parent.tags.highway && parent !== entity;
})
.length === 0;
});
}


var validation = function(changes, graph) {
var warnings = [];
for (var i = 0; i < changes.created.length; i++) {
var entity = changes.created[i];

if (isDisconnectedHighway(entity, graph)) {
warnings.push({
id: 'missing_tag',
message: t('validations.disconnected_highway'),
tooltip: t('validations.disconnected_highway_tooltip'),
entity: entity
});
}
}

return warnings;
};


return validation;
}
1 change: 1 addition & 0 deletions modules/validations/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { validationDeprecatedTag } from './deprecated_tag';
export { validationDisconnectedHighway } from './disconnected_highway';
export { validationManyDeletions } from './many_deletions';
export { validationMissingTag } from './missing_tag';
export { validationTagSuggestsArea } from './tag_suggests_area';

0 comments on commit e9e442e

Please sign in to comment.