Ignore:
Timestamp:
2014-09-21T23:00:38+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #7976 - Get downloaded gpx areas, on the same model as osm data

Location:
trunk/src/org/openstreetmap/josm/data/gpx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxConstants.java

    r7518 r7575  
    3939    public static final String META_NAME = META_PREFIX + "name";
    4040    public static final String META_TIME = META_PREFIX + "time";
     41    public static final String META_BOUNDS = META_PREFIX + "bounds";
    4142    public static final String META_EXTENSIONS = META_PREFIX + "extensions";
    4243
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r7518 r7575  
    22package org.openstreetmap.josm.data.gpx;
    33
     4import java.awt.geom.Area;
    45import java.io.File;
    56import java.util.Collection;
    67import java.util.Date;
     8import java.util.HashSet;
    79import java.util.Iterator;
    810import java.util.LinkedList;
     11import java.util.List;
    912import java.util.Map;
     13import java.util.Set;
    1014
    1115import org.openstreetmap.josm.Main;
    1216import org.openstreetmap.josm.data.Bounds;
     17import org.openstreetmap.josm.data.Data;
     18import org.openstreetmap.josm.data.DataSource;
    1319import org.openstreetmap.josm.data.coor.EastNorth;
    1420
     
    2026 * @author Raphael Mack <ramack@raphael-mack.de>
    2127 */
    22 public class GpxData extends WithAttributes {
     28public class GpxData extends WithAttributes implements Data {
    2329
    2430    public File storageFile;
     
    3036    public final Collection<GpxRoute> routes = new LinkedList<>();
    3137    public final Collection<WayPoint> waypoints = new LinkedList<>();
     38
     39    /**
     40     * All data sources (bounds of downloaded bounds) of this GpxData.<br>
     41     * Not part of GPX standard but rather a JOSM extension, needed by the fact that
     42     * OSM API does not provide {@code <bounds>} element in its GPX reply.
     43     * @since 7575
     44     */
     45    public final Set<DataSource> dataSources = new HashSet<>();
    3246
    3347    public void mergeFrom(GpxData other) {
     
    5266        routes.addAll(other.routes);
    5367        waypoints.addAll(other.waypoints);
    54     }
    55 
     68        dataSources.addAll(other.dataSources);
     69    }
     70
     71    /**
     72     * Determines if this GPX data has one or more track points
     73     * @return {@code true} if this GPX data has track points, {@code false} otherwise
     74     */
    5675    public boolean hasTrackPoints() {
    5776        for (GpxTrack trk : tracks) {
     
    6483    }
    6584
     85    /**
     86     * Determines if this GPX data has one or more route points
     87     * @return {@code true} if this GPX data has route points, {@code false} otherwise
     88     */
    6689    public boolean hasRoutePoints() {
    6790        for (GpxRoute rte : routes) {
     
    7295    }
    7396
     97    /**
     98     * Determines if this GPX data is empty (i.e. does not contain any point)
     99     * @return {@code true} if this GPX data is empty, {@code false} otherwise
     100     */
    74101    public boolean isEmpty() {
    75102        return !hasRoutePoints() && !hasTrackPoints() && waypoints.isEmpty();
     
    77104
    78105    /**
    79      * calculates the bounding box of available data and returns it.
     106     * Returns the bounds defining the extend of this data, as read in metadata, if any.
     107     * If no bounds is defined in metadata, {@code null} is returned. There is no guarantee
     108     * that data entirely fit in this bounds, as it is not recalculated. To get recalculated bounds,
     109     * see {@link #recalculateBounds()}. To get downloaded areas, see {@link #dataSources}.
     110     * @return the bounds defining the extend of this data, or {@code null}.
     111     * @see #recalculateBounds()
     112     * @see #dataSources
     113     * @since 7575
     114     */
     115    public Bounds getMetaBounds() {
     116        Object value = get(META_BOUNDS);
     117        if (value instanceof Bounds) {
     118            return (Bounds) value;
     119        }
     120        return null;
     121    }
     122
     123    /**
     124     * Calculates the bounding box of available data and returns it.
    80125     * The bounds are not stored internally, but recalculated every time
    81      * this function is called.
     126     * this function is called.<br>
     127     * To get bounds as read from metadata, see {@link #getMetaBounds()}.<br>
     128     * To get downloaded areas, see {@link #dataSources}.<br>
    82129     *
    83130     * FIXME might perhaps use visitor pattern?
    84131     * @return the bounds
     132     * @see #getMetaBounds()
     133     * @see #dataSources
    85134     */
    86135    public Bounds recalculateBounds() {
     
    119168     * @return the length in meters
    120169     */
    121     public double length(){
     170    public double length() {
    122171        double result = 0.0; // in meters
    123172
     
    402451    }
    403452
     453    @Override
     454    public Collection<DataSource> getDataSources() {
     455        return dataSources;
     456    }
     457
     458    @Override
     459    public Area getDataSourceArea() {
     460        return DataSource.getDataSourceArea(dataSources);
     461    }
     462
     463    @Override
     464    public List<Bounds> getDataSourceBounds() {
     465        return DataSource.getDataSourceBounds(dataSources);
     466    }
    404467}
Note: See TracChangeset for help on using the changeset viewer.