Changeset 7518 in josm for trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
- Timestamp:
- 2014-09-10T02:29:55+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r7414 r7518 51 51 import org.openstreetmap.josm.data.conflict.ConflictCollection; 52 52 import org.openstreetmap.josm.data.coor.LatLon; 53 import org.openstreetmap.josm.data.gpx.GpxConstants; 53 54 import org.openstreetmap.josm.data.gpx.GpxData; 55 import org.openstreetmap.josm.data.gpx.GpxLink; 54 56 import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack; 55 57 import org.openstreetmap.josm.data.gpx.WayPoint; … … 581 583 WayPoint wpt = new WayPoint(n.getCoor()); 582 584 if (!n.isTimestampEmpty()) { 583 wpt. attr.put("time", DateUtils.fromDate(n.getTimestamp()));585 wpt.put("time", DateUtils.fromDate(n.getTimestamp())); 584 586 wpt.setTime(); 585 587 } … … 600 602 } 601 603 WayPoint wpt = new WayPoint(n.getCoor()); 602 String name = n.get("name"); 603 if (name != null) { 604 wpt.attr.put("name", name); 605 } 604 605 // Position info 606 607 addDoubleIfPresent(wpt, n, GpxConstants.PT_ELE); 608 606 609 if (!n.isTimestampEmpty()) { 607 wpt. attr.put("time", DateUtils.fromDate(n.getTimestamp()));610 wpt.put("time", DateUtils.fromDate(n.getTimestamp())); 608 611 wpt.setTime(); 609 612 } 610 String desc = n.get("description"); 611 if (desc != null) { 612 wpt.attr.put("desc", desc); 613 } 613 614 addDoubleIfPresent(wpt, n, GpxConstants.PT_MAGVAR); 615 addDoubleIfPresent(wpt, n, GpxConstants.PT_GEOIDHEIGHT); 616 617 // Description info 618 619 addStringIfPresent(wpt, n, GpxConstants.GPX_NAME); 620 addStringIfPresent(wpt, n, GpxConstants.GPX_DESC, "description"); 621 addStringIfPresent(wpt, n, GpxConstants.GPX_CMT, "comment"); 622 addStringIfPresent(wpt, n, GpxConstants.GPX_SRC, "source", "source:position"); 623 624 Collection<GpxLink> links = new ArrayList<>(); 625 for (String key : new String[]{"link", "url", "website", "contact:website"}) { 626 String value = n.get(key); 627 if (value != null) { 628 links.add(new GpxLink(value)); 629 } 630 } 631 wpt.put(GpxConstants.META_LINKS, links); 632 633 addStringIfPresent(wpt, n, GpxConstants.PT_SYM, "wpt_symbol"); 634 addStringIfPresent(wpt, n, GpxConstants.PT_TYPE); 635 636 // Accuracy info 637 addStringIfPresent(wpt, n, GpxConstants.PT_FIX, "gps:fix"); 638 addIntegerIfPresent(wpt, n, GpxConstants.PT_SAT, "gps:sat"); 639 addDoubleIfPresent(wpt, n, GpxConstants.PT_HDOP, "gps:hdop"); 640 addDoubleIfPresent(wpt, n, GpxConstants.PT_VDOP, "gps:vdop"); 641 addDoubleIfPresent(wpt, n, GpxConstants.PT_PDOP, "gps:pdop"); 642 addDoubleIfPresent(wpt, n, GpxConstants.PT_AGEOFDGPSDATA, "gps:ageofdgpsdata"); 643 addIntegerIfPresent(wpt, n, GpxConstants.PT_DGPSID, "gps:dgpsid"); 614 644 615 645 gpxData.waypoints.add(wpt); 646 } 647 } 648 649 private static void addIntegerIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String ... osmKeys) { 650 ArrayList<String> possibleKeys = new ArrayList<>(Arrays.asList(osmKeys)); 651 possibleKeys.add(0, gpxKey); 652 for (String key : possibleKeys) { 653 String value = p.get(key); 654 if (value != null) { 655 try { 656 int i = Integer.parseInt(value); 657 // Sanity checks 658 if ((!GpxConstants.PT_SAT.equals(gpxKey) || i >= 0) && 659 (!GpxConstants.PT_DGPSID.equals(gpxKey) || (0 <= i && i <= 1023))) { 660 wpt.put(gpxKey, value); 661 break; 662 } 663 } catch (NumberFormatException e) { 664 if (Main.isTraceEnabled()) { 665 Main.trace(e.getMessage()); 666 } 667 } 668 } 669 } 670 } 671 672 private static void addDoubleIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String ... osmKeys) { 673 ArrayList<String> possibleKeys = new ArrayList<>(Arrays.asList(osmKeys)); 674 possibleKeys.add(0, gpxKey); 675 for (String key : possibleKeys) { 676 String value = p.get(key); 677 if (value != null) { 678 try { 679 double d = Double.parseDouble(value); 680 // Sanity checks 681 if (!GpxConstants.PT_MAGVAR.equals(gpxKey) || (0.0 <= d && d < 360.0)) { 682 wpt.put(gpxKey, value); 683 break; 684 } 685 } catch (NumberFormatException e) { 686 if (Main.isTraceEnabled()) { 687 Main.trace(e.getMessage()); 688 } 689 } 690 } 691 } 692 } 693 694 private static void addStringIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String ... osmKeys) { 695 ArrayList<String> possibleKeys = new ArrayList<>(Arrays.asList(osmKeys)); 696 possibleKeys.add(0, gpxKey); 697 for (String key : possibleKeys) { 698 String value = p.get(key); 699 if (value != null) { 700 // Sanity checks 701 if (!GpxConstants.PT_FIX.equals(gpxKey) || GpxConstants.FIX_VALUES.contains(value)) { 702 wpt.put(gpxKey, value); 703 break; 704 } 705 } 616 706 } 617 707 }
Note:
See TracChangeset
for help on using the changeset viewer.