mirror of
https://gitlab.com/oeffi/oeffi.git
synced 2025-07-07 06:08:51 +00:00
StationsActivity: Fix zoom to general area if no station is selected.
This commit is contained in:
parent
2d3e76f534
commit
c7ece64273
2 changed files with 28 additions and 2 deletions
|
@ -606,6 +606,27 @@ public class OeffiMapView extends MapView {
|
|||
}
|
||||
}
|
||||
|
||||
public void zoomToStations(final List<Station> stations) {
|
||||
// show at least 16 stations
|
||||
final List<GeoPoint> points = new LinkedList<>();
|
||||
for (final Station station : stations) {
|
||||
points.add(new GeoPoint(station.location.getLatAsDouble(), station.location.getLonAsDouble()));
|
||||
if (points.size() >= 16)
|
||||
break;
|
||||
}
|
||||
|
||||
// make sure a minimum area is shown
|
||||
final GeoPoint centerPoint = points.get(0);
|
||||
final float delta = 0.002f;
|
||||
points.add(new GeoPoint(centerPoint.getLatitude() - delta, centerPoint.getLongitude() - delta));
|
||||
points.add(new GeoPoint(centerPoint.getLatitude() + delta, centerPoint.getLongitude() + delta));
|
||||
final BoundingBox boundingBox = BoundingBox.fromGeoPoints(points).increaseByScale(1.05f);
|
||||
|
||||
// zoom
|
||||
zoomToBoundingBox(boundingBox, !firstLocation);
|
||||
firstLocation = false;
|
||||
}
|
||||
|
||||
private void showZoomControls() {
|
||||
zoomControls.clearAnimation();
|
||||
zoomControls.startAnimation(zoomControlsAnimation);
|
||||
|
|
|
@ -37,6 +37,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.osmdroid.util.BoundingBox;
|
||||
import org.osmdroid.util.GeoPoint;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -1025,6 +1026,9 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
|||
mapView.invalidate();
|
||||
}
|
||||
|
||||
if (added)
|
||||
mapView.zoomToStations(stations);
|
||||
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
|
@ -1313,8 +1317,9 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
|||
|
||||
// scroll map
|
||||
if (station != null && station.location.hasLocation())
|
||||
mapView.getController()
|
||||
.animateTo(new GeoPoint(station.location.getLatAsDouble(), station.location.getLonAsDouble()));
|
||||
mapView.zoomToStations(Arrays.asList(station));
|
||||
else if (!stations.isEmpty())
|
||||
mapView.zoomToStations(stations);
|
||||
else if (station == null && deviceLocation != null)
|
||||
mapView.getController()
|
||||
.animateTo(new GeoPoint(deviceLocation.getLatAsDouble(), deviceLocation.getLonAsDouble()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue