mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-20 23:44:47 +02:00
Fix a couple of rotate bugs
This commit is contained in:
+14
-27
@@ -1,39 +1,26 @@
|
||||
iD.actions.RotateWay = function(wayId, ref_points, pivot, mousePoint, projection) {
|
||||
iD.actions.RotateWay = function(wayId, pivot, angle, projection) {
|
||||
return function(graph) {
|
||||
return graph.update(function(graph) {
|
||||
var way = graph.entity(wayId),
|
||||
nodes = _.uniq(graph.childNodes(way)),
|
||||
angle, i, points;
|
||||
var way = graph.entity(wayId);
|
||||
|
||||
points = deepCopy(ref_points);
|
||||
_.unique(way.nodes).forEach(function(id) {
|
||||
|
||||
angle = Math.atan2(mousePoint[1] - pivot[1], mousePoint[0] - pivot[0]);
|
||||
var node = graph.entity(id),
|
||||
point = projection(node.loc),
|
||||
radial = [0,0];
|
||||
|
||||
for (i = 0; i < points.length; i++) {
|
||||
var radial = [0,0];
|
||||
radial[0] = point[0] - pivot[0];
|
||||
radial[1] = point[1] - pivot[1];
|
||||
|
||||
radial[0] = points[i][0] - pivot[0];
|
||||
radial[1] = points[i][1] - pivot[1];
|
||||
point = [
|
||||
radial[0] * Math.cos(angle) - radial[1] * Math.sin(angle) + pivot[0],
|
||||
radial[0] * Math.sin(angle) + radial[1] * Math.cos(angle) + pivot[1]
|
||||
];
|
||||
|
||||
points[i][0] = radial[0] * Math.cos(angle) - radial[1] * Math.sin(angle) + pivot[0];
|
||||
points[i][1] = radial[0] * Math.sin(angle) + radial[1] * Math.cos(angle) + pivot[1];
|
||||
graph = graph.replace(node.move(projection.invert(point)));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
for (i = 0; i < points.length; i++) {
|
||||
graph = graph.replace(graph.entity(nodes[i].id).move(projection.invert(points[i])));
|
||||
}
|
||||
|
||||
function deepCopy(o) {
|
||||
var copy = o,k;
|
||||
if (o && typeof o === 'object') {
|
||||
copy = Object.prototype.toString.call(o) === '[object Array]' ? [] : {};
|
||||
for (k in o) {
|
||||
copy[k] = deepCopy(o[k]);
|
||||
}
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -11,8 +11,9 @@ iD.modes.RotateWay = function(context, wayId) {
|
||||
var annotation = t('operations.rotate.annotation.' + context.geometry(wayId)),
|
||||
way = context.graph().entity(wayId),
|
||||
nodes = _.uniq(context.graph().childNodes(way)),
|
||||
ref_points = nodes.map(function(n) { return context.projection(n.loc); }),
|
||||
pivot = d3.geom.polygon(ref_points).centroid();
|
||||
points = nodes.map(function(n) { return context.projection(n.loc); }),
|
||||
pivot = d3.geom.polygon(points).centroid(),
|
||||
angle;
|
||||
|
||||
context.perform(
|
||||
iD.actions.Noop(),
|
||||
@@ -23,11 +24,17 @@ iD.modes.RotateWay = function(context, wayId) {
|
||||
}
|
||||
|
||||
function rotate() {
|
||||
var mousePoint = point();
|
||||
|
||||
var mousePoint = point(),
|
||||
newAngle = Math.atan2(mousePoint[1] - pivot[1], mousePoint[0] - pivot[0]);
|
||||
|
||||
if (typeof angle === 'undefined') angle = newAngle;
|
||||
|
||||
context.replace(
|
||||
iD.actions.RotateWay(wayId, ref_points, pivot, mousePoint, context.projection),
|
||||
iD.actions.RotateWay(wayId, pivot, newAngle - angle, context.projection),
|
||||
annotation);
|
||||
|
||||
angle = newAngle;
|
||||
}
|
||||
|
||||
function finish() {
|
||||
|
||||
@@ -8,7 +8,7 @@ iD.operations.Rotate = function(selection, context) {
|
||||
operation.available = function() {
|
||||
return selection.length === 1 &&
|
||||
context.entity(entityId).type === 'way' &&
|
||||
context.entity(entityId).isClosed();
|
||||
context.entity(entityId).geometry() === 'area';
|
||||
};
|
||||
|
||||
operation.enabled = function() {
|
||||
|
||||
Reference in New Issue
Block a user