Files
iD/modules/modes/draw_line.js
Quincy Morgan a1af118f0e Ensure locales and presets are loaded before the UI loads (close #7406)
Consolidate localization behavior and init to a coreLocalizer function and singleton
Explicitly support `en-US` locale
Rename coreData to coreFileFetcher and export a singleton rather than using a property of coreContext
Add `apiConnections` property of coreContext to simplify adding a source switcher
Replace some init functions with re-callable, promise-supporting `ensureLoaded` functions
Make coreContext itself load the UI if a container has been specified at init time
Fix code tests
2020-03-31 12:23:31 -07:00

58 lines
1.4 KiB
JavaScript

import { t } from '../core/localizer';
import { behaviorDrawWay } from '../behavior/draw_way';
export function modeDrawLine(context, wayID, startGraph, button, affix, continuing) {
var mode = {
button: button,
id: 'draw-line'
};
var behavior;
mode.wayID = wayID;
mode.isContinuing = continuing;
mode.enter = function() {
var way = context.entity(wayID);
var index = (affix === 'prefix') ? 0 : undefined;
var headID = (affix === 'prefix') ? way.first() : way.last();
behavior = behaviorDrawWay(context, wayID, index, mode, startGraph)
.tail(t('modes.draw_line.tail'))
.on('rejectedSelfIntersection.modeDrawLine', function() {
context.ui().flash
.text(t('self_intersection.error.lines'))();
});
var addNode = behavior.addNode;
behavior.addNode = function(node, d) {
if (node.id === headID) {
behavior.finish();
} else {
addNode(node, d);
}
};
context.install(behavior);
};
mode.exit = function() {
context.uninstall(behavior);
};
mode.selectedIDs = function() {
return [wayID];
};
mode.activeID = function() {
return (behavior && behavior.activeID()) || [];
};
return mode;
}