mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

Can`t add a custom icon on Marker

Open andreinass opened this issue 10 years ago • 2 comments

Hello,

I'm trying to add a custom Icon to my markers in my app. Before it was made like this way:

marker.setMarker(getResources().getDrawable(R.drawable.ic_marker_no_premium));

Now, according with the documentation, in order to add a Marker I have to do it with MarkerOptions, and do the following:

SpriteFactory spriteFactory = mv.getSpriteFactory();
                Drawable drawable = ContextCompat.getDrawable(this, R.mipmap.ic_directions_boat_black_18dp);
                Sprite icon = spriteFactory.fromDrawable(drawable);

The thing is that I'm not able to make this work. First of all SpriteFactory library is not recognized in mapbox 3.2.0 version, and I can't find any other function that allow me to pursue this.

Is this an external library that I need to add?

Would you please give me any guidance on how to do this?

Regards

andreinass avatar Feb 01 '16 12:02 andreinass

Hi,

You should now use IconFactory. Sth like this should do the job.

IconFactory iconFactory = IconFactory.getInstance(context);
Icon icon = iconFactory.fromResource(R.id.your_img_res_id);

MarkerOptions markerOptions = new MarkerOptions();
markerOptions.icon(icon);

mpuchala avatar Feb 01 '16 13:02 mpuchala

@andreinass Thank you for reaching out and reporting your problem, The explanation from @mpuchala is correct. More information about this change can be found in https://github.com/mapbox/mapbox-gl-native/issues/3304.

Since nothing actionable is left to do, closing.

tobrun avatar Feb 01 '16 13:02 tobrun