diff --git a/OsmAnd/src/net/osmand/plus/track/clickable/ClickableWay.java b/OsmAnd/src/net/osmand/plus/track/clickable/ClickableWay.java index bcfd86a34a0..f9c0510be83 100644 --- a/OsmAnd/src/net/osmand/plus/track/clickable/ClickableWay.java +++ b/OsmAnd/src/net/osmand/plus/track/clickable/ClickableWay.java @@ -26,6 +26,10 @@ public ClickableWay(@NonNull GpxFile gpxFile, long osmId, @Nullable String name, this.selectedGpxPoint = new SelectedGpxPoint(null, wpt); } + public long getOsmId() { + return osmId; + } + public GpxFile getGpxFile() { return gpxFile; } @@ -34,6 +38,10 @@ public SelectedGpxPoint getSelectedGpxPoint() { return selectedGpxPoint; } + public String getGpxFileName() { + return Algorithms.sanitizeFileName(getWayName()); + } + public String getWayName() { return Algorithms.isEmpty(name) ? Long.toString(osmId) : name; } diff --git a/OsmAnd/src/net/osmand/plus/track/clickable/ClickableWayActivator.java b/OsmAnd/src/net/osmand/plus/track/clickable/ClickableWayActivator.java index dd16a9fd638..b8f9175f62e 100644 --- a/OsmAnd/src/net/osmand/plus/track/clickable/ClickableWayActivator.java +++ b/OsmAnd/src/net/osmand/plus/track/clickable/ClickableWayActivator.java @@ -18,7 +18,6 @@ import net.osmand.shared.gpx.GpxFile; import net.osmand.shared.gpx.GpxTrackAnalysis; import net.osmand.shared.gpx.primitives.WptPt; -import net.osmand.util.Algorithms; import java.io.File; import java.util.List; @@ -40,8 +39,8 @@ public boolean showMenuAction(@Nullable Object object) { GpxFile gpxFile = that.getGpxFile(); GpxTrackAnalysis analysis = gpxFile.getAnalysis(0); WptPt selectedPoint = that.getSelectedGpxPoint().getSelectedPoint(); - String safeFileName = Algorithms.sanitizeFileName(that.getWayName()); - File file = new File(FileUtils.getTempDir(app), safeFileName + GPX_FILE_EXT); + String safeFileName = that.getGpxFileName() + GPX_FILE_EXT; + File file = new File(FileUtils.getTempDir(app), safeFileName); GpxUiHelper.saveAndOpenGpx(mapActivity, file, gpxFile, selectedPoint, analysis, null, true); return true; } diff --git a/OsmAnd/src/net/osmand/plus/track/clickable/ClickableWayLoader.java b/OsmAnd/src/net/osmand/plus/track/clickable/ClickableWayLoader.java index 506b4f506d8..80580c333cb 100644 --- a/OsmAnd/src/net/osmand/plus/track/clickable/ClickableWayLoader.java +++ b/OsmAnd/src/net/osmand/plus/track/clickable/ClickableWayLoader.java @@ -2,6 +2,9 @@ import static net.osmand.data.MapObject.AMENITY_ID_RIGHT_SHIFT; +// THINK use similar icon="piste_high_difficulty" for no-name pistes +// THINK auto-reverse Way (assume downhill OR detect start by minDist to currentLocation) + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -137,16 +140,14 @@ private ClickableWay searchClickableWay(LatLon searchLatLon, int searchRadius, String color = getGpxColorByTags(tags); if (color != null) { - System.err.printf("XXX color (%s)\n", color); gpxFile.setColor(color); } - // TODO check unique gpx // TODO cache - // TODO close previous on open new - // TODO fetch elevation data from routing-section + + // TODO fetch elevation data from routing-section - RouteSectionReader.java + // TODO calc distance stats, elevation stats, etc (automatically if data exists) - // THINK auto-reverse Way (assume downhill OR detect start by minDist to currentLocation) return new ClickableWay(gpxFile, osmId, name, searchLatLon); } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java index e5bc8fb163a..e07b5862649 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java @@ -477,7 +477,7 @@ private Amenity getAmenity(LatLon latLon, ObfMapObject obfMapObject, Map tags) { ClickableWay clickableWay = clickableWayLoader.searchClickableWayV2(result.pointLatLon, obfMapObject, tags); - if (clickableWay != null) { + if (clickableWay != null && isUniqueClickableWay(result.selectedObjects, clickableWay)) { result.selectedObjects.put(clickableWay, clickableWayLoader.getContextMenuProvider()); return true; } return false; } - private boolean isUniqueGpx(@NonNull Map selectedObjects, - @NonNull TravelGpx travelGpx) { - String travelGpxFileName = travelGpx.getGpxFileName() + GPX_FILE_EXT; + private boolean isUniqueGpxFileName(Map selectedObjects, String gpxFileName) { + for (Map.Entry entry : selectedObjects.entrySet()) { + if (entry.getKey() instanceof SelectedGpxPoint && entry.getValue() instanceof GPXLayer) { + SelectedGpxPoint selectedGpxPoint = (SelectedGpxPoint) entry.getKey(); + if (selectedGpxPoint.getSelectedGpxFile().getGpxFile().getPath().endsWith(gpxFileName)) { + return false; + } + } + } + return true; + } + + private boolean isUniqueClickableWay(@NonNull Map selectedObjects, + @NonNull ClickableWay clickableWay) { + for (Object object : selectedObjects.keySet()) { + if (object instanceof ClickableWay that) { + if (clickableWay.getOsmId() == that.getOsmId()) { + return false; + } + } + } + return isUniqueGpxFileName(selectedObjects, clickableWay.getGpxFileName() + GPX_FILE_EXT); + } + + private boolean isUniqueTravelGpx(@NonNull Map selectedObjects, + @NonNull TravelGpx travelGpx) { for (Map.Entry entry : selectedObjects.entrySet()) { if (entry.getKey() instanceof Pair && entry.getValue() instanceof GPXLayer && ((Pair) entry.getKey()).first instanceof TravelGpx) { @@ -520,14 +543,8 @@ private boolean isUniqueGpx(@NonNull Map selectedO return false; } } - if (entry.getKey() instanceof SelectedGpxPoint && entry.getValue() instanceof GPXLayer) { - SelectedGpxPoint selectedGpxPoint = (SelectedGpxPoint) entry.getKey(); - if (selectedGpxPoint.getSelectedGpxFile().getGpxFile().getPath().endsWith(travelGpxFileName)) { - return false; - } - } } - return true; + return isUniqueGpxFileName(selectedObjects, travelGpx.getGpxFileName() + GPX_FILE_EXT); } private void addOsmRoute(@NonNull MapSelectionResult result, @NonNull RotatedTileBox tileBox, @NonNull PointF point, @@ -582,13 +599,13 @@ private void putRouteGpxToSelected(@NonNull Map se log.error(e); } for (RouteKey routeKey : routes.keySet()) { - if (isUniqueRoute(selectedObjects.keySet(), routeKey)) { + if (isUniqueOsmRoute(selectedObjects.keySet(), routeKey)) { selectedObjects.put(new Pair<>(routeKey, rect), provider); } } } - private boolean isUniqueRoute(@NonNull Set set, @NonNull RouteKey tmpRouteKey) { + private boolean isUniqueOsmRoute(@NonNull Set set, @NonNull RouteKey tmpRouteKey) { for (Object selectedObject : set) { if (selectedObject instanceof Pair && ((Pair) selectedObject).first instanceof RouteKey) { RouteKey routeKey = (RouteKey) ((Pair) selectedObject).first;