1

I am setting markers on an Android Mapbox. Those markers are not squarred images and can not be centered, they need an offset.

On Google Maps I can use Anchor, X and Y.

On previous versions of Mapbox I could have used MarkerView with the same Anchor.

But now in Mapbox 5.2 MarkerView is deprecated.

So how to align my markers correctly on my map ?

Thanks

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ben-J
  • 1,084
  • 8
  • 24

1 Answers1

0

I am currently using this solution :

 /**
 * Generate a new bitmap to center it on Mapbox
 * @param icon the icon to display
 * @param centerFromTop The center of the picto from the top, in percentage, from 0.0 to 1.0. 1.0 
 *                      means the picto will be centered on the exact bottom of the original image.
 * @return
 */
public static Bitmap cheatMapboxMarker(Bitmap icon, float centerFromTop) {
    int height = (int) (2 * centerFromTop * icon.getHeight());
    Bitmap loc_img = Bitmap.createBitmap(icon.getWidth(), height, Bitmap.Config.ARGB_8888);
    Canvas bitmapCanvas = new Canvas(loc_img);
    Bitmap tempBitmap = icon.copy(Bitmap.Config.ARGB_8888, false);
    bitmapCanvas.drawBitmap(tempBitmap, 0, 0, null);
    return loc_img;
}
Ben-J
  • 1,084
  • 8
  • 24