I faced the same situation a couple of weeks ago.
You should use one ItemizedOverlay for each different drawable, and then add overlayItems to the ItemizedOverlay.
The most convenient way is to extend ItemizedOverlay, so you can define a marker and a click behavoir for each style you need.
For the second part, for performance concerns, you shouldn't populate your map with all your 500 items once at a time. I used a system that dynamically adds to the map markers that belongs to the displayed scope of map.
Here is the snippet of my ItemizedOverlay that could be useful for both of your questions :
private class MarkerItemized_Overlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
Context mContext;
public MarkerItemizedOverlay(Drawable marker, Context context) {
super(boundCenterBottom(marker));
mContext = context;
}
public void addOverlay(OverlayItem overlay) {
if (!mOverlays.contains(overlay)) {
mOverlays.add(overlay);
populate();
}
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
@Override
protected boolean onTap(final int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.setNegativeButton("Annuler",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
});
dialog.setPositiveButton("Naviguer",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){ showDirections(mOverlays.get(index).getPoint()); }
});
dialog.setInverseBackgroundForced(true);
dialog.show();
return true;
}
public boolean contains(Store store) {
return mOverlays.contains(store);
}
@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView) {
if (e.getAction() == MotionEvent.ACTION_UP) {
GeoPoint newCenter = mapView.getMapCenter();
int minLat, maxLat, minLng, maxLng;
minLat = mapCenter.getLatitudeE6() - mapView.getLatitudeSpan()/2;
maxLat = mapCenter.getLatitudeE6() + mapView.getLatitudeSpan()/2;
minLng = mapCenter.getLongitudeE6() - mapView.getLongitudeSpan()/2;
maxLng = mapCenter.getLongitudeE6() + mapView.getLongitudeSpan()/2;
if (newCenter.getLatitudeE6() > maxLat ||
newCenter.getLatitudeE6() < minLat ||
newCenter.getLongitudeE6() > maxLng ||
newCenter.getLongitudeE6() < minLng)
{
mapCenter = mapView.getMapCenter();
Location mapCenterLoc = new Location(providerName);
mapCenterLoc.setLatitude(newCenter.getLatitudeE6()/1E6);
mapCenterLoc.setLongitude(newCenter.getLongitudeE6()/1E6);
Store[] newClosestStores = storeDB.getClosestStores(mapCenterLoc);
for (int i = 0; i < newClosestStores.length; i++)
if (! itemizedOverlay.contains(newClosestStores[i]))
setMarker(newClosestStores[i]);
}
}
return super.onTouchEvent(e, mapView);
}
}