Alter implementation. Need to see if projection.translate is required

This commit is contained in:
Jon D
2016-11-05 18:23:40 +00:00
parent 3052466f75
commit a4b7b341ed
2 changed files with 14 additions and 34 deletions

View File

@@ -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 ?

View File

@@ -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')
);
};