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;
}
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");
}
}));
}
Aggregations