Files
iD/js/id/operations/delete.js
tyr e8d637f2bb Add iD.geo.sphericalDistance
iD.geo.euclideanDistance should only be used for calculations of 
projected coordinates or display (pixel) coordinates.

iD.geo.sphericalDistance calculates approximate geographical 
distances, accounting for distortions at higher latitudes. This 
can be used for determining the nearest node (operations.Delete,
actions.Circularize) or relative length comparisons (actions.Split).
2013-09-29 07:45:04 -07:00

71 lines
2.2 KiB
JavaScript

iD.operations.Delete = function(selectedIDs, context) {
var action = iD.actions.DeleteMultiple(selectedIDs);
var operation = function() {
var annotation,
nextSelectedID;
if (selectedIDs.length > 1) {
annotation = t('operations.delete.annotation.multiple', {n: selectedIDs.length});
} else {
var id = selectedIDs[0],
entity = context.entity(id),
geometry = context.geometry(id),
parents = context.graph().parentWays(entity),
parent = parents[0];
annotation = t('operations.delete.annotation.' + geometry);
// Select the next closest node in the way.
if (geometry === 'vertex' && parents.length === 1 && parent.nodes.length > 2) {
var nodes = parent.nodes,
i = nodes.indexOf(id);
if (i === 0) {
i++;
} else if (i === nodes.length - 1) {
i--;
} else {
var a = iD.geo.sphericalDistance(entity.loc, context.entity(nodes[i - 1]).loc),
b = iD.geo.sphericalDistance(entity.loc, context.entity(nodes[i + 1]).loc);
i = a < b ? i - 1 : i + 1;
}
nextSelectedID = nodes[i];
}
}
context.perform(
action,
annotation);
if (nextSelectedID && context.hasEntity(nextSelectedID)) {
context.enter(iD.modes.Select(context, [nextSelectedID]));
} else {
context.enter(iD.modes.Browse(context));
}
};
operation.available = function() {
return true;
};
operation.disabled = function() {
return action.disabled(context.graph());
};
operation.tooltip = function() {
var disable = operation.disabled();
return disable ?
t('operations.delete.' + disable) :
t('operations.delete.description');
};
operation.id = "delete";
operation.keys = [iD.ui.cmd('⌘⌫'), iD.ui.cmd('⌘⌦')];
operation.title = t('operations.delete.title');
return operation;
};