OSMdroid add custom icons to ItemizedOverlay
Asked Answered
R

1

8

I am using ItemizedIconOverlay class and I'm currently displaying events on the map along with the user's position with the same default icon.

How do I change the icon set for each overlay?

Is there something similar to the google.maps example:

    drawable = getResources().getDrawable(R.drawable.marker);
    drawable3 = getResources().getDrawable(R.drawable.disruption);
    drawable2 = getResources().getDrawable(R.drawable.marker_me);

    itemizedOverlay = new MyItemizedOverlay(drawable, mapView);
    itemizedOverlay2 = new MyItemizedOverlay(drawable2, mapView);
    itemizedOverlay3 = new MyItemizedOverlay(drawable3, mapView);

I had each itemizedOverlay have its own marker...

How do I do this with Open Street Maps?

mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(mItems, new Glistener(), mResourceProxy);

Thank you for your help and its a shame not much support is available online for this open source project ...

Rikki answered 10/5, 2012 at 11:30 Comment(0)
S
20

Presumably your mItems is an ArrayList of OverlayItems created like:

mItems = new ArrayList<OverlayItem>();

To this list you will be adding individual OveralyItems, so when you create each item you can do it like this, setting the marker before you add it to the list:

OverlayItem olItem = new OverlayItem("Here", "SampleDescription", point);
Drawable newMarker = this.getResources().getDrawable(R.drawable.mymarker);
olItem.setMarker(newMarker);
mItems.add(olItem);

where mymarker is a .png in your drawables folder.

Update - to set default marker for whole overlay, change

this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(mItems, new Glistener(), mResourceProxy);

to

this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(mItems, newMarker, new Glistener(), mResourceProxy);

where newMarker is as before

Serpasil answered 10/5, 2012 at 12:24 Comment(3)
But can I add a default marker for the whole overlay? Like itemizedOverlay = new MyItemizedOverlay(drawable, mapView); and then each item added to that overlay gets the specific marker.Rikki
Yes, it appears there is another constructor available which takes a default marker as well. I'll edit my answer with an updateSerpasil
The problem that I'm having is that my custom markers look extremely big :/Craner

© 2022 - 2024 — McMap. All rights reserved.