Files
iD/modules/modes/add_area.js
Quincy Morgan a1af118f0e Ensure locales and presets are loaded before the UI loads (close #7406)
Consolidate localization behavior and init to a coreLocalizer function and singleton
Explicitly support `en-US` locale
Rename coreData to coreFileFetcher and export a singleton rather than using a property of coreContext
Add `apiConnections` property of coreContext to simplify adding a source switcher
Replace some init functions with re-callable, promise-supporting `ensureLoaded` functions
Make coreContext itself load the UI if a container has been specified at init time
Fix code tests
2020-03-31 12:23:31 -07:00

90 lines
2.3 KiB
JavaScript

import { t } from '../core/localizer';
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)
.tail(t('modes.add_area.tail'))
.on('start', start)
.on('startFromWay', startFromWay)
.on('startFromNode', startFromNode);
var defaultTags = { area: 'yes' };
if (mode.preset) defaultTags = mode.preset.setTags(defaultTags, 'area');
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 });
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 });
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 });
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;
}