Index: applications/editors/josm/plugins/surveyor/build.xml
===================================================================
--- applications/editors/josm/plugins/surveyor/build.xml	(revision 6163)
+++ applications/editors/josm/plugins/surveyor/build.xml	(revision 6164)
@@ -21,5 +21,5 @@
   
   <!-- plugin meta data (enter new version number if anything changed!) -->
-  <property name="plugin.version" value="1.3.3"/>
+  <property name="plugin.version" value="1.4"/>
   <property name="plugin.description" value="Allow adding markers/nodes on current gps positions (V${plugin.version})."/>
   <property name="plugin.stage" value="60"/>
Index: applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveAction.java
===================================================================
--- applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveAction.java	(revision 6163)
+++ applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveAction.java	(revision 6164)
@@ -57,6 +57,5 @@
             
             String gpxFilename = MessageFormat.format(GPS_FILE_NAME_PATTERN, new Date());
-            task = new AutoSaveGpsAndMarkerLayerTimeTask(gpxFilename, 
-                LiveGpsLayer.LAYER_NAME, SetWaypointAction.MARKER_LAYER_NAME);
+            task = new AutoSaveGpsLayerTimerTask(gpxFilename, LiveGpsLayer.LAYER_NAME);
             gpsDataTimer.schedule(task, 1000, AUTO_SAVE_PERIOD_SEC * 1000);
             
Index: applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveGpsAndMarkerLayerTimeTask.java
===================================================================
--- applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveGpsAndMarkerLayerTimeTask.java	(revision 6163)
+++ 	(revision )
@@ -1,57 +1,0 @@
-/**
- * Copyright by Christof Dallermassl
- * This program is free software and licensed under GPL.
- */
-package at.dallermassl.josm.plugin.surveyor;
-
-import java.util.Collection;
-
-import org.openstreetmap.josm.gui.layer.RawGpsLayer;
-import org.openstreetmap.josm.gui.layer.markerlayer.Marker;
-import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
-import org.openstreetmap.josm.io.XmlWriter.OsmWriterInterface;
-
-/**
- * TimerTask that writes the data of a {@link RawGpsLayer} and from a {@link MarkerLayer} to a 
- * gpx file.
- * Every time the task is run, the layers are retrieved from the map view so it even works
- * if the layer does not exist at the start of the timer task. If the layer does not exist,
- * the file is not written.
- * 
- * @author cdaller
- *
- */
-public class AutoSaveGpsAndMarkerLayerTimeTask extends AutoSaveGpsLayerTimerTask {
-    private String markerLayerName;
-
-    /**
-     * Constructor using the file to write to and the names of the layers.
-     * @param filename the file to write to.
-     * @param gpsLayername the name of the layer holding the gps data.
-     * @param markerLayerName the name of the layer holding markers. 
-     */
-    public AutoSaveGpsAndMarkerLayerTimeTask(String filename, String gpsLayername, String markerLayerName) {
-        super(filename, gpsLayername);
-        this.markerLayerName = markerLayerName;
-    }
-
-    /* (non-Javadoc)
-     * @see at.dallermassl.josm.plugin.surveyor.AutoSaveGpsLayerTimerTask#getXmlWriter()
-     */
-    @Override
-    public OsmWriterInterface getXmlWriter() {
-        Collection<Collection<RawGpsLayer.GpsPoint>> gpsPoints = null;
-        Collection<Marker> markers = null;
-        
-        RawGpsLayer gpsLayer = findGpsLayer(getGpsLayerName(), RawGpsLayer.class);
-        if(gpsLayer != null) {
-            gpsPoints = gpsLayer.data;
-        }
-        MarkerLayer markerLayer = findGpsLayer(markerLayerName, MarkerLayer.class);
-        if(markerLayer != null) {
-            markers = markerLayer.data;
-        }
-        return new GpxTrackMarkerWriter(gpsPoints, markers);
-    }
-
-}
Index: applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveGpsLayerTimerTask.java
===================================================================
--- applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveGpsLayerTimerTask.java	(revision 6163)
+++ applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveGpsLayerTimerTask.java	(revision 6164)
@@ -7,7 +7,9 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
+import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.TimerTask;
 
@@ -17,11 +19,11 @@
 
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.gui.layer.Layer;
-import org.openstreetmap.josm.gui.layer.RawGpsLayer;
+import org.openstreetmap.josm.gui.layer.GpxLayer;
 import org.openstreetmap.josm.io.GpxWriter;
