Add a disconnected highway validation

(closes #3786)
This commit is contained in:
Bryan Housel
2017-01-23 16:50:31 -05:00
parent 2194ea2355
commit e9e442e998
4 changed files with 47 additions and 0 deletions
+2
View File
@@ -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
+2
View File
@@ -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",
@@ -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
View File
@@ -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';