Mapbox-gl-native: IconFactory - fromDrawable() not avaible.

Created on 23 Feb 2017  路  1Comment  路  Source: mapbox/mapbox-gl-native

Android:
5.0.0

Steps to trigger behavior

  1. Create android project
  2. import dependencies
  3. Create a marker and try to set icon !

fromDrawable should show up, when using iconfactory

only fromFile,fromBitmap,fromAsset and fromPath are shown !

Most helpful comment

We have limited support to only using Bitmaps,
though you can convert any drawable to an Icon using the following utility method:

public class IconUtils {

  /**
   * Demonstrates converting any Drawable to an Icon, for use as a marker icon.
   */
  public static Icon drawableToIcon(@NonNull Context context, @DrawableRes int id, @ColorInt int colorRes) {
    Drawable vectorDrawable = ResourcesCompat.getDrawable(context.getResources(), id, context.getTheme());
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
      vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    DrawableCompat.setTint(vectorDrawable, colorRes);
    vectorDrawable.draw(canvas);
    return IconFactory.getInstance(context).fromBitmap(bitmap);
  }
}

Refs #7897

>All comments

We have limited support to only using Bitmaps,
though you can convert any drawable to an Icon using the following utility method:

public class IconUtils {

  /**
   * Demonstrates converting any Drawable to an Icon, for use as a marker icon.
   */
  public static Icon drawableToIcon(@NonNull Context context, @DrawableRes int id, @ColorInt int colorRes) {
    Drawable vectorDrawable = ResourcesCompat.getDrawable(context.getResources(), id, context.getTheme());
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
      vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    DrawableCompat.setTint(vectorDrawable, colorRes);
    vectorDrawable.draw(canvas);
    return IconFactory.getInstance(context).fromBitmap(bitmap);
  }
}

Refs #7897

Was this page helpful?
0 / 5 - 0 ratings