Search in sources :

Example 6 with MapPoint

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

the class GeoPolyActivity method updateUi.

/**
 * Updates the state of various UI widgets to reflect internal state.
 */
private void updateUi() {
    final int numPoints = map.getPolyPoints(featureId).size();
    final MapPoint location = map.getGpsLocation();
    // Visibility state
    playButton.setVisibility(inputActive ? View.GONE : View.VISIBLE);
    pauseButton.setVisibility(inputActive ? View.VISIBLE : View.GONE);
    recordButton.setVisibility(inputActive && recordingEnabled && !recordingAutomatic ? View.VISIBLE : View.GONE);
    // Enabled state
    zoomButton.setEnabled(location != null);
    backspaceButton.setEnabled(numPoints > 0);
    clearButton.setEnabled(!inputActive && numPoints > 0);
    settingsView.findViewById(R.id.manual_mode).setEnabled(location != null);
    settingsView.findViewById(R.id.automatic_mode).setEnabled(location != null);
    if (intentReadOnly) {
        playButton.setEnabled(false);
        backspaceButton.setEnabled(false);
        clearButton.setEnabled(false);
    }
    // Settings dialog
    // GPS status
    boolean usingThreshold = isAccuracyThresholdActive();
    boolean acceptable = location != null && isLocationAcceptable(location);
    int seconds = INTERVAL_OPTIONS[intervalIndex];
    int minutes = seconds / 60;
    int meters = ACCURACY_THRESHOLD_OPTIONS[accuracyThresholdIndex];
    locationStatus.setText(location == null ? getString(R.string.location_status_searching) : !usingThreshold ? getString(R.string.location_status_accuracy, location.sd) : acceptable ? getString(R.string.location_status_acceptable, location.sd) : getString(R.string.location_status_unacceptable, location.sd));
    locationStatus.setBackgroundColor(location == null ? getThemeAttributeValue(this, R.attr.colorPrimary) : acceptable ? getThemeAttributeValue(this, R.attr.colorPrimary) : getThemeAttributeValue(this, R.attr.colorError));
    collectionStatus.setText(!inputActive ? getString(R.string.collection_status_paused, numPoints) : !recordingEnabled ? getString(R.string.collection_status_placement, numPoints) : !recordingAutomatic ? getString(R.string.collection_status_manual, numPoints) : !usingThreshold ? (minutes > 0 ? getString(R.string.collection_status_auto_minutes, numPoints, minutes) : getString(R.string.collection_status_auto_seconds, numPoints, seconds)) : (minutes > 0 ? getString(R.string.collection_status_auto_minutes_accuracy, numPoints, minutes, meters) : getString(R.string.collection_status_auto_seconds_accuracy, numPoints, seconds, meters)));
}
Also used : MapPoint(org.odk.collect.geo.maps.MapPoint) MapPoint(org.odk.collect.geo.maps.MapPoint)

Example 7 with MapPoint

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

the class GeoPolyActivity method parsePoints.

/**
 * Parses a form result string, as previously formatted by formatPoints,
 * into a list of vertices.
 */
private List<MapPoint> parsePoints(String coords) {
    List<MapPoint> points = new ArrayList<>();
    for (String vertex : (coords == null ? "" : coords).split(";")) {
        String[] words = vertex.trim().split(" ");
        if (words.length >= 2) {
            double lat;
            double lon;
            double alt;
            double sd;
            try {
                lat = Double.parseDouble(words[0]);
                lon = Double.parseDouble(words[1]);
                alt = words.length > 2 ? Double.parseDouble(words[2]) : 0;
                sd = words.length > 3 ? Double.parseDouble(words[3]) : 0;
            } catch (NumberFormatException e) {
                continue;
            }
            points.add(new MapPoint(lat, lon, alt, sd));
        }
    }
    if (outputMode == OutputMode.GEOSHAPE) {
        // Closed polygons are stored with a last point that duplicates the
        // first point.  To prepare a polygon for display and editing, we
        // need to remove this duplicate point.
        int count = points.size();
        if (count > 1 && points.get(0).equals(points.get(count - 1))) {
            points.remove(count - 1);
        }
    }
    return points;
}
Also used : MapPoint(org.odk.collect.geo.maps.MapPoint) ArrayList(java.util.ArrayList) MapPoint(org.odk.collect.geo.maps.MapPoint)

