Changeset 3865 in osm
- Timestamp:
- 2007-07-29T22:33:42+02:00 (18 years ago)
- Location:
- applications/editors/josm/plugins/navigator
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/navigator/build.xml
r3837 r3865 9 9 10 10 <!-- plugin meta data (enter new version number if anything changed!) --> 11 <property name="plugin.version" value="0.3"/> 11 <property name="plugin.version" value="0.3.1"/> 12 12 <property name="plugin.description" value="Provides navigation/autorouting functionality (V${plugin.version})."/> 13 13 <property name="plugin.stage" value="50"/> -
applications/editors/josm/plugins/navigator/readme.txt
r3736 r3865 6 6 directory as well! 7 7 8 Use the navigator mode and click all nodes that should be navigated to. 9 Use the middle mouse button to remove the selected nodes. 10 8 11 Christof Dallermassl 9 12 christof@dallermassl.at -
applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorLayer.java
r3828 r3865 147 147 endIcon.paintIcon(mv, g, screen.x, screen.y - endIcon.getIconHeight()); 148 148 } 149 150 Main.pref.hasKey(KEY_ROUTE_COLOR);151 String selectString = Main.pref.get(KEY_ROUTE_SELECT);152 if(selectString.length() == 0) {153 selectString = "true";154 Main.pref.put(KEY_ROUTE_SELECT, selectString);155 }156 157 if(Boolean.parseBoolean(selectString)) {158 List<Segment> path = navigatorNodeModel.getSegmentPath();159 if(path != null) {160 synchronized(path) {161 Main.ds.setSelected(path);162 // Main.map.mapView.repaint();163 }164 }165 }166 149 167 150 String colorString = Main.pref.get(KEY_ROUTE_COLOR); … … 243 226 public void navigate() { 244 227 navigatorNodeModel.calculateShortesPath(); 228 Main.pref.hasKey(KEY_ROUTE_COLOR); 229 String selectString = Main.pref.get(KEY_ROUTE_SELECT); 230 if(selectString.length() == 0) { 231 selectString = "true"; 232 Main.pref.put(KEY_ROUTE_SELECT, selectString); 233 } 234 235 if(Boolean.parseBoolean(selectString)) { 236 List<Segment> path = navigatorNodeModel.getSegmentPath(); 237 if(path != null) { 238 synchronized(path) { 239 Main.ds.setSelected(path); 240 } 241 } 242 } 245 243 Main.map.repaint(); 246 244 } -
applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorModeAction.java
r3829 r3865 26 26 27 27 public NavigatorModeAction(MapFrame mapFrame, NavigatorModel navigatorModel, NavigatorLayer navigationLayer) { 28 super(tr("Navigator"), "navigation", tr("Set start/end for autorouting"), KeyEvent.VK_F, mapFrame, ImageProvider.getCursor("crosshair", "selection")); 28 super(tr("Navigator"), "navigation", tr("Set start/end for autorouting. Middle Mouse button to reset."), KeyEvent.VK_F, mapFrame, ImageProvider.getCursor("crosshair", "selection")); 29 29 this.navigatorModel = navigatorModel; 30 30 this.navigatorLayer = navigationLayer; -
applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorModel.java
r3830 r3865 6 6 import java.util.ArrayList; 7 7 import java.util.Collection; 8 import java.util.HashMap; 8 9 import java.util.LinkedList; 9 10 import java.util.List; 11 import java.util.Map; 10 12 11 13 import org.jgrapht.Graph; … … 24 26 */ 25 27 public class NavigatorModel { 26 private Graph graph; 28 private Graph<Node, SegmentEdge> graph; 27 29 private List<Node> nodes; 28 private int selectionChangedCalls;29 List<Segment > segmentPath;30 List<SegmentEdge> edgePath;30 private List<Segment> segmentPath; 31 private List<SegmentEdge> edgePath; 32 private Map<String, Double> highwayWeight; 31 33 32 34 public NavigatorModel() { 33 35 nodes = new ArrayList<Node>(); 36 highwayWeight = new HashMap<String, Double>(); 37 } 38 39 /** 40 * Set the weight for the given highway type. The higher the weight is, 41 * the more it is preferred in routing. 42 * @param type the type of the highway. 43 * @param weigth the weight. 44 */ 45 public void setHighwayTypeWeight(String type, double weigth) { 46 highwayWeight.put(type, weigth); 34 47 } 35 48 … … 45 58 if (graph == null) { 46 59 OsmGraphCreator graphCreator = new OsmGraphCreator(); 60 for(String type : highwayWeight.keySet()) { 61 graphCreator.setHighwayTypeWeight(type, highwayWeight.get(type)); 62 } 47 63 // graph = graphCreator.createGraph(); 48 64 graph = graphCreator.createSegmentGraph(); … … 80 96 edgePath.addAll(fullPath); 81 97 82 System.out.println("shortest path found: " + fullPath + " 98 System.out.println("shortest path found: " + fullPath + "\nweight: " + fullWeight); 83 99 System.out.println(getPathDescription()); 84 100 // double weight2 = 0; … … 121 137 Way oldWay = null; 122 138 Way way = null; 123 for(SegmentEdge edge : edgePath) { 139 140 SegmentEdge edge; 141 for(int segIndex = 0; segIndex < edgePath.size(); ++segIndex) { 142 edge = edgePath.get(segIndex); 124 143 way = edge.getWay(); 144 if(way == null) { 145 System.out.println("way is null!"); 146 } 125 147 length += edge.getLengthInM(); 126 if(oldWay != null && !oldWay.equals(way)) { 127 description = new PathDescription(oldWay, length); 148 // if way changes or it is the last way add the description: 149 if(oldWay != null && !way.equals(oldWay)) { 150 description = new PathDescription(oldWay, length); // add finished way 128 151 pathDescriptions.add(description); 129 length = 0; 152 length = 0; 153 } 154 if(segIndex == edgePath.size() - 1) { 155 description = new PathDescription(way, length); 156 pathDescriptions.add(description); 130 157 } 131 158 oldWay = way; 132 159 } 133 if(way != null) { 134 description = new PathDescription(way, length); 135 pathDescriptions.add(description); 136 } 160 161 162 // for(SegmentEdge edge : edgePath) { 163 // way = edge.getWay(); 164 // length += edge.getLengthInM(); 165 // if(oldWay != null && !oldWay.equals(way)) { 166 // description = new PathDescription(oldWay, length); 167 // pathDescriptions.add(description); 168 // length = 0; 169 // } 170 // oldWay = way; 171 // } 172 // if(way != null) { 173 // description = new PathDescription(way, length); 174 // pathDescriptions.add(description); 175 // } 137 176 return pathDescriptions; 138 177 } -
applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorPlugin.java
r3831 r3865 8 8 import java.awt.event.ActionEvent; 9 9 import java.awt.event.ActionListener; 10 import java.util.ArrayList; 11 import java.util.List; 10 import java.util.Map; 12 11 13 import javax.swing.AbstractButton;14 12 import javax.swing.JMenu; 15 13 import javax.swing.JMenuBar; 16 14 import javax.swing.JMenuItem; 17 15 18 import org.jgrapht.Graph;19 import org.jgrapht.alg.DijkstraShortestPath;20 16 import org.openstreetmap.josm.Main; 21 import org.openstreetmap.josm.data.osm.Node;22 import org.openstreetmap.josm.data.osm.Segment;23 17 import org.openstreetmap.josm.gui.IconToggleButton; 24 18 import org.openstreetmap.josm.gui.MapFrame; 25 import org.openstreetmap.josm.gui.dialogs.ToggleDialog;26 19 import org.openstreetmap.josm.plugins.Plugin; 27 20 … … 33 26 */ 34 27 public class NavigatorPlugin extends Plugin { 28 private static final String KEY_HIGHWAY_WEIGHT_PREFIX = "navigator.weight."; 35 29 private NavigatorLayer navigatorLayer; 36 30 private NavigatorModel navigatorModel; … … 41 35 public NavigatorPlugin() { 42 36 super(); 43 37 checkWeights(); 44 38 navigatorModel = new NavigatorModel(); 39 setHighwayTypeWeights(); 45 40 navigatorLayer = new NavigatorLayer(tr("Navigation")); 46 41 navigatorLayer.setNavigatorNodeModel(navigatorModel); … … 54 49 public void actionPerformed(ActionEvent e) { 55 50 navigatorModel.resetGraph(); 51 setHighwayTypeWeights(); 56 52 } 57 53 }); 58 54 navigatorMenu.add(resetMenuItem); 59 55 menu.add(navigatorMenu); 56 } 57 58 /** 59 * Reads the weight values for the different highway types from the preferences. 60 */ 61 private void setHighwayTypeWeights() { 62 Map<String, String> weightMap = Main.pref.getAllPrefix(KEY_HIGHWAY_WEIGHT_PREFIX); 63 String type; 64 double weight; 65 String value; 66 for(String typeKey : weightMap.keySet()) { 67 type = typeKey.substring(KEY_HIGHWAY_WEIGHT_PREFIX.length()); 68 weight = Double.parseDouble(weightMap.get(typeKey)); 69 navigatorModel.setHighwayTypeWeight(type, weight); 70 } 71 } 72 73 /** 74 * Checks if there are any highway weights set in the preferences. If not, default 75 * values are used. 76 */ 77 private void checkWeights() { 78 setDefaultWeight("motorway", 100.0); 79 setDefaultWeight("primary", 80.0); 80 setDefaultWeight("secondary", 70.0); 81 setDefaultWeight("tertiary", 60.0); 82 setDefaultWeight("unclassified", 60.0); 83 setDefaultWeight("residential", 40.0); 84 setDefaultWeight("pedestrian", 0.0); 85 setDefaultWeight("cycleway", 0.0); 86 setDefaultWeight("footway", 0.0); 87 } 88 89 private void setDefaultWeight(String type, double value) { 90 if(!Main.pref.hasKey(KEY_HIGHWAY_WEIGHT_PREFIX + type)) { 91 Main.pref.put(KEY_HIGHWAY_WEIGHT_PREFIX + type, String.valueOf(value)); 92 } 60 93 } 61 94 -
applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/OsmGraphCreator.java
r3832 r3865 33 33 34 34 private Map<String, Double> highwayWeight; 35 private static final double DEFAULT_WEIGHT = Double.MAX_VALUE;35 private static final double DEFAULT_WEIGHT = 0.0; 36 36 37 37 public OsmGraphCreator() { 38 38 highwayWeight = new HashMap<String, Double>(); 39 highwayWeight.put("motorway", 130.0); 40 highwayWeight.put("primary", 100.0); 41 highwayWeight.put("secondary", 70.0); 42 highwayWeight.put("unclassified", 50.0); 43 highwayWeight.put("residential", 40.0); 44 highwayWeight.put("footway", 1.0); 39 } 40 41 /** 42 * Set the weight for the given highway type. The higher the weight is, 43 * the more it is preferred in routing. 44 * @param type the type of the highway. 45 * @param weigth the weight. 46 */ 47 public void setHighwayTypeWeight(String type, double weigth) { 48 highwayWeight.put(type, weigth); 49 System.out.println("set " + type + " to " + weigth); 45 50 } 46 51 47 52 public Graph<Node, SegmentEdge> createSegmentGraph() { 48 SimpleDirectedWeightedGraph<Node, SegmentEdge> graph = new SimpleDirectedWeightedGraph<Node, SegmentEdge>(SegmentEdge.class); 53 DirectedWeightedMultigraph<Node, SegmentEdge> graph = new DirectedWeightedMultigraph<Node, SegmentEdge>(SegmentEdge.class); 54 // SimpleDirectedWeightedGraph<Node, SegmentEdge> graph = new SimpleDirectedWeightedGraph<Node, SegmentEdge>(SegmentEdge.class); 49 55 // SimpleGraph<Node, SegmentEdge> graph = new SimpleGraph<Node, SegmentEdge>(SegmentEdge.class); 50 56 SegmentEdge edge; … … 81 87 /** 82 88 * Returns the weight for the given segment depending on the highway type and the length of the 83 * segment. 84 * 89 * segment. The higher the value, the less it is used in routing. 85 90 * @param way 86 91 * @param segment … … 90 95 String type = way.get("highway"); 91 96 if (type == null) { 92 return 0.0d;97 return Double.MAX_VALUE; 93 98 } 94 99 Double weightValue = highwayWeight.get(type); … … 99 104 weight = weightValue.doubleValue(); 100 105 } 101 double distance = Math.sqrt(segment.from.coor.distance(segment.to.coor)) * 111000; // deg102 // to m103 // (at104 // equator105 // :-)106 return distance ; // weight;106 // deg to m (at equator :-): 107 double distance = Math.sqrt(segment.from.coor.distance(segment.to.coor)) * 111000; 108 if(weight == 0.0) { 109 weight = 1E-20; 110 } 111 return distance / weight; 107 112 } 108 113
Note:
See TracChangeset
for help on using the changeset viewer.