source: osm/applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/DirectDownload.java

Last change on this file was 35944, checked in by taylor.smock, 2 years ago

DirectDownload: fix #21935 and #21952

#21935: "Error fetching URL" when trying to download a GPS track

This was caused due to a change in where OSM stores GPX data files.
OSM now uses s3 buckets, and redirects using a signed URL. S3 does
not like multiple authentication methods.

#21952: Only the first tag in the Tags column in "Download Track" window is shown

This was caused due to only keeping the last encountered tag.

File size: 3.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.plugins.directdownload;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.KeyEvent;
8import java.util.ArrayList;
9import java.util.HashMap;
10import java.util.List;
11
12import org.openstreetmap.josm.actions.JosmAction;
13import org.openstreetmap.josm.data.gpx.GpxConstants;
14import org.openstreetmap.josm.data.gpx.GpxData;
15import org.openstreetmap.josm.data.gpx.GpxTrack;
16import org.openstreetmap.josm.data.gpx.IGpxTrack;
17import org.openstreetmap.josm.gui.MainApplication;
18import org.openstreetmap.josm.gui.MainMenu;
19import org.openstreetmap.josm.gui.layer.GpxLayer;
20import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
21import org.openstreetmap.josm.plugins.Plugin;
22import org.openstreetmap.josm.plugins.PluginInformation;
23import org.openstreetmap.josm.spi.preferences.Config;
24import org.openstreetmap.josm.tools.Shortcut;
25
26public class DirectDownload extends Plugin {
27 /**
28 * Will be invoked by JOSM to bootstrap the plugin
29 *
30 * @param info information about the plugin and its local installation
31 */
32 public DirectDownload(PluginInformation info) {
33 super(info);
34
35 MainMenu.add(MainApplication.getMenu().gpsMenu, new DownloadAction());
36 }
37
38 static class DownloadAction extends JosmAction {
39 DownloadAction() {
40 super(tr("Download Track ..."), "DownloadAction", tr("Download GPX track from openstreetmap.org"),
41 Shortcut.registerShortcut("directdownload:downloadgpxaction", tr("DirectDownload: Download GPX Track"),
42 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false);
43 }
44
45 @Override
46 public void actionPerformed(ActionEvent event) {
47 DownloadDataGui go = new DownloadDataGui();
48 go.setVisible(true);
49
50 List<UserTrack> tracks = go.getSelectedUserTracks();
51
52 if (!((go.getValue() == 1) && (tracks != null))) {
53 return;
54 }
55
56 for (UserTrack track: tracks) {
57
58 GpxData data = new GpxServerReader().loadGpx(Long.parseLong(track.id));
59 if (data == null) {
60 return;
61 }
62 GpxData dataNew = new GpxData();
63
64 for (IGpxTrack trk : data.getTracks()) {
65 HashMap<String, Object> attrib = new HashMap<>(trk.getAttributes());
66 if (!trk.getAttributes().containsKey(GpxConstants.GPX_NAME)) {
67 attrib.put(GpxConstants.GPX_NAME, track.filename);
68 }
69 if (!trk.getAttributes().containsKey(GpxConstants.GPX_DESC)) {
70 attrib.put(GpxConstants.GPX_DESC, track.description);
71 }
72 // replace the existing trace in the unmodifiable tracks
73 dataNew.addTrack(new GpxTrack(new ArrayList<>(trk.getSegments()), attrib));
74 }
75
76 data = dataNew;
77
78 final GpxLayer gpxLayer = new GpxLayer(data, (track.filename + " " + track.description).trim());
79
80 if (data.hasRoutePoints() || data.hasTrackPoints()) {
81 MainApplication.getLayerManager().addLayer(gpxLayer);
82 }
83
84 if (Config.getPref().getBoolean("marker.makeautomarkers", true) && !data.waypoints.isEmpty()) {
85 MarkerLayer ml = new MarkerLayer(data, tr("Markers from {0}", track.filename), null, gpxLayer);
86 if (!ml.data.isEmpty()) {
87 MainApplication.getLayerManager().addLayer(ml);
88 }
89 }
90 }
91 }
92 }
93}
Note: See TracBrowser for help on using the repository browser.