mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
77 lines
2.2 KiB
JavaScript
77 lines
2.2 KiB
JavaScript
import { t } from '../util/locale';
|
|
import { modeDrawLine } from '../modes';
|
|
import { behaviorOperation } from '../behavior';
|
|
import { utilArrayGroupBy } from '../util';
|
|
|
|
|
|
export function operationContinue(selectedIDs, context) {
|
|
var graph = context.graph();
|
|
var entities = selectedIDs.map(function(id) { return graph.entity(id); });
|
|
var geometries = Object.assign(
|
|
{ line: [], vertex: [] },
|
|
utilArrayGroupBy(entities, function(entity) { return entity.geometry(graph); })
|
|
);
|
|
var vertex = geometries.vertex[0];
|
|
var _disabled;
|
|
|
|
|
|
function candidateWays() {
|
|
return graph.parentWays(vertex).filter(function(parent) {
|
|
return parent.geometry(graph) === 'line' &&
|
|
!parent.isClosed() &&
|
|
parent.affix(vertex.id) &&
|
|
(geometries.line.length === 0 || geometries.line[0] === parent);
|
|
});
|
|
}
|
|
|
|
|
|
var operation = function() {
|
|
var candidate = candidateWays()[0];
|
|
context.enter(
|
|
modeDrawLine(context, candidate.id, context.graph(), context.graph(), 'line', candidate.affix(vertex.id), true)
|
|
);
|
|
};
|
|
|
|
|
|
operation.available = function() {
|
|
return geometries.vertex.length === 1 &&
|
|
geometries.line.length <= 1 &&
|
|
!context.features().hasHiddenConnections(vertex, context.graph());
|
|
};
|
|
|
|
|
|
operation.disabled = function() {
|
|
if (_disabled !== undefined) return _disabled;
|
|
|
|
var candidates = candidateWays();
|
|
if (candidates.length === 0) {
|
|
return _disabled = 'not_eligible';
|
|
} else if (candidates.length > 1) {
|
|
return _disabled = 'multiple';
|
|
}
|
|
|
|
return _disabled = false;
|
|
};
|
|
|
|
|
|
operation.tooltip = function() {
|
|
var disable = operation.disabled();
|
|
return disable ?
|
|
t('operations.continue.' + disable) :
|
|
t('operations.continue.description');
|
|
};
|
|
|
|
|
|
operation.annotation = function() {
|
|
return t('operations.continue.annotation.line');
|
|
};
|
|
|
|
|
|
operation.id = 'continue';
|
|
operation.keys = [t('operations.continue.key')];
|
|
operation.title = t('operations.continue.title');
|
|
operation.behavior = behaviorOperation(context).which(operation);
|
|
|
|
return operation;
|
|
}
|