Changeset 16864 in josm for trunk/src/org


Ignore:
Timestamp:
2020-08-10T23:19:05+02:00 (4 years ago)
Author:
simon04
Message:

fix #15441 - Separate GpxRouteLayer

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

    r16643 r16864  
    2222import org.openstreetmap.josm.gui.io.importexport.GpxImporter.GpxImporterData;
    2323import org.openstreetmap.josm.gui.layer.GpxLayer;
     24import org.openstreetmap.josm.gui.layer.GpxRouteLayer;
    2425import org.openstreetmap.josm.gui.layer.Layer;
    2526import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
     
    144145            addOrMergeLayer(gpxLayer, findGpxMergeLayer());
    145146            addOrMergeLayer(layers.getMarkerLayer(), findMarkerMergeLayer(gpxLayer));
     147            addOrMergeLayer(layers.getGpxRouteLayer(), findGpxRouteMergeLayer(gpxLayer));
    146148
    147149            layers.getPostLayerTask().run();
     
    190192        }
    191193
     194        private GpxRouteLayer findGpxRouteMergeLayer(GpxLayer fromLayer) {
     195            return MainApplication.getLayerManager().getLayersOfType(GpxRouteLayer.class).stream()
     196                    .filter(l -> fromLayer != null && l.fromLayer == fromLayer)
     197                    .findFirst().orElse(null);
     198        }
     199
    192200        @Override
    193201        protected void cancel() {
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r16862 r16864  
    905905        private int idxTracks;
    906906        private Iterator<IGpxTrackSegment> itTrackSegments;
    907         private final Iterator<GpxRoute> itRoutes;
    908907
    909908        private Line next;
     
    921920            itTracks = data.tracks.iterator();
    922921            idxTracks = -1;
    923             itRoutes = data.routes.iterator();
    924922            this.trackVisibility = trackVisibility;
    925923            next = getNext();
     
    961959                    itTracks = null;
    962960                }
    963             }
    964             if (itRoutes.hasNext()) {
    965                 return new Line(itRoutes.next());
    966961            }
    967962            return null;
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/GpxImporter.java

    r16625 r16864  
    1515import org.openstreetmap.josm.gui.Notification;
    1616import org.openstreetmap.josm.gui.layer.GpxLayer;
     17import org.openstreetmap.josm.gui.layer.GpxRouteLayer;
    1718import org.openstreetmap.josm.gui.layer.ImageryLayer;
    1819import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    4142        private final GpxLayer gpxLayer;
    4243        /**
     44         * The imported GPX route layer. May be null if no marker.
     45         */
     46        private final GpxRouteLayer gpxRouteLayer;
     47        /**
    4348         * The imported marker layer. May be null if no marker.
    4449         */
     
    5560         * @param postLayerTask The task to run after GPX and/or marker layer has been added to MapView.
    5661         */
    57         public GpxImporterData(GpxLayer gpxLayer, MarkerLayer markerLayer, Runnable postLayerTask) {
     62        public GpxImporterData(GpxLayer gpxLayer, GpxRouteLayer gpxRouteLayer, MarkerLayer markerLayer, Runnable postLayerTask) {
    5863            this.gpxLayer = gpxLayer;
     64            this.gpxRouteLayer = gpxRouteLayer;
    5965            this.markerLayer = markerLayer;
    6066            this.postLayerTask = postLayerTask;
     
    6773        public GpxLayer getGpxLayer() {
    6874            return gpxLayer;
     75        }
     76
     77        /**
     78         * Returns the imported GPX route layer. May be null if no GPX data.
     79         * @return the imported GPX route layer. May be null if no GPX data.
     80         */
     81        public GpxRouteLayer getGpxRouteLayer() {
     82            return gpxRouteLayer;
    6983        }
    7084
     
    128142                MainApplication.getLayerManager().addLayer(data.markerLayer);
    129143            }
     144            if (data.gpxRouteLayer != null) {
     145                MainApplication.getLayerManager().addLayer(data.gpxRouteLayer);
     146            }
    130147            if (data.gpxLayer != null) {
    131148                MainApplication.getLayerManager().addLayer(data.gpxLayer);
     
    147164            final String gpxLayerName, String markerLayerName) {
    148165        MarkerLayer markerLayer = null;
     166        GpxRouteLayer gpxRouteLayer = null;
    149167        GpxLayer gpxLayer = new GpxLayer(data, gpxLayerName, data.storageFile != null);
    150168        if (Config.getPref().getBoolean("marker.makeautomarkers", true) && !data.waypoints.isEmpty()) {
     
    155173                gpxLayer.setLinkedMarkerLayer(markerLayer);
    156174            }
     175        }
     176        if (Config.getPref().getBoolean("gpx.makeautoroutes", true)) {
     177            gpxRouteLayer = new GpxRouteLayer(tr("Routes from {0}", gpxLayerName), gpxLayer);
    157178        }
    158179
     
    182203            }
    183204        };
    184         return new GpxImporterData(gpxLayer, markerLayer, postLayerTask);
     205        return new GpxImporterData(gpxLayer, gpxRouteLayer, markerLayer, postLayerTask);
    185206    }
    186207
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

    r16643 r16864  
    370370
    371371        ensureTrackVisibilityLength();
    372         for (Line segment : data.getLinesIterable(layer.trackVisibility)) {
     372        for (Line segment : getLinesIterable(layer.trackVisibility)) {
    373373
    374374            for (WayPoint pt : segment) {
     
    396396    }
    397397
     398    protected Iterable<Line> getLinesIterable(final boolean[] trackVisibility) {
     399        return data.getLinesIterable(trackVisibility);
     400    }
     401
    398402    /** ensures the trackVisibility array has the correct length without losing data.
    399403     * TODO: Make this nicer by syncing the trackVisibility automatically.
     
    508512            if (colored == ColorMode.VELOCITY) {
    509513                final List<Double> velocities = new ArrayList<>();
    510                 for (Line segment : data.getLinesIterable(null)) {
     514                for (Line segment : getLinesIterable(null)) {
    511515                    if (!forceLines) {
    512516                        oldWp = null;
     
    533537                }
    534538            } else if (colored == ColorMode.HDOP) {
    535                 for (Line segment : data.getLinesIterable(null)) {
     539                for (Line segment : getLinesIterable(null)) {
    536540                    for (WayPoint trkPnt : segment) {
    537541                        Object val = trkPnt.get(GpxConstants.PT_HDOP);
     
    573577
    574578        // Now the colors for all the points will be assigned
    575         for (Line segment : data.getLinesIterable(null)) {
     579        for (Line segment : getLinesIterable(null)) {
    576580            if (!forceLines) { // don't draw lines between segments, unless forced to
    577581                oldWp = null;
Note: See TracChangeset for help on using the changeset viewer.