mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-19 15:08:23 +02:00
Add circularize action. Fixes #491
This commit is contained in:
@@ -81,6 +81,7 @@
|
||||
<script src="js/id/actions/delete_way.js"></script>
|
||||
<script src='js/id/actions/move_node.js'></script>
|
||||
<script src='js/id/actions/move_way.js'></script>
|
||||
<script src='js/id/actions/circular.js'></script>
|
||||
<script src='js/id/actions/noop.js'></script>
|
||||
<script src='js/id/actions/reverse_way.js'></script>
|
||||
<script src='js/id/actions/split_way.js'></script>
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
iD.actions.Circular = function(wayId, map) {
|
||||
|
||||
var action = function(graph) {
|
||||
var way = graph.fetch(wayId),
|
||||
tags = {}, key, role;
|
||||
|
||||
var points = way.nodes.map(function(n) {
|
||||
return map.projection(n.loc);
|
||||
}),
|
||||
centroid = d3.geom.polygon(points).centroid(),
|
||||
radius = d3.median(points, function(p) {
|
||||
return iD.geo.dist(centroid, p);
|
||||
}),
|
||||
circular_nodes = [];
|
||||
|
||||
for (var i = 0; i < 12; i++) {
|
||||
circular_nodes.push(iD.Node({ loc: map.projection.invert([
|
||||
centroid[0] + Math.cos((i / 12) * Math.PI * 2) * radius,
|
||||
centroid[1] + Math.sin((i / 12) * Math.PI * 2) * radius])
|
||||
}));
|
||||
}
|
||||
|
||||
circular_nodes.push(circular_nodes[0]);
|
||||
|
||||
for (i = 0; i < way.nodes.length; i++) {
|
||||
if (graph.parentWays(way.nodes[i]).length > 1) {
|
||||
var closest, closest_dist = Infinity, dist;
|
||||
for (var j = 0; j < circular_nodes.length; j++) {
|
||||
dist = iD.geo.dist(circular_nodes[j].loc, way.nodes[i].loc);
|
||||
if (dist < closest_dist) {
|
||||
closest_dist = dist;
|
||||
closest = j;
|
||||
}
|
||||
}
|
||||
circular_nodes.splice(closest, 1, way.nodes[i]);
|
||||
if (closest === 0) circular_nodes.splice(circular_nodes.length - 1, 1, way.nodes[i]);
|
||||
else if (closest === circular_nodes.length - 1) circular_nodes.splice(0, 1, way.nodes[i]);
|
||||
} else {
|
||||
graph = graph.remove(way.nodes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < circular_nodes.length; i++) {
|
||||
graph = graph.replace(circular_nodes[i]);
|
||||
}
|
||||
|
||||
return graph.replace(way.update({
|
||||
nodes: _.pluck(circular_nodes, 'id')
|
||||
}));
|
||||
};
|
||||
|
||||
action.enabled = function(graph) {
|
||||
return true;
|
||||
};
|
||||
|
||||
return action;
|
||||
};
|
||||
@@ -137,7 +137,7 @@ iD.modes.Select = function(entity, initial) {
|
||||
})
|
||||
.classed('selected', true);
|
||||
|
||||
radialMenu = iD.ui.RadialMenu(entity, history);
|
||||
radialMenu = iD.ui.RadialMenu(entity, history, mode.map);
|
||||
|
||||
if (d3.event && !initial) {
|
||||
var loc = map.mouseCoordinates();
|
||||
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
iD.ui.RadialMenu = function(entity, history) {
|
||||
iD.ui.RadialMenu = function(entity, history, map) {
|
||||
var radialMenu = function(selection, center) {
|
||||
var operations,
|
||||
graph = history.graph(),
|
||||
@@ -49,6 +49,14 @@ iD.ui.RadialMenu = function(entity, history) {
|
||||
action: iD.actions.ReverseWay(entity.id)
|
||||
}
|
||||
];
|
||||
if (entity.isClosed()) {
|
||||
operations.push({
|
||||
id: 'circlar',
|
||||
text: 'Circular',
|
||||
description: 'made way circular',
|
||||
action: iD.actions.Circular(entity.id, map)
|
||||
});
|
||||
}
|
||||
} else if (geometry === 'area') {
|
||||
operations = [
|
||||
{
|
||||
@@ -56,8 +64,15 @@ iD.ui.RadialMenu = function(entity, history) {
|
||||
text: 'Delete',
|
||||
description: 'deleted an area',
|
||||
action: iD.actions.DeleteWay(entity.id)
|
||||
},
|
||||
{
|
||||
id: 'circlar',
|
||||
text: 'Circular',
|
||||
description: 'made area circular',
|
||||
action: iD.actions.Circular(entity.id, map)
|
||||
}
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
var arc = d3.svg.arc()
|
||||
|
||||
Reference in New Issue
Block a user