Changeset 5845 in josm for trunk/src/org/openstreetmap/josm/io/remotecontrol/handler
- Timestamp:
- 2013-04-13T14:19:56+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/remotecontrol/handler
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java
r5844 r5845 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Point; 6 7 import java.util.HashMap; 7 8 import org.openstreetmap.josm.Main; … … 10 11 import org.openstreetmap.josm.data.coor.LatLon; 11 12 import org.openstreetmap.josm.data.osm.Node; 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 14 import org.openstreetmap.josm.gui.util.GuiHelper; 13 15 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; … … 64 66 // Create a new node 65 67 LatLon ll = new LatLon(lat, lon); 66 Node nnew = new Node(ll);67 68 68 // Now execute the commands to add this node. 69 Main.main.undoRedo.add(new AddCommand(nnew)); 70 Main.main.getCurrentDataSet().setSelected(nnew); 69 Node nd = null; 70 71 if (Main.map != null && Main.map.mapView != null) { 72 Point p = Main.map.mapView.getPoint(ll); 73 nd = Main.map.mapView.getNearestNode(p, OsmPrimitive.isUsablePredicate); 74 if (nd!=null && nd.getCoor().greatCircleDistance(ll) > Main.pref.getDouble("remotecontrol.tolerance", 0.1)) { 75 nd = null; // node is too far 76 } 77 } 78 79 if (nd==null) { 80 nd = new Node(ll); 81 // Now execute the commands to add this node. 82 Main.main.undoRedo.add(new AddCommand(nd)); 83 } 84 85 Main.main.getCurrentDataSet().setSelected(nd); 71 86 if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) { 72 87 AutoScaleAction.autoScale("selection"); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java
r5844 r5845 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Point; 5 6 import java.util.ArrayList; 6 7 import java.util.Arrays; 8 import java.util.HashMap; 7 9 import java.util.LinkedList; 8 10 import java.util.List; … … 15 17 import org.openstreetmap.josm.data.coor.LatLon; 16 18 import org.openstreetmap.josm.data.osm.Node; 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 20 import org.openstreetmap.josm.data.osm.Way; 18 21 import org.openstreetmap.josm.gui.util.GuiHelper; … … 31 34 32 35 private final List<LatLon> allCoordinates = new ArrayList<LatLon>(); 36 37 /** 38 * The place to remeber already added nodes (they are reused if needed @since 5845 39 */ 40 HashMap<LatLon, Node> addedNodes; 33 41 34 42 @Override … … 84 92 } 85 93 } 94 95 /** 96 * Find the node with almost the same ccords in dataset or in already added nodes 97 * @since 5845 98 **/ 99 Node findOrCreateNode(LatLon ll, List<Command> commands) { 100 Node nd = null; 101 102 if (Main.map != null && Main.map.mapView != null) { 103 Point p = Main.map.mapView.getPoint(ll); 104 nd = Main.map.mapView.getNearestNode(p, OsmPrimitive.isUsablePredicate); 105 if (nd!=null && nd.getCoor().greatCircleDistance(ll) > Main.pref.getDouble("remote.tolerance", 0.1)) { 106 nd = null; // node is too far 107 } 108 } 109 110 Node prev = null; 111 for (LatLon lOld: addedNodes.keySet()) { 112 if (lOld.greatCircleDistance(ll) < Main.pref.getDouble("remotecontrol.tolerance", 0.1)) { 113 prev = addedNodes.get(lOld); 114 break; 115 } 116 } 86 117 118 if (prev!=null) { 119 nd = prev; 120 } else if (nd==null) { 121 nd = new Node(ll); 122 // Now execute the commands to add this node. 123 commands.add(new AddCommand(nd)); 124 addedNodes.put(ll, nd); 125 } 126 return nd; 127 } 128 87 129 /* 88 130 * This function creates the way with given coordinates of nodes 89 131 */ 90 132 private void addWay() { 133 addedNodes = new HashMap<LatLon, Node>(); 91 134 Way way = new Way(); 92 135 List<Command> commands = new LinkedList<Command>(); 93 136 for (LatLon ll : allCoordinates) { 94 Node node = new Node(ll);137 Node node = findOrCreateNode(ll, commands); 95 138 way.addNode(node); 96 commands.add(new AddCommand(node));97 139 } 98 140 allCoordinates.clear();
Note:
See TracChangeset
for help on using the changeset viewer.