Search in sources :

Example 21 with MapPoint

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

the class GeoPolyActivity method initMap.

public void initMap(MapFragment newMapFragment) {
    map = newMapFragment;
    locationStatus = findViewById(R.id.location_status);
    collectionStatus = findViewById(R.id.collection_status);
    settingsView = getLayoutInflater().inflate(R.layout.geopoly_dialog, null);
    clearButton = findViewById(R.id.clear);
    clearButton.setOnClickListener(v -> showClearDialog());
    pauseButton = findViewById(R.id.pause);
    pauseButton.setOnClickListener(v -> {
        inputActive = false;
        try {
            schedulerHandler.cancel(true);
        } catch (Exception e) {
        // Do nothing
        }
        updateUi();
    });
    backspaceButton = findViewById(R.id.backspace);
    backspaceButton.setOnClickListener(v -> removeLastPoint());
    ImageButton saveButton = findViewById(R.id.save);
    saveButton.setOnClickListener(v -> {
        if (!map.getPolyPoints(featureId).isEmpty()) {
            if (outputMode == OutputMode.GEOTRACE) {
                saveAsPolyline();
            } else {
                saveAsPolygon();
            }
        } else {
            finishWithResult();
        }
    });
    playButton = findViewById(R.id.play);
    playButton.setOnClickListener(v -> {
        if (map.getPolyPoints(featureId).isEmpty()) {
            DialogFragmentUtils.showIfNotShowing(GeoPolySettingsDialogFragment.class, getSupportFragmentManager());
        } else {
            startInput();
        }
    });
    recordButton = findViewById(R.id.record_button);
    recordButton.setOnClickListener(v -> recordPoint(map.getGpsLocation()));
    findViewById(R.id.layers).setOnClickListener(v -> {
        referenceLayerSettingsNavigator.navigateToReferenceLayerSettings(this);
    });
    zoomButton = findViewById(R.id.zoom);
    zoomButton.setOnClickListener(v -> map.zoomToPoint(map.getGpsLocation(), true));
    List<MapPoint> points = new ArrayList<>();
    Intent intent = getIntent();
    if (intent != null && intent.hasExtra(ANSWER_KEY)) {
        originalAnswerString = intent.getStringExtra(ANSWER_KEY);
        points = parsePoints(originalAnswerString);
    }
    if (restoredPoints != null) {
        points = restoredPoints;
    }
    featureId = map.addDraggablePoly(points, outputMode == OutputMode.GEOSHAPE);
    if (inputActive && !intentReadOnly) {
        startInput();
    }
    map.setClickListener(this::onClick);
    // Also allow long press to place point to match prior versions
    map.setLongPressListener(this::onClick);
    map.setGpsLocationEnabled(true);
    map.setGpsLocationListener(this::onGpsLocation);
    if (restoredMapCenter != null && restoredMapZoom != null) {
        map.zoomToPoint(restoredMapCenter, restoredMapZoom, false);
    } else if (!points.isEmpty()) {
        map.zoomToBoundingBox(points, 0.6, false);
    } else {
        map.runOnGpsLocationReady(this::onGpsLocationReady);
    }
    updateUi();
}
Also used : ImageButton(android.widget.ImageButton) MapPoint(org.odk.collect.geo.maps.MapPoint) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Example 22 with MapPoint

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

the class MapboxMapFragment method addDraggablePoly.

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

Example 23 with MapPoint

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

the class MapboxMapFragment method addMarker.

@Override
public int addMarker(MapPoint point, boolean draggable, @IconAnchor String iconAnchor) {
    int featureId = nextFeatureId++;
    features.put(featureId, new MarkerFeature(featureId, symbolManager, point, draggable, iconAnchor));
    return featureId;
}
Also used : MapPoint(org.odk.collect.geo.maps.MapPoint) SuppressLint(android.annotation.SuppressLint)

Example 24 with MapPoint

use of org.odk.collect.geo.maps.MapPoint 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)

Example 25 with MapPoint

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

the class OsmDroidMapFragment method fromMarker.

@NonNull
private static MapPoint fromMarker(@NonNull Marker marker) {
    GeoPoint geoPoint = marker.getPosition();
    double sd = 0;
    try {
        sd = Double.parseDouble(marker.getSubDescription());
    } catch (NumberFormatException e) {
        Timber.w("Marker.getSubDescription() did not contain a number");
    }
    return new MapPoint(geoPoint.getLatitude(), geoPoint.getLongitude(), geoPoint.getAltitude(), sd);
}
Also used : IGeoPoint(org.osmdroid.api.IGeoPoint) GeoPoint(org.osmdroid.util.GeoPoint) MapPoint(org.odk.collect.geo.maps.MapPoint) NonNull(androidx.annotation.NonNull)

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