4

I have a problem with ItemizedOverlayWithFocus, when trying the a osmdorid example it works just fine. I tried to change Icons of markers then a problem occurred. When tapping on an item it shows another overlay with description instead of showing the description above the item.

    final Context context = getActivity();

    /* Create a static ItemizedOverlay showing some Markers on various cities. */
    final ArrayList<OverlayItem> items = new ArrayList<>();

    OverlayItem overlayItem;
       Drawable marker = getResources().getDrawable(R.drawable.ic_hospital_);
    for (Hospital h : hospitals) {
        overlayItem = new OverlayItem(
                h.getName(), h.getAdresse(), new GeoPoint(h.getLatitude(), h.getLongitude()));
        overlayItem.setMarker(marker);
        items.add(overlayItem);
    }

    /* OnTapListener for the Markers, shows a simple Toast. */
    final ItemizedOverlayWithFocus itemizedOverlayWithFocus = new ItemizedOverlayWithFocus<OverlayItem>(items,
            new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
                @Override
                public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
                    Toast.makeText(
                            context,
                            "Item '" + item.getTitle() + "' (index=" + index
                                    + ") got single tapped up", Toast.LENGTH_LONG).show();
                    return true;
                }

                @Override
                public boolean onItemLongPress(final int index, final OverlayItem item) {

                    return false;
                }
            },context);

      itemizedOverlayWithFocus.setFocusItemsOnTap(true);
    //  itemizedOverlayWithFocus.setFocusedItem(0);
    itemizedOverlayWithFocus.setOnFocusChangeListener(new ItemizedOverlay.OnFocusChangeListener() {
        @Override
        public void onFocusChanged(ItemizedOverlay<?> overlay, OverlayItem newFocus) {
            itemizedOverlayWithFocus.unSetFocusedItem();
            itemizedOverlayWithFocus.setFocusedItem(newFocus);
        }
    });

    itemizedOverlayWithFocus.setMarkerBackgroundColor(Color.BLUE);
    itemizedOverlayWithFocus.setMarkerTitleForegroundColor(Color.WHITE);
    itemizedOverlayWithFocus.setMarkerDescriptionForegroundColor(Color.WHITE);
    itemizedOverlayWithFocus.setDescriptionBoxPadding(15);

    mapView.getOverlays().add(itemizedOverlayWithFocus);

    RotationGestureOverlay mRotationGestureOverlay = new RotationGestureOverlay(mapView);
    mRotationGestureOverlay.setEnabled(false);
    mapView.getOverlays().add(mRotationGestureOverlay);

    MinimapOverlay miniMapOverlay = new MinimapOverlay(context,
            mapView.getTileRequestCompleteHandler());
    mapView.getOverlays().add(miniMapOverlay);


    // Zoom and center on the focused item.

    setHasOptionsMenu(true);
}

I have two items in my map:

map with two items

And when tapping on an overlay it shows another item with a description:

map with focused item and visible defect

Josef Adamcik
  • 5,620
  • 3
  • 36
  • 42

0 Answers0