mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 17:23:02 +00:00
Now that addNode tries to preserve circularity, this could cause the continued segment to loop back. And anyway it's confusing why one vertex allows it and none others do.
63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
import _ from 'lodash';
|
|
import { t } from '../util/locale';
|
|
import { modeDrawLine } from '../modes/index';
|
|
import { behaviorOperation } from '../behavior/index';
|
|
|
|
|
|
export function operationContinue(selectedIDs, context) {
|
|
var graph = context.graph(),
|
|
entities = selectedIDs.map(function(id) { return graph.entity(id); }),
|
|
geometries = _.extend({ line: [], vertex: [] },
|
|
_.groupBy(entities, function(entity) { return entity.geometry(graph); })),
|
|
vertex = geometries.vertex[0];
|
|
|
|
|
|
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(), candidate.affix(vertex.id))
|
|
);
|
|
};
|
|
|
|
|
|
operation.available = function() {
|
|
return geometries.vertex.length === 1 && geometries.line.length <= 1 &&
|
|
!context.features().hasHiddenConnections(vertex, context.graph());
|
|
};
|
|
|
|
|
|
operation.disabled = function() {
|
|
var candidates = candidateWays();
|
|
if (candidates.length === 0)
|
|
return 'not_eligible';
|
|
if (candidates.length > 1)
|
|
return 'multiple';
|
|
};
|
|
|
|
|
|
operation.tooltip = function() {
|
|
var disable = operation.disabled();
|
|
return disable ?
|
|
t('operations.continue.' + disable) :
|
|
t('operations.continue.description');
|
|
};
|
|
|
|
|
|
operation.id = 'continue';
|
|
operation.keys = [t('operations.continue.key')];
|
|
operation.title = t('operations.continue.title');
|
|
operation.behavior = behaviorOperation(context).which(operation);
|
|
|
|
return operation;
|
|
}
|