diff --git a/data/core.yaml b/data/core.yaml index 916dfc6de9..6134989790 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -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 diff --git a/dist/locales/en.json b/dist/locales/en.json index 967241b6c5..60f77acde6 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -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", diff --git a/modules/validations/disconnected_highway.js b/modules/validations/disconnected_highway.js new file mode 100644 index 0000000000..c556e4e494 --- /dev/null +++ b/modules/validations/disconnected_highway.js @@ -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; +} diff --git a/modules/validations/index.js b/modules/validations/index.js index c6abfda2a6..6f38a500ea 100644 --- a/modules/validations/index.js +++ b/modules/validations/index.js @@ -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';