Search in sources :

Example 1 with BoundingBox

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();
}
Also used : GeoPoint(org.osmdroid.util.GeoPoint) BoundingBox(org.osmdroid.util.BoundingBox) Handler(android.os.Handler)

Example 2 with BoundingBox

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();
}
Also used : GeoPoint(org.osmdroid.util.GeoPoint) BoundingBox(org.osmdroid.util.BoundingBox) Handler(android.os.Handler)

Example 3 with BoundingBox

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);
        }
    }
}
Also used : IGeoPoint(org.osmdroid.api.IGeoPoint) GeoPoint(org.osmdroid.util.GeoPoint) MapPoint(org.odk.collect.geo.maps.MapPoint) BoundingBox(org.osmdroid.util.BoundingBox) ArrayList(java.util.ArrayList) Handler(android.os.Handler) IGeoPoint(org.osmdroid.api.IGeoPoint) Paint(android.graphics.Paint) MapPoint(org.odk.collect.geo.maps.MapPoint) GeoPoint(org.osmdroid.util.GeoPoint)

Aggregations

Handler (android.os.Handler)3 BoundingBox (org.osmdroid.util.BoundingBox)3 GeoPoint (org.osmdroid.util.GeoPoint)3 Paint (android.graphics.Paint)1 ArrayList (java.util.ArrayList)1 MapPoint (org.odk.collect.geo.maps.MapPoint)1 IGeoPoint (org.osmdroid.api.IGeoPoint)1