Allow user to adjust the threshold for the unsquare building warning

This commit is contained in:
Bryan Housel
2019-05-18 15:44:29 -04:00
parent 03dd95e00f
commit 511f8ecc82
5 changed files with 136 additions and 13 deletions
+53 -2
View File
@@ -1,6 +1,7 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { coreDifference } from './difference';
import { geoExtent } from '../geo/extent';
import { modeSelect } from '../modes/select';
import { utilArrayGroupBy, utilRebind } from '../util';
import { t } from '../util/locale';
@@ -69,6 +70,56 @@ export function coreValidator(context) {
dispatch.call('validated');
};
// when the user changes the squaring thereshold, rerun this on all buildings
validator.changeSquareThreshold = function() {
var checkUnsquareWay = _rules.unsquare_way;
if (typeof checkUnsquareWay !== 'function') return;
// uncache existing
Object.values(_issuesByIssueID)
.filter(function(issue) { return issue.type === 'unsquare_way'; })
.forEach(function(issue) {
var entityId = issue.entityIds[0]; // always 1 entity for unsquare way
if (_issuesByEntityID[entityId]) {
_issuesByEntityID[entityId].delete(issue.id);
}
delete _issuesByIssueID[issue.id];
});
var buildings = context.intersects(geoExtent([-180,-90],[180, 90])) // everywhere
.filter(function(entity) {
return entity.type === 'way' && entity.tags.building && entity.tags.building !== 'no';
});
// rerun for all buildings
buildings.forEach(function(entity) {
var detected = checkUnsquareWay(entity, context);
if (detected.length !== 1) return;
var issue = detected[0];
var ignoreFix = new validationIssueFix({
title: t('issues.fix.ignore_issue.title'),
icon: 'iD-icon-close',
onClick: function() {
ignoreIssue(this.issue.id);
}
});
ignoreFix.type = 'ignore';
ignoreFix.issue = issue;
issue.fixes.push(ignoreFix);
if (!_issuesByEntityID[entity.id]) {
_issuesByEntityID[entity.id] = new Set();
}
_issuesByEntityID[entity.id].add(issue.id);
_issuesByIssueID[issue.id] = issue;
});
dispatch.call('validated');
};
// options = {
// what: 'all', // 'all' or 'edited'
// where: 'all', // 'all' or 'visible'
@@ -89,13 +140,13 @@ export function coreValidator(context) {
if (!opts.includeIgnored && _ignoredIssueIDs[issue.id]) return false;
// Sanity check: This issue may be for an entity that not longer exists.
// If we detect this, uncache and return false so it is not incluced..
// If we detect this, uncache and return false so it is not included..
var entityIds = issue.entityIds || [];
for (var i = 0; i < entityIds.length; i++) {
var entityId = entityIds[i];
if (!context.hasEntity(entityId)) {
delete _issuesByEntityID[entityId];
delete _issuesByIssueID[entityId];
delete _issuesByIssueID[issue.id];
return false;
}
}