Changeset 3889 in josm for trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
- Timestamp:
- 2011-02-11T23:00:56+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r3888 r3889 44 44 import org.openstreetmap.josm.tools.ImageProvider; 45 45 import org.openstreetmap.josm.tools.LanguageInfo; 46 import org.openstreetmap.josm.tools.Pair; 46 47 47 48 public class MapPainter { … … 104 105 } 105 106 106 public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor, TextElement text, boolean showDirection, 107 boolean reversedDirection, boolean showHeadArrowOnly) { 107 /** 108 * draw way 109 * @param showOrientation show arrows that indicate the technical orientation of 110 * the way (defined by order of nodes) 111 * @param showOneway show symbols that indicate the direction of the feature, 112 * e.g. oneway street or waterway 113 * @param onewayReversed for oneway=-1 and similar 114 */ 115 public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor, 116 TextElement text, boolean showOrientation, boolean showHeadArrowOnly, 117 boolean showOneway, boolean onewayReversed) { 108 118 109 119 GeneralPath path = new GeneralPath(); 110 GeneralPath arrows = new GeneralPath(); 120 GeneralPath orientationArrows = showOrientation ? new GeneralPath() : null; 121 GeneralPath onewayArrows = showOneway ? new GeneralPath() : null; 122 GeneralPath onewayArrowsCasing = showOneway ? new GeneralPath() : null; 111 123 Rectangle bounds = g.getClipBounds(); 112 124 bounds.grow(100, 100); // avoid arrow heads at the border 113 125 126 double wayLength = 0; 114 127 Point lastPoint = null; 115 128 boolean initialMoveToNeeded = true; … … 140 153 141 154 /* draw arrow */ 142 if (showHeadArrowOnly ? !it.hasNext() : showDirection) { 143 if (reversedDirection) { 144 Point tmp = p1; 145 p1 = p2; 146 p2 = tmp; 147 } 148 final double l = 10. / p1.distance(p2); 155 if (showHeadArrowOnly ? !it.hasNext() : showOrientation) { 156 final double l = (10. + line.getLineWidth()) / p1.distance(p2); 149 157 150 158 final double sx = l * (p1.x - p2.x); 151 159 final double sy = l * (p1.y - p2.y); 152 160 153 arrows.moveTo(p2.x, p2.y); 154 arrows.lineTo (p2.x + (int) Math.round(cosPHI * sx - sinPHI * sy), p2.y + (int) Math.round(sinPHI * sx + cosPHI * sy)); 155 arrows.moveTo (p2.x + (int) Math.round(cosPHI * sx + sinPHI * sy), p2.y + (int) Math.round(- sinPHI * sx + cosPHI * sy)); 156 arrows.lineTo(p2.x, p2.y); 161 orientationArrows.moveTo(p2.x, p2.y); 162 orientationArrows.lineTo (p2.x + cosPHI * sx - sinPHI * sy, p2.y + sinPHI * sx + cosPHI * sy); 163 orientationArrows.moveTo (p2.x + cosPHI * sx + sinPHI * sy, p2.y - sinPHI * sx + cosPHI * sy); 164 orientationArrows.lineTo(p2.x, p2.y); 165 } 166 if (showOneway) { 167 final double segmentLength = p1.distance(p2); 168 final double nx = (p2.x - p1.x) / segmentLength; 169 final double ny = (p2.y - p1.y) / segmentLength; 170 171 final double interval = 60; 172 // distance from p1 173 double dist = interval - (wayLength % interval); 174 175 while (dist < segmentLength) { 176 for (Pair<Float, GeneralPath> sizeAndPath : Arrays.asList(new Pair[] { 177 new Pair<Float, GeneralPath>(3f, onewayArrowsCasing), 178 new Pair<Float, GeneralPath>(2f, onewayArrows)})) { 179 180 // scale such that border is 1 px 181 final double fac = - (onewayReversed ? -1 : 1) * sizeAndPath.a * (1 + sinPHI) / (sinPHI * cosPHI); 182 final double sx = nx * fac; 183 final double sy = ny * fac; 184 185 // Attach the triangle at the incenter and not at the tip. 186 // Makes the border even at all sides. 187 final double x = p1.x + nx * (dist + (onewayReversed ? -1 : 1) * (sizeAndPath.a / sinPHI)); 188 final double y = p1.y + ny * (dist + (onewayReversed ? -1 : 1) * (sizeAndPath.a / sinPHI)); 189 190 sizeAndPath.b.moveTo(x, y); 191 sizeAndPath.b.lineTo (x + cosPHI * sx - sinPHI * sy, y + sinPHI * sx + cosPHI * sy); 192 sizeAndPath.b.lineTo (x + cosPHI * sx + sinPHI * sy, y - sinPHI * sx + cosPHI * sy); 193 sizeAndPath.b.lineTo(x, y); 194 } 195 dist += interval; 196 } 197 wayLength += segmentLength; 157 198 } 158 199 } … … 160 201 lastPoint = p; 161 202 } 162 displaySegments(path, arrows, color, line, dashes, dashedColor);203 displaySegments(path, orientationArrows, onewayArrows, onewayArrowsCasing, color, line, dashes, dashedColor); 163 204 drawTextOnPath(way, text); 164 205 } 165 206 166 private void displaySegments(GeneralPath path, GeneralPath arrows, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor) { 207 private void displaySegments(GeneralPath path, GeneralPath orientationArrows, GeneralPath onewayArrows, GeneralPath onewayArrowsCasing, 208 Color color, BasicStroke line, BasicStroke dashes, Color dashedColor) { 167 209 g.setColor(inactive ? inactiveColor : color); 168 210 if (useStrokes) { … … 170 212 } 171 213 g.draw(path); 172 g.draw(arrows);173 214 174 215 if(!inactive && useStrokes && dashes != null) { … … 176 217 g.setStroke(dashes); 177 218 g.draw(path); 178 g.draw(arrows); 219 } 220 221 if (orientationArrows != null) { 222 g.setColor(inactive ? inactiveColor : color); 223 g.setStroke(new BasicStroke(line.getLineWidth(), line.getEndCap(), BasicStroke.JOIN_MITER, line.getMiterLimit())); 224 g.draw(orientationArrows); 225 } 226 227 if (onewayArrows != null) { 228 g.setStroke(new BasicStroke(1, line.getEndCap(), BasicStroke.JOIN_MITER, line.getMiterLimit())); 229 g.fill(onewayArrowsCasing); 230 g.setColor(inactive ? inactiveColor : backgroundColor); 231 g.fill(onewayArrows); 179 232 } 180 233
Note:
See TracChangeset
for help on using the changeset viewer.