Example 8 with MapPoint

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

the class GeoPointMapActivity method initMap.

// Permission handled in Constructor
@SuppressLint("MissingPermission")
public void initMap(MapFragment newMapFragment) {
    map = newMapFragment;
    map.setDragEndListener(this::onDragEnd);
    map.setLongPressListener(this::onLongPress);
    ImageButton acceptLocation = findViewById(R.id.accept_location);
    acceptLocation.setOnClickListener(v -> returnLocation());
    placeMarkerButton.setEnabled(false);
    placeMarkerButton.setOnClickListener(v -> {
        MapPoint mapPoint = map.getGpsLocation();
        if (mapPoint != null) {
            placeMarker(mapPoint);
            zoomToMarker(true);
        }
    });
    // Focuses on marked location
    zoomButton.setEnabled(false);
    zoomButton.setOnClickListener(v -> map.zoomToPoint(map.getGpsLocation(), true));
    // Menu Layer Toggle
    findViewById(R.id.layer_menu).setOnClickListener(v -> {
        referenceLayerSettingsNavigator.navigateToReferenceLayerSettings(this);
    });
    clearButton = findViewById(R.id.clear);
    clearButton.setEnabled(false);
    clearButton.setOnClickListener(v -> {
        clear();
        if (map.getGpsLocation() != null) {
            placeMarkerButton.setEnabled(true);
        // locationStatus.setVisibility(View.VISIBLE);
        }
        // placeMarkerButton.setEnabled(true);
        locationInfo.setVisibility(View.VISIBLE);
        locationStatus.setVisibility(View.VISIBLE);
        pointFromIntent = false;
    });
    Intent intent = getIntent();
    if (intent != null && intent.getExtras() != null) {
        intentDraggable = intent.getBooleanExtra(EXTRA_DRAGGABLE_ONLY, false);
        if (!intentDraggable) {
            // Not Draggable, set text for Map else leave as placement-map text
            locationInfo.setText(getString(R.string.geopoint_no_draggable_instruction));
        }
        intentReadOnly = intent.getBooleanExtra(EXTRA_READ_ONLY, false);
        if (intentReadOnly) {
            captureLocation = true;
            clearButton.setEnabled(false);
        }
        if (intent.hasExtra(EXTRA_LOCATION)) {
            double[] point = intent.getDoubleArrayExtra(EXTRA_LOCATION);
            // If the point is initially set from the intent, the "place marker"
            // button, dragging, and long-pressing are all initially disabled.
            // To enable them, the user must clear the marker and add a new one.
            isPointLocked = true;
            placeMarker(new MapPoint(point[0], point[1], point[2], point[3]));
            placeMarkerButton.setEnabled(false);
            captureLocation = true;
            pointFromIntent = true;
            locationInfo.setVisibility(View.GONE);
            locationStatus.setVisibility(View.GONE);
            zoomButton.setEnabled(true);
            foundFirstLocation = true;
            zoomToMarker(false);
        }
    }
    map.setRetainMockAccuracy(intent.getBooleanExtra(EXTRA_RETAIN_MOCK_ACCURACY, false));
    map.setGpsLocationListener(this::onLocationChanged);
    map.setGpsLocationEnabled(true);
    if (previousState != null) {
        restoreFromInstanceState(previousState);
    }
}
Also used : ImageButton(android.widget.ImageButton) MapPoint(org.odk.collect.geo.maps.MapPoint) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint)

Example 9 with MapPoint

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

the class GoogleMapFragment method addDraggablePoly.

@Override
public int addDraggablePoly(@NonNull Iterable<MapPoint> points, boolean closedPolygon) {
    int featureId = nextFeatureId++;
    features.put(featureId, new PolyFeature(map, points, closedPolygon));
    return featureId;
}
Also used : MapPoint(org.odk.collect.geo.maps.MapPoint) SuppressLint(android.annotation.SuppressLint)

Example 10 with MapPoint

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

the class GoogleMapFragment 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) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) Handler(android.os.Handler) MapPoint(org.odk.collect.geo.maps.MapPoint) SuppressLint(android.annotation.SuppressLint)

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