From a4b7b341ed0c40c001f1bd7dfa391fc47c6849e4 Mon Sep 17 00:00:00 2001 From: Jon D Date: Sat, 5 Nov 2016 18:23:40 +0000 Subject: [PATCH] Alter implementation. Need to see if projection.translate is required --- modules/actions/flip.js | 46 +++++++++++--------------------------- modules/operations/flip.js | 2 +- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/modules/actions/flip.js b/modules/actions/flip.js index e7fd4fe88..979a805c9 100644 --- a/modules/actions/flip.js +++ b/modules/actions/flip.js @@ -6,49 +6,29 @@ Only operates on "area" ways export function actionFlip(wayId, isVertical, projection) { return function (graph) { - var targetWay = graph.entity(wayId); + const targetWay = graph.entity(wayId); // If the way is not an area, we will not process it if (!targetWay.isArea()) { // return input graph without changes return graph; } - // Obtain all of the nodes on the way - var nodesAndRects = _(targetWay.nodes) + // Get the bounding rectangle of the area + const boundingRect = targetWay.extent(graph).rectangle(); + // rectangle returned as [ lon (x) top left, lat (y) top left, lon (x) bottom right, lat (y) bottom right] + // Obtain the left/top lonlat and the right/bottom + const leftOrTop = isVertical ? boundingRect[1] : boundingRect[0]; + const rightOrBottom = isVertical ? boundingRect[3] : boundingRect[2]; + // Determine the mid-point that we will flip on + const midPoint = leftOrTop + (rightOrBottom - leftOrTop); + + // Obtain all of the nodes on the way, iterate over them to translate then aggreate up + return _(targetWay.nodes) .map(function (nodeId) { return graph.entity(nodeId); }) - // and their rectangles .map(function (node) { - return { - node: node, - rect: node.extent().rectangle() - }; - }); - // Obtain the left/top lonlat - // rectangle returned as [ lon (x) top left, lat (y) top left, lon (x) bottom right, lat (y) bottom right] - var leftOrTop = nodesAndRects - .map(function (nodeAndRect) { - return nodeAndRect.rect; - }) - .minBy(function (rect) { - return isVertical ? rect[1] : rect[0]; - }); - // Now the same for right/bottom - var rightOrBottom = nodesAndRects - .map(function (nodeAndRect) { - return nodeAndRect.rect; - }) - .minBy(function (rect) { - return isVertical ? rect[3] : rect[2]; - }); - // Determine the mid-point that we will flip on - var midPoint = rightOrBottom - leftOrTop; - // Iterate and aggregate - return nodesAndRects - .map(function (nodeAndRect) { // Get distance from midPoint - var node = nodeAndRect.node; - var delta = isVertical ? + const delta = isVertical ? node.loc[1] - midPoint : node.loc[0] - midPoint; return isVertical ? diff --git a/modules/operations/flip.js b/modules/operations/flip.js index ed133f665..846dfbaed 100644 --- a/modules/operations/flip.js +++ b/modules/operations/flip.js @@ -7,7 +7,7 @@ export function operationFlip(selectedIDs, context) { var operation = function() { context.perform( - actionFlip(entityId), + actionFlip(entityId, false, context.projection), t('operations.flip.annotation') ); };