Changeset 16850 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2020-08-04T23:38:35+02:00 (4 years ago)
Author:
simon04
Message:

fix #17836 - Download along several gpx tracks at once

Location:
trunk/src/org/openstreetmap/josm/gui/layer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r16847 r16850  
    270270                jumpToPrevious,
    271271                new ConvertFromGpxLayerAction(this),
    272                 new DownloadAlongTrackAction(data),
     272                new DownloadAlongTrackAction(Collections.singleton(data)),
    273273                new DownloadWmsAlongTrackAction(data),
    274274                SeparatorLayerAction.INSTANCE,
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackAction.java

    r15502 r16850  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Component;
    67import java.awt.geom.Path2D;
     8import java.util.Collection;
     9import java.util.List;
     10import java.util.stream.Collectors;
     11
     12import javax.swing.Action;
     13import javax.swing.JMenuItem;
    714
    815import org.openstreetmap.josm.actions.DownloadAlongAction;
    916import org.openstreetmap.josm.data.gpx.GpxData;
    10 import org.openstreetmap.josm.data.gpx.IGpxTrack;
    11 import org.openstreetmap.josm.data.gpx.IGpxTrackSegment;
    1217import org.openstreetmap.josm.data.gpx.WayPoint;
    1318import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    1419import org.openstreetmap.josm.gui.help.HelpUtil;
     20import org.openstreetmap.josm.gui.layer.GpxLayer;
     21import org.openstreetmap.josm.gui.layer.Layer;
     22import org.openstreetmap.josm.tools.Utils;
    1523
    1624/**
     
    2028 * @since 5715
    2129 */
    22 public class DownloadAlongTrackAction extends DownloadAlongAction {
     30public class DownloadAlongTrackAction extends DownloadAlongAction implements Layer.LayerAction, Layer.MultiLayerAction {
    2331
    2432    private static final int NEAR_TRACK = 0;
     
    3341    private static final String PREF_DOWNLOAD_ALONG_TRACK_NEAR = "downloadAlongTrack.near";
    3442
    35     private final transient GpxData data;
     43    private final transient Collection<GpxData> data;
    3644
    3745    /**
     
    3947     * @param data The GPX data used to download along
    4048     */
    41     public DownloadAlongTrackAction(GpxData data) {
     49    public DownloadAlongTrackAction(Collection<GpxData> data) {
    4250        super(tr("Download from OSM along this track"), "downloadalongtrack", null, null, false);
    4351        this.data = data;
     
    6068        Path2D gpxPath = new Path2D.Double();
    6169        if (near == NEAR_TRACK || near == NEAR_BOTH) {
    62             for (IGpxTrack 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                         }
     70            data.stream().flatMap(GpxData::getTrackSegmentsStream).forEach(segment -> {
     71                boolean first = true;
     72                for (WayPoint p : segment.getWayPoints()) {
     73                    if (first) {
     74                        gpxPath.moveTo(p.lon(), p.lat());
     75                        first = false;
     76                    } else {
     77                        gpxPath.lineTo(p.lon(), p.lat());
    7278                    }
    7379                }
    74             }
     80            });
    7581        }
    7682        if (near == NEAR_WAYPOINTS || near == NEAR_BOTH) {
    77             for (WayPoint p : data.waypoints) {
     83            data.stream().flatMap(d -> d.getWaypoints().stream()).forEach(p -> {
    7884                gpxPath.moveTo(p.lon(), p.lat());
    7985                gpxPath.closePath();
    80             }
     86            });
    8187        }
    8288        return createCalcTask(gpxPath, panel, tr("Download from OSM along this track"), 1 == ret);
    8389    }
     90
     91    @Override
     92    public Component createMenuComponent() {
     93        return new JMenuItem(this);
     94    }
     95
     96    @Override
     97    public boolean supportLayers(List<Layer> layers) {
     98        return !Utils.filteredCollection(layers, GpxLayer.class).isEmpty();
     99    }
     100
     101    @Override
     102    public Action getMultiLayerAction(List<Layer> layers) {
     103        final List<GpxData> gpxData = Utils.filteredCollection(layers, GpxLayer.class)
     104                .stream().map(layer -> layer.data)
     105                .collect(Collectors.toList());
     106        return new DownloadAlongTrackAction(gpxData);
     107    }
    84108}
Note: See TracChangeset for help on using the changeset viewer.