mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 17:23:02 +00:00
79 lines
2.1 KiB
JavaScript
79 lines
2.1 KiB
JavaScript
import { t } from '../util/locale';
|
|
import { actionAddEntity } from '../actions/add_entity';
|
|
import { actionAddMidpoint } from '../actions/add_midpoint';
|
|
import { actionAddVertex } from '../actions/add_vertex';
|
|
|
|
import { behaviorAddWay } from '../behavior/add_way';
|
|
import { modeDrawLine } from './draw_line';
|
|
import { osmNode, osmWay } from '../osm';
|
|
|
|
|
|
export function modeAddLine(context, mode) {
|
|
mode.id = 'add-line';
|
|
|
|
var behavior = behaviorAddWay(context)
|
|
.tail(t('modes.add_line.tail'))
|
|
.on('start', start)
|
|
.on('startFromWay', startFromWay)
|
|
.on('startFromNode', startFromNode);
|
|
|
|
var defaultTags = {};
|
|
if (mode.preset) defaultTags = mode.preset.setTags(defaultTags, 'line');
|
|
|
|
|
|
function start(loc) {
|
|
var startGraph = context.graph();
|
|
var node = osmNode({ loc: loc });
|
|
var way = osmWay({ tags: defaultTags });
|
|
|
|
context.perform(
|
|
actionAddEntity(node),
|
|
actionAddEntity(way),
|
|
actionAddVertex(way.id, node.id)
|
|
);
|
|
|
|
context.enter(modeDrawLine(context, way.id, startGraph, context.graph(), mode.button));
|
|
}
|
|
|
|
|
|
function startFromWay(loc, edge) {
|
|
var startGraph = context.graph();
|
|
var node = osmNode({ loc: loc });
|
|
var way = osmWay({ tags: defaultTags });
|
|
|
|
context.perform(
|
|
actionAddEntity(node),
|
|
actionAddEntity(way),
|
|
actionAddVertex(way.id, node.id),
|
|
actionAddMidpoint({ loc: loc, edge: edge }, node)
|
|
);
|
|
|
|
context.enter(modeDrawLine(context, way.id, startGraph, context.graph(), mode.button));
|
|
}
|
|
|
|
|
|
function startFromNode(node) {
|
|
var startGraph = context.graph();
|
|
var way = osmWay({ tags: defaultTags });
|
|
|
|
context.perform(
|
|
actionAddEntity(way),
|
|
actionAddVertex(way.id, node.id)
|
|
);
|
|
|
|
context.enter(modeDrawLine(context, way.id, startGraph, context.graph(), mode.button));
|
|
}
|
|
|
|
|
|
mode.enter = function() {
|
|
context.install(behavior);
|
|
};
|
|
|
|
|
|
mode.exit = function() {
|
|
context.uninstall(behavior);
|
|
};
|
|
|
|
return mode;
|
|
}
|