Search in sources :

Example 11 with MapPoint

use of org.odk.collect.geo.maps.MapPoint in project collect by opendatakit.

the class MapboxMapFragment method zoomToBoundingBox.

@Override
public void zoomToBoundingBox(Iterable<MapPoint> points, double scaleFactor, boolean animate) {
    if (map == null) {
        // during Robolectric tests, map will be null
        return;
    }
    if (points != null) {
        int count = 0;
        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        MapPoint lastPoint = null;
        for (MapPoint point : points) {
            lastPoint = point;
            builder.include(toLatLng(point));
            count++;
        }
        if (count == 1) {
            zoomToPoint(lastPoint, animate);
        } else if (count > 1) {
            final LatLngBounds bounds = expandBounds(builder.build(), 1 / scaleFactor);
            new Handler().postDelayed(() -> {
                moveOrAnimateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0), animate);
            }, 100);
        }
    }
}
Also used : MapPoint(org.odk.collect.geo.maps.MapPoint) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Handler(android.os.Handler) MapPoint(org.odk.collect.geo.maps.MapPoint) SuppressLint(android.annotation.SuppressLint)

Example 12 with MapPoint

use of org.odk.collect.geo.maps.MapPoint in project collect by opendatakit.

the class OsmDroidMapFragment method addMarker.

@Override
public int addMarker(MapPoint point, boolean draggable, @IconAnchor String iconAnchor) {
    int featureId = nextFeatureId++;
    features.put(featureId, new MarkerFeature(map, point, draggable, iconAnchor));
    return featureId;
}
Also used : IGeoPoint(org.osmdroid.api.IGeoPoint) Paint(android.graphics.Paint) MapPoint(org.odk.collect.geo.maps.MapPoint) GeoPoint(org.osmdroid.util.GeoPoint)

Example 13 with MapPoint

use of org.odk.collect.geo.maps.MapPoint in project collect by opendatakit.

the class OsmDroidMapFragment method createMarker.

private Marker createMarker(MapView map, MapPoint point, MapFeature feature, @IconAnchor String iconAnchor) {
    // A Marker's position is a GeoPoint with latitude, longitude, and
    // altitude fields.  We need to store the standard deviation value
    // somewhere, so it goes in the marker's sub-description field.
    Marker marker = new Marker(map);
    marker.setPosition(toGeoPoint(point));
    marker.setSubDescription(Double.toString(point.sd));
    marker.setDraggable(feature != null);
    marker.setIcon(ContextCompat.getDrawable(map.getContext(), R.drawable.ic_map_point));
    marker.setAnchor(getIconAnchorValueX(iconAnchor), getIconAnchorValueY(iconAnchor));
    marker.setOnMarkerClickListener((clickedMarker, mapView) -> {
        int featureId = findFeature(clickedMarker);
        if (featureClickListener != null && featureId != -1) {
            featureClickListener.onFeature(featureId);
            // consume the event
            return true;
        }
        return false;
    });
    marker.setOnMarkerDragListener(new Marker.OnMarkerDragListener() {

        @Override
        public void onMarkerDragStart(Marker marker) {
        }

        @Override
        public void onMarkerDrag(Marker marker) {
            // When a marker is manually dragged, the position is no longer
            // obtained from a GPS reading, so the standard deviation field
            // is no longer meaningful; reset it to zero.
            marker.setSubDescription("0");
            updateFeature(findFeature(marker));
        }

        @Override
        public void onMarkerDragEnd(Marker marker) {
            int featureId = findFeature(marker);
            updateFeature(featureId);
            if (dragEndListener != null && featureId != -1) {
                dragEndListener.onFeature(featureId);
            }
        }
    });
    map.getOverlays().add(marker);
    return marker;
}
Also used : Marker(org.osmdroid.views.overlay.Marker) IGeoPoint(org.osmdroid.api.IGeoPoint) Paint(android.graphics.Paint) MapPoint(org.odk.collect.geo.maps.MapPoint) GeoPoint(org.osmdroid.util.GeoPoint)

Example 14 with MapPoint

use of org.odk.collect.geo.maps.MapPoint in project collect by opendatakit.

the class FormMapActivityTest method tappingOnInstance_centersToThatInstanceAndKeepsTheSameZoom.

@Test
public void tappingOnInstance_centersToThatInstanceAndKeepsTheSameZoom() {
    MapPoint sent = new MapPoint(10.3, 125.7);
    map.zoomToPoint(new MapPoint(7, 8), 7, false);
    assertThat(map.getLatestZoomPoint().lat, is(7.0));
    assertThat(map.getLatestZoomPoint().lon, is(8.0));
    assertThat(map.getZoom(), is(7.0));
    activity.onFeatureClicked(map.getFeatureIdFor(sent));
    assertThat(map.getLatestZoomPoint().lat, is(10.3));
    assertThat(map.getLatestZoomPoint().lon, is(125.7));
    assertThat(map.getZoom(), is(7.0));
}
Also used : MapPoint(org.odk.collect.geo.maps.MapPoint) Test(org.junit.Test)

Example 15 with MapPoint

use of org.odk.collect.geo.maps.MapPoint in project collect by opendatakit.

the class FormMapActivityTest method recreating_maintainsZoom.

@Test
public void recreating_maintainsZoom() {
    map.zoomToPoint(new MapPoint(55d, 66d), 7, false);
    activityController.recreate();
    assertThat(map.getLatestZoomBoundingBox(), is(nullValue()));
    assertThat(map.getCenter(), is(new MapPoint(55d, 66d)));
    assertThat(map.getZoom(), is(7d));
}
Also used : MapPoint(org.odk.collect.geo.maps.MapPoint) Test(org.junit.Test)

Aggregations

MapPoint (org.odk.collect.geo.maps.MapPoint)28 Test (org.junit.Test)8 SuppressLint (android.annotation.SuppressLint)7 IGeoPoint (org.osmdroid.api.IGeoPoint)5 GeoPoint (org.osmdroid.util.GeoPoint)5 Paint (android.graphics.Paint)4 Pair (android.util.Pair)4 Date (java.util.Date)4 Instance (org.odk.collect.forms.instances.Instance)4 Intent (android.content.Intent)3 Handler (android.os.Handler)3 ArrayList (java.util.ArrayList)3 ImageButton (android.widget.ImageButton)2 NonNull (androidx.annotation.NonNull)2 LatLng (com.google.android.gms.maps.model.LatLng)1 LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)1 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1 Ignore (org.junit.Ignore)1 Location (org.odk.collect.location.Location)1