Changeset 4250 in josm
- Timestamp:
- 2011-07-15T21:52:06+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r4230 r4250 92 92 private int computeCacheMaxLineLengthUsed; 93 93 private Color computeCacheColorUsed; 94 private boolean computeCacheColorDynamic; 94 95 private colorModes computeCacheColored; 95 96 private int computeCacheColorTracksTune; … … 421 422 // allows to tweak line coloring for different speed levels. 422 423 int colorTracksTune = Main.pref.getInteger("draw.rawgps.colorTracksTune", "layer "+getName(), 45); 424 boolean colorModeDynamic = Main.pref.getBoolean("draw.rawgps.colors.dynamic", "layer "+getName(), false); 425 int hdopfactor = Main.pref.getInteger("hdop.factor", 25); 423 426 424 427 if(lineWidth != 0) … … 431 434 ****************************************************************/ 432 435 if ((computeCacheMaxLineLengthUsed != maxLineLength) || (!neutralColor.equals(computeCacheColorUsed)) 433 || (computeCacheColored != colored) || (computeCacheColorTracksTune != colorTracksTune)) { 434 // System.out.println("(re-)computing gpx line styles, reason: CCIS=" + 435 // computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + 436 // " CCCU=" + (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + 437 // (computeCacheColored != colored)); 436 || (computeCacheColored != colored) || (computeCacheColorTracksTune != colorTracksTune) 437 || (computeCacheColorDynamic != colorModeDynamic)) { 438 438 computeCacheMaxLineLengthUsed = maxLineLength; 439 439 computeCacheInSync = false; … … 441 441 computeCacheColored = colored; 442 442 computeCacheColorTracksTune = colorTracksTune; 443 computeCacheColorDynamic = colorModeDynamic; 443 444 } 444 445 … … 447 448 ****************************************************************/ 448 449 if (!computeCacheInSync) { // don't compute if the cache is good 450 Float minval = null; 451 Float maxval = null; 449 452 WayPoint oldWp = null; 453 if (colorModeDynamic) { 454 if (colored == colorModes.velocity) { 455 for (GpxTrack trk : data.tracks) { 456 for (GpxTrackSegment segment : trk.getSegments()) { 457 if(!forceLines) oldWp = null; 458 for (WayPoint trkPnt : segment.getWayPoints()) { 459 LatLon c = trkPnt.getCoor(); 460 if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) { 461 continue; 462 } 463 if (oldWp != null && trkPnt.time > oldWp.time) { 464 Float vel = new Float(c.greatCircleDistance(oldWp.getCoor()) / (trkPnt.time - oldWp.time)); 465 if(maxval == null || vel > maxval) maxval = vel; 466 if(minval == null || vel < minval) minval = vel; 467 } 468 oldWp = trkPnt; 469 } 470 } 471 } 472 } else if (colored == colorModes.dilution) { 473 for (GpxTrack trk : data.tracks) { 474 for (GpxTrackSegment segment : trk.getSegments()) { 475 for (WayPoint trkPnt : segment.getWayPoints()) { 476 Object val = trkPnt.attr.get("hdop"); 477 if (val != null) { 478 Float hdop = (Float) val; 479 if(maxval == null || hdop > maxval) maxval = hdop; 480 if(minval == null || hdop < minval) minval = hdop; 481 } 482 } 483 } 484 } 485 } 486 oldWp = null; 487 } 450 488 for (GpxTrack trk : data.tracks) { 451 489 for (GpxTrackSegment segment : trk.getSegments()) { … … 459 497 } 460 498 trkPnt.customColoring = neutralColor; 499 if(colored == colorModes.dilution && trkPnt.attr.get("hdop") != null) { 500 float hdop = ((Float) trkPnt.attr.get("hdop")).floatValue(); 501 int hdoplvl = Math.round(colorModeDynamic ? ((hdop-minval)*255/(maxval-minval)) 502 : (hdop <= 0 ? 0 : hdop * hdopfactor)); 503 // High hdop is bad, but high values in colors are green. 504 // Therefore inverse the logic 505 int hdopcolor = 255 - (hdoplvl > 255 ? 255 : hdoplvl); 506 trkPnt.customColoring = colors[hdopcolor]; 507 } 461 508 if (oldWp != null) { 462 509 double dist = c.greatCircleDistance(oldWp.getCoor()); … … 465 512 case velocity: 466 513 double dtime = trkPnt.time - oldWp.time; 467 double vel = dist / dtime; 468 double velColor = vel / colorTracksTune * 255; 469 // Bad case first 470 if (dtime <= 0 || vel < 0 || velColor > 255) { 514 if(dtime > 0) { 515 float vel = (float) (dist / dtime); 516 int velColor = Math.round(colorModeDynamic ? ((vel-minval)*255/(maxval-minval)) 517 : (vel <= 0 ? 0 : vel / colorTracksTune * 255)); 518 trkPnt.customColoring = colors[velColor > 255 ? 255 : velColor]; 519 } else { 471 520 trkPnt.customColoring = colors[255]; 472 } else {473 trkPnt.customColoring = colors[(int) (velColor)];474 521 } 475 522 break; 476 477 523 case direction: 478 524 double dirColor = oldWp.getCoor().heading(trkPnt.getCoor()) / (2.0 * Math.PI) * 256; … … 482 528 } else { 483 529 trkPnt.customColoring = colors_cyclic[(int) (dirColor)]; 484 }485 break;486 case dilution:487 if (trkPnt.attr.get("hdop") != null) {488 float hdop = ((Float) trkPnt.attr.get("hdop")).floatValue();489 if (hdop < 0) {490 hdop = 0;491 }492 int hdoplvl = Math.round(hdop * Main.pref.getInteger("hdop.factor", 25));493 // High hdop is bad, but high values in colors are green.494 // Therefore inverse the logic495 int hdopcolor = 255 - (hdoplvl > 255 ? 255 : hdoplvl);496 trkPnt.customColoring = colors[hdopcolor];497 530 } 498 531 break; -
trunk/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java
r4235 r4250 62 62 private JCheckBox makeAutoMarkers = new JCheckBox(tr("Create markers when reading GPX.")); 63 63 private JCheckBox outlineOnly = new JCheckBox(tr("Draw only outlines of areas")); 64 private JCheckBox colorDynamic = new JCheckBox(tr("Dynamic color range based on data limits")); 64 65 private JComboBox waypointLabel = new JComboBox(new String[] {tr("Auto"), /* gpx data field name */ trc("gpx_field", "Name"), 65 66 /* gpx data field name */ trc("gpx_field", "Desc(ription)"), tr("Both"), tr("None")}); … … 177 178 public void stateChanged(ChangeEvent e) { 178 179 colorTypeVelocityTune.setEnabled(colorTypeVelocity.isSelected()); 180 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected()); 181 } 182 }); 183 colorTypeDilution.addChangeListener(new ChangeListener(){ 184 public void stateChanged(ChangeEvent e) { 185 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected()); 179 186 } 180 187 }); … … 214 221 panel.add(colorTypeDirection, GBC.eol().insets(40,0,0,0)); 215 222 panel.add(colorTypeDilution, GBC.eol().insets(40,0,0,0)); 223 colorDynamic.setToolTipText(tr("Draw direction arrows for lines, connecting GPS points.")); 224 colorDynamic.setSelected(Main.pref.getBoolean("draw.rawgps.colors.dynamic", false)); 225 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected()); 226 panel.add(colorDynamic, GBC.eop().insets(40,0,0,0)); 216 227 217 228 // waypointLabel … … 302 313 Main.pref.put("draw.rawgps.alternatedirection", drawGpsArrowsFast.isSelected()); 303 314 Main.pref.put("draw.rawgps.min-arrow-distance", drawGpsArrowsMinDist.getText()); 315 Main.pref.put("draw.rawgps.colors.dynamic", colorDynamic.isSelected()); 304 316 if(colorTypeVelocity.isSelected()) { 305 317 Main.pref.putInteger("draw.rawgps.colors", 1);
Note:
See TracChangeset
for help on using the changeset viewer.