Files
iD/modules/modes/draw_area.js
Quincy Morgan b5856e2415 Rewrite behaviorDrawWay to only always use one and only one temporary edit
Fix issues involving undoing while drawing ways
Prevent self-intersection when adding nodes to ways on touch devices (close #7423)
2020-03-11 17:48:09 -07:00

60 lines
1.4 KiB
JavaScript

import { t } from '../util/locale';
import { behaviorDrawWay } from '../behavior/draw_way';
import { uiFlash } from '../ui/flash';
export function modeDrawArea(context, wayID, startGraph, button) {
var mode = {
button: button,
id: 'draw-area'
};
var behavior;
mode.wayID = wayID;
mode.enter = function() {
var way = context.entity(wayID);
behavior = behaviorDrawWay(context, wayID, undefined, mode, startGraph)
.tail(t('modes.draw_area.tail'))
.on('rejectedSelfIntersection.modeDrawArea', function() {
uiFlash()
.text(t('self_intersection.error.areas'))();
});
var addNode = behavior.addNode;
behavior.addNode = function(node, d) {
var length = way.nodes.length;
var penultimate = length > 2 ? way.nodes[length - 2] : null;
if (node.id === way.first() || node.id === penultimate) {
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;
}