mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 09:42:56 +00:00
60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
import _uniq from 'lodash-es/uniq';
|
|
|
|
import { t } from '../util/locale';
|
|
import { actionOrthogonalize } from '../actions/index';
|
|
import { behaviorOperation } from '../behavior/index';
|
|
|
|
|
|
export function operationOrthogonalize(selectedIDs, context) {
|
|
var entityId = selectedIDs[0],
|
|
entity = context.entity(entityId),
|
|
extent = entity.extent(context.graph()),
|
|
geometry = context.geometry(entityId),
|
|
action = actionOrthogonalize(entityId, context.projection);
|
|
|
|
|
|
var operation = function() {
|
|
context.perform(action, operation.annotation());
|
|
};
|
|
|
|
|
|
operation.available = function() {
|
|
return selectedIDs.length === 1 &&
|
|
entity.type === 'way' &&
|
|
entity.isClosed() &&
|
|
_uniq(entity.nodes).length > 2;
|
|
};
|
|
|
|
|
|
operation.disabled = function() {
|
|
var reason;
|
|
if (extent.percentContainedIn(context.extent()) < 0.8) {
|
|
reason = 'too_large';
|
|
} else if (context.hasHiddenConnections(entityId)) {
|
|
reason = 'connected_to_hidden';
|
|
}
|
|
return action.disabled(context.graph()) || reason;
|
|
};
|
|
|
|
|
|
operation.tooltip = function() {
|
|
var disable = operation.disabled();
|
|
return disable ?
|
|
t('operations.orthogonalize.' + disable) :
|
|
t('operations.orthogonalize.description.' + geometry);
|
|
};
|
|
|
|
|
|
operation.annotation = function() {
|
|
return t('operations.orthogonalize.annotation.' + geometry);
|
|
};
|
|
|
|
|
|
operation.id = 'orthogonalize';
|
|
operation.keys = [t('operations.orthogonalize.key')];
|
|
operation.title = t('operations.orthogonalize.title');
|
|
operation.behavior = behaviorOperation(context).which(operation);
|
|
|
|
return operation;
|
|
}
|