Issue
I have a class that extends ItemizedOverlay<OverlayItem>
to put 200 markers on a MapView
.
Now I want 1 specific marker to always be on top of the others.
How would I do this?
This is how I add the markers to the overlay:
boolean isTopMarker;
for (Location location : locationList) {
isTopMarker = location.getTitle().equals("MyMarker");
markerOverlay.addOverlayItem(location.getLatitude(), location.getLongitude(), location.getTitle(), isTopMarker);
}
markerOverlay.moveTopMarkerToTop();
The methods in the MarkerOverlay
class:
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
public void addOverlayItem(OverlayItem overlayItem, boolean isTopMarker) {
if (isTopMarker) {
Drawable markerDrawable = getResources().getDrawable(R.drawable.marker_top);
boundCenterBottom(markerDrawable);
overlayItem.setMarker(markerDrawable);
topMarkerOverlayItem = overlayItem;
}
mOverlays.add(overlayItem);
populate();
}
public void addOverlayItem(double latitude, double longitude, String title, boolean isTopMarker) {
GeoPoint point = new GeoPoint((int) (latitude * 1000000), (int) (longitude * 1000000));
OverlayItem overlayItem = new OverlayItem(point, title, null);
addOverlayItem(overlayItem, isTopMarker);
}
public void moveTopMarkerToTop(){
if(topMarkerOverlayItem != null){
//What to do here?
}
}
I've tried to reassing a marker Drawable
to the topMarkerOverlayItem
, that didn't work. I also tried to remove and add the topMarkerOverlayItem
to the list of OverlayItem
s.
Solution
Try to make an extra ItemizedOverlay
for your special Marker, and add this ItemizedOverlay
at the end of the MapView.getOverlays()
List. MapView
will traverse through all Overlays
starting from 0 to Overlays.count(). This Way your Special Overlay should be drawn as last one and is therefore always on top!
Answered By - Rafael T
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.