ItemizedOverlayWithFocus在聚焦osmdroid时显示另一个叠加

时间:2019-02-19 11:05:28

标签: java android openstreetmap osmdroid

我对ItemizedOverlayWithFocus遇到问题,尝试使用渗透压示例时,它可以正常工作。我试图更改标记的图标,然后出现了问题。点击项目时,它会显示另一个带有说明的覆盖层,而不是在项目上方显示说明。

    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);
}

我的地图上有两项:

map with two items

点击覆盖时,它会显示另一个带有说明的项目:

map with focused item and visible defect

0 个答案:

没有答案