mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-20 07:25:15 +02:00
Merge pull request #6284 from Bonkles/id-5869
Improve validation for disconnected highways #5869
This commit is contained in:
@@ -12,13 +12,20 @@ export function validationDisconnectedWay() {
|
||||
function isTaggedAsHighway(entity) {
|
||||
return osmRoutableHighwayTagValues[entity.tags.highway];
|
||||
}
|
||||
|
||||
|
||||
function isNewRoad(entityId) {
|
||||
return entityId[0] === 'w' && entityId[1] === '-';
|
||||
}
|
||||
|
||||
var validation = function checkDisconnectedWay(entity, context) {
|
||||
var graph = context.graph();
|
||||
|
||||
if (!isTaggedAsHighway(entity)) return [];
|
||||
if (!isDisconnectedWay(entity) && !isDisconnectedMultipolygon(entity)) return [];
|
||||
|
||||
if (!isDisconnectedWay(entity) && !isDisconnectedMultipolygon(entity)
|
||||
&& !isNewRoadUnreachableFromExistingRoads(entity, graph)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
var entityLabel = utilDisplayLabel(entity, context);
|
||||
var fixes = [];
|
||||
@@ -79,7 +86,14 @@ export function validationDisconnectedWay() {
|
||||
return [new validationIssue({
|
||||
type: type,
|
||||
severity: 'warning',
|
||||
message: t('issues.disconnected_way.highway.message', { highway: entityLabel }),
|
||||
message: (isNewRoad(entity.id)
|
||||
? t('issues.disconnected_way.highway.message_new_road', { highway: entityLabel })
|
||||
: t('issues.disconnected_way.highway.message', { highway: entityLabel })
|
||||
),
|
||||
tooltip: (isNewRoad(entity.id)
|
||||
? t('issues.disconnected_way.highway.reference_new_road')
|
||||
: t('issues.disconnected_way.highway.reference')
|
||||
),
|
||||
reference: showReference,
|
||||
entityIds: [entity.id],
|
||||
fixes: fixes
|
||||
@@ -138,6 +152,34 @@ export function validationDisconnectedWay() {
|
||||
}
|
||||
|
||||
|
||||
// check if entity is a new road that cannot eventually connect to any
|
||||
// existing roads
|
||||
function isNewRoadUnreachableFromExistingRoads(entity) {
|
||||
if (!isNewRoad(entity.id) || !isTaggedAsHighway(entity)) return false;
|
||||
|
||||
var visitedWids = new Set();
|
||||
return !connectToExistingRoadOrEntrance(entity, visitedWids);
|
||||
}
|
||||
|
||||
|
||||
function connectToExistingRoadOrEntrance(way, visitedWids) {
|
||||
visitedWids.add(way.id);
|
||||
for (var i = 0; i < way.nodes.length; i++) {
|
||||
var vertex = graph.entity(way.nodes[i]);
|
||||
if (vertex.tags.entrance && vertex.tags.entrance !== 'no') return true;
|
||||
|
||||
var parentWays = graph.parentWays(vertex);
|
||||
for (var j = 0; j < parentWays.length; j++) {
|
||||
var parentWay = parentWays[j];
|
||||
if (visitedWids.has(parentWay.id)) continue;
|
||||
if (isTaggedAsHighway(parentWay) && !isNewRoad(parentWay.id)) return true;
|
||||
if (connectToExistingRoadOrEntrance(parentWay, visitedWids)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function isDisconnectedMultipolygon(entity) {
|
||||
if (entity.type !== 'relation' || !entity.isMultipolygon()) return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user