From 6e1e28d2ac4252d866d5fd0f2a3d41e7f6227a1d Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 1 May 2024 19:38:26 +0300 Subject: [PATCH 1/2] Fix Hermannplatz only one metro line suggested --- .../controllers/TransportStopController.java | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index 43af118b8d1..3935c55aca9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -1,5 +1,7 @@ package net.osmand.plus.mapcontextmenu.controllers; +import static net.osmand.util.MapUtils.ROUNDING_ERROR; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -27,8 +29,6 @@ import java.util.Comparator; import java.util.List; -import static net.osmand.util.MapUtils.ROUNDING_ERROR; - public class TransportStopController extends MenuController { public static final int SHOW_STOPS_RADIUS_METERS = 150; @@ -40,8 +40,8 @@ public class TransportStopController extends MenuController { private TransportStopType topType; public TransportStopController(@NonNull MapActivity mapActivity, - @NonNull PointDescription pointDescription, - @NonNull TransportStop transportStop) { + @NonNull PointDescription pointDescription, + @NonNull TransportStop transportStop) { super(new TransportStopMenuBuilder(mapActivity, transportStop), pointDescription, mapActivity); this.transportStop = transportStop; processRoutes(); @@ -86,7 +86,7 @@ public List getTransportStopRoutes() { protected List getSubTransportStopRoutes(boolean nearby) { return nearby ? routesNearby : routesOnTheSameExit; } - + @Override public boolean needStreetName() { return Algorithms.isEmpty(getNameStr()); @@ -300,18 +300,22 @@ private static void processTransportStopAggregated(OsmandApplication app, Transp private static TransportStopAggregated processTransportStopsForAmenity(List transportStops, Amenity amenity) { TransportStopAggregated stopAggregated = new TransportStopAggregated(); stopAggregated.setAmenity(amenity); + List amenityStops = null; + if ("subway_entrance".equals(amenity.getSubType())) { + amenityStops = findSubwayStopsForSubwayExit(transportStops, amenity); + } LatLon amenityLocation = amenity.getLocation(); for (TransportStop stop : transportStops) { stop.setTransportStopAggregated(stopAggregated); - List stopExits = stop.getExits(); boolean stopAddedAsLocal = false; if ("public_transport_station".equals(amenity.getSubType()) && (stop.getName().equals(amenity.getName()) || stop.getEnName(false).equals(amenity.getEnName(false)))) { stopAggregated.addLocalTransportStop(stop); stopAddedAsLocal = true; } else { - for (TransportStopExit exit : stopExits) { - if (MapUtils.getDistance(exit.getLocation(), amenityLocation) < ROUNDING_ERROR) { + for (TransportStopExit exit : stop.getExits()) { + if (MapUtils.getDistance(exit.getLocation(), amenityLocation) < ROUNDING_ERROR + || isEqualsToAnyStopExit(exit.getLocation(), amenityStops)) { stopAddedAsLocal = true; stopAggregated.addLocalTransportStop(stop); break; @@ -328,6 +332,35 @@ private static TransportStopAggregated processTransportStopsForAmenity(List amenityStops) { + if (amenityStops == null) { + return false; + } + for (TransportStop amenityStop : amenityStops) { + for (TransportStopExit amenityExit : amenityStop.getExits()) { + if (MapUtils.getDistance(amenityExit.getLocation(), exit) < ROUNDING_ERROR) { + return true; + } + } + } + return false; + } + + private static List findSubwayStopsForSubwayExit(List transportStops, Amenity amenity) { + List foundStops = null; + for (TransportStop stop : transportStops) { + for (TransportStopExit exit : stop.getExits()) { + if (MapUtils.getDistance(exit.getLocation(), amenity.getLocation()) < ROUNDING_ERROR) { + if (foundStops == null) { + foundStops = new ArrayList<>(); + } + foundStops.add(stop); + } + } + } + return foundStops; + } + private static boolean checkSameRoute(List stopRoutes, TransportRoute route) { for (TransportStopRoute stopRoute : stopRoutes) { if (stopRoute.route.compareRoute(route)) { From 5ac05e9d560edc28a86e93346775f8d210550aad Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 9 May 2024 16:32:49 +0300 Subject: [PATCH 2/2] Fix review --- .../controllers/TransportStopController.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index 3935c55aca9..272e11379a2 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -300,9 +300,9 @@ private static void processTransportStopAggregated(OsmandApplication app, Transp private static TransportStopAggregated processTransportStopsForAmenity(List transportStops, Amenity amenity) { TransportStopAggregated stopAggregated = new TransportStopAggregated(); stopAggregated.setAmenity(amenity); - List amenityStops = null; + List amenityStops = new ArrayList<>(); if ("subway_entrance".equals(amenity.getSubType())) { - amenityStops = findSubwayStopsForSubwayExit(transportStops, amenity); + amenityStops = findSubwayStopsForAmenityExit(transportStops, amenity.getLocation()); } LatLon amenityLocation = amenity.getLocation(); for (TransportStop stop : transportStops) { @@ -314,8 +314,9 @@ private static TransportStopAggregated processTransportStopsForAmenity(List amenityStops) { - if (amenityStops == null) { - return false; - } + private static boolean hasCommonExit(@NonNull LatLon exitLocation, @NonNull List amenityStops) { for (TransportStop amenityStop : amenityStops) { for (TransportStopExit amenityExit : amenityStop.getExits()) { - if (MapUtils.getDistance(amenityExit.getLocation(), exit) < ROUNDING_ERROR) { + if (MapUtils.getDistance(amenityExit.getLocation(), exitLocation) < ROUNDING_ERROR) { return true; } } @@ -346,14 +344,13 @@ private static boolean isEqualsToAnyStopExit(LatLon exit, List am return false; } - private static List findSubwayStopsForSubwayExit(List transportStops, Amenity amenity) { - List foundStops = null; + @NonNull + private static List findSubwayStopsForAmenityExit(@NonNull List transportStops, + @NonNull LatLon amenityExitLocation) { + List foundStops = new ArrayList<>(); for (TransportStop stop : transportStops) { for (TransportStopExit exit : stop.getExits()) { - if (MapUtils.getDistance(exit.getLocation(), amenity.getLocation()) < ROUNDING_ERROR) { - if (foundStops == null) { - foundStops = new ArrayList<>(); - } + if (MapUtils.getDistance(exit.getLocation(), amenityExitLocation) < ROUNDING_ERROR) { foundStops.add(stop); } }