Search in sources :

Example 1 with Circle

use of com.mapbox.mapboxsdk.plugins.annotation.Circle in project mapbox-plugins-android by mapbox.

the class CircleActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_action_draggable) {
        for (int i = 0; i < circleManager.getAnnotations().size(); i++) {
            Circle circle = circleManager.getAnnotations().get(i);
            circle.setDraggable(!circle.isDraggable());
        }
        return true;
    }
    return false;
}
Also used : Circle(com.mapbox.mapboxsdk.plugins.annotation.Circle)

Example 2 with Circle

use of com.mapbox.mapboxsdk.plugins.annotation.Circle in project mapbox-plugins-android by mapbox.

the class CircleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_annotation);
    TextView draggableInfoTv = findViewById(R.id.draggable_position_tv);
    mapView = findViewById(R.id.mapView);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
        findViewById(R.id.fabStyles).setOnClickListener(v -> mapboxMap.setStyle(Utils.INSTANCE.getNextStyle()));
        mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(2));
        // create circle manager
        circleManager = new CircleManager(mapView, mapboxMap, style);
        circleManager.addClickListener(circle -> {
            Toast.makeText(CircleActivity.this, String.format("Circle clicked %s", circle.getId()), Toast.LENGTH_SHORT).show();
            return false;
        });
        circleManager.addLongClickListener(circle -> {
            Toast.makeText(CircleActivity.this, String.format("Circle long clicked %s", circle.getId()), Toast.LENGTH_SHORT).show();
            return false;
        });
        // create a fixed circle
        CircleOptions circleOptions = new CircleOptions().withLatLng(new LatLng(6.687337, 0.381457)).withCircleColor(ColorUtils.colorToRgbaString(Color.YELLOW)).withCircleRadius(12f).withDraggable(true);
        circleManager.create(circleOptions);
        // random add circles across the globe
        List<CircleOptions> circleOptionsList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            int color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256));
            circleOptionsList.add(new CircleOptions().withLatLng(createRandomLatLng()).withCircleColor(ColorUtils.colorToRgbaString(color)).withCircleRadius(8f).withDraggable(true));
        }
        circleManager.create(circleOptionsList);
        try {
            circleManager.create(Utils.INSTANCE.loadStringFromAssets(this, "annotations.json"));
        } catch (IOException e) {
            throw new RuntimeException("Unable to parse annotations.json");
        }
        circleManager.addDragListener(new OnCircleDragListener() {

            @Override
            public void onAnnotationDragStarted(Circle annotation) {
                draggableInfoTv.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnnotationDrag(Circle annotation) {
                draggableInfoTv.setText(String.format(Locale.US, "ID: %s\nLatLng:%f, %f", annotation.getId(), annotation.getLatLng().getLatitude(), annotation.getLatLng().getLongitude()));
            }

            @Override
            public void onAnnotationDragFinished(Circle annotation) {
                draggableInfoTv.setVisibility(View.GONE);
            }
        });
    }));
}
Also used : CircleManager(com.mapbox.mapboxsdk.plugins.annotation.CircleManager) Circle(com.mapbox.mapboxsdk.plugins.annotation.Circle) Bundle(android.os.Bundle) ColorUtils(com.mapbox.mapboxsdk.utils.ColorUtils) MapView(com.mapbox.mapboxsdk.maps.MapView) R(com.mapbox.mapboxsdk.plugins.testapp.R) IOException(java.io.IOException) Random(java.util.Random) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Utils(com.mapbox.mapboxsdk.plugins.testapp.Utils) MenuItem(android.view.MenuItem) CircleOptions(com.mapbox.mapboxsdk.plugins.annotation.CircleOptions) ArrayList(java.util.ArrayList) Color(android.graphics.Color) CameraUpdateFactory(com.mapbox.mapboxsdk.camera.CameraUpdateFactory) List(java.util.List) TextView(android.widget.TextView) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) OnCircleDragListener(com.mapbox.mapboxsdk.plugins.annotation.OnCircleDragListener) Locale(java.util.Locale) Toast(android.widget.Toast) Style(com.mapbox.mapboxsdk.maps.Style) Menu(android.view.Menu) View(android.view.View) CircleManager(com.mapbox.mapboxsdk.plugins.annotation.CircleManager) Circle(com.mapbox.mapboxsdk.plugins.annotation.Circle) CircleOptions(com.mapbox.mapboxsdk.plugins.annotation.CircleOptions) OnCircleDragListener(com.mapbox.mapboxsdk.plugins.annotation.OnCircleDragListener) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) IOException(java.io.IOException)

Aggregations

Circle (com.mapbox.mapboxsdk.plugins.annotation.Circle)2 Color (android.graphics.Color)1 Bundle (android.os.Bundle)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 CameraUpdateFactory (com.mapbox.mapboxsdk.camera.CameraUpdateFactory)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 MapView (com.mapbox.mapboxsdk.maps.MapView)1 Style (com.mapbox.mapboxsdk.maps.Style)1 CircleManager (com.mapbox.mapboxsdk.plugins.annotation.CircleManager)1 CircleOptions (com.mapbox.mapboxsdk.plugins.annotation.CircleOptions)1 OnCircleDragListener (com.mapbox.mapboxsdk.plugins.annotation.OnCircleDragListener)1 R (com.mapbox.mapboxsdk.plugins.testapp.R)1 Utils (com.mapbox.mapboxsdk.plugins.testapp.Utils)1 ColorUtils (com.mapbox.mapboxsdk.utils.ColorUtils)1 IOException (java.io.IOException)1