Changeset 813 in josm
- Timestamp:
- 2008-08-21T00:34:53+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r805 r813 206 206 private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p) { 207 207 MapView c = Main.map.mapView; 208 int snapDistance = Main.pref.getInteger("mappaint.node.virtual-snap-distance", 8); 209 snapDistance *= snapDistance; 208 210 OsmPrimitive osm = c.getNearestNode(p); 209 211 if (osm == null) … … 220 222 int xd = p2.x-p1.x; if(xd < 0) xd = -xd; 221 223 int yd = p2.y-p1.y; if(yd < 0) yd = -yd; 222 if(xd+yd > Main.pref.getInteger("mappaint.node.virtual-space", 50))224 if(xd+yd > Main.pref.getInteger("mappaint.node.virtual-space", 70)) 223 225 { 224 226 Point pc = new Point((p1.x+p2.x)/2, (p1.y+p2.y)/2); 225 if(p.distanceSq(pc) < Main.map.mapView.snapDistance)227 if(p.distanceSq(pc) < snapDistance) 226 228 { 227 229 Collection<Command> cmds = new LinkedList<Command>(); -
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r748 r813 35 35 * Convert the time stamp of the waypoint into seconds from the epoch 36 36 */ 37 public void setTime 37 public void setTime() { 38 38 if (! attr.containsKey("time")) { 39 time = 0.0;40 39 return; 41 40 } 42 41 SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); // ignore timezone 43 42 Date d = f.parse(attr.get("time").toString(), new ParsePosition(0)); 44 if (d == null /* failed to parse */) { 45 time = 0.0; 46 } else { 43 if (d != null /* parsing ok */) { 44 time = d.getTime() / 1000.0; /* ms => seconds */ 45 } 46 } 47 48 /** 49 * Convert a time stamp of the waypoint from the <cmt> or <desc> field 50 * into seconds from the epoch. Handles the date format as it is used by 51 * Garmin handhelds. Does not overwrite an existing timestamp (!= 0.0). 52 * A value of <time> fields overwrites values set with by method. 53 * Does nothing if specified key does not exist or text cannot be parsed. 54 * 55 * @param key The key that contains the text to convert. 56 */ 57 public void setGarminCommentTime(String key) { 58 // do not overwrite time if already set 59 if (time != 0.0) { 60 return; 61 } 62 if (! attr.containsKey(key)) { 63 return; 64 } 65 // example date format "18-AUG-08 13:33:03" 66 SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); // Garmin wpts have no timezone 67 Date d = f.parse(attr.get(key).toString(), new ParsePosition(0)); 68 if (d != null /* parsing OK */) { 47 69 time = d.getTime() / 1000.0; /* ms => seconds */ 48 70 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r805 r813 108 108 fillUnselectedNode = Main.pref.getBoolean("mappaint.node.fill-unselected", false); 109 109 virtualNodeSize = virtual ? Main.pref.getInteger("mappaint.node.virtual-size", 4) / 2 : 0; 110 virtualNodeSpace = Main.pref.getInteger("mappaint.node.virtual-space", 50);110 virtualNodeSpace = Main.pref.getInteger("mappaint.node.virtual-space", 70); 111 111 112 112 ((Graphics2D)g) -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r804 r813 81 81 private Color computeCacheColorUsed; 82 82 private boolean computeCacheColored; 83 83 84 84 public GpxLayer(GpxData d) { 85 85 super((String) d.attr.get("name")); … … 162 162 for (Collection<WayPoint> seg : track.trackSegs) 163 163 for (WayPoint point : seg) 164 if (point.attr.containsKey("name") || point.attr.containsKey("desc")) 164 if (point.attr.containsKey("name") || point.attr.containsKey("desc")) 165 165 namedTrackPoints.waypoints.add(point); 166 166 167 168 169 170 167 MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), associatedFile, me); 168 if (ml.data.size() > 0) { 169 Main.main.addLayer(ml); 170 } 171 171 } 172 172 }); … … 191 191 if(fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) { 192 192 if (!fc.getCurrentDirectory().getAbsolutePath().equals(dir)) 193 Main.pref.put("markers.lastaudiodirectory", fc 194 .getCurrentDirectory().getAbsolutePath()); 195 196 // FIXME: properly support multi-selection here. 193 Main.pref.put("markers.lastaudiodirectory", fc.getCurrentDirectory().getAbsolutePath()); 194 195 // FIXME: properly support multi-selection here. 197 196 // Calling importAudio several times just creates N maker layers, which 198 197 // is sub-optimal. 199 198 File sel[] = fc.getSelectedFiles(); 200 199 if(sel != null) 201 for (int i = 0; i < sel.length; i++) 200 for (int i = 0; i < sel.length; i++) 202 201 importAudio(sel[i]); 203 202 204 203 Main.map.repaint(); 205 204 } … … 256 255 new JMenuItem(new LayerListPopup.InfoAction(this))}; 257 256 return new Component[] { 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 257 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 258 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 259 new JSeparator(), 260 new JMenuItem(new SaveAction(this)), 261 new JMenuItem(new SaveAsAction(this)), 262 // new JMenuItem(new UploadTraceAction()), 263 color, 264 line, 265 tagimage, 266 importAudio, 267 markersFromNamedTrackpoints, 268 new JMenuItem(new ConvertToDataLayerAction()), 269 new JSeparator(), 270 new JMenuItem(new RenameLayerAction(associatedFile, this)), 271 new JSeparator(), 272 new JMenuItem(new LayerListPopup.InfoAction(this))}; 274 273 } 275 274 … … 278 277 279 278 info.append(trn("{0} track, ", "{0} tracks, ", 280 data.tracks.size(), data.tracks.size())) 281 .append(trn("{0} route, ", "{0} routes, ", 282 data.routes.size(), data.routes.size())) 283 .append(trn("{0} waypoint", "{0} waypoints", 284 data.waypoints.size(), data.waypoints.size())) 285 .append("<br>"); 279 data.tracks.size(), data.tracks.size())).append(trn("{0} route, ", "{0} routes, ", 280 data.routes.size(), data.routes.size())).append(trn("{0} waypoint", "{0} waypoints", 281 data.waypoints.size(), data.waypoints.size())).append("<br>"); 286 282 287 283 if (data.attr.containsKey("name")) 288 info.append(tr("Name: {0}", data.attr.get("name"))) 289 .append("<br>"); 284 info.append(tr("Name: {0}", data.attr.get("name"))).append("<br>"); 290 285 291 286 if (data.attr.containsKey("desc")) 292 info.append(tr("Description: {0}", data.attr.get("desc"))) 293 .append("<br>"); 294 295 if(data.tracks.size() > 0){ 296 boolean first = true;297 WayPoint earliest = null, latest = null; 298 299 for(GpxTrack trk: data.tracks){300 for(Collection<WayPoint> seg:trk.trackSegs){301 for(WayPoint pnt:seg){302 if(first){ 303 latest = earliest = pnt;304 first = false; 305 }else{306 if(pnt.compareTo(earliest) < 0){ 307 earliest = pnt; 308 }else{ 309 latest = pnt; 310 311 312 313 314 } 315 if(earliest != null && latest != null){ 316 DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); 317 info.append(tr("Timespan: ") + df.format(new Date((long)(earliest.time * 1000))) + " - "+ df.format(new Date((long)(latest.time * 1000))));318 319 320 321 322 323 324 325 287 info.append(tr("Description: {0}", data.attr.get("desc"))).append("<br>"); 288 289 if(data.tracks.size() > 0){ 290 boolean first = true; 291 WayPoint earliest = null, latest = null; 292 293 for(GpxTrack trk: data.tracks){ 294 for(Collection<WayPoint> seg:trk.trackSegs){ 295 for(WayPoint pnt:seg){ 296 if(first){ 297 latest = earliest = pnt; 298 first = false; 299 }else{ 300 if(pnt.compareTo(earliest) < 0){ 301 earliest = pnt; 302 }else{ 303 latest = pnt; 304 } 305 } 306 } 307 } 308 } 309 if(earliest != null && latest != null){ 310 DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); 311 info.append(tr("Timespan: ") + df.format(new Date((long)(earliest.time * 1000))) + " - " 312 + df.format(new Date((long)(latest.time * 1000)))); 313 int diff = (int)(latest.time - earliest.time); 314 info.append(" (" + (diff / 3600) + ":" + ((diff % 3600)/60) + ")"); 315 info.append("<br>"); 316 } 317 } 318 info.append(tr("Length: ") + new DecimalFormat("#0.00").format(data.length() / 1000) + "km"); 319 info.append("<br>"); 320 326 321 return info.append("</html>").toString(); 327 322 } … … 389 384 ****************************************************************/ 390 385 if (computeCacheInSync && ((computeCacheMaxLineLengthUsed != maxLineLength) || 391 392 393 // 386 (!neutralColor.equals(computeCacheColorUsed)) || 387 (computeCacheColored != colored))) { 388 // System.out.println("(re-)computing gpx line styles, reason: CCIS=" + computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + " CCCU=" + (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + (computeCacheColored != colored)); 394 389 computeCacheMaxLineLengthUsed = maxLineLength; 395 390 computeCacheInSync = false; … … 440 435 computeCacheInSync = true; 441 436 } 442 437 443 438 /**************************************************************** 444 439 ********** STEP 3a - DRAW LINES ******************************** … … 453 448 Point screen = mv.getPoint(trkPnt.eastNorth); 454 449 if (trkPnt.drawLine) { 455 if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { // skip points that are on the same screenposition 450 // skip points that are on the same screenposition 451 if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { 456 452 g.setColor(trkPnt.speedLineColor); 457 453 g.drawLine(old.x, old.y, screen.x, screen.y); 458 454 } 459 455 } … … 476 472 if (trkPnt.drawLine) { 477 473 Point screen = mv.getPoint(trkPnt.eastNorth); 478 if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { // skip points that are on the same screenposition 474 // skip points that are on the same screenposition 475 if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { 479 476 g.setColor(trkPnt.speedLineColor); 480 double t = Math.atan2(screen.y-old.y, screen.x-old.x) + Math.PI; 481 g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t-PHI)), (int)(screen.y + 10*Math.sin(t-PHI))); 482 g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t+PHI)), (int)(screen.y + 10*Math.sin(t+PHI))); 483 } 477 double t = Math.atan2(screen.y-old.y, screen.x-old.x) + Math.PI; 478 g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t-PHI)), (int)(screen.y 479 + 10*Math.sin(t-PHI))); 480 g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t+PHI)), (int)(screen.y 481 + 10*Math.sin(t+PHI))); 482 } 484 483 old = screen; 485 484 } 486 485 } // end for trkpnt 487 486 } // end for segment … … 501 500 if (trkPnt.drawLine) { 502 501 Point screen = mv.getPoint(trkPnt.eastNorth); 503 if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { // skip points that are on the same screenposition 502 // skip points that are on the same screenposition 503 if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { 504 504 g.setColor(trkPnt.speedLineColor); 505 505 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y + dir[trkPnt.dir][1]); 506 506 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][2], screen.y + dir[trkPnt.dir][3]); 507 }507 } 508 508 old = screen; 509 509 } 510 510 } // end for trkpnt 511 511 } // end for segment … … 566 566 } // end if large 567 567 568 Long duration = System.currentTimeMillis() - startTime; 569 //System.out.println(duration); 570 568 //Long duration = System.currentTimeMillis() - startTime; 569 //System.out.println(duration); 571 570 } // end paint 572 571 … … 634 633 try { 635 634 String version = Main.pref.get("osm-server.version", "0.5"); 636 URL url = new URL(Main.pref.get("osm-server.url") + 637 "/" + version + "/gpx/create"); 635 URL url = new URL(Main.pref.get("osm-server.url") + "/" + version + "/gpx/create"); 638 636 639 637 // create a boundary string … … 641 639 URLConnection urlConn = MultiPartFormOutputStream.createConnection(url); 642 640 urlConn.setRequestProperty("Accept", "*/*"); 643 urlConn.setRequestProperty("Content-Type", 644 MultiPartFormOutputStream.getContentType(boundary)); 641 urlConn.setRequestProperty("Content-Type", MultiPartFormOutputStream.getContentType(boundary)); 645 642 // set some other request headers... 646 643 urlConn.setRequestProperty("Connection", "Keep-Alive"); 647 644 urlConn.setRequestProperty("Cache-Control", "no-cache"); 648 645 // no need to connect cuz getOutputStream() does it 649 MultiPartFormOutputStream out = 650 new MultiPartFormOutputStream(urlConn.getOutputStream(), boundary); 646 MultiPartFormOutputStream out = new MultiPartFormOutputStream(urlConn.getOutputStream(), boundary); 651 647 out.writeField("description", description.getText()); 652 648 out.writeField("tags", tags.getText()); … … 655 651 // out.writeFile("gpx_file", "text/xml", associatedFile); 656 652 // can also write bytes directly 657 // out.writeFile("myFile", "text/plain", "C:\\test.txt", 653 // out.writeFile("myFile", "text/plain", "C:\\test.txt", 658 654 // "This is some file text.".getBytes("ASCII")); 659 655 File tmp = File.createTempFile("josm", "tmp.gpx"); … … 667 663 tmp.delete(); 668 664 // read response from server 669 BufferedReader in = new BufferedReader( 670 new InputStreamReader(urlConn.getInputStream())); 665 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); 671 666 String line = ""; 672 667 while((line = in.readLine()) != null) { … … 676 671 677 672 //TODO check response 678 /* 673 /* int retCode = urlConn.getResponseCode(); 679 674 System.out.println("got return: " + retCode); 680 675 String retMsg = urlConn.getResponseMessage(); … … 695 690 } catch (Exception ex) { 696 691 //if (cancel) 697 // 692 // return; // assume cancel 698 693 if (ex instanceof RuntimeException) 699 694 throw (RuntimeException)ex; 700 695 throw new RuntimeException(ex.getMessage(), ex); 701 } 696 } 702 697 } 703 698 } … … 736 731 } 737 732 } 738 733 739 734 /** 740 * Makes a new marker layer derived from this GpxLayer containing at least one 735 * Makes a new marker layer derived from this GpxLayer containing at least one 741 736 * audio marker which the given audio file is associated with. 742 737 * Markers are derived from the following … … 749 744 private void importAudio(File wavFile) { 750 745 String uri = "file:".concat(wavFile.getAbsolutePath()); 751 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", name), associatedFile, me); 752 753 Collection<WayPoint> waypoints = new ArrayList<WayPoint>(); 754 boolean timedMarkersOmitted = false; 755 boolean untimedMarkersOmitted = false; 756 757 // determine time of first point in track 758 double firstTime = -1.0; 759 if (data.tracks != null && ! data.tracks.isEmpty()) { 760 for (GpxTrack track : data.tracks) { 761 if (track.trackSegs == null) continue; 762 for (Collection<WayPoint> seg : track.trackSegs) { 763 for (WayPoint w : seg) { 764 firstTime = w.time; 765 break; 766 } 767 if (firstTime >= 0.0) break; 768 } 769 if (firstTime >= 0.0) break; 770 } 771 } 772 if (firstTime < 0.0) { 746 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", name), associatedFile, me); 747 748 Collection<WayPoint> waypoints = new ArrayList<WayPoint>(); 749 boolean timedMarkersOmitted = false; 750 boolean untimedMarkersOmitted = false; 751 double snapDistance = Main.pref.getDouble("marker.audiofromuntimedwaypoints.distance", 1.0e-3); /* about 25m */ 752 753 // determine time of first point in track 754 double firstTime = -1.0; 755 if (data.tracks != null && ! data.tracks.isEmpty()) { 756 for (GpxTrack track : data.tracks) { 757 if (track.trackSegs == null) continue; 758 for (Collection<WayPoint> seg : track.trackSegs) { 759 for (WayPoint w : seg) { 760 firstTime = w.time; 761 break; 762 } 763 if (firstTime >= 0.0) break; 764 } 765 if (firstTime >= 0.0) break; 766 } 767 } 768 if (firstTime < 0.0) { 773 769 JOptionPane.showMessageDialog(Main.parent, tr("No GPX track available in layer to associate audio with.")); 774 770 return; 775 } 776 777 // (a) try explicit timestamped waypoints - unless suppressed 778 if (Main.pref.getBoolean("marker.audiofromexplicitwaypoints", true) && 779 data.waypoints != null && ! data.waypoints.isEmpty()) 780 { 781 for (WayPoint w : data.waypoints) { 782 if (w.time > firstTime) { 783 waypoints.add(w); 784 } else if (w.time > 0.0) { 785 timedMarkersOmitted = true; 786 } 787 } 788 } 789 790 // (b) try explicit waypoints without timestamps - unless suppressed 791 if (Main.pref.getBoolean("marker.audiofromuntimedwaypoints", true) && 792 data.waypoints != null && ! data.waypoints.isEmpty()) 793 { 794 for (WayPoint w : data.waypoints) { 795 if (waypoints.contains(w)) { continue; } 796 WayPoint wNear = nearestPointOnTrack(w.eastNorth, 10.0e-7 /* about 25m */); 797 if (wNear != null) { 798 WayPoint wc = new WayPoint(w.latlon); 799 wc.time = wNear.time; 800 if (w.attr.containsKey("name")) wc.attr.put("name", w.getString("name")); 801 waypoints.add(wc); 802 } else { 803 untimedMarkersOmitted = true; 804 } 805 } 806 } 807 808 // (c) use explicitly named track points, again unless suppressed 809 if ((Main.pref.getBoolean("marker.audiofromnamedtrackpoints", Main.pref.getBoolean("marker.namedtrackpoints") /* old name */)) && 810 data.tracks != null && ! data.tracks.isEmpty()) 811 { 812 for (GpxTrack track : data.tracks) { 813 if (track.trackSegs == null) continue; 814 for (Collection<WayPoint> seg : track.trackSegs) { 815 for (WayPoint w : seg) { 816 if (w.attr.containsKey("name") || w.attr.containsKey("desc")) { 817 waypoints.add(w); 818 } 819 } 820 } 821 } 822 } 823 824 // (d) analyse audio for spoken markers here, in due course 825 826 // (e) simply add a single marker at the start of the track 827 if ((Main.pref.getBoolean("marker.audiofromstart") || waypoints.isEmpty()) && 828 data.tracks != null && ! data.tracks.isEmpty()) 771 } 772 773 // (a) try explicit timestamped waypoints - unless suppressed 774 if (Main.pref.getBoolean("marker.audiofromexplicitwaypoints", true) && 775 data.waypoints != null && ! data.waypoints.isEmpty()) 829 776 { 830 boolean gotOne = false; 831 for (GpxTrack track : data.tracks) { 832 if (track.trackSegs == null) continue; 833 for (Collection<WayPoint> seg : track.trackSegs) { 834 for (WayPoint w : seg) { 835 WayPoint wStart = new WayPoint(w.latlon); 836 wStart.attr.put("name", "start"); 837 wStart.time = w.time; 838 waypoints.add(wStart); 839 gotOne = true; 840 break; 841 } 842 if (gotOne) break; 843 } 844 if (gotOne) break; 845 } 846 } 847 848 /* we must have got at least one waypoint now */ 849 850 Collections.sort((ArrayList<WayPoint>) waypoints, new Comparator<WayPoint>() { 851 public int compare(WayPoint a, WayPoint b) { 852 return a.time <= b.time ? -1 : 1; 853 } 854 }); 855 856 firstTime = -1.0; /* this time of the first waypoint, not first trackpoint */ 857 for (WayPoint w : waypoints) { 858 if (firstTime < 0.0) firstTime = w.time; 859 double offset = w.time - firstTime; 777 for (WayPoint w : data.waypoints) { 778 if (w.time > firstTime) { 779 waypoints.add(w); 780 } else if (w.time > 0.0) { 781 timedMarkersOmitted = true; 782 } 783 } 784 } 785 786 // (b) try explicit waypoints without timestamps - unless suppressed 787 if (Main.pref.getBoolean("marker.audiofromuntimedwaypoints", true) && 788 data.waypoints != null && ! data.waypoints.isEmpty()) 789 { 790 for (WayPoint w : data.waypoints) { 791 if (waypoints.contains(w)) { continue; } 792 WayPoint wNear = nearestPointOnTrack(w.eastNorth, snapDistance); 793 if (wNear != null) { 794 WayPoint wc = new WayPoint(w.latlon); 795 wc.time = wNear.time; 796 if (w.attr.containsKey("name")) wc.attr.put("name", w.getString("name")); 797 waypoints.add(wc); 798 } else { 799 untimedMarkersOmitted = true; 800 } 801 } 802 } 803 804 // (c) use explicitly named track points, again unless suppressed 805 if ((Main.pref.getBoolean("marker.audiofromnamedtrackpoints", false)) && 806 data.tracks != null && ! data.tracks.isEmpty()) 807 { 808 for (GpxTrack track : data.tracks) { 809 if (track.trackSegs == null) continue; 810 for (Collection<WayPoint> seg : track.trackSegs) { 811 for (WayPoint w : seg) { 812 if (w.attr.containsKey("name") || w.attr.containsKey("desc")) { 813 waypoints.add(w); 814 } 815 } 816 } 817 } 818 } 819 820 // (d) analyse audio for spoken markers here, in due course 821 822 // (e) simply add a single marker at the start of the track 823 if ((Main.pref.getBoolean("marker.audiofromstart") || waypoints.isEmpty()) && 824 data.tracks != null && ! data.tracks.isEmpty()) 825 { 826 boolean gotOne = false; 827 for (GpxTrack track : data.tracks) { 828 if (track.trackSegs == null) continue; 829 for (Collection<WayPoint> seg : track.trackSegs) { 830 for (WayPoint w : seg) { 831 WayPoint wStart = new WayPoint(w.latlon); 832 wStart.attr.put("name", "start"); 833 wStart.time = w.time; 834 waypoints.add(wStart); 835 gotOne = true; 836 break; 837 } 838 if (gotOne) break; 839 } 840 if (gotOne) break; 841 } 842 } 843 844 /* we must have got at least one waypoint now */ 845 846 Collections.sort((ArrayList<WayPoint>) waypoints, new Comparator<WayPoint>() { 847 public int compare(WayPoint a, WayPoint b) { 848 return a.time <= b.time ? -1 : 1; 849 } 850 }); 851 852 firstTime = -1.0; /* this time of the first waypoint, not first trackpoint */ 853 for (WayPoint w : waypoints) { 854 if (firstTime < 0.0) firstTime = w.time; 855 double offset = w.time - firstTime; 860 856 String name; 861 857 if (w.attr.containsKey("name")) … … 865 861 else 866 862 name = AudioMarker.inventName(offset); 867 AudioMarker am = AudioMarker.create(w.latlon, 863 AudioMarker am = AudioMarker.create(w.latlon, 868 864 name, uri, ml, w.time, offset); 869 ml.data.add(am); 870 } 871 Main.main.addLayer(ml); 872 873 if (timedMarkersOmitted) { 874 JOptionPane.showMessageDialog(Main.parent, tr("Some waypoints with timestamps from before the start of the track were omitted.")); 875 } 876 if (untimedMarkersOmitted) { 877 JOptionPane.showMessageDialog(Main.parent, tr("Some waypoints which were too far from the track to sensibly estimate their time were omitted.")); 878 } 865 ml.data.add(am); 866 } 867 Main.main.addLayer(ml); 868 869 if (timedMarkersOmitted) { 870 JOptionPane.showMessageDialog(Main.parent, 871 tr("Some waypoints with timestamps from before the start of the track were omitted.")); 872 } 873 if (untimedMarkersOmitted) { 874 JOptionPane.showMessageDialog(Main.parent, 875 tr("Some waypoints which were too far from the track to sensibly estimate their time were omitted.")); 876 } 879 877 } 880 878 881 879 /** 882 * Makes a WayPoint at the projection of point P onto the track providing P is 883 * less than tolerance away from the track 880 * Makes a WayPoint at the projection of point P onto the track providing P is 881 * less than tolerance away from the track 884 882 885 883 * @param P : the point to determine the projection for 886 884 * @param tolerance : must be no further than this from the track 887 * @return the closest point on the track to P, which may be the 888 * first or last point if off the end of a segment, or may be null if 885 * @return the closest point on the track to P, which may be the 886 * first or last point if off the end of a segment, or may be null if 889 887 * nothing close enough 890 888 */ 891 889 public WayPoint nearestPointOnTrack(EastNorth P, double tolerance) { 892 890 /* 893 * assume the coordinates of P are xp,yp, and those of a section of track 891 * assume the coordinates of P are xp,yp, and those of a section of track 894 892 * between two trackpoints are R=xr,yr and S=xs,ys. Let N be the projected point. 895 * 893 * 896 894 * The equation of RS is Ax + By + C = 0 where 897 895 * A = ys - yr 898 896 * B = xr - xs 899 897 * C = - Axr - Byr 900 * 898 * 901 899 * Also, note that the distance RS^2 is A^2 + B^2 902 * 900 * 903 901 * If RS^2 == 0.0 ignore the degenerate section of track 904 * 902 * 905 903 * PN^2 = (Axp + Byp + C)^2 / RS^2 906 904 * that is the distance from P to the line 907 * 908 * so if PN^2 is less than PNmin^2 (initialized to tolerance) we can reject 905 * 906 * so if PN^2 is less than PNmin^2 (initialized to tolerance) we can reject 909 907 * the line; otherwise... 910 908 * determine if the projected poijnt lies within the bounds of the line: 911 909 * PR^2 - PN^2 <= RS^2 and PS^2 - PN^2 <= RS^2 912 * 910 * 913 911 * where PR^2 = (xp - xr)^2 + (yp-yr)^2 914 912 * and PS^2 = (xp - xs)^2 + (yp-ys)^2 915 * 913 * 916 914 * If so, calculate N as 917 915 * xn = xr + (RN/RS) B 918 916 * yn = y1 + (RN/RS) A 919 * 917 * 920 918 * where RN = sqrt(PR^2 - PN^2) 921 919 */ 922 920 923 921 double PNminsq = tolerance * tolerance; 924 922 EastNorth bestEN = null; … … 929 927 if (data.tracks == null) return null; 930 928 for (GpxTrack track : data.tracks) { 931 if (track.trackSegs == null) continue; 929 if (track.trackSegs == null) continue; 932 930 for (Collection<WayPoint> seg : track.trackSegs) { 933 931 WayPoint R = null; … … 988 986 bestTime = R.time; 989 987 } 990 991 988 } 992 989 } -
trunk/src/org/openstreetmap/josm/gui/preferences/AudioPreference.java
r795 r813 120 120 } 121 121 }); 122 audioMarkersFromNamedTrackpoints.setSelected(Main.pref.getBoolean("marker.audiofromnamedtrackpoints", Main.pref.getBoolean("marker.namedtrackpoints")));122 audioMarkersFromNamedTrackpoints.setSelected(Main.pref.getBoolean("marker.audiofromnamedtrackpoints", false)); 123 123 audioMarkersFromNamedTrackpoints.setToolTipText(tr("Automatically create audio markers from trackpoints (rather than explicit waypoints) with names or descriptions.")); 124 124 gui.audio.add(audioMarkersFromNamedTrackpoints, GBC.eol().insets(10,0,0,0)); -
trunk/src/org/openstreetmap/josm/io/GpxReader.java
r627 r813 224 224 break; 225 225 case wpt: 226 if (qName.equals("ele") || qName.equals("desc") 227 || qName.equals("magvar") || qName.equals("geoidheight") 228 || qName.equals("name") || qName.equals("sym") 229 || qName.equals("cmt") || qName.equals("type")) { 226 if (qName.equals("ele") || qName.equals("magvar") 227 || qName.equals("geoidheight") || qName.equals("name") 228 || qName.equals("sym") || qName.equals("type")) { 230 229 currentWayPoint.attr.put(qName, accumulator.toString()); 231 230 } else if (qName.equals("time")) { 232 231 currentWayPoint.attr.put(qName, accumulator.toString()); 233 232 currentWayPoint.setTime(); 233 } else if (qName.equals("cmt") || qName.equals("desc")) { 234 currentWayPoint.attr.put(qName, accumulator.toString()); 235 currentWayPoint.setGarminCommentTime(qName); 234 236 } else if (qName.equals("rtept")) { 235 237 currentState = states.pop();
Note:
See TracChangeset
for help on using the changeset viewer.