Custom maker from vector assets

Hi all,

I am trying to create custom maker from vector assets. However everytime ti said icon cannot be created for empty image

java.lang.RuntimeException: Icon cannot be created for empty image
at com.tomtom.online.sdk.map.Icon.(Icon.java:63)
at com.tomtom.online.sdk.map.Icon$Factory.fromResources(Icon.java:145)
at com.tomtom.online.sdk.map.Icon$Factory.fromResources(Icon.java:131)

and the code I use is below:

 MarkerBuilder markerBuilder = new MarkerBuilder(position)
                .icon(Icon.Factory.fromResources(getApplicationContext(),R.drawable.ic_location_pin))
                .markerBalloon(markerBalloonData);

Is that the only way to create marker is via image?

Moreover are there any methods can automatically resize the marker when zoom in / out the map?

Thank you

Hi.
Please take a look at one of my answer on a similar topic here: Can someone explain how to change marker icon with kotlin

Let me know if this helps.

Regards,
Mateusz

Hi Mateusz,

Thank you so much. It works perfectly.

If others need Java version I can post the code here for reference.

Hi.

Glad to hear :slight_smile:

It would be great if you’ll could paste a Java snippet :slight_smile:

Regards,
Mateusz

Hi here is the code for reference, may not the best but can do the job:

private BitmapDrawable customMarker(){

    
    Drawable drawable = getApplicationContext().getDrawable(R.drawable.ic_location); 

    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight(),Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);

    drawable.setBounds(0,0,canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    BitmapDrawable bitmapDrawable = new BitmapDrawable(this.getResources(),bitmap);
    return bitmapDrawable;
}
1 Like