Skip to content

Commit

Permalink
Merge pull request osmandapp#19758 from osmandapp/fix-19354-PT-subway
Browse files Browse the repository at this point in the history
Fix Hermannplatz only one metro line suggested
  • Loading branch information
Chumva authored May 9, 2024
2 parents 638f94a + 5ac05e9 commit f385b83
Showing 1 changed file with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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_UI = 150;
Expand Down Expand Up @@ -88,7 +88,7 @@ public List<TransportStopRoute> getTransportStopRoutes() {
protected List<TransportStopRoute> getSubTransportStopRoutes(boolean nearby) {
return nearby ? routesNearby : routesOnTheSameExit;
}

@Override
public boolean needStreetName() {
return Algorithms.isEmpty(getNameStr());
Expand Down Expand Up @@ -310,18 +310,23 @@ private static void processTransportStopAggregated(OsmandApplication app, Transp
private static TransportStopAggregated processTransportStopsForAmenity(List<TransportStop> transportStops, Amenity amenity) {
TransportStopAggregated stopAggregated = new TransportStopAggregated();
stopAggregated.setAmenity(amenity);
List<TransportStop> amenityStops = new ArrayList<>();
if ("subway_entrance".equals(amenity.getSubType())) {
amenityStops = findSubwayStopsForAmenityExit(transportStops, amenity.getLocation());
}
LatLon amenityLocation = amenity.getLocation();
for (TransportStop stop : transportStops) {
stop.setTransportStopAggregated(stopAggregated);
List<TransportStopExit> 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()) {
LatLon exitLocation = exit.getLocation();
if (MapUtils.getDistance(exitLocation, amenityLocation) < ROUNDING_ERROR
|| hasCommonExit(exitLocation, amenityStops)) {
stopAddedAsLocal = true;
stopAggregated.addLocalTransportStop(stop);
break;
Expand All @@ -338,6 +343,31 @@ private static TransportStopAggregated processTransportStopsForAmenity(List<Tran
return stopAggregated;
}

private static boolean hasCommonExit(@NonNull LatLon exitLocation, @NonNull List<TransportStop> amenityStops) {
for (TransportStop amenityStop : amenityStops) {
for (TransportStopExit amenityExit : amenityStop.getExits()) {
if (MapUtils.getDistance(amenityExit.getLocation(), exitLocation) < ROUNDING_ERROR) {
return true;
}
}
}
return false;
}

@NonNull
private static List<TransportStop> findSubwayStopsForAmenityExit(@NonNull List<TransportStop> transportStops,
@NonNull LatLon amenityExitLocation) {
List<TransportStop> foundStops = new ArrayList<>();
for (TransportStop stop : transportStops) {
for (TransportStopExit exit : stop.getExits()) {
if (MapUtils.getDistance(exit.getLocation(), amenityExitLocation) < ROUNDING_ERROR) {
foundStops.add(stop);
}
}
}
return foundStops;
}

private static boolean checkSameRoute(List<TransportStopRoute> stopRoutes, TransportRoute route) {
for (TransportStopRoute stopRoute : stopRoutes) {
if (stopRoute.route.compareRoute(route)) {
Expand Down

0 comments on commit f385b83

Please sign in to comment.