use of org.odk.collect.android.spatial.MapHelper in project collect by opendatakit.
the class GeoPointOsmMapActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
if (savedInstanceState != null) {
locationCount = savedInstanceState.getInt(LOCATION_COUNT);
}
try {
setContentView(R.layout.geopoint_osm_layout);
} catch (NoClassDefFoundError e) {
ToastUtils.showShortToast(R.string.google_play_services_error_occured);
finish();
return;
}
map = findViewById(R.id.omap);
if (helper == null) {
// For testing:
helper = new MapHelper(this, map, this);
map.setMultiTouchControls(true);
map.setBuiltInZoomControls(true);
map.setTilesScaledToDpi(true);
}
marker = new Marker(map);
marker.setIcon(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_place_black_36dp));
myLocationOverlay = new MyLocationNewOverlay(map);
handler.postDelayed(new Runnable() {
public void run() {
GeoPoint point = new GeoPoint(34.08145, -39.85007);
map.getController().setZoom(4);
map.getController().setCenter(point);
}
}, 100);
locationStatus = findViewById(R.id.location_status);
TextView locationInfo = findViewById(R.id.location_info);
locationClient = LocationClients.clientForContext(this);
locationClient.setListener(this);
ImageButton saveLocationButton = findViewById(R.id.accept_location);
saveLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "acceptLocation", "OK");
returnLocation();
}
});
reloadLocationButton = findViewById(R.id.reload_location);
reloadLocationButton.setEnabled(false);
reloadLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
map.getOverlays().add(marker);
setClear = false;
latLng = new GeoPoint(location.getLatitude(), location.getLongitude());
marker.setPosition(latLng);
captureLocation = true;
isDragged = false;
zoomToPoint();
}
});
// Focuses on marked location
showLocationButton = findViewById(R.id.show_location);
showLocationButton.setVisibility(View.VISIBLE);
showLocationButton.setEnabled(false);
showLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "showLocation", "onClick");
showZoomDialog();
}
});
// not clickable until we have a marker set....
showLocationButton.setClickable(false);
// Menu Layer Toggle
ImageButton layersButton = findViewById(R.id.layer_menu);
layersButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
helper.showLayersDialog(GeoPointOsmMapActivity.this);
}
});
zoomDialogView = getLayoutInflater().inflate(R.layout.geopoint_zoom_dialog, null);
zoomLocationButton = zoomDialogView.findViewById(R.id.zoom_location);
zoomLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToLocation();
map.invalidate();
zoomDialog.dismiss();
}
});
zoomPointButton = zoomDialogView.findViewById(R.id.zoom_point);
zoomPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToPoint();
map.invalidate();
zoomDialog.dismiss();
}
});
ImageButton clearPointButton = findViewById(R.id.clear);
clearPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
map.getOverlays().remove(marker);
marker.remove(map);
if (location != null) {
reloadLocationButton.setEnabled(true);
// locationStatus.setVisibility(View.VISIBLE);
}
locationStatus.setVisibility(View.VISIBLE);
map.getOverlays().remove(marker);
marker.remove(map);
setClear = true;
isDragged = false;
captureLocation = false;
draggable = intentDraggable;
locationFromIntent = false;
overlayMyLocationLayers();
map.invalidate();
}
});
Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
if (intent.hasExtra(GeoPointWidget.DRAGGABLE_ONLY)) {
draggable = intent.getBooleanExtra(GeoPointWidget.DRAGGABLE_ONLY, false);
intentDraggable = draggable;
if (!intentDraggable) {
// Not Draggable, set text for Map else leave as placement-map text
locationInfo.setText(getString(R.string.geopoint_no_draggable_instruction));
}
}
if (intent.hasExtra(GeoPointWidget.READ_ONLY)) {
readOnly = intent.getBooleanExtra(GeoPointWidget.READ_ONLY, false);
if (readOnly) {
captureLocation = true;
clearPointButton.setEnabled(false);
}
}
if (intent.hasExtra(GeoPointWidget.LOCATION)) {
double[] location = intent.getDoubleArrayExtra(GeoPointWidget.LOCATION);
latLng = new GeoPoint(location[0], location[1]);
reloadLocationButton.setEnabled(false);
captureLocation = true;
isDragged = true;
// If data loaded, must clear first
draggable = false;
locationFromIntent = true;
}
}
if (latLng != null) {
marker.setPosition(latLng);
map.getOverlays().add(marker);
map.invalidate();
captureLocation = true;
foundFirstLocation = true;
zoomToPoint();
}
}
use of org.odk.collect.android.spatial.MapHelper in project collect by opendatakit.
the class GeoShapeOsmMapActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.geoshape_osm_layout);
// Setting title of the action
setTitle(getString(R.string.geoshape_title));
ImageButton saveButton = findViewById(R.id.save);
clearButton = findViewById(R.id.clear);
map = findViewById(R.id.geoshape_mapview);
helper = new MapHelper(this, map, this);
map.setMultiTouchControls(true);
map.setBuiltInZoomControls(true);
map.setTilesScaledToDpi(true);
map.setMapListener(mapViewListener);
overlayPointPathListener();
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
returnLocation();
}
});
clearButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mapMarkers.size() != 0) {
showClearDialog();
}
}
});
ImageButton layersButton = findViewById(R.id.layers);
layersButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
helper.showLayersDialog(GeoShapeOsmMapActivity.this);
}
});
locationButton = findViewById(R.id.gps);
locationButton.setEnabled(false);
locationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
showZoomDialog();
}
});
GpsMyLocationProvider imlp = new GpsMyLocationProvider(this.getBaseContext());
imlp.setLocationUpdateMinDistance(1000);
imlp.setLocationUpdateMinTime(60000);
myLocationOverlay = new MyLocationNewOverlay(map);
Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
if (intent.hasExtra(GeoShapeWidget.SHAPE_LOCATION)) {
clearButton.setEnabled(true);
dataLoaded = true;
String s = intent.getStringExtra(GeoShapeWidget.SHAPE_LOCATION);
overlayIntentPolygon(s);
// zoomToCentroid();
locationButton.setEnabled(true);
zoomToBounds();
}
} else {
myLocationOverlay.runOnFirstFix(centerAroundFix);
clearButton.setEnabled(false);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
GeoPoint point = new GeoPoint(34.08145, -39.85007);
map.getController().setZoom(3);
map.getController().setCenter(point);
}
}, 100);
}
map.invalidate();
zoomDialogView = getLayoutInflater().inflate(R.layout.geoshape_zoom_dialog, null);
zoomLocationButton = zoomDialogView.findViewById(R.id.zoom_location);
zoomLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToMyLocation();
map.invalidate();
zoomDialog.dismiss();
}
});
zoomPointButton = zoomDialogView.findViewById(R.id.zoom_shape);
zoomPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// zoomToCentroid();
zoomToBounds();
map.invalidate();
zoomDialog.dismiss();
}
});
}
use of org.odk.collect.android.spatial.MapHelper in project collect by opendatakit.
the class GeoTraceOsmMapActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.geotrace_osm_layout);
// Setting title of the action
setTitle(getString(R.string.geotrace_title));
// For testing purposes:
if (mapView == null) {
mapView = findViewById(R.id.geotrace_mapview);
}
if (helper == null) {
helper = new MapHelper(this, mapView, this);
}
if (myLocationOverlay == null) {
myLocationOverlay = new MyLocationNewOverlay(mapView);
}
mapView.setMultiTouchControls(true);
mapView.setBuiltInZoomControls(true);
mapView.setTilesScaledToDpi(true);
mapView.getController().setZoom(zoomLevel);
inflater = this.getLayoutInflater();
traceSettingsView = inflater.inflate(R.layout.geotrace_dialog, null);
polygonPolylineView = inflater.inflate(R.layout.polygon_polyline_dialog, null);
timeDelay = traceSettingsView.findViewById(R.id.trace_delay);
timeDelay.setSelection(3);
timeUnits = traceSettingsView.findViewById(R.id.trace_scale);
layersButton = findViewById(R.id.layers);
layersButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
helper.showLayersDialog(GeoTraceOsmMapActivity.this);
}
});
locationButton = findViewById(R.id.show_location);
locationButton.setEnabled(false);
locationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
reset_trace_settings();
showZoomDialog();
}
});
clearButton = findViewById(R.id.clear);
clearButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showClearDialog();
}
});
ImageButton saveButton = findViewById(R.id.geotrace_save);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mapMarkers.size() != 0) {
alertDialog.show();
} else {
saveGeoTrace();
}
}
});
if (mapMarkers == null || mapMarkers.size() == 0) {
clearButton.setEnabled(false);
}
manualCaptureButton = findViewById(R.id.manual_button);
manualCaptureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addLocationMarker();
}
});
pauseButton = findViewById(R.id.pause);
playButton = findViewById(R.id.play);
playButton.setEnabled(false);
beenPaused = false;
traceMode = 1;
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
if (!playCheck) {
if (!beenPaused) {
alert.show();
} else {
RadioGroup rb = traceSettingsView.findViewById(R.id.radio_group);
int radioButtonID = rb.getCheckedRadioButtonId();
View radioButton = rb.findViewById(radioButtonID);
traceMode = rb.indexOfChild(radioButton);
if (traceMode == 0) {
setupManualMode();
} else if (traceMode == 1) {
setupAutomaticMode();
} else {
reset_trace_settings();
}
}
playCheck = true;
} else {
playCheck = false;
startGeoTrace();
}
}
});
pauseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
playButton.setVisibility(View.VISIBLE);
if (mapMarkers != null && mapMarkers.size() > 0) {
clearButton.setEnabled(true);
}
pauseButton.setVisibility(View.GONE);
manualCaptureButton.setVisibility(View.GONE);
playCheck = true;
modeActive = false;
myLocationOverlay.disableFollowLocation();
try {
schedulerHandler.cancel(true);
} catch (Exception e) {
// Do nothing
}
}
});
overlayMapLayerListener();
buildDialogs();
Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
if (intent.hasExtra(GeoTraceWidget.TRACE_LOCATION)) {
String s = intent.getStringExtra(GeoTraceWidget.TRACE_LOCATION);
playButton.setEnabled(false);
clearButton.setEnabled(true);
overlayIntentTrace(s);
locationButton.setEnabled(true);
// zoomToCentroid();
zoomToBounds();
}
} else {
myLocationOverlay.runOnFirstFix(centerAroundFix);
}
Button polygonSaveButton = polygonPolylineView.findViewById(R.id.polygon_save);
polygonSaveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mapMarkers.size() > 2) {
createPolygon();
alertDialog.dismiss();
saveGeoTrace();
} else {
alertDialog.dismiss();
showPolygonErrorDialog();
}
}
});
Button polylineSaveButton = polygonPolylineView.findViewById(R.id.polyline_save);
polylineSaveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
saveGeoTrace();
}
});
zoomDialogView = getLayoutInflater().inflate(R.layout.geoshape_zoom_dialog, null);
zoomLocationButton = zoomDialogView.findViewById(R.id.zoom_location);
zoomLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToMyLocation();
mapView.invalidate();
zoomDialog.dismiss();
}
});
zoomPointButton = zoomDialogView.findViewById(R.id.zoom_shape);
zoomPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// zoomToCentroid();
zoomToBounds();
mapView.invalidate();
zoomDialog.dismiss();
}
});
mapView.invalidate();
locationClient = LocationClients.clientForContext(this);
locationClient.setListener(this);
}
use of org.odk.collect.android.spatial.MapHelper in project collect by opendatakit.
the class GeoPointMapActivity method setupMap.
private void setupMap(GoogleMap googleMap) {
map = googleMap;
if (map == null) {
ToastUtils.showShortToast(R.string.google_play_services_error_occured);
finish();
return;
}
helper = new MapHelper(this, map);
map.setMyLocationEnabled(true);
map.getUiSettings().setCompassEnabled(true);
map.getUiSettings().setMyLocationButtonEnabled(false);
map.getUiSettings().setZoomControlsEnabled(false);
markerOptions = new MarkerOptions();
helper = new MapHelper(this, map);
ImageButton acceptLocation = findViewById(R.id.accept_location);
acceptLocation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "acceptLocation", "OK");
returnLocation();
}
});
reloadLocation.setEnabled(false);
reloadLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (marker != null) {
marker.remove();
}
latLng = null;
marker = null;
setClear = false;
latLng = new LatLng(location.getLatitude(), location.getLongitude());
markerOptions.position(latLng);
if (marker == null) {
marker = map.addMarker(markerOptions);
if (draggable && !readOnly) {
marker.setDraggable(true);
}
}
captureLocation = true;
isDragged = false;
zoomToPoint();
}
});
// Focuses on marked location
// showLocation.setClickable(false);
showLocation.setEnabled(false);
showLocation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showZoomDialog();
}
});
// Menu Layer Toggle
ImageButton layers = findViewById(R.id.layer_menu);
layers.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
helper.showLayersDialog(GeoPointMapActivity.this);
}
});
zoomDialogView = getLayoutInflater().inflate(R.layout.geopoint_zoom_dialog, null);
zoomLocationButton = zoomDialogView.findViewById(R.id.zoom_location);
zoomLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToLocation();
zoomDialog.dismiss();
}
});
zoomPointButton = zoomDialogView.findViewById(R.id.zoom_point);
zoomPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToPoint();
zoomDialog.dismiss();
}
});
ImageButton clearPointButton = findViewById(R.id.clear);
clearPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (marker != null) {
marker.remove();
}
if (location != null) {
reloadLocation.setEnabled(true);
// locationStatus.setVisibility(View.VISIBLE);
}
// reloadLocation.setEnabled(true);
locationInfo.setVisibility(View.VISIBLE);
locationStatus.setVisibility(View.VISIBLE);
latLng = null;
marker = null;
setClear = true;
isDragged = false;
captureLocation = false;
draggable = intentDraggable;
locationFromIntent = false;
overlayMyLocationLayers();
}
});
Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
if (intent.hasExtra(GeoPointWidget.DRAGGABLE_ONLY)) {
draggable = intent.getBooleanExtra(GeoPointWidget.DRAGGABLE_ONLY, false);
intentDraggable = draggable;
if (!intentDraggable) {
// Not Draggable, set text for Map else leave as placement-map text
locationInfo.setText(getString(R.string.geopoint_no_draggable_instruction));
}
}
if (intent.hasExtra(GeoPointWidget.READ_ONLY)) {
readOnly = intent.getBooleanExtra(GeoPointWidget.READ_ONLY, false);
if (readOnly) {
captureLocation = true;
clearPointButton.setEnabled(false);
}
}
if (intent.hasExtra(GeoPointWidget.LOCATION)) {
double[] location = intent.getDoubleArrayExtra(GeoPointWidget.LOCATION);
latLng = new LatLng(location[0], location[1]);
captureLocation = true;
reloadLocation.setEnabled(false);
// If data loaded, must clear first
draggable = false;
locationFromIntent = true;
}
}
/*Zoom only if there's a previous location*/
if (latLng != null) {
locationInfo.setVisibility(View.GONE);
locationStatus.setVisibility(View.GONE);
showLocation.setEnabled(true);
markerOptions.position(latLng);
marker = map.addMarker(markerOptions);
captureLocation = true;
foundFirstLocation = true;
zoomToPoint();
}
helper.setBasemap();
isMapReady = true;
upMyLocationOverlayLayers();
}
use of org.odk.collect.android.spatial.MapHelper in project collect by opendatakit.
the class GeoShapeGoogleMapActivity method setupMap.
private void setupMap(GoogleMap googleMap) {
map = googleMap;
if (map == null) {
ToastUtils.showShortToast(R.string.google_play_services_error_occured);
finish();
return;
}
helper = new MapHelper(this, map);
map.setMyLocationEnabled(true);
map.setOnMapLongClickListener(this);
map.setOnMarkerDragListener(this);
map.getUiSettings().setMyLocationButtonEnabled(false);
map.getUiSettings().setCompassEnabled(true);
map.getUiSettings().setZoomControlsEnabled(false);
polygonOptions = new PolygonOptions();
polygonOptions.strokeColor(Color.RED);
polygonOptions.zIndex(1);
gpsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// if(curLocation !=null){
// map.animateCamera(CameraUpdateFactory.newLatLngZoom(curlatLng,16));
// }
showZoomDialog();
}
});
clearButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (markerArray.size() != 0) {
showClearDialog();
}
}
});
ImageButton returnButton = findViewById(R.id.save);
returnButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
returnLocation();
}
});
Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
if (intent.hasExtra(GeoShapeWidget.SHAPE_LOCATION)) {
clearButton.setEnabled(true);
String s = intent.getStringExtra(GeoShapeWidget.SHAPE_LOCATION);
gpsButton.setEnabled(true);
overlayIntentPolygon(s);
}
}
ImageButton layersButton = findViewById(R.id.layers);
layersButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
helper.showLayersDialog(GeoShapeGoogleMapActivity.this);
}
});
zoomDialogView = getLayoutInflater().inflate(R.layout.geoshape_zoom_dialog, null);
zoomLocationButton = zoomDialogView.findViewById(R.id.zoom_location);
zoomLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (curLocation != null && curlatLng != null) {
map.animateCamera(CameraUpdateFactory.newLatLngZoom(curlatLng, 17));
}
zoomDialog.dismiss();
}
});
zoomPointButton = zoomDialogView.findViewById(R.id.zoom_shape);
zoomPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// zoomToCentroid();
zoomToBounds();
zoomDialog.dismiss();
}
});
// If there is a last know location go there
if (curLocation != null) {
curlatLng = new LatLng(curLocation.getLatitude(), curLocation.getLongitude());
foundFirstLocation = true;
gpsButton.setEnabled(true);
showZoomDialog();
}
helper.setBasemap();
}
Aggregations