Search in sources :

Example 6 with MapHelper

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();
}
Also used : ImageButton(android.widget.ImageButton) RadioGroup(android.widget.RadioGroup) ImageButton(android.widget.ImageButton) RadioButton(android.widget.RadioButton) Button(android.widget.Button) MapHelper(org.odk.collect.android.spatial.MapHelper) Intent(android.content.Intent) LatLng(com.google.android.gms.maps.model.LatLng) View(android.view.View) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions)

Aggregations

Intent (android.content.Intent)6 View (android.view.View)6 ImageButton (android.widget.ImageButton)6 MapHelper (org.odk.collect.android.spatial.MapHelper)6 LatLng (com.google.android.gms.maps.model.LatLng)3 MapView (org.osmdroid.views.MapView)3 MyLocationNewOverlay (org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay)3 Button (android.widget.Button)2 RadioButton (android.widget.RadioButton)2 RadioGroup (android.widget.RadioGroup)2 TextView (android.widget.TextView)2 GeoPoint (org.osmdroid.util.GeoPoint)2 Handler (android.os.Handler)1 OnClickListener (android.view.View.OnClickListener)1 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)1 PolygonOptions (com.google.android.gms.maps.model.PolygonOptions)1 PolylineOptions (com.google.android.gms.maps.model.PolylineOptions)1 Marker (org.osmdroid.views.overlay.Marker)1 GpsMyLocationProvider (org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider)1