diff --git a/data/core.yaml b/data/core.yaml index 289a5aa0e..2c5babc66 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -168,13 +168,18 @@ en: description: points: Straighten these points. line: Straighten this line. + lines: Straighten these lines. key: S annotation: points: Straightened several points. line: Straightened a line. + lines: Straightened several lines. too_bendy: This can't be straightened because it bends too much. connected_to_hidden: This can't be straightened because it is connected to a hidden feature. not_downloaded: This can't be straightened because parts of it have not yet been downloaded. + too_large: + single: This can't be straightened because not enough of it is currently visible. + multiple: These can't be straightened because not enough of them are currently visible. delete: title: Delete description: diff --git a/dist/locales/en.json b/dist/locales/en.json index 795ba224a..fd403ef21 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -220,16 +220,22 @@ "title": "Straighten", "description": { "points": "Straighten these points.", - "line": "Straighten this line." + "line": "Straighten this line.", + "lines": "Straighten these lines." }, "key": "S", "annotation": { "points": "Straightened several points.", - "line": "Straightened a line." + "line": "Straightened a line.", + "lines": "Straightened several lines." }, "too_bendy": "This can't be straightened because it bends too much.", "connected_to_hidden": "This can't be straightened because it is connected to a hidden feature.", - "not_downloaded": "This can't be straightened because parts of it have not yet been downloaded." + "not_downloaded": "This can't be straightened because parts of it have not yet been downloaded.", + "too_large": { + "single": "This can't be straightened because not enough of it is currently visible.", + "multiple": "These can't be straightened because not enough of them are currently visible." + } }, "delete": { "title": "Delete", diff --git a/modules/operations/straighten.js b/modules/operations/straighten.js index 51951d500..d685df4cd 100644 --- a/modules/operations/straighten.js +++ b/modules/operations/straighten.js @@ -2,6 +2,7 @@ import { t } from '../core/localizer'; import { actionStraightenNodes } from '../actions/straighten_nodes'; import { actionStraightenWay } from '../actions/straighten_way'; import { behaviorOperation } from '../behavior/operation'; +import { geoExtent } from '../geo'; import { utilArrayDifference, utilGetAllNodes } from '../util/index'; @@ -11,6 +12,9 @@ export function operationStraighten(context, selectedIDs) { var nodes = utilGetAllNodes(selectedIDs, context.graph()); var coords = nodes.map(function(n) { return n.loc; }); + var extent = nodes.reduce(function(extent, node) { + return extent.extend(node.extent(context.graph())); + }, geoExtent()); var action = chooseAction(); var geometry; @@ -31,7 +35,7 @@ export function operationStraighten(context, selectedIDs) { if (entity.type === 'node') { continue; } else if (entity.type !== 'way' || entity.isClosed()) { - return false; // exit early, can't straighten these + return null; // exit early, can't straighten these } startNodeIDs.push(entity.first()); @@ -48,23 +52,23 @@ export function operationStraighten(context, selectedIDs) { // Ensure all ways are connected (i.e. only 2 unique endpoints/startpoints) if (utilArrayDifference(startNodeIDs, endNodeIDs).length + - utilArrayDifference(endNodeIDs, startNodeIDs).length !== 2) return false; + utilArrayDifference(endNodeIDs, startNodeIDs).length !== 2) return null; // Ensure path contains at least 3 unique nodes var wayNodeIDs = utilGetAllNodes(wayIDs, context.graph()) .map(function(node) { return node.id; }); - if (wayNodeIDs.length <= 2) return false; + if (wayNodeIDs.length <= 2) return null; // If range of 2 selected nodes is supplied, ensure nodes lie on the selected path if (nodeIDs.length === 2 && ( wayNodeIDs.indexOf(nodeIDs[0]) === -1 || wayNodeIDs.indexOf(nodeIDs[1]) === -1 - )) return false; + )) return null; - geometry = 'line'; + geometry = wayIDs.length === 1 ? 'line' : 'lines'; return actionStraightenWay(selectedIDs, context.projection); } - return false; + return null; } @@ -88,6 +92,8 @@ export function operationStraighten(context, selectedIDs) { var reason = action.disabled(context.graph()); if (reason) { return reason; + } else if (extent.percentContainedIn(context.map().extent()) < 0.8) { + return 'too_large.' + ((wayIDs.length ? wayIDs : nodeIDs).length === 1 ? 'single' : 'multiple'); } else if (someMissing()) { return 'not_downloaded'; } else if (selectedIDs.some(context.hasHiddenConnections)) {