- Timestamp:
- 2011-02-11T23:00:56+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 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 -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r3888 r3889 193 193 the way is tagged with a direction key 194 194 (even if the tag is negated as in oneway=false) or the way is selected */ 195 boolean showDirection = !isModifier && (selected || ((!paintSettings.isUseRealWidth()) && (paintSettings.isShowDirectionArrow() 196 && (!paintSettings.isShowRelevantDirectionsOnly() || w.hasDirectionKeys())))); 197 boolean reversedDirection = w.reversedDirection(); 195 boolean showOrientation = !isModifier && selected && !paintSettings.isUseRealWidth(); 196 boolean showOneway = !isModifier && !selected && 197 !paintSettings.isUseRealWidth() && 198 paintSettings.isShowDirectionArrow() && w.hasDirectionKeys(); 199 boolean onewayReversed = w.reversedDirection(); 198 200 /* head only takes over control if the option is true, 199 201 the direction should be shown at all and not only because it's selected */ 200 boolean showOnlyHeadArrowOnly = show Direction && !selected && paintSettings.isShowHeadArrowOnly();202 boolean showOnlyHeadArrowOnly = showOrientation && !selected && paintSettings.isShowHeadArrowOnly(); 201 203 Node lastN; 202 204 203 205 Color myDashedColor = dashesBackground; 204 206 BasicStroke myLine = line, myDashLine = dashesLine; 205 if (realWidth > 0 && paintSettings.isUseRealWidth() && !show Direction) {207 if (realWidth > 0 && paintSettings.isUseRealWidth() && !showOrientation) { 206 208 float myWidth = (int) (100 / (float) (painter.getCircum() / realWidth)); 207 209 if (myWidth < line.getLineWidth()) { … … 216 218 } 217 219 218 Color m arkColor = null;220 Color myColor = color; 219 221 if(w.isHighlighted()) { 220 m arkColor = paintSettings.getHighlightColor();222 myColor = paintSettings.getHighlightColor(); 221 223 } else if (selected) { 222 m arkColor = paintSettings.getSelectedColor(color.getAlpha());224 myColor = paintSettings.getSelectedColor(color.getAlpha()); 223 225 } else if (member) { 224 m arkColor = paintSettings.getRelationSelectedColor(color.getAlpha());226 myColor = paintSettings.getRelationSelectedColor(color.getAlpha()); 225 227 } else if(w.isDisabled()) { 226 m arkColor = paintSettings.getInactiveColor();228 myColor = paintSettings.getInactiveColor(); 227 229 myDashedColor = paintSettings.getInactiveColor(); 228 230 } 229 231 230 painter.drawWay(w, m arkColor != null ? markColor : color, myLine, myDashLine, myDashedColor, text, showDirection,231 s elected ? false : reversedDirection, showOnlyHeadArrowOnly);232 painter.drawWay(w, myColor, myLine, myDashLine, myDashedColor, text, showOrientation, 233 showOnlyHeadArrowOnly, showOneway, onewayReversed); 232 234 233 235 if(paintSettings.isShowOrderNumber()) {
Note:
See TracChangeset
for help on using the changeset viewer.