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