mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-14 21:28:11 +02:00
Add "autofix" for the unsquare building validation
This commit is contained in:
@@ -6,9 +6,9 @@ import {
|
||||
} from '../geo';
|
||||
|
||||
|
||||
export function actionOrthogonalize(wayID, projection, vertexID) {
|
||||
var epsilon = 1e-4;
|
||||
var threshold = 13; // degrees within right or straight to alter
|
||||
export function actionOrthogonalize(wayID, projection, vertexID, ep, degThresh) {
|
||||
var epsilon = ep || 1e-4;
|
||||
var threshold = degThresh || 13; // degrees within right or straight to alter
|
||||
|
||||
// We test normalized dot products so we can compare as cos(angle)
|
||||
var lowerThreshold = Math.cos((90 - threshold) * Math.PI / 180);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { t } from '../util/locale';
|
||||
import { modeDrawLine } from '../modes/draw_line';
|
||||
import { operationDelete } from '../operations/index';
|
||||
import { operationDelete } from '../operations/delete';
|
||||
import { utilDisplayLabel } from '../util';
|
||||
import { validationIssue, validationIssueFix } from '../core/validation';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { t } from '../util/locale';
|
||||
import { operationOrthogonalize } from '../operations';
|
||||
import { actionOrthogonalize } from '../actions/orthogonalize';
|
||||
import { geoOrthoCanOrthogonalize } from '../geo';
|
||||
import { utilDisplayLabel } from '../util';
|
||||
import { validationIssue, validationIssueFix } from '../core/validation';
|
||||
@@ -8,6 +8,10 @@ import { validationIssue, validationIssueFix } from '../core/validation';
|
||||
export function validationUnsquareWay() {
|
||||
var type = 'unsquare_way';
|
||||
|
||||
// use looser constraints for detection than those for completing the action
|
||||
var epsilon = 0.01;
|
||||
var degreeThreshold = 6;
|
||||
|
||||
function isBuilding(entity, graph) {
|
||||
if (entity.type !== 'way' || entity.geometry(graph) !== 'area') return false;
|
||||
|
||||
@@ -27,22 +31,32 @@ export function validationUnsquareWay() {
|
||||
// don't flag ways with lots of nodes since they are likely detail-mapped
|
||||
if (nodes.length > 6) return [];
|
||||
|
||||
var osm = context.connection();
|
||||
var connectedToUnloadedTile = nodes.some(function(node) {
|
||||
return !osm.isDataLoaded(node.loc);
|
||||
});
|
||||
// ignore if not all conncted tiles are downloaded
|
||||
if (connectedToUnloadedTile) return [];
|
||||
|
||||
var hasConnectedSquarableWays = nodes.some(function(node) {
|
||||
return graph.parentWays(node).some(function(way) {
|
||||
if (way.id === entity.id) return false;
|
||||
return isBuilding(way, graph);
|
||||
});
|
||||
});
|
||||
|
||||
// don't flag connected ways to avoid unresolvable unsquare loops
|
||||
if (hasConnectedSquarableWays) return [];
|
||||
|
||||
var locs = nodes.map(function(node) {
|
||||
var projectedLocs = nodes.map(function(node) {
|
||||
return context.projection(node.loc);
|
||||
});
|
||||
|
||||
// use loose constraints compared to actionOrthogonalize
|
||||
if (!geoOrthoCanOrthogonalize(locs, isClosed, 0.015, 7, true)) return [];
|
||||
if (!geoOrthoCanOrthogonalize(projectedLocs, isClosed, epsilon, degreeThreshold, true)) return [];
|
||||
|
||||
var action = actionOrthogonalize(entity.id, context.projection, undefined, epsilon, degreeThreshold);
|
||||
action.onCompletion = function() {
|
||||
context.validator().validate();
|
||||
};
|
||||
|
||||
return new validationIssue({
|
||||
type: type,
|
||||
@@ -56,12 +70,9 @@ export function validationUnsquareWay() {
|
||||
new validationIssueFix({
|
||||
icon: 'iD-operation-orthogonalize',
|
||||
title: t('issues.fix.square_feature.title'),
|
||||
autoArgs: [action, t('operations.orthogonalize.annotation.area')],
|
||||
onClick: function() {
|
||||
var id = this.issue.entities[0].id;
|
||||
var operation = operationOrthogonalize([id], context);
|
||||
if (!operation.disabled()) {
|
||||
operation();
|
||||
}
|
||||
context.perform(action, t('operations.orthogonalize.annotation.area'));
|
||||
}
|
||||
})
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user