I created a custom OverlayItem class so that I could essentially have one kind of OverlayItem whose Drawable marker would set itself depending on the state of some data that I pass into it.
I have attempted to accomplish this by, on my first attempt, utilizing the setMarker
method within the OverlayItem class. Once that did not work I attempt to override the getMarker
method and have it return the appropriate marker to represent the data.
Both of these attempts ended with nothing being drawn on the map...however if they are commented out the markers draw just fine (except they of course use the default marker, which isn't what I want).
Here is my code for my custom OverlayItem class (the commented out methods I have tried and they have not worked):
private class MyOverlayItem extends OverlayItem {
private Context mContext;
private MyData mData;
public MyOverlayItem(GeoPoint point, MyData data, Context context) {
super(point, data.getWhat(), data.getWhere());
this.mContext = context;
this.mData = data;
/*if(data.getTemp() > 200)
this.setMarker(res.getDrawable(R.drawable.icon_data_hot_l));
else if(data.getTemp() > 100)
this.setMarker(res.getDrawable(R.drawable.icon_data_neutral_l));
else
this.setMarker(res.getDrawable(R.drawable.icon_data_frozen_l));*/
}
/*@Override
public Drawable getMarker(int stateBitset) {
Resources res = this.mContext.getResources();
if(this.mData.getTemp() > 200)
return res.getDrawable(R.drawable.icon_data_hot_l);
else if(this.mData.getTemp() > 100)
return res.getDrawable(R.drawable.icon_data_neutral_l);
return res.getDrawable(R.drawable.icon_data_frozen_l);
}*/
}
Is there a way to do what I am attempting to do...or do I need to make a unique OverlayItem class corresponding to each state of my data? (Ew.)
I have been able to make the markers appear, however they are appearing upside-down (at least, I think they are, it may just be that their shadow is at the top-left rather than the bottom-right).
All I needed to do was add this line:
this.mMarker.setBounds(0, 0, this.mMarker.getIntrinsicWidth(), this.mMarker.getIntrinsicHeight());
...as well as this line to correctly orient the markers (I added this when my ItemizedOverlay adds tan overlay item:
overlay.setMarker(boundCenterBottom(overlay.getMarker(0)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With