1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.gpx;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.geom.Path2D;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.actions.DownloadAlongAction;
|
---|
9 | import org.openstreetmap.josm.data.gpx.GpxData;
|
---|
10 | import org.openstreetmap.josm.data.gpx.GpxTrack;
|
---|
11 | import org.openstreetmap.josm.data.gpx.IGpxTrackSegment;
|
---|
12 | import org.openstreetmap.josm.data.gpx.WayPoint;
|
---|
13 | import org.openstreetmap.josm.gui.PleaseWaitRunnable;
|
---|
14 | import org.openstreetmap.josm.gui.help.HelpUtil;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Action that issues a series of download requests to the API, following the GPX track.
|
---|
18 | *
|
---|
19 | * @author fred
|
---|
20 | * @since 5715
|
---|
21 | */
|
---|
22 | public class DownloadAlongTrackAction extends DownloadAlongAction {
|
---|
23 |
|
---|
24 | private static final int NEAR_TRACK = 0;
|
---|
25 | private static final int NEAR_WAYPOINTS = 1;
|
---|
26 | private static final int NEAR_BOTH = 2;
|
---|
27 |
|
---|
28 | private static final String PREF_DOWNLOAD_ALONG_TRACK_OSM = "downloadAlongTrack.download.osm";
|
---|
29 | private static final String PREF_DOWNLOAD_ALONG_TRACK_GPS = "downloadAlongTrack.download.gps";
|
---|
30 |
|
---|
31 | private static final String PREF_DOWNLOAD_ALONG_TRACK_DISTANCE = "downloadAlongTrack.distance";
|
---|
32 | private static final String PREF_DOWNLOAD_ALONG_TRACK_AREA = "downloadAlongTrack.area";
|
---|
33 | private static final String PREF_DOWNLOAD_ALONG_TRACK_NEAR = "downloadAlongTrack.near";
|
---|
34 |
|
---|
35 | private final transient GpxData data;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Constructs a new {@code DownloadAlongTrackAction}
|
---|
39 | * @param data The GPX data used to download along
|
---|
40 | */
|
---|
41 | public DownloadAlongTrackAction(GpxData data) {
|
---|
42 | super(tr("Download from OSM along this track"), "downloadalongtrack", null, null, false);
|
---|
43 | this.data = data;
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | protected PleaseWaitRunnable createTask() {
|
---|
48 | final DownloadAlongPanel panel = new DownloadAlongPanel(
|
---|
49 | PREF_DOWNLOAD_ALONG_TRACK_OSM, PREF_DOWNLOAD_ALONG_TRACK_GPS,
|
---|
50 | PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, PREF_DOWNLOAD_ALONG_TRACK_AREA, PREF_DOWNLOAD_ALONG_TRACK_NEAR);
|
---|
51 |
|
---|
52 | int ret = panel.showInDownloadDialog(tr("Download from OSM along this track"), HelpUtil.ht("/Action/DownloadAlongTrack"));
|
---|
53 | if (0 != ret && 1 != ret) {
|
---|
54 | return null;
|
---|
55 | }
|
---|
56 |
|
---|
57 | final int near = panel.getNear();
|
---|
58 |
|
---|
59 | // Convert the GPX data into a Path2D.
|
---|
60 | Path2D gpxPath = new Path2D.Double();
|
---|
61 | if (near == NEAR_TRACK || near == NEAR_BOTH) {
|
---|
62 | for (GpxTrack trk : data.tracks) {
|
---|
63 | for (IGpxTrackSegment segment : trk.getSegments()) {
|
---|
64 | boolean first = true;
|
---|
65 | for (WayPoint p : segment.getWayPoints()) {
|
---|
66 | if (first) {
|
---|
67 | gpxPath.moveTo(p.lon(), p.lat());
|
---|
68 | first = false;
|
---|
69 | } else {
|
---|
70 | gpxPath.lineTo(p.lon(), p.lat());
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 | if (near == NEAR_WAYPOINTS || near == NEAR_BOTH) {
|
---|
77 | for (WayPoint p : data.waypoints) {
|
---|
78 | gpxPath.moveTo(p.lon(), p.lat());
|
---|
79 | gpxPath.closePath();
|
---|
80 | }
|
---|
81 | }
|
---|
82 | return createCalcTask(gpxPath, panel, tr("Download from OSM along this track"), 1 == ret);
|
---|
83 | }
|
---|
84 | }
|
---|