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();
}
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;
}
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;
}
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);
}
}
}
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);
}
Aggregations