-import org.openstreetmap.josm.io.XmlWriter;
+
+import at.dallermassl.josm.plugin.surveyor.util.LayerUtil;
 
 /**
- * TimerTask that writes the data of a {@link RawGpsLayer} to a gpx file.
+ * TimerTask that writes the data of a {@link GpxLayer} to a gpx file.
  * Every time the task is run, the layer is retrieved from the map view so it even works
  * if the layer does not exist at the start of the timer task. If the layer does not exist,
@@ -61,66 +63,28 @@
 
         try {            
-            XmlWriter.OsmWriterInterface writer = getXmlWriter();
-            if(writer != null) {
-                // write to temporary file, on success, rename tmp file to target file:
-                File tmpFile = new File(file.getAbsoluteFile()+".tmp");
-                System.out.println("AutoSaving data to file " + file.getAbsolutePath());
-                // synchronize on layer to prevent concurrent adding of data to the layer
-                // quite a hack, but no other object to sync available :-(
-                // @see LiveGpsLayer
-                synchronized(LiveGpsLock.class) {
-                    XmlWriter.output(new FileOutputStream(tmpFile), writer);
-                }   
-                tmpFile.renameTo(file);
+
+            GpxLayer gpsLayer = LayerUtil.findGpsLayer(gpsLayerName, GpxLayer.class);
+            if(gpsLayer == null) {
+                return;
             }
-        } catch (IOException x) {
-            x.printStackTrace();
+            // write to temporary file, on success, rename tmp file to target file:
+            File tmpFile = new File(file.getAbsoluteFile()+".tmp");
+            System.out.println("AutoSaving data to file " + file.getAbsolutePath());
+            // synchronize on layer to prevent concurrent adding of data to the layer
+            // quite a hack, but no other object to sync available :-(
+            // @see LiveGpsLayer
+            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(tmpFile)));
+            GpxWriter gpxWriter = new GpxWriter(out);
+            synchronized(LiveGpsLock.class) {
+                gpxWriter.write(gpsLayer.data);
+            }   
+            tmpFile.renameTo(file);
+        } catch (IOException ioExc) {
+            ioExc.printStackTrace();
             JOptionPane.showMessageDialog(Main.parent, 
-                tr("Error while exporting {0}: {1}", file.getAbsoluteFile(), x.getMessage()), 
+                tr("Error while exporting {0}: {1}", file.getAbsoluteFile(), ioExc.getMessage()), 
                 tr("Error"), 
                 JOptionPane.ERROR_MESSAGE);
         }       
     }
-    
-    /**
-     * Returns the layer with the given name and type from the map view or <code>null</code>.
-     * @param <LayerType> the type of the layer.
-     * @param layerName the name of the layer.
-     * @param layerType the type of the layer.
-     * @return the layer or <code>null</code>.
-     */
-    public <LayerType extends Layer> LayerType findGpsLayer(String layerName, Class<LayerType> layerType) {
-        LayerType result = null;
-        if(Main.map != null && Main.map.mapView != null) {
-            for(Layer layer : Main.map.mapView.getAllLayers()) {
-                if(layerName.equals(layer.name) && layerType.isAssignableFrom(layer.getClass())) {
-                    result = (LayerType) layer;
-                    break;
-                }
-            }
-        }
-        return result;
-    }
-    
-    
-    /**
-     * Returns the writer that writes the data. Override this method, if another type
-     * of writer should be used.
-     * @return the writer.
-     */
-    public XmlWriter.OsmWriterInterface getXmlWriter() {
-        return null;
-
-        /*
-         * FIXME! this disables auto-save. need to work with new GPX writing code in JOSM.
-         *
-        RawGpsLayer gpsLayer = findGpsLayer(gpsLayerName, RawGpsLayer.class);
-        if(gpsLayer == null) {
-            return null;
-        }
-        return new GpxWriter.Trk(gpsLayer.data);
-        */
-    }
-
-
 }
Index: applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/action/SetWaypointAction.java
===================================================================
--- applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/action/SetWaypointAction.java	(revision 6163)
+++ applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/action/SetWaypointAction.java	(revision 6164)
@@ -7,9 +7,9 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
-import java.util.ArrayList;
 import java.util.Collection;
 
 import javax.swing.JToggleButton;
 
+import livegps.LiveGpsLayer;
 import livegps.LiveGpsLock;
 
@@ -17,4 +17,6 @@
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.gpx.GpxData;
+import org.openstreetmap.josm.data.gpx.WayPoint;
+import org.openstreetmap.josm.gui.layer.GpxLayer;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.markerlayer.Marker;
@@ -24,4 +26,5 @@
 import at.dallermassl.josm.plugin.surveyor.SurveyorPlugin;
 import at.dallermassl.josm.plugin.surveyor.action.gui.WaypointDialog;
