mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-21 10:33:34 +00:00
see #542. Also included: 1. DRY up code for "% contained in" extent testing. 2. If action.disabled() returns a better reason, show that instead of the too_large one.
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
iD.operations.Circularize = function(selectedIDs, context) {
|
|
var entityId = selectedIDs[0],
|
|
entity = context.entity(entityId),
|
|
extent = entity.extent(context.graph()),
|
|
geometry = context.geometry(entityId),
|
|
action = iD.actions.Circularize(entityId, context.projection);
|
|
|
|
var operation = function() {
|
|
var annotation = t('operations.circularize.annotation.' + geometry);
|
|
context.perform(action, annotation);
|
|
};
|
|
|
|
operation.available = function() {
|
|
return selectedIDs.length === 1 &&
|
|
entity.type === 'way' &&
|
|
_.uniq(entity.nodes).length > 1;
|
|
};
|
|
|
|
operation.disabled = function() {
|
|
var reason;
|
|
if (extent.percentContainedIn(context.extent()) < 0.8) {
|
|
reason = 'too_large';
|
|
}
|
|
return action.disabled(context.graph()) || reason;
|
|
};
|
|
|
|
operation.tooltip = function() {
|
|
var disable = operation.disabled();
|
|
return disable ?
|
|
t('operations.circularize.' + disable) :
|
|
t('operations.circularize.description.' + geometry);
|
|
};
|
|
|
|
operation.id = 'circularize';
|
|
operation.keys = [t('operations.circularize.key')];
|
|
operation.title = t('operations.circularize.title');
|
|
|
|
return operation;
|
|
};
|