diff --git a/modules/actions/orthogonalize.js b/modules/actions/orthogonalize.js index 3cd0042f3..3eb0f13ca 100644 --- a/modules/actions/orthogonalize.js +++ b/modules/actions/orthogonalize.js @@ -6,7 +6,7 @@ import { } from '../geo'; -export function actionOrthogonalize(wayID, projection, vertexID, ep, degThresh) { +export function actionOrthogonalize(wayID, projection, vertexID, degThresh, ep) { var epsilon = ep || 1e-4; var threshold = degThresh || 13; // degrees within right or straight to alter diff --git a/modules/ui/issues.js b/modules/ui/issues.js index 4cccfdc54..92100bac5 100644 --- a/modules/ui/issues.js +++ b/modules/ui/issues.js @@ -18,7 +18,7 @@ export function uiIssues(context) { var MINSQUARE = 0; var MAXSQUARE = 20; - var DEFAULTSQUARE = 6.5; // see also unsquare_way.js + var DEFAULTSQUARE = 5; // see also unsquare_way.js var _errorsSelection = d3_select(null); var _warningsSelection = d3_select(null); @@ -610,6 +610,17 @@ export function uiIssues(context) { .on('input', function() { this.style.width = (this.value.length + 1) + 'ch'; // resize }) + .on('click', function () { + d3_event.preventDefault(); + d3_event.stopPropagation(); + this.select(); + }) + .on('keyup', function () { + if (d3_event.keyCode === 13) { // enter + this.blur(); + this.select(); + } + }) .on('blur', changeSquare) .merge(input) .property('value', degStr) @@ -622,8 +633,12 @@ export function uiIssues(context) { var degStr = utilGetSetValue(input).trim(); var degNum = parseFloat(degStr, 10); - if (!isFinite(degNum) || degNum > MAXSQUARE || degNum < MINSQUARE) { + if (!isFinite(degNum)) { degNum = DEFAULTSQUARE; + } else if (degNum > MAXSQUARE) { + degNum = MAXSQUARE; + } else if (degNum < MINSQUARE) { + degNum = MINSQUARE; } degNum = Math.round(degNum * 10 ) / 10; // round to 1 decimal diff --git a/modules/validations/unsquare_way.js b/modules/validations/unsquare_way.js index 5ce332340..8ecdebb05 100644 --- a/modules/validations/unsquare_way.js +++ b/modules/validations/unsquare_way.js @@ -1,21 +1,18 @@ import { t } from '../util/locale'; import { actionChangeTags } from '../actions/change_tags'; import { actionOrthogonalize } from '../actions/orthogonalize'; -import { geoOrthoCanOrthogonalize, geoOrthoMaxOffsetAngle } from '../geo/ortho'; +import { geoOrthoCanOrthogonalize } from '../geo/ortho'; import { utilDisplayLabel } from '../util'; import { validationIssue, validationIssueFix } from '../core/validation'; export function validationUnsquareWay() { var type = 'unsquare_way'; - var DEFAULTSQUARE = 6.5; // see also issues.js + var DEFAULT_DEG_THRESHOLD = 5; // see also issues.js // use looser epsilon for detection to reduce warnings of buildings that are essentially square already var epsilon = 0.05; var nodeThreshold = 10; - // var degreeThreshold = 13; - // var autofixDegreeThreshold = 6.5; - function isBuilding(entity, graph) { if (entity.type !== 'way' || entity.geometry(graph) !== 'area') return false; @@ -56,22 +53,18 @@ export function validationUnsquareWay() { if (hasConnectedSquarableWays) return []; -// testing: user-configurable square threshold -var degreeThreshold = context.storage('validate-square-degrees'); -if (degreeThreshold === null) { - degreeThreshold = '' + DEFAULTSQUARE; -} -var autofixDegreeThreshold = degreeThreshold; + // user-configurable square threshold + var storedDegreeThreshold = context.storage('validate-square-degrees'); + var degreeThreshold = isNaN(storedDegreeThreshold) ? DEFAULT_DEG_THRESHOLD : parseFloat(storedDegreeThreshold); var points = nodes.map(function(node) { return context.projection(node.loc); }); if (!geoOrthoCanOrthogonalize(points, isClosed, epsilon, degreeThreshold, true)) return []; var autoArgs; - // only allow autofixing features that are very close to square already - var maxOffsetAngle = geoOrthoMaxOffsetAngle(points, isClosed, degreeThreshold); - if (maxOffsetAngle && maxOffsetAngle < autofixDegreeThreshold) { - // note: use default params for actionOrthogonalize, not relaxed epsilon - var autoAction = actionOrthogonalize(entity.id, context.projection); + // don't allow autosquaring features linked to wikidata + if (!entity.tags.wikidata) { + // use same degree threshold as for detection + var autoAction = actionOrthogonalize(entity.id, context.projection, undefined, degreeThreshold); autoAction.transitionable = false; // when autofixing, do it instantly autoArgs = [autoAction, t('operations.orthogonalize.annotation.area')]; } @@ -85,7 +78,7 @@ var autofixDegreeThreshold = degreeThreshold; }, reference: showReference, entityIds: [entity.id], - hash: JSON.stringify(autoArgs !== undefined), + hash: JSON.stringify(autoArgs !== undefined) + degreeThreshold, fixes: [ new validationIssueFix({ icon: 'iD-operation-orthogonalize', @@ -93,9 +86,9 @@ var autofixDegreeThreshold = degreeThreshold; autoArgs: autoArgs, onClick: function(completionHandler) { var entityId = this.issue.entityIds[0]; - // note: use default params for actionOrthogonalize, not relaxed epsilon + // use same degree threshold as for detection context.perform( - actionOrthogonalize(entityId, context.projection), + actionOrthogonalize(entityId, context.projection, undefined, degreeThreshold), t('operations.orthogonalize.annotation.area') ); // run after the squaring transition (currently 150ms)