+import at.dallermassl.josm.plugin.surveyor.util.LayerUtil;
 
 /**
@@ -33,4 +36,5 @@
  */
 public class SetWaypointAction extends AbstractSurveyorAction {
+    private LiveGpsLayer liveGpsLayer;
     private MarkerLayer markerLayer;
     public static final String MARKER_LAYER_NAME = "surveyorwaypointlayer";
@@ -38,5 +42,5 @@
     
     /**
-     * Default Condstructor
+     * Default Constructor.
      */
     public SetWaypointAction() {
@@ -51,5 +55,4 @@
         LatLon coordinates = event.getCoordinates();
         System.out.println(getClass().getSimpleName() + " KOORD: " + coordinates.lat() + ", " + coordinates.lon());
-        MarkerLayer layer = getGpsLayer();
         String markerTitle = getParameters().get(0);
         Object source = event.getSource();
@@ -74,21 +77,32 @@
         
         String iconName = getParameters().size() > 1 ? getParameters().get(1) : null;
+        
+        // add the waypoint to the marker layer AND to the gpx layer 
+        // (easy export of data + waypoints):
+        MarkerLayer layer = getMarkerLayer();
+        GpxLayer gpsLayer = getGpxLayer();
+        WayPoint waypoint = new WayPoint(event.getCoordinates());
+        waypoint.attr.put("name", markerText);
+        waypoint.attr.put("sym", iconName);
         synchronized(LiveGpsLock.class) {
             layer.data.add(new Marker(event.getCoordinates(), markerText, iconName));
+            if(gpsLayer != null) {
+                gpsLayer.data.waypoints.add(waypoint);
+            }
         }
+        
         Main.map.repaint();
     }
     
-    public MarkerLayer getGpsLayer() {
+    /**
+     * Returns the marker layer with the name {@link #MARKER_LAYER_NAME}.
+     * @return the marker layer with the name {@link #MARKER_LAYER_NAME}.
+     */
+    public MarkerLayer getMarkerLayer() {
         if(markerLayer == null) {
-            Collection<Layer> layers = Main.map.mapView.getAllLayers();
-            for (Layer layer : layers) {
-                if(MARKER_LAYER_NAME.equals(layer.name)) {
-                    markerLayer = (MarkerLayer) layer;
-                    break;
-                }
-            }
-            // not found:
+            markerLayer = LayerUtil.findGpsLayer(MARKER_LAYER_NAME, MarkerLayer.class);
+           
             if(markerLayer == null) {
+                // not found, add a new one
                 markerLayer = new MarkerLayer(new GpxData(), MARKER_LAYER_NAME, null);
                 Main.main.addLayer(markerLayer);
@@ -97,4 +111,21 @@
         return markerLayer;
     }
+    
+    /**
+     * Returns the gpx layer that is filled by the live gps data.
+     * @return the gpx layer that is filled by the live gps data.
+     */
+    public GpxLayer getGpxLayer() {
+        if(liveGpsLayer == null) {
+            Collection<Layer> layers = Main.map.mapView.getAllLayers();
+            for (Layer layer : layers) {
+                if(layer instanceof LiveGpsLayer) {
+                    liveGpsLayer = (LiveGpsLayer) layer;
+                    break;
+                }
+            } 
+        }
+        return liveGpsLayer;
+    }
 
 }
Index: applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/util/LayerUtil.java
===================================================================
--- applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/util/LayerUtil.java	(revision 6164)
+++ applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/util/LayerUtil.java	(revision 6164)
@@ -0,0 +1,35 @@
+/**
+ * 
+ */
+package at.dallermassl.josm.plugin.surveyor.util;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.layer.Layer;
+
+/**
+ * @author cdaller
+ *
+ */
+public class LayerUtil {
+
+    /**
+     * Returns the layer with the given name and type from the map view or <code>null</code>.
+     * @param <LayerType> the type of the layer.
+     * @param layerName the name of the layer.
+     * @param layerType the type of the layer.
+     * @return the layer or <code>null</code>.
+     */
+    public static <LayerType extends Layer> LayerType findGpsLayer(String layerName, Class<LayerType> layerType) {
+        LayerType result = null;
+        if(Main.map != null && Main.map.mapView != null) {
+            for(Layer layer : Main.map.mapView.getAllLayers()) {
+                if(layerName.equals(layer.name) && layerType.isAssignableFrom(layer.getClass())) {
+                    result = (LayerType) layer;
+                    break;
+                }
+            }
+        }
+        return result;
+    }
+
+}
