Search in sources :

Example 1 with SymbolManager

use of com.mapbox.mapboxsdk.plugins.annotation.SymbolManager in project collect by opendatakit.

the class MapboxMapFragment method createSymbolManager.

private SymbolManager createSymbolManager() {
    SymbolManager symbolManager = new SymbolManager(getMapView(), map, map.getStyle());
    // Turning on allowOverlap and ignorePlacement causes the symbols to
    // always be shown (otherwise Mapbox hides them automatically when they
    // come too close to other symbols or labels on the map).
    symbolManager.setIconAllowOverlap(true);
    symbolManager.setIconIgnorePlacement(true);
    symbolManager.setIconPadding(0f);
    return symbolManager;
}
Also used : SymbolManager(com.mapbox.mapboxsdk.plugins.annotation.SymbolManager)

Example 2 with SymbolManager

use of com.mapbox.mapboxsdk.plugins.annotation.SymbolManager in project apps-android-wikipedia by wikimedia.

the class NearbyFragment method onStyleLoaded.

@Override
public void onStyleLoaded(@NonNull Style style) {
    if (!isAdded() || mapboxMap == null) {
        return;
    }
    symbolManager = new SymbolManager(mapView, mapboxMap, style);
    symbolManager.setIconAllowOverlap(true);
    symbolManager.setTextAllowOverlap(true);
    symbolManager.addClickListener(symbol -> {
        NearbyPage page = findNearbyPageFromSymbol(symbol);
        if (page != null) {
            onLoadPage(new HistoryEntry(page.getTitle(), HistoryEntry.SOURCE_NEARBY), page.getLocation());
        }
    });
    enableUserLocationMarker();
    if (lastCameraPos != null) {
        mapboxMap.setCameraPosition(lastCameraPos);
    } else {
        goToUserLocationOrPromptPermissions();
    }
    showNearbyPages();
}
Also used : SymbolManager(com.mapbox.mapboxsdk.plugins.annotation.SymbolManager) HistoryEntry(org.wikipedia.history.HistoryEntry) NearbyPage(org.wikipedia.dataclient.mwapi.NearbyPage)

Example 3 with SymbolManager

use of com.mapbox.mapboxsdk.plugins.annotation.SymbolManager 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();
        }
    });
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) SymbolManager(com.mapbox.mapboxsdk.plugins.annotation.SymbolManager) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) SymbolOptions(com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions)

Example 4 with SymbolManager

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

the class PressForSymbolActivity method onCreate.

@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_annotation);
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    mapView = findViewById(R.id.mapView);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(map -> {
        mapboxMap = map;
        mapboxMap.setCameraPosition(new CameraPosition.Builder().target(new LatLng(60.169091, 24.939876)).zoom(12).tilt(20).bearing(90).build());
        mapboxMap.addOnMapLongClickListener(this::addSymbol);
        mapboxMap.addOnMapClickListener(this::addSymbol);
        mapboxMap.setStyle(getStyleBuilder(Style.MAPBOX_STREETS), style -> {
            findViewById(R.id.fabStyles).setOnClickListener(v -> mapboxMap.setStyle(getStyleBuilder(Utils.INSTANCE.getNextStyle())));
            symbolManager = new SymbolManager(mapView, mapboxMap, style);
            symbolManager.setIconAllowOverlap(true);
            symbolManager.setTextAllowOverlap(true);
        });
    });
}
Also used : SymbolManager(com.mapbox.mapboxsdk.plugins.annotation.SymbolManager) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 5 with SymbolManager

use of com.mapbox.mapboxsdk.plugins.annotation.SymbolManager 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);
            }
        });
    }));
}
Also used : PointF(android.graphics.PointF) 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) Random(java.util.Random) Expression.get(com.mapbox.mapboxsdk.style.expressions.Expression.get) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Expression.not(com.mapbox.mapboxsdk.style.expressions.Expression.not) Utils(com.mapbox.mapboxsdk.plugins.testapp.Utils) Expression.eq(com.mapbox.mapboxsdk.style.expressions.Expression.eq) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) CameraUpdateFactory(com.mapbox.mapboxsdk.camera.CameraUpdateFactory) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Locale(java.util.Locale) Toast(android.widget.Toast) Menu(android.view.Menu) View(android.view.View) Point(com.mapbox.geojson.Point) GeoJsonOptions(com.mapbox.mapboxsdk.style.sources.GeoJsonOptions) Expression(com.mapbox.mapboxsdk.style.expressions.Expression) SymbolManager(com.mapbox.mapboxsdk.plugins.annotation.SymbolManager) OnSymbolDragListener(com.mapbox.mapboxsdk.plugins.annotation.OnSymbolDragListener) IOException(java.io.IOException) Expression.toNumber(com.mapbox.mapboxsdk.style.expressions.Expression.toNumber) Symbol(com.mapbox.mapboxsdk.plugins.annotation.Symbol) Timber(timber.log.Timber) BitmapUtils(com.mapbox.mapboxsdk.utils.BitmapUtils) Color(android.graphics.Color) List(java.util.List) TextView(android.widget.TextView) LinearInterpolator(android.view.animation.LinearInterpolator) Style(com.mapbox.mapboxsdk.maps.Style) SymbolOptions(com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions) Property(com.mapbox.mapboxsdk.style.layers.Property) ValueAnimator(android.animation.ValueAnimator) GeoJsonOptions(com.mapbox.mapboxsdk.style.sources.GeoJsonOptions) Symbol(com.mapbox.mapboxsdk.plugins.annotation.Symbol) SymbolManager(com.mapbox.mapboxsdk.plugins.annotation.SymbolManager) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) IOException(java.io.IOException) OnSymbolDragListener(com.mapbox.mapboxsdk.plugins.annotation.OnSymbolDragListener) SymbolOptions(com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions)

Aggregations

SymbolManager (com.mapbox.mapboxsdk.plugins.annotation.SymbolManager)6 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)4 SymbolOptions (com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions)2 ValueAnimator (android.animation.ValueAnimator)1 Color (android.graphics.Color)1 PointF (android.graphics.PointF)1 Bundle (android.os.Bundle)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 LinearInterpolator (android.view.animation.LinearInterpolator)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 FloatingActionButton (com.google.android.material.floatingactionbutton.FloatingActionButton)1 FeatureCollection (com.mapbox.geojson.FeatureCollection)1 Point (com.mapbox.geojson.Point)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 CameraUpdateFactory (com.mapbox.mapboxsdk.camera.CameraUpdateFactory)1 MapView (com.mapbox.mapboxsdk.maps.MapView)1