mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 17:23:02 +00:00
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
import _ from 'lodash';
|
|
import { t } from '../util/locale';
|
|
import { geoExtent } from '../geo/index';
|
|
import { actionMove } from '../actions/index';
|
|
import { modeMove } from '../modes/index';
|
|
|
|
|
|
export function operationMove(selectedIDs, context) {
|
|
var extent = selectedIDs.reduce(function(extent, id) {
|
|
return extent.extend(context.entity(id).extent(context.graph()));
|
|
}, geoExtent());
|
|
|
|
var operation = function() {
|
|
context.enter(modeMove(context, selectedIDs));
|
|
};
|
|
|
|
|
|
operation.available = function() {
|
|
return selectedIDs.length > 1 ||
|
|
context.entity(selectedIDs[0]).type !== 'node';
|
|
};
|
|
|
|
|
|
operation.disabled = function() {
|
|
var reason;
|
|
if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) {
|
|
reason = 'too_large';
|
|
} else if (_.some(selectedIDs, context.hasHiddenConnections)) {
|
|
reason = 'connected_to_hidden';
|
|
}
|
|
|
|
return actionMove(selectedIDs).disabled(context.graph()) || reason;
|
|
};
|
|
|
|
|
|
operation.tooltip = function() {
|
|
var disable = operation.disabled();
|
|
return disable ?
|
|
t('operations.move.' + disable) :
|
|
t('operations.move.description');
|
|
};
|
|
|
|
|
|
operation.id = 'move';
|
|
operation.keys = [t('operations.move.key')];
|
|
operation.title = t('operations.move.title');
|
|
|
|
|
|
return operation;
|
|
}
|