mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-25 06:55:46 +00:00
68 lines
1.7 KiB
JavaScript
68 lines
1.7 KiB
JavaScript
import { AddWay } from '../behavior/index';
|
|
import { Node, Way } from '../core/index';
|
|
import { DrawLine } from './index';
|
|
import { AddEntity, AddVertex, AddMidpoint } from '../actions/index';
|
|
export function AddLine(context) {
|
|
var mode = {
|
|
id: 'add-line',
|
|
button: 'line',
|
|
title: t('modes.add_line.title'),
|
|
description: t('modes.add_line.description'),
|
|
key: '2'
|
|
};
|
|
|
|
var behavior = AddWay(context)
|
|
.tail(t('modes.add_line.tail'))
|
|
.on('start', start)
|
|
.on('startFromWay', startFromWay)
|
|
.on('startFromNode', startFromNode);
|
|
|
|
function start(loc) {
|
|
var baseGraph = context.graph(),
|
|
node = Node({loc: loc}),
|
|
way = Way();
|
|
|
|
context.perform(
|
|
AddEntity(node),
|
|
AddEntity(way),
|
|
AddVertex(way.id, node.id));
|
|
|
|
context.enter(DrawLine(context, way.id, baseGraph));
|
|
}
|
|
|
|
function startFromWay(loc, edge) {
|
|
var baseGraph = context.graph(),
|
|
node = Node({loc: loc}),
|
|
way = Way();
|
|
|
|
context.perform(
|
|
AddEntity(node),
|
|
AddEntity(way),
|
|
AddVertex(way.id, node.id),
|
|
AddMidpoint({ loc: loc, edge: edge }, node));
|
|
|
|
context.enter(DrawLine(context, way.id, baseGraph));
|
|
}
|
|
|
|
function startFromNode(node) {
|
|
var baseGraph = context.graph(),
|
|
way = Way();
|
|
|
|
context.perform(
|
|
AddEntity(way),
|
|
AddVertex(way.id, node.id));
|
|
|
|
context.enter(DrawLine(context, way.id, baseGraph));
|
|
}
|
|
|
|
mode.enter = function() {
|
|
context.install(behavior);
|
|
};
|
|
|
|
mode.exit = function() {
|
|
context.uninstall(behavior);
|
|
};
|
|
|
|
return mode;
|
|
}
|