Files
iD/modules/operations/merge.js
Quincy Morgan 8b258d2cbd Load the maximum nodes per way value from the OSM API and add a getter to the service object
Disable the Merge operation if the resultant way would have more than the maximum number of nodes (close #6030)
Simplify some code in operationMerge
2020-06-08 14:38:49 -04:00

92 lines
2.9 KiB
JavaScript

import { t } from '../core/localizer';
import { actionJoin } from '../actions/join';
import { actionMerge } from '../actions/merge';
import { actionMergeNodes } from '../actions/merge_nodes';
import { actionMergePolygon } from '../actions/merge_polygon';
import { behaviorOperation } from '../behavior/operation';
import { modeSelect } from '../modes/select';
import { presetManager } from '../presets';
export function operationMerge(context, selectedIDs) {
var _action = getAction();
function getAction() {
var join = actionJoin(selectedIDs);
if (join.disabled(context.graph()) !== 'not_eligible') {
return join;
}
var merge = actionMerge(selectedIDs);
if (merge.disabled(context.graph()) !== 'not_eligible') {
return merge;
}
var mergePolygon = actionMergePolygon(selectedIDs);
if (mergePolygon.disabled(context.graph()) !== 'not_eligible') {
return mergePolygon;
}
var mergeNodes = actionMergeNodes(selectedIDs);
return mergeNodes;
}
var operation = function() {
if (operation.disabled()) return;
context.perform(_action, operation.annotation());
context.validator().validate();
var resultIDs = selectedIDs.filter(context.hasEntity);
if (resultIDs.length > 1) {
var interestingIDs = resultIDs.filter(function(id) {
return context.entity(id).hasInterestingTags();
});
if (interestingIDs.length) resultIDs = interestingIDs;
}
context.enter(modeSelect(context, resultIDs));
};
operation.available = function() {
return selectedIDs.length >= 2;
};
operation.disabled = function() {
var actionDisabled = _action.disabled(context.graph());
if (actionDisabled) return actionDisabled;
var osm = context.connection();
if (osm &&
_action.resultingWayNodesLength &&
_action.resultingWayNodesLength(context.graph()) > osm.maxWayNodes()) {
return 'too_many_vertices';
}
return false;
};
operation.tooltip = function() {
var disabled = operation.disabled();
if (disabled) {
if (disabled === 'restriction') {
return t('operations.merge.restriction',
{ relation: presetManager.item('type/restriction').name() });
}
return t('operations.merge.' + disabled);
}
return t('operations.merge.description');
};
operation.annotation = function() {
return t('operations.merge.annotation', { n: selectedIDs.length });
};
operation.id = 'merge';
operation.keys = [t('operations.merge.key')];
operation.title = t('operations.merge.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}