- Timestamp:
- 2015-09-29T19:56:37+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/layer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r8557 r8804 193 193 new ImportAudioAction(this), 194 194 new MarkersFromNamedPointsAction(this), 195 new ConvertToDataLayerAction (this),195 new ConvertToDataLayerAction.FromGpxLayer(this), 196 196 new DownloadAlongTrackAction(data), 197 197 new DownloadWmsAlongTrackAction(data), -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerAction.java
r8540 r8804 25 25 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 26 26 import org.openstreetmap.josm.gui.layer.GpxLayer; 27 import org.openstreetmap.josm.gui.layer.Layer; 27 28 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 29 import org.openstreetmap.josm.gui.layer.markerlayer.Marker; 30 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 28 31 import org.openstreetmap.josm.gui.widgets.UrlLabel; 29 32 import org.openstreetmap.josm.tools.GBC; … … 31 34 import org.openstreetmap.josm.tools.date.DateUtils; 32 35 33 public class ConvertToDataLayerAction extends AbstractAction { 34 private final transient GpxLayer layer; 36 /** 37 * An abstract action for a conversion from a {@code T} {@link Layer} to a {@link OsmDataLayer}. 38 * @param <T> the source layer class 39 */ 40 public abstract class ConvertToDataLayerAction<T extends Layer> extends AbstractAction { 41 protected final transient T layer; 35 42 36 p ublic ConvertToDataLayerAction(final GpxLayerlayer) {43 protected ConvertToDataLayerAction(final T layer) { 37 44 super(tr("Convert to data layer"), ImageProvider.get("converttoosm")); 38 45 this.layer = layer; 39 46 putValue("help", ht("/Action/ConvertToDataLayer")); 40 47 } 48 49 /** 50 * Converts a {@link GpxLayer} to a {@link OsmDataLayer}. 51 */ 52 public static class FromGpxLayer extends ConvertToDataLayerAction<GpxLayer> { 53 54 /** 55 * Creates a new {@code FromGpxLayer}. 56 * @param layer the source layer 57 */ 58 public FromGpxLayer(GpxLayer layer) { 59 super(layer); 60 } 61 62 @Override 63 public DataSet convert() { 64 final DataSet ds = new DataSet(); 65 for (GpxTrack trk : layer.data.tracks) { 66 for (GpxTrackSegment segment : trk.getSegments()) { 67 List<Node> nodes = new ArrayList<>(); 68 for (WayPoint p : segment.getWayPoints()) { 69 Node n = new Node(p.getCoor()); 70 String timestr = p.getString(GpxConstants.PT_TIME); 71 if (timestr != null) { 72 n.setTimestamp(DateUtils.fromString(timestr)); 73 } 74 ds.addPrimitive(n); 75 nodes.add(n); 76 } 77 Way w = new Way(); 78 w.setNodes(nodes); 79 ds.addPrimitive(w); 80 } 81 } 82 return ds; 83 } 84 } 85 86 /** 87 * Converts a {@link MarkerLayer} to a {@link OsmDataLayer}. 88 */ 89 public static class FromMarkerLayer extends ConvertToDataLayerAction<MarkerLayer> { 90 91 /** 92 * Converts a {@link MarkerLayer} to a {@link OsmDataLayer}. 93 */ 94 public FromMarkerLayer(MarkerLayer layer) { 95 super(layer); 96 } 97 98 @Override 99 public DataSet convert() { 100 final DataSet ds = new DataSet(); 101 for (Marker marker : layer.data) { 102 final Node node = new Node(marker.getCoor()); 103 node.put("name", marker.getText()); 104 ds.addPrimitive(node); 105 } 106 return ds; 107 } 108 } 109 110 /** 111 * Performs the conversion to a {@link DataSet}. 112 * @return the resulting dataset 113 */ 114 public abstract DataSet convert(); 41 115 42 116 @Override … … 53 127 return; 54 128 } 55 DataSet ds = new DataSet(); 56 for (GpxTrack trk : layer.data.tracks) { 57 for (GpxTrackSegment segment : trk.getSegments()) { 58 List<Node> nodes = new ArrayList<>(); 59 for (WayPoint p : segment.getWayPoints()) { 60 Node n = new Node(p.getCoor()); 61 String timestr = p.getString(GpxConstants.PT_TIME); 62 if (timestr != null) { 63 n.setTimestamp(DateUtils.fromString(timestr)); 64 } 65 ds.addPrimitive(n); 66 nodes.add(n); 67 } 68 Way w = new Way(); 69 w.setNodes(nodes); 70 ds.addPrimitive(w); 71 } 72 } 73 Main.main.addLayer(new OsmDataLayer(ds, tr("Converted from: {0}", layer.getName()), layer.getAssociatedFile())); 74 Main.main.removeLayer(layer); 129 final DataSet ds = convert(); 130 final OsmDataLayer layer = new OsmDataLayer(ds, tr("Converted from: {0}", this.layer.getName()), this.layer.getAssociatedFile()); 131 layer.setUploadDiscouraged(true); 132 Main.main.addLayer(layer); 133 Main.main.removeLayer(this.layer); 75 134 } 76 135 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r8510 r8804 48 48 import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToPreviousMarker; 49 49 import org.openstreetmap.josm.gui.layer.Layer; 50 import org.openstreetmap.josm.gui.layer.gpx.ConvertToDataLayerAction; 50 51 import org.openstreetmap.josm.tools.AudioPlayer; 51 52 import org.openstreetmap.josm.tools.ImageProvider; … … 261 262 components.add(new JumpToNextMarker(this)); 262 263 components.add(new JumpToPreviousMarker(this)); 264 components.add(new ConvertToDataLayerAction.FromMarkerLayer(this)); 263 265 components.add(new RenameLayerAction(getAssociatedFile(), this)); 264 266 components.add(SeparatorLayerAction.INSTANCE);
Note:
See TracChangeset
for help on using the changeset viewer.