Ignore:
Timestamp:
2019-02-23T17:46:51+01:00 (7 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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.