mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-18 14:45:12 +02:00
Add validation warning for unsquare buildings
This commit is contained in:
@@ -11,3 +11,4 @@ export { validationOutdatedTags } from './outdated_tags';
|
||||
export { validationPrivateData } from './private_data';
|
||||
export { validationTagSuggestsArea } from './tag_suggests_area';
|
||||
export { validationUnknownRoad } from './unknown_road';
|
||||
export { validationUnsquareWay } from './unsquare_way';
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { t } from '../util/locale';
|
||||
import { operationOrthogonalize } from '../operations';
|
||||
import { geoOrthoCanOrthogonalize } from '../geo';
|
||||
import { utilDisplayLabel } from '../util';
|
||||
import { validationIssue, validationIssueFix } from '../core/validator';
|
||||
|
||||
|
||||
export function validationUnsquareWay() {
|
||||
var type = 'unsquare_way';
|
||||
|
||||
var validation = function checkMissingRole(entity, context) {
|
||||
|
||||
if (entity.type !== 'way' || entity.geometry(context.graph()) !== 'area') return [];
|
||||
|
||||
if (!entity.tags.building || entity.tags.building === 'no') return [];
|
||||
|
||||
var isClosed = entity.isClosed();
|
||||
var nodes = context.childNodes(entity).slice(); // shallow copy
|
||||
if (isClosed) nodes.pop();
|
||||
|
||||
var locs = nodes.map(function(node) {
|
||||
return context.projection(node.loc);
|
||||
});
|
||||
|
||||
// use loose constraints compared to actionOrthogonalize
|
||||
if (!geoOrthoCanOrthogonalize(locs, isClosed, 0.015, 7, true)) return [];
|
||||
|
||||
return new validationIssue({
|
||||
type: type,
|
||||
severity: 'warning',
|
||||
message: t('issues.unsquare_way.message', {
|
||||
feature: utilDisplayLabel(entity, context)
|
||||
}),
|
||||
reference: showReference,
|
||||
entities: [entity],
|
||||
fixes: [
|
||||
new validationIssueFix({
|
||||
icon: 'iD-operation-orthogonalize',
|
||||
title: t('issues.fix.square_feature.title'),
|
||||
onClick: function() {
|
||||
var id = this.issue.entities[0].id;
|
||||
var operation = operationOrthogonalize([id], context);
|
||||
if (!operation.disabled()) {
|
||||
operation();
|
||||
}
|
||||
}
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
function showReference(selection) {
|
||||
selection.selectAll('.issue-reference')
|
||||
.data([0])
|
||||
.enter()
|
||||
.append('div')
|
||||
.attr('class', 'issue-reference')
|
||||
.text(t('issues.unsquare_way.buildings.reference'));
|
||||
}
|
||||
};
|
||||
|
||||
validation.type = type;
|
||||
|
||||
return validation;
|
||||
}
|
||||
Reference in New Issue
Block a user