Files
iD/modules/modes/add_area.js
Martin Raifer 43784e2eff take entity loc into account when resolving fields via parent preset, fixes #9524
this necessary when a regional preset (e.g. from NSI) is supposed to inherit fields from a parent preset, but the direct parent does NOT apply at the location of the entity to be added/edited. In that case we need to search for a potential regional variant of the parent preset.
2023-05-25 19:19:09 +02:00

90 lines
2.3 KiB
JavaScript

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 { modeDrawArea } from './draw_area';
import { osmNode, osmWay } from '../osm';
export function modeAddArea(context, mode) {
mode.id = 'add-area';
var behavior = behaviorAddWay(context)
.on('start', start)
.on('startFromWay', startFromWay)
.on('startFromNode', startFromNode);
function defaultTags(loc) {
var defaultTags = { area: 'yes' };
if (mode.preset) defaultTags = mode.preset.setTags(defaultTags, 'area', false, loc);
return defaultTags;
}
function actionClose(wayId) {
return function (graph) {
return graph.replace(graph.entity(wayId).close());
};
}
function start(loc) {
var startGraph = context.graph();
var node = osmNode({ loc: loc });
var way = osmWay({ tags: defaultTags(loc) });
context.perform(
actionAddEntity(node),
actionAddEntity(way),
actionAddVertex(way.id, node.id),
actionClose(way.id)
);
context.enter(modeDrawArea(context, way.id, startGraph, mode.button));
}
function startFromWay(loc, edge) {
var startGraph = context.graph();
var node = osmNode({ loc: loc });
var way = osmWay({ tags: defaultTags(loc) });
context.perform(
actionAddEntity(node),
actionAddEntity(way),
actionAddVertex(way.id, node.id),
actionClose(way.id),
actionAddMidpoint({ loc: loc, edge: edge }, node)
);
context.enter(modeDrawArea(context, way.id, startGraph, mode.button));
}
function startFromNode(node) {
var startGraph = context.graph();
var way = osmWay({ tags: defaultTags(node.loc) });
context.perform(
actionAddEntity(way),
actionAddVertex(way.id, node.id),
actionClose(way.id)
);
context.enter(modeDrawArea(context, way.id, startGraph, mode.button));
}
mode.enter = function() {
context.install(behavior);
};
mode.exit = function() {
context.uninstall(behavior);
};
return mode;
}