public
List<OverlayItem> mGeoList =
new
ArrayList<OverlayItem>();
private
Drawable marker;
private
Activity mContext;
View mPopView =
null
;
MapView mMapView;
List<?> list;
public
MyOverlay(Drawable marker, Activity context, MapView mMapView, List<?> list) {
super
(boundCenterBottom(marker));
this
.marker = marker;
this
.mContext = context;
this
.mMapView = mMapView;
this
.list = list;
addIteam();
mPopView = mContext.getLayoutInflater().inflate(R.layout.popview,
null
);
mMapView.addView(mPopView,
new
MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
null
,
MapView.LayoutParams.TOP_LEFT));
mPopView.setVisibility(View.GONE);
populate();
}
private
void
addIteam() {
int
listSize = list.size();
for
(
int
i =
0
; i < listSize; i++) {
GeoPoint geoPoint = ((List<MKPoiInfo>) list).get(i).pt;
String title = ((List<MKPoiInfo>) list).get(i).name;
String snippet = ((List<MKPoiInfo>) list).get(i).address;
mGeoList.add(
new
OverlayItem(geoPoint, title, snippet));
}
}
public
void
updateOverlay() {
populate();
}
@Override
protected
OverlayItem createItem(
int
i) {
mGeoList.get(i).setMarker(
new
BitmapDrawable(mContext.getResources(), markerBitmap(i)));
return
mGeoList.get(i);
}
String s =
"ABCDEFGHIJKLMNOPQWSXYZ"
;
String ss =
"骚年祝福激情燃烧其中有个猥琐滴"
;
private
Bitmap markerBitmap(
int
i) {
Bitmap bmp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.icon_marki_h);
Bitmap newb = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888);
Canvas canvasTmp =
new
Canvas(newb);
canvasTmp.drawColor(Color.TRANSPARENT);
Paint p =
new
Paint();
p.setColor(Color.WHITE);
p.setTextSize(
18
);
canvasTmp.drawBitmap(bmp,
0
,
0
, p);
canvasTmp.drawText(ss.charAt(i) +
""
, bmp.getWidth() /
7
, bmp.getHeight() /
7
*
4
, p);
canvasTmp.save(Canvas.ALL_SAVE_FLAG);
canvasTmp.restore();
return
newb;
}
@Override
public
void
draw(Canvas canvas, MapView mapView,
boolean
shadow) {
Projection projection = mapView.getProjection();
for
(
int
index = size() -
1
; index >=
0
; index--) {
OverlayItem overLayItem = getItem(index);
String title = overLayItem.getTitle();
Point point = projection.toPixels(overLayItem.getPoint(),
null
);
}
super
.draw(canvas, mapView, shadow);
boundCenterBottom(marker);
}
@Override
public
int
size() {
return
mGeoList.size();
}
protected
boolean
onTap(
int
i) {
setFocus(mGeoList.get(i));
GeoPoint pt = mGeoList.get(i).getPoint();
mMapView.updateViewLayout(mPopView,
new
MapView.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, pt, MapView.LayoutParams.BOTTOM_CENTER));
mPopView.setVisibility(View.VISIBLE);
Toast.makeText(
this
.mContext, mGeoList.get(i).getSnippet(), Toast.LENGTH_SHORT).show();
return
true
;
}
@Override
public
boolean
onTap(GeoPoint arg0, MapView arg1) {
mPopView.setVisibility(View.GONE);
return
super
.onTap(arg0, arg1);
}