Changeset 14802 in josm


Ignore:
Timestamp:
2019-02-23T17:46:51+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #17131 - add mapcss function gpx_distance to get the distance to a gpx track (patch by Taylor Smock, modified)

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java

    r14156 r14802  
    1313import javax.swing.JOptionPane;
    1414
     15import org.openstreetmap.josm.data.gpx.GpxData;
    1516import org.openstreetmap.josm.data.osm.DataSet;
    1617import org.openstreetmap.josm.data.osm.OsmData;
    1718import org.openstreetmap.josm.gui.MainApplication;
    1819import org.openstreetmap.josm.gui.io.AsynchronousUploadPrimitivesTask;
     20import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer;
    1921import org.openstreetmap.josm.gui.util.GuiHelper;
    2022import org.openstreetmap.josm.tools.Logging;
     
    542544        }
    543545    }
     546
     547    /**
     548     * Returns all {@link GpxData} we can get from current layers.
     549     * @return all {@code GpxData} we can get from current layers
     550     * @since 14802
     551     */
     552    public List<GpxData> getAllGpxData() {
     553        List<GpxData> result = new ArrayList<>();
     554        for (Layer layer : getLayers()) {
     555            if (layer instanceof GpxLayer) {
     556                result.add(((GpxLayer) layer).data);
     557            } else if (layer instanceof GeoImageLayer) {
     558                result.add(((GeoImageLayer) layer).getFauxGpxLayer().data);
     559            }
     560        }
     561        return result;
     562    }
    544563}
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r14615 r14802  
    4343import org.openstreetmap.josm.data.ImageData;
    4444import org.openstreetmap.josm.data.ImageData.ImageDataUpdateListener;
     45import org.openstreetmap.josm.data.gpx.GpxData;
     46import org.openstreetmap.josm.data.gpx.WayPoint;
    4547import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    4648import org.openstreetmap.josm.gui.MainApplication;
     
    7678    private final ImageData data;
    7779    GpxLayer gpxLayer;
     80    GpxLayer gpxFauxLayer;
    7881
    7982    private final Icon icon = ImageProvider.get("dialogs/geoimage/photo-marker");
     
    925928    }
    926929
     930    /**
     931     * Returns a faux GPX layer built from the images or the associated GPX layer.
     932     * @return A faux GPX layer or the associated GPX layer
     933     * @since 14802
     934     */
     935    public synchronized GpxLayer getFauxGpxLayer() {
     936        if (gpxLayer != null) return getGpxLayer();
     937        if (gpxFauxLayer == null) {
     938            GpxData gpxData = new GpxData();
     939            List<ImageEntry> imageList = data.getImages();
     940            for (ImageEntry image : imageList) {
     941                WayPoint twaypoint = new WayPoint(image.getPos());
     942                gpxData.addWaypoint(twaypoint);
     943            }
     944            gpxFauxLayer = new GpxLayer(gpxData);
     945        }
     946        return gpxFauxLayer;
     947    }
     948
    927949    @Override
    928950    public void jumpToNextMarker() {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r14484 r14802  
    2525
    2626import org.openstreetmap.josm.data.coor.LatLon;
     27import org.openstreetmap.josm.data.gpx.GpxDistance;
    2728import org.openstreetmap.josm.data.osm.IPrimitive;
    2829import org.openstreetmap.josm.data.osm.Node;
     30import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2931import org.openstreetmap.josm.data.osm.Way;
    3032import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    3133import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
    3234import org.openstreetmap.josm.data.osm.search.SearchParseError;
     35import org.openstreetmap.josm.gui.MainApplication;
    3336import org.openstreetmap.josm.gui.mappaint.Cascade;
    3437import org.openstreetmap.josm.gui.mappaint.Environment;
     
    520523
    521524        /**
     525         * Returns the lowest distance between the OSM object and a GPX point
     526         * <p>
     527         * @param env the environment
     528         * @return the distance between the object and the closest gpx point or {@code Double.MAX_VALUE}
     529         * @since 14802
     530         */
     531        public static double gpx_distance(final Environment env) { // NO_UCD (unused code)
     532            if (env.osm instanceof OsmPrimitive) {
     533                return MainApplication.getLayerManager().getAllGpxData().stream()
     534                        .mapToDouble(gpx -> GpxDistance.getLowestDistance((OsmPrimitive) env.osm, gpx))
     535                        .min().orElse(Double.MAX_VALUE);
     536            }
     537            return Double.MAX_VALUE;
     538        }
     539
     540        /**
    522541         * Determines whether the object has a tag with the given key.
    523542         * @param env the environment
Note: See TracChangeset for help on using the changeset viewer.