Changeset 189 in josm for src


Ignore:
Timestamp:
2007-01-06T15:10:37+01:00 (18 years ago)
Author:
imi
Message:
  • added MarkerLayer (thanks Frederik)
Location:
src/org/openstreetmap/josm
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/actions/OpenAction.java

    r175 r189  
    1818import org.openstreetmap.josm.Main;
    1919import org.openstreetmap.josm.data.osm.DataSet;
     20import org.openstreetmap.josm.gui.layer.MarkerLayer;
    2021import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2122import org.openstreetmap.josm.gui.layer.RawGpsLayer;
     23import org.openstreetmap.josm.gui.layer.MarkerLayer.Marker;
    2224import org.openstreetmap.josm.gui.layer.RawGpsLayer.GpsPoint;
    2325import org.openstreetmap.josm.io.OsmReader;
     
    5759                try {
    5860                        if (asRawData(fn)) {
    59                                 Collection<Collection<GpsPoint>> data;
     61                                Collection<Collection<GpsPoint>> gpsData = null;
     62                                Collection<Marker> markerData = null;
    6063                                if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) {
    61                                         data = RawGpsReader.parse(new FileInputStream(file));
     64                                        RawGpsReader r = new RawGpsReader(new FileInputStream(file));
     65                                        gpsData = r.trackData;
     66                                        markerData = r.markerData;
    6267                                } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) {
    63                                         data = new LinkedList<Collection<GpsPoint>>();
    64                                         data.add(new RawCsvReader(new FileReader(file)).parse());
     68                                        gpsData = new LinkedList<Collection<GpsPoint>>();
     69                                        gpsData.add(new RawCsvReader(new FileReader(file)).parse());
    6570                                } else
    6671                                        throw new IllegalStateException();
    67                                 Main.main.addLayer(new RawGpsLayer(data, file.getName(), file));
     72                                if ((gpsData != null) && (!gpsData.isEmpty()))
     73                                        Main.main.addLayer(new RawGpsLayer(gpsData, tr("Tracks from {0}", file.getName()), file));
     74                                if ((markerData != null) && (!markerData.isEmpty()))
     75                                        Main.main.addLayer(new MarkerLayer(markerData, tr ("Markers from {0}", file.getName()), file));
     76                               
    6877                        } else {
    6978                                DataSet dataSet;
  • src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r175 r189  
    4848                        if (in == null)
    4949                                break;
    50                         Collection<Collection<GpsPoint>> allWays = RawGpsReader.parse(in);
     50                        // Use only track points, since the server mix everything together
     51                        Collection<Collection<GpsPoint>> allWays = new RawGpsReader(in).trackData;
     52
    5153                        boolean foundSomething = false;
    5254                        for (Collection<GpsPoint> t : allWays) {
  • src/org/openstreetmap/josm/io/RawGpsReader.java

    r118 r189  
    66import java.io.InputStream;
    77import java.io.InputStreamReader;
     8import java.util.ArrayList;
    89import java.util.Collection;
    910import java.util.LinkedList;
     
    1112
    1213import org.openstreetmap.josm.data.coor.LatLon;
     14import org.openstreetmap.josm.gui.layer.MarkerLayer.Marker;
    1315import org.openstreetmap.josm.gui.layer.RawGpsLayer.GpsPoint;
    1416import org.xml.sax.Attributes;
     
    2426public class RawGpsReader {
    2527
    26         private static class Parser extends MinML2 {
     28        /**
     29         * Hold the resulting gps data (tracks and their track points)
     30         */
     31        public Collection<Collection<GpsPoint>> trackData = new LinkedList<Collection<GpsPoint>>();
     32
     33        /**
     34         * Hold the waypoints of the gps data.
     35         */
     36        public Collection<Marker> markerData = new ArrayList<Marker>();
     37
     38        private class Parser extends MinML2 {
    2739                /**
    2840                 * Current track to be read. The last entry is the current trkpt.
     
    3042                 */
    3143                private Collection<GpsPoint> current = new LinkedList<GpsPoint>();
    32                 public Collection<Collection<GpsPoint>> data = new LinkedList<Collection<GpsPoint>>();
    3344                private LatLon currentLatLon;
    3445                private String currentTime = "";
     46                private String currentName = "";
    3547                private Stack<String> tags = new Stack<String>();
    3648
     
    5062                }
    5163                currentTime = "";
     64                currentName = "";
    5265                        }
    5366                        tags.push(qName);
     
    5568
    5669                @Override public void characters(char[] ch, int start, int length) {
    57                         if (tags.peek().equals("time")) {
    58                                 String time = tags.pop();
     70                        String peek = tags.peek();
     71                        if (peek.equals("time") || peek.equals("name")) {
     72                                String tag = tags.pop();
    5973                                if (tags.empty() || (!tags.peek().equals("wpt") && !tags.peek().equals("trkpt"))) {
    60                                         tags.push(time);
     74                                        tags.push(tag);
    6175                                        return;
    6276                                }
    63                                 String ct = new String(ch, start, length);
    64                                 currentTime += ct;
    65                                 tags.push(time);
     77                                String contents = new String(ch, start, length);
     78                                if (peek.equals("time")) currentTime += contents; else currentName += contents;
     79                                tags.push(tag);
    6680                        }
    6781                }
    6882
    6983                @Override public void endElement(String namespaceURI, String localName, String qName) {
    70                         if (qName.equals("wpt") || qName.equals("trkpt")) {
     84                        if (qName.equals("trkpt")) {
    7185                                current.add(new GpsPoint(currentLatLon, currentTime));
    7286                                currentTime = "";
     87                                currentName = "";
     88                        } else if (qName.equals("wpt")) {
     89                                markerData.add(new Marker(currentLatLon, currentName, null));
     90                                currentTime = "";
     91                                currentName = "";
    7392                        } else if (qName.equals("trkseg") || qName.equals("trk") || qName.equals("gpx")) {
    7493                                newTrack();
    7594                                currentTime = "";
     95                                currentName = "";
    7696                        }
    7797                        tags.pop();
     
    80100                private void newTrack() {
    81101                        if (!current.isEmpty()) {
    82                                 data.add(current);
     102                                trackData.add(current);
    83103                                current = new LinkedList<GpsPoint>();
    84104                        }
     
    86106        }
    87107
     108
    88109        /**
    89          * Parse and return the read data
     110         * Parse the input stream and store the result in trackData and markerData
    90111         */
    91         public static Collection<Collection<GpsPoint>> parse(InputStream source) throws SAXException, IOException {
     112        public RawGpsReader(InputStream source) throws SAXException, IOException {
    92113                Parser parser = new Parser();
    93114                parser.parse(new InputStreamReader(source, "UTF-8"));
    94                 return parser.data;
    95115        }
    96116}
Note: See TracChangeset for help on using the changeset viewer.