Changeset 16847 in josm for trunk/src/org
- Timestamp:
- 2020-08-04T22:19:41+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r16553 r16847 13 13 import java.util.ArrayList; 14 14 import java.util.Arrays; 15 import java.util.Collections; 15 16 import java.util.Date; 16 17 import java.util.List; 18 import java.util.NoSuchElementException; 17 19 import java.util.stream.Collectors; 18 20 … … 34 36 import org.openstreetmap.josm.data.gpx.GpxData.GpxDataChangeListener; 35 37 import org.openstreetmap.josm.data.gpx.IGpxTrack; 38 import org.openstreetmap.josm.data.gpx.IGpxTrackSegment; 36 39 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 37 40 import org.openstreetmap.josm.data.projection.Projection; 41 import org.openstreetmap.josm.gui.MainApplication; 38 42 import org.openstreetmap.josm.gui.MapView; 39 43 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 40 44 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 41 45 import org.openstreetmap.josm.gui.io.importexport.GpxImporter; 46 import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToMarkerLayer; 47 import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToNextMarker; 48 import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToPreviousMarker; 42 49 import org.openstreetmap.josm.gui.layer.gpx.ChooseTrackVisibilityAction; 43 50 import org.openstreetmap.josm.gui.layer.gpx.ConvertFromGpxLayerAction; … … 60 67 * A layer that displays data from a Gpx file / the OSM gpx downloads. 61 68 */ 62 public class GpxLayer extends AbstractModifiableLayer implements ExpertModeChangeListener {69 public class GpxLayer extends AbstractModifiableLayer implements ExpertModeChangeListener, JumpToMarkerLayer { 63 70 64 71 /** GPX data */ … … 83 90 */ 84 91 private MarkerLayer linkedMarkerLayer; 92 93 /** 94 * Current segment for {@link JumpToMarkerLayer}. 95 */ 96 private IGpxTrackSegment currentSegment = null; 85 97 86 98 /** … … 239 251 @Override 240 252 public Action[] getMenuEntries() { 253 JumpToNextMarker jumpToNext = new JumpToNextMarker(this); 254 jumpToNext.putValue(Action.NAME, tr("Jump to next segment")); 255 JumpToPreviousMarker jumpToPrevious = new JumpToPreviousMarker(this); 256 jumpToPrevious.putValue(Action.NAME, tr("Jump to previous segment")); 241 257 List<Action> entries = new ArrayList<>(Arrays.asList( 242 258 LayerListDialog.getInstance().createShowHideLayerAction(), … … 251 267 new ImportAudioAction(this), 252 268 new MarkersFromNamedPointsAction(this), 269 jumpToNext, 270 jumpToPrevious, 253 271 new ConvertFromGpxLayerAction(this), 254 272 new DownloadAlongTrackAction(data), … … 555 573 return data; 556 574 } 575 576 /** 577 * Jump (move the viewport) to the next track segment. 578 */ 579 @Override 580 public void jumpToNextMarker() { 581 List<IGpxTrackSegment> segments = data.getTrackSegmentsStream().collect(Collectors.toList()); 582 jumpToNext(segments); 583 } 584 585 /** 586 * Jump (move the viewport) to the previous track segment. 587 */ 588 @Override 589 public void jumpToPreviousMarker() { 590 List<IGpxTrackSegment> segments = data.getTrackSegmentsStream().collect(Collectors.toList()); 591 Collections.reverse(segments); 592 jumpToNext(segments); 593 } 594 595 private void jumpToNext(List<IGpxTrackSegment> segments) { 596 if (segments.isEmpty()) { 597 return; 598 } else if (currentSegment == null) { 599 currentSegment = segments.get(0); 600 MainApplication.getMap().mapView.zoomTo(currentSegment.getBounds()); 601 } else { 602 try { 603 int index = segments.indexOf(currentSegment); 604 currentSegment = segments.listIterator(index + 1).next(); 605 MainApplication.getMap().mapView.zoomTo(currentSegment.getBounds()); 606 } catch (IndexOutOfBoundsException | NoSuchElementException ignore) { 607 Logging.trace(ignore); 608 } 609 } 610 } 557 611 }
Note:
See TracChangeset
for help on using the changeset viewer.