mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 09:42:56 +00:00
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
import { t } from '../util/locale';
|
|
import { Browse, Select } from './index';
|
|
import { AddEntity } from '../actions/index';
|
|
import { Draw } from '../behavior/index';
|
|
import { Node } from '../core/index';
|
|
|
|
export function AddPoint(context) {
|
|
var mode = {
|
|
id: 'add-point',
|
|
button: 'point',
|
|
title: t('modes.add_point.title'),
|
|
description: t('modes.add_point.description'),
|
|
key: '1'
|
|
};
|
|
|
|
var behavior = Draw(context)
|
|
.tail(t('modes.add_point.tail'))
|
|
.on('click', add)
|
|
.on('clickWay', addWay)
|
|
.on('clickNode', addNode)
|
|
.on('cancel', cancel)
|
|
.on('finish', cancel);
|
|
|
|
function add(loc) {
|
|
var node = Node({loc: loc});
|
|
|
|
context.perform(
|
|
AddEntity(node),
|
|
t('operations.add.annotation.point'));
|
|
|
|
context.enter(
|
|
Select(context, [node.id])
|
|
.suppressMenu(true)
|
|
.newFeature(true));
|
|
}
|
|
|
|
function addWay(loc) {
|
|
add(loc);
|
|
}
|
|
|
|
function addNode(node) {
|
|
add(node.loc);
|
|
}
|
|
|
|
function cancel() {
|
|
context.enter(Browse(context));
|
|
}
|
|
|
|
mode.enter = function() {
|
|
context.install(behavior);
|
|
};
|
|
|
|
mode.exit = function() {
|
|
context.uninstall(behavior);
|
|
};
|
|
|
|
return mode;
|
|
}
|