Search in sources :

Example 1 with Fill

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

the class FillActivity method onOptionsItemSelected.

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

Example 2 with Fill

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

the class FillActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_annotation);
    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));
        fillManager = new FillManager(mapView, mapboxMap, style);
        fillManager.addClickListener(fill -> {
            Toast.makeText(FillActivity.this, String.format("Fill clicked %s with title: %s", fill.getId(), getTitleFromFill(fill)), Toast.LENGTH_SHORT).show();
            return false;
        });
        fillManager.addLongClickListener(fill -> {
            Toast.makeText(FillActivity.this, String.format("Fill long clicked %s with title: %s", fill.getId(), getTitleFromFill(fill)), Toast.LENGTH_SHORT).show();
            return false;
        });
        // create a fixed fill
        List<LatLng> innerLatLngs = new ArrayList<>();
        innerLatLngs.add(new LatLng(-35.317366, -74.179687));
        innerLatLngs.add(new LatLng(-35.317366, -30.761718));
        innerLatLngs.add(new LatLng(4.740675, -30.761718));
        innerLatLngs.add(new LatLng(4.740675, -74.179687));
        innerLatLngs.add(new LatLng(-35.317366, -74.179687));
        List<List<LatLng>> latLngs = new ArrayList<>();
        latLngs.add(innerLatLngs);
        FillOptions fillOptions = new FillOptions().withLatLngs(latLngs).withData(new JsonPrimitive("Foobar")).withFillColor(ColorUtils.colorToRgbaString(Color.RED));
        fillManager.create(fillOptions);
        // random add fills across the globe
        List<FillOptions> fillOptionsList = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            int color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256));
            fillOptionsList.add(new FillOptions().withLatLngs(createRandomLatLngs()).withFillColor(ColorUtils.colorToRgbaString(color)));
        }
        fillManager.create(fillOptionsList);
        try {
            fillManager.create(FeatureCollection.fromJson(Utils.INSTANCE.loadStringFromAssets(this, "annotations.json")));
        } catch (IOException e) {
            throw new RuntimeException("Unable to parse annotations.json");
        }
    }));
}
Also used : Bundle(android.os.Bundle) ColorUtils(com.mapbox.mapboxsdk.utils.ColorUtils) FeatureCollection(com.mapbox.geojson.FeatureCollection) 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) FillOptions(com.mapbox.mapboxsdk.plugins.annotation.FillOptions) Utils(com.mapbox.mapboxsdk.plugins.testapp.Utils) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Color(android.graphics.Color) JsonElement(com.google.gson.JsonElement) CameraUpdateFactory(com.mapbox.mapboxsdk.camera.CameraUpdateFactory) List(java.util.List) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Toast(android.widget.Toast) Style(com.mapbox.mapboxsdk.maps.Style) Menu(android.view.Menu) FillManager(com.mapbox.mapboxsdk.plugins.annotation.FillManager) JsonPrimitive(com.google.gson.JsonPrimitive) Fill(com.mapbox.mapboxsdk.plugins.annotation.Fill) JsonPrimitive(com.google.gson.JsonPrimitive) ArrayList(java.util.ArrayList) List(java.util.List) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) IOException(java.io.IOException) FillManager(com.mapbox.mapboxsdk.plugins.annotation.FillManager) FillOptions(com.mapbox.mapboxsdk.plugins.annotation.FillOptions)

Aggregations

Fill (com.mapbox.mapboxsdk.plugins.annotation.Fill)2 Color (android.graphics.Color)1 Bundle (android.os.Bundle)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 Toast (android.widget.Toast)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 JsonElement (com.google.gson.JsonElement)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 FeatureCollection (com.mapbox.geojson.FeatureCollection)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 FillManager (com.mapbox.mapboxsdk.plugins.annotation.FillManager)1 FillOptions (com.mapbox.mapboxsdk.plugins.annotation.FillOptions)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