use of org.osmdroid.util.BoundingBox in project collect by opendatakit.
the class GeoShapeOsmMapActivity method zoomToBounds.
/*
This functions should be added to the mapHelper Class
*/
private void zoomToBounds() {
map.getController().setZoom(4);
map.invalidate();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
double minLat = Double.MAX_VALUE;
double maxLat = Double.MIN_VALUE;
double minLong = Double.MAX_VALUE;
double maxLong = Double.MIN_VALUE;
Integer size = mapMarkers.size();
for (int i = 0; i < size; i++) {
GeoPoint tempMarker = mapMarkers.get(i).getPosition();
if (tempMarker.getLatitude() < minLat) {
minLat = tempMarker.getLatitude();
}
if (tempMarker.getLatitude() > maxLat) {
maxLat = tempMarker.getLatitude();
}
if (tempMarker.getLongitude() < minLong) {
minLong = tempMarker.getLongitude();
}
if (tempMarker.getLongitude() > maxLong) {
maxLong = tempMarker.getLongitude();
}
}
BoundingBox boundingBox = new BoundingBox(maxLat, maxLong, minLat, minLong);
map.zoomToBoundingBox(boundingBox, false);
map.invalidate();
}
}, 100);
map.invalidate();
}
use of org.osmdroid.util.BoundingBox in project collect by opendatakit.
the class GeoTraceOsmMapActivity method zoomToBounds.
private void zoomToBounds() {
mapView.getController().setZoom(4);
mapView.invalidate();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
double minLat = Double.MAX_VALUE;
double maxLat = Double.MIN_VALUE;
double minLong = Double.MAX_VALUE;
double maxLong = Double.MIN_VALUE;
Integer size = mapMarkers.size();
for (int i = 0; i < size; i++) {
GeoPoint tempMarker = mapMarkers.get(i).getPosition();
if (tempMarker.getLatitude() < minLat) {
minLat = tempMarker.getLatitude();
}
if (tempMarker.getLatitude() > maxLat) {
maxLat = tempMarker.getLatitude();
}
if (tempMarker.getLongitude() < minLong) {
minLong = tempMarker.getLongitude();
}
if (tempMarker.getLongitude() > maxLong) {
maxLong = tempMarker.getLongitude();
}
}
BoundingBox boundingBox = new BoundingBox(maxLat, maxLong, minLat, minLong);
mapView.zoomToBoundingBox(boundingBox, false);
mapView.invalidate();
}
}, 100);
mapView.invalidate();
}
use of org.osmdroid.util.BoundingBox in project collect by opendatakit.
the class OsmDroidMapFragment method zoomToBoundingBox.
@Override
public void zoomToBoundingBox(Iterable<MapPoint> points, double scaleFactor, boolean animate) {
if (points != null) {
int count = 0;
List<GeoPoint> geoPoints = new ArrayList<>();
MapPoint lastPoint = null;
for (MapPoint point : points) {
lastPoint = point;
geoPoints.add(toGeoPoint(point));
count++;
}
if (count == 1) {
zoomToPoint(lastPoint, animate);
} else if (count > 1) {
// TODO(ping): Find a better solution.
// zoomToBoundingBox sometimes fails to zoom correctly, either
// zooming by the correct amount but leaving the bounding box
// off-center, or centering correctly but not zooming in enough.
// Adding a 100-ms delay avoids the problem most of the time, but
// not always; it's here because the old GeoShapeOsmMapActivity
// did it, not because it's known to be the best solution.
final BoundingBox box = BoundingBox.fromGeoPoints(geoPoints).increaseByScale((float) (1 / scaleFactor));
new Handler().postDelayed(() -> map.zoomToBoundingBox(box, animate), 100);
}
}
}