use of org.odk.collect.android.spatial.MapHelper in project collect by opendatakit.
the class GeoTraceGoogleMapActivity 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().setZoomControlsEnabled(true);
map.getUiSettings().setMyLocationButtonEnabled(false);
map.getUiSettings().setZoomControlsEnabled(false);
polylineOptions = new PolylineOptions();
polylineOptions.color(Color.RED);
clearButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (markerArray.size() != 0) {
showClearDialog();
}
}
});
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);
pauseButton = findViewById(R.id.pause);
pauseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
playButton.setVisibility(View.VISIBLE);
if (markerArray != null && markerArray.size() > 0) {
clearButton.setEnabled(true);
}
pauseButton.setVisibility(View.GONE);
manualButton.setVisibility(View.GONE);
playCheck = true;
modeActive = false;
try {
schedulerHandler.cancel(true);
} catch (Exception e) {
// Do nothing
}
}
});
ImageButton saveButton = findViewById(R.id.geotrace_save);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (markerArray.size() != 0) {
alertDialog.show();
} else {
saveGeoTrace();
}
}
});
playButton.setEnabled(false);
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 {
// Do nothing
}
}
playCheck = true;
} else {
playCheck = false;
startGeoTrace();
}
}
});
if (markerArray == null || markerArray.size() == 0) {
clearButton.setEnabled(false);
}
manualButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addLocationMarker();
}
});
Button polygonSave = polygonPolylineView.findViewById(R.id.polygon_save);
polygonSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (markerArray.size() > 2) {
createPolygon();
alertDialog.dismiss();
saveGeoTrace();
} else {
alertDialog.dismiss();
showPolygonErrorDialog();
}
}
});
Button polylineSave = polygonPolylineView.findViewById(R.id.polyline_save);
polylineSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
saveGeoTrace();
}
});
buildDialogs();
layersButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
helper.showLayersDialog(GeoTraceGoogleMapActivity.this);
}
});
ImageButton locationButton = findViewById(R.id.show_location);
locationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showZoomDialog();
}
});
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();
zoomDialog.dismiss();
}
});
zoomPointButton = zoomDialogView.findViewById(R.id.zoom_shape);
zoomPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToBounds();
zoomDialog.dismiss();
}
});
Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
if (intent.hasExtra(GeoTraceWidget.TRACE_LOCATION)) {
playButton.setEnabled(false);
clearButton.setEnabled(true);
firstLocationFound = true;
locationButton.setEnabled(true);
String s = intent.getStringExtra(GeoTraceWidget.TRACE_LOCATION);
overlayIntentTrace(s);
zoomToBounds();
}
} else {
if (curLocation != null) {
curlatLng = new LatLng(curLocation.getLatitude(), curLocation.getLongitude());
}
}
helper.setBasemap();
}
Aggregations