Changeset 7340 in josm
- Timestamp:
- 2014-07-28T00:15:43+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
r7323 r7340 3 3 package org.openstreetmap.josm.gui.layer.gpx; 4 4 5 import static org.openstreetmap.josm.tools.I18n.marktr; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 6 import static org.openstreetmap.josm.tools.I18n.marktr;7 7 8 8 import java.awt.BasicStroke; … … 15 15 import java.util.Date; 16 16 import java.util.List; 17 17 18 import org.openstreetmap.josm.Main; 18 19 import org.openstreetmap.josm.data.coor.LatLon; … … 24 25 25 26 /** 26 * Class that helps to draw large set of GPS tracks with different colors and options 27 * Class that helps to draw large set of GPS tracks with different colors and options 27 28 * @since 7319 28 29 */ 29 30 public class GpxDrawHelper { 30 31 private GpxData data; 31 32 32 33 // draw lines between points belonging to different segments 33 34 private boolean forceLines; … … 51 52 52 53 private static final double PHI = Math.toRadians(15); 53 54 54 55 //// Variables used only to check cache validity 55 56 private boolean computeCacheInSync = false; … … 62 63 //// Color-related fields 63 64 /** Mode of the line coloring **/ 64 private ColorMode colored; 65 private ColorMode colored; 65 66 /** max speed for coloring - allows to tweak line coloring for different speed levels. **/ 66 67 private int colorTracksTune; … … 75 76 ColorScale dateScale; 76 77 ColorScale directionScale; 77 78 78 79 /** Opacity for hdop points **/ 79 80 private int hdopAlpha; 80 81 81 82 82 83 // lookup array to draw arrows without doing any math … … 88 89 { +ll0, -sl4, +sl4, -ll0 }, { +ll0, +sl9, +ll0, -sl9 }, { +sl4, +ll0, +ll0, +sl4 }, 89 90 { -sl9, +ll0, +sl9, +ll0 }, { -ll0, +sl4, -sl4, +ll0 }, { -ll0, -sl9, -ll0, +sl9 } }; 90 91 91 92 private void setupColors() { 92 93 hdopAlpha = Main.pref.getInteger("hdop.color.alpha", -1); … … 104 105 NONE, VELOCITY, HDOP, DIRECTION, TIME 105 106 } 106 107 107 108 public GpxDrawHelper(GpxData gpxData) { 108 109 data = gpxData; 109 110 setupColors(); 110 111 } 111 112 112 113 /** 113 * Get the default color for gps tracks for specified layer 114 * Get the default color for gps tracks for specified layer 114 115 * @param layerName name of the GpxLayer 115 116 * @param ignoreCustom do not use preferences 116 * @return the color or null if the color is not constant 117 * @return the color or null if the color is not constant 117 118 */ 118 119 public Color getColor(String layerName, boolean ignoreCustom) { … … 142 143 return Main.pref.getColor(marktr("gps point"), Color.gray); 143 144 } 144 145 145 146 /** 146 147 * Read all drawing-related settings from preferences … … 177 178 hdopScale.setNoDataColor(neutralColor); 178 179 directionScale.setNoDataColor(neutralColor); 179 180 180 181 largesize += lineWidth; 181 182 } 182 183 183 184 184 185 public void drawAll(Graphics2D g, MapView mv, List<WayPoint> visibleSegments) { 185 186 186 187 checkCache(); 187 188 188 189 // STEP 2b - RE-COMPUTE CACHE DATA ********************* 189 190 if (!computeCacheInSync) { // don't compute if the cache is good … … 192 193 193 194 Stroke storedStroke = g.getStroke(); 194 195 195 196 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 196 197 Main.pref.getBoolean("mappaint.gpx.use-antialiasing", false) ? 197 198 RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); 198 199 199 200 if(lineWidth != 0) { 200 201 g.setStroke(new BasicStroke(lineWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); … … 207 208 } 208 209 } 209 210 210 211 public void calculateColors() { 211 212 double minval = +1e10; 212 213 double maxval = -1e10; 213 214 WayPoint oldWp = null; 214 215 215 216 if (colorModeDynamic) { 216 217 if (colored == ColorMode.VELOCITY) { … … 280 281 } 281 282 282 283 283 284 // Now the colors for all the points will be assigned 284 285 for (Collection<WayPoint> segment : data.getLinesIterable(null)) { … … 293 294 } 294 295 // now we are sure some color will be assigned 295 Color color = null; 296 296 Color color = null; 297 297 298 if (colored == ColorMode.HDOP) { 298 299 Float hdop = ((Float) trkPnt.attr.get("hdop")); … … 329 330 } else { 330 331 trkPnt.drawLine = false; 331 } 332 } 332 333 } else { // make sure we reset outdated data 333 334 trkPnt.drawLine = false; … … 340 341 } 341 342 } 342 343 343 344 computeCacheInSync = true; 344 345 } 345 346 346 347 347 348 348 349 private void drawLines(Graphics2D g, MapView mv, List<WayPoint> visibleSegments) { 349 350 if (lines) { … … 396 397 } 397 398 } // end for trkpnt 398 } 399 399 } 400 400 401 /**************************************************************** 401 402 ********** STEP 3c - DRAW FAST ARROWS ************************** … … 425 426 } 426 427 } // end for trkpnt 427 } 428 } 428 429 } 429 430 … … 440 441 } 441 442 Point screen = mv.getPoint(trkPnt.getEastNorth()); 442 443 443 444 444 445 if (hdopCircle && trkPnt.attr.get("hdop") != null) { 445 446 // hdop value … … 457 458 if (large) { 458 459 // color the large GPS points like the gps lines 459 Color customColoringTransparent = largePointAlpha<0 ? trkPnt.customColoring: 460 new Color(trkPnt.customColoring.getRGB() & 0x00ffffff | largePointAlpha<<24, true); 461 462 g.setColor(customColoringTransparent); 460 if (trkPnt.customColoring != null) { 461 Color customColoringTransparent = largePointAlpha<0 ? trkPnt.customColoring: 462 new Color(trkPnt.customColoring.getRGB() & 0x00ffffff | largePointAlpha<<24, true); 463 464 g.setColor(customColoringTransparent); 465 } 463 466 g.fillRect(screen.x-halfSize, screen.y-halfSize, largesize, largesize); 464 467 } … … 519 522 computeCacheInSync = false; 520 523 } 521 524 522 525 public void drawColorBar(Graphics2D g, MapView mv) { 523 526 int w = mv.getWidth(); … … 531 534 } 532 535 } 533 536 534 537 }
Note:
See TracChangeset
for help on using the changeset viewer.