Fix transport stop menu (stops close to each other) #5117
This commit is contained in:
parent
159796f3e2
commit
d81c98a13b
2 changed files with 30 additions and 7 deletions
|
@ -1,8 +1,9 @@
|
|||
package net.osmand.data;
|
||||
|
||||
public class TransportStop extends MapObject {
|
||||
int[] referencesToRoutes = null;
|
||||
|
||||
private int[] referencesToRoutes = null;
|
||||
public int distance;
|
||||
|
||||
public TransportStop(){
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,8 @@ import net.osmand.util.Algorithms;
|
|||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -754,13 +756,20 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
List<TransportStop> transportStops = findTransportStopsAt(latLon.getLatitude(), latLon.getLongitude());
|
||||
List<TransportStop> transportStopsReplacement = new ArrayList<>();
|
||||
for (Amenity amenity : transportStopAmenities) {
|
||||
List<TransportStop> amenityTransportStops = new ArrayList<>();
|
||||
for (TransportStop transportStop : transportStops) {
|
||||
if (transportStop.getName().startsWith(amenity.getName())) {
|
||||
selectedObjects.remove(amenity);
|
||||
if (!transportStopsReplacement.contains(transportStop)) {
|
||||
transportStopsReplacement.add(transportStop);
|
||||
}
|
||||
break;
|
||||
amenityTransportStops.add(transportStop);
|
||||
}
|
||||
}
|
||||
if (amenityTransportStops.size() > 0) {
|
||||
selectedObjects.remove(amenity);
|
||||
if (amenityTransportStops.size() > 1) {
|
||||
sort(amenity.getLocation(), amenityTransportStops);
|
||||
}
|
||||
TransportStop amenityTransportStop = amenityTransportStops.get(0);
|
||||
if (!transportStopsReplacement.contains(amenityTransportStop)) {
|
||||
transportStopsReplacement.add(amenityTransportStop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -776,6 +785,19 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
}
|
||||
}
|
||||
|
||||
private void sort(@NonNull LatLon latLon, List<TransportStop> transportStops) {
|
||||
for (TransportStop transportStop : transportStops) {
|
||||
transportStop.distance = (int) MapUtils.getDistance(latLon, transportStop.getLocation());
|
||||
}
|
||||
Collections.sort(transportStops, new Comparator<TransportStop>() {
|
||||
|
||||
@Override
|
||||
public int compare(TransportStop s1, TransportStop s2) {
|
||||
return Algorithms.compare(s1.distance, s2.distance);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private List<TransportStop> findTransportStopsAt(double latitude, double longitude) {
|
||||
ArrayList<TransportStop> transportStops = new ArrayList<>();
|
||||
|
|
Loading…
Reference in a new issue