use of com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions in project mapbox-plugins-android by mapbox.
the class DynamicSymbolChangeActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_annotation);
mapView = findViewById(R.id.mapView);
mapView.setTag(false);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(mapboxMap -> {
DynamicSymbolChangeActivity.this.mapboxMap = mapboxMap;
LatLng target = new LatLng(51.506675, -0.128699);
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().bearing(90).tilt(40).zoom(10).target(target).build()));
mapboxMap.setStyle(new Style.Builder().fromUri(Style.MAPBOX_STREETS).withImage(ID_ICON_1, generateBitmap(R.drawable.mapbox_ic_place), true).withImage(ID_ICON_2, generateBitmap(R.drawable.mapbox_ic_offline), true), style -> {
symbolManager = new SymbolManager(mapView, mapboxMap, style);
symbolManager.setIconAllowOverlap(true);
symbolManager.setTextAllowOverlap(true);
// Create Symbol
SymbolOptions SymbolOptions = new SymbolOptions().withLatLng(LAT_LNG_CHELSEA).withIconImage(ID_ICON_1);
symbol = symbolManager.create(SymbolOptions);
});
});
FloatingActionButton fab = findViewById(R.id.fabStyles);
fab.setVisibility(MapView.VISIBLE);
fab.setOnClickListener(view -> {
if (mapboxMap != null) {
updateSymbol();
}
});
}
use of com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions in project mapbox-plugins-android by mapbox.
the class SymbolActivity 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.LIGHT, style -> {
findViewById(R.id.fabStyles).setOnClickListener(v -> {
mapboxMap.setStyle(Utils.INSTANCE.getNextStyle());
mapboxMap.getStyle(this::addAirplaneImageToStyle);
});
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(2));
addAirplaneImageToStyle(style);
// create symbol manager
GeoJsonOptions geoJsonOptions = new GeoJsonOptions().withTolerance(0.4f);
symbolManager = new SymbolManager(mapView, mapboxMap, style, null, geoJsonOptions);
symbolManager.addClickListener(symbol -> {
Toast.makeText(SymbolActivity.this, String.format("Symbol clicked %s", symbol.getId()), Toast.LENGTH_SHORT).show();
return false;
});
symbolManager.addLongClickListener(symbol -> {
Toast.makeText(SymbolActivity.this, String.format("Symbol long clicked %s", symbol.getId()), Toast.LENGTH_SHORT).show();
return false;
});
// set non data driven properties
symbolManager.setIconAllowOverlap(true);
symbolManager.setTextAllowOverlap(true);
// create a symbol
SymbolOptions symbolOptions = new SymbolOptions().withLatLng(new LatLng(6.687337, 0.381457)).withIconImage(ID_ICON_AIRPORT).withIconSize(1.3f).withSymbolSortKey(10.0f).withDraggable(true);
symbol = symbolManager.create(symbolOptions);
Timber.e(symbol.toString());
// create nearby symbols
SymbolOptions nearbyOptions = new SymbolOptions().withLatLng(new LatLng(6.626384, 0.367099)).withIconImage(MAKI_ICON_CIRCLE).withIconColor(ColorUtils.colorToRgbaString(Color.YELLOW)).withIconSize(2.5f).withSymbolSortKey(5.0f).withDraggable(true);
symbolManager.create(nearbyOptions);
// random add symbols across the globe
List<SymbolOptions> symbolOptionsList = new ArrayList<>();
for (int i = 0; i < 20; i++) {
symbolOptionsList.add(new SymbolOptions().withLatLng(createRandomLatLng()).withIconImage(MAKI_ICON_CAR).withDraggable(true));
}
symbolManager.create(symbolOptionsList);
try {
symbolManager.create(FeatureCollection.fromJson(Utils.INSTANCE.loadStringFromAssets(this, "annotations.json")));
} catch (IOException e) {
throw new RuntimeException("Unable to parse annotations.json");
}
symbolManager.addDragListener(new OnSymbolDragListener() {
@Override
public void onAnnotationDragStarted(Symbol annotation) {
draggableInfoTv.setVisibility(View.VISIBLE);
}
@Override
public void onAnnotationDrag(Symbol annotation) {
draggableInfoTv.setText(String.format(Locale.US, "ID: %s\nLatLng:%f, %f", annotation.getId(), annotation.getLatLng().getLatitude(), annotation.getLatLng().getLongitude()));
}
@Override
public void onAnnotationDragFinished(Symbol annotation) {
draggableInfoTv.setVisibility(View.GONE);
}
});
}));
}
use of com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions in project apps-android-wikipedia by wikimedia.
the class NearbyFragment method showNearbyPages.
private void showNearbyPages() {
if (mapboxMap == null || getActivity() == null) {
return;
}
getActivity().invalidateOptionsMenu();
symbolManager.delete(currentSymbols);
currentSymbols.clear();
List<SymbolOptions> optionsList = new ArrayList<>();
for (NearbyPage item : currentResults.getList()) {
if (item.getLocation() != null) {
optionsList.add(getSymbolOptions(item));
}
}
currentSymbols = symbolManager.create(optionsList);
}
use of com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions in project mapbox-plugins-android by mapbox.
the class BulkSymbolActivity method showSymbols.
private void showSymbols(int amount) {
List<SymbolOptions> options = new ArrayList<>();
Random random = new Random();
int randomIndex;
List<Feature> features = locations.features();
if (features == null) {
return;
}
for (int i = 0; i < amount; i++) {
randomIndex = random.nextInt(features.size());
Feature feature = features.get(randomIndex);
options.add(new SymbolOptions().withGeometry((Point) feature.geometry()).withIconImage("fire-station-11"));
}
symbols = symbolManager.create(options);
}
Aggregations