Changeset 32457 in osm for applications/editors/josm/plugins/pt_assistant
- Timestamp:
- 2016-06-30T00:22:24+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java
r32438 r32457 5 5 import java.awt.Graphics; 6 6 import java.awt.Point; 7 import java.util.HashMap; 7 8 import java.util.List; 8 9 … … 11 12 import org.openstreetmap.josm.data.osm.Relation; 12 13 import org.openstreetmap.josm.data.osm.RelationMember; 14 import org.openstreetmap.josm.data.osm.Way; 13 15 import org.openstreetmap.josm.data.validation.PaintVisitor; 14 16 import org.openstreetmap.josm.gui.MapView; … … 31 33 public void visit(Relation r) { 32 34 35 HashMap<Long, String> stopOrderMap = new HashMap<>(); 36 33 37 int stopCount = 1; 38 34 39 for (RelationMember rm : r.getMembers()) { 40 35 41 if (RouteUtils.isPTStop(rm)) { 42 36 43 String label = ""; 37 if (r.hasKey("ref")) { 38 label = label + r.get("ref"); 39 } else if (r.hasKey("name")) { 40 label = label + r.get("name"); 41 } 42 label = label + "." + stopCount; 44 45 if (stopOrderMap.containsKey(rm.getMember().getId())) { 46 label = stopOrderMap.get(rm.getMember().getId()); 47 label = label + ";" + stopCount; 48 } else { 49 if (r.hasKey("ref")) { 50 label = label + r.get("ref"); 51 } else if (r.hasKey("name")) { 52 label = label + r.get("name"); 53 } 54 label = label + ":" + stopCount; 55 } 56 57 stopOrderMap.put(rm.getMember().getId(), label); 43 58 drawStop(rm.getMember(), label); 44 59 stopCount++; 60 45 61 } else if (RouteUtils.isPTWay(rm)) { 46 62 if (rm.isWay()) { … … 61 77 62 78 @Override 63 public void visit(List<Node> nodes) { 79 public void visit(Way w) { 80 81 if (w == null) { 82 return; 83 } 84 85 /*- 86 * oneway values: 87 * 0 two-way street 88 * 1 oneway street in the way's direction 89 * 2 oneway street in ways's direction but public transport allowed 90 * -1 oneway street in reverse direction 91 * -2 oneway street in reverse direction but public transport allowed 92 */ 93 int oneway = 0; 94 95 if (w.hasTag("junction", "roundabout") || w.hasTag("highway", "motorway")) { 96 oneway = 1; 97 } else if (w.hasTag("oneway", "1") || w.hasTag("oneway", "yes") || w.hasTag("oneway", "true")) { 98 if (w.hasTag("busway", "lane") || w.hasTag("busway:left", "lane") || w.hasTag("busway:right", "lane") 99 || w.hasTag("oneway:bus", "no") || w.hasTag("busway", "opposite_lane") 100 || w.hasTag("oneway:psv", "no") || w.hasTag("trolley_wire", "backward")) { 101 oneway = 2; 102 } else { 103 oneway = 1; 104 } 105 } else if (w.hasTag("oneway", "-1") || w.hasTag("oneway", "reverse")) { 106 if (w.hasTag("busway", "lane") || w.hasTag("busway:left", "lane") || w.hasTag("busway:right", "lane") 107 || w.hasTag("oneway:bus", "no") || w.hasTag("busway", "opposite_lane") 108 || w.hasTag("oneway:psv", "no") || w.hasTag("trolley_wire", "backward")) { 109 oneway = -2; 110 } else { 111 oneway = -1; 112 } 113 } 114 115 visit(w.getNodes(), oneway); 116 117 } 118 119 public void visit(List<Node> nodes, int oneway) { 64 120 Node lastN = null; 65 121 for (Node n : nodes) { … … 68 124 continue; 69 125 } 70 drawSegment(lastN, n, new Color(208, 80, 208, 179)); 126 this.drawSegment(lastN, n, new Color(208, 80, 208, 179), oneway); 71 127 lastN = n; 72 128 } … … 83 139 if (n.isDrawable() && isNodeVisible(n)) { 84 140 drawNode(n, Color.BLUE); 141 } 142 } 143 144 /** 145 * Draws a line around the segment 146 * 147 * @param n1 148 * The first node of segment 149 * @param n2 150 * The second node of segment 151 * @param color 152 * The color 153 */ 154 protected void drawSegment(Node n1, Node n2, Color color, int oneway) { 155 if (n1.isDrawable() && n2.isDrawable() && isSegmentVisible(n1, n2)) { 156 drawSegment(mv.getPoint(n1), mv.getPoint(n2), color, oneway); 85 157 } 86 158 } … … 96 168 * The color 97 169 */ 98 protected void drawSegment(Point p1, Point p2, Color color) { 170 protected void drawSegment(Point p1, Point p2, Color color, int oneway) { 99 171 100 172 double t = Math.atan2((double) p2.x - p1.x, (double) p2.y - p1.y); … … 109 181 g.fillOval((int) (p2.x - 8), (int) (p2.y - 8), 16, 16); 110 182 183 if (oneway != 0) { 184 double middleX = (double) (p1.x + p2.x) / 2.0; 185 double middleY = (double) (p1.y + p2.y) / 2.0; 186 double cosTriangle = 6 * Math.cos(t); 187 double sinTriangle = 6 * Math.sin(t); 188 g.setColor(new Color(50, 50, 50)); 189 190 if (oneway > 0) { 191 int[] xFillTriangle = { (int) (middleX + cosTriangle), (int) (middleX - cosTriangle), 192 (int) (middleX + 2 * sinTriangle) }; 193 int[] yFillTriangle = { (int) (middleY - sinTriangle), (int) (middleY + sinTriangle), 194 (int) (middleY + 2 * cosTriangle) }; 195 g.fillPolygon(xFillTriangle, yFillTriangle, 3); 196 197 if (oneway == 2) { 198 int[] xDrawTriangle = { (int) (middleX + cosTriangle), (int) (middleX - cosTriangle), 199 (int) (middleX - 2 * sinTriangle) }; 200 int[] yDrawTriangle = { (int) (middleY - sinTriangle), (int) (middleY + sinTriangle), 201 (int) (middleY - 2 * cosTriangle) }; 202 g.fillPolygon(xDrawTriangle, yDrawTriangle, 3); 203 } 204 } 205 206 if (oneway < 0) { 207 int[] xFillTriangle = { (int) (middleX + cosTriangle), (int) (middleX - cosTriangle), 208 (int) (middleX - 2 * sinTriangle) }; 209 int[] yFillTriangle = { (int) (middleY - sinTriangle), (int) (middleY + sinTriangle), 210 (int) (middleY - 2 * cosTriangle) }; 211 g.fillPolygon(xFillTriangle, yFillTriangle, 3); 212 213 if (oneway == -2) { 214 int[] xDrawTriangle = { (int) (middleX + cosTriangle), (int) (middleX - cosTriangle), 215 (int) (middleX + 2 * sinTriangle) }; 216 int[] yDrawTriangle = { (int) (middleY - sinTriangle), (int) (middleY + sinTriangle), 217 (int) (middleY + 2 * cosTriangle) }; 218 g.fillPolygon(xDrawTriangle, yDrawTriangle, 3); 219 } 220 } 221 222 } 223 111 224 // g.drawLine((int) (p1.x - cosT), (int) (p1.y - sinT), (int) (p2.x + 112 225 // cosT), (int) (p2.y - sinT)); … … 139 252 140 253 Point p = mv.getPoint(n); 141 254 142 255 g.setColor(Color.WHITE); 143 256 Font stringFont = new Font("SansSerif", Font.PLAIN, 24); … … 160 273 } 161 274 162 163 275 } 164 276
Note:
See TracChangeset
for help on using the changeset viewer.