Philippe Castellin
Philippe Castellin

Reputation: 83

Hiding / showing markers: OSMDroid / OpenMaps

I have an app which uses or googlemaps or openMaps (offline) depending of connection state.

In each case there are markers, for places or point of interest or… I want that the user can display or hide some category of markers.

When using google maps I have a menu and in the action bar when some item is selected it toggles between showing or hiding the markers from the correpondent category; As for google maps that works easily & perfectly using isVisible();

As for osmdroid i have not found in the doc any equivalent to isVisible(), neither any show() or hide() method. So I have tried to use as a workaround somemarkers.getAlpha() & somemarkers.setAlpha(), toggling between 0 & 1 alpha values.

No error occurs but the visibility of markers remains the same, not toggling, or only randomly when i tap 10 or 20 times on the action icon.

In the log i get "InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed" which seems to me to be the cause.

But what to do to avoid this?

KitKat, SonyXperia Z

Upvotes: 0

Views: 2225

Answers (2)

amsurana
amsurana

Reputation: 234

I have done this bit differently.

  1. Extend ItemizedIconOverlay
  2. Add as an overlay to mapView
  3. Hide markers by using removeAllItems or removeItem
  4. Show marker by adding it to the itemized overlay list

Create a new Overlay class by extending ItemizedIconOverlay. Note: WaypointOverlayItem extends OverlayItem. {It's your custom overlay model class}

        public class NavigatorItemizedOverlay extends ItemizedIconOverlay<WaypointOverlayItem> {

        private Context mContext;

        public NavigatorItemizedOverlay(final Context context, final List<WaypointOverlayItem> aList) {
            super(context, aList, new OnItemGestureListener<WaypointOverlayItem>() {

                @Override
                public boolean onItemSingleTapUp(int index, WaypointOverlayItem item) {
                    return false;
                }

                @Override
                public boolean onItemLongPress(int index, WaypointOverlayItem item) {
                    return false;
                }
            });
            // TODO Auto-generated constructor stub
            mContext = context;
        }
      }

Add this Overlay to your map

      //Add Itemized overlay
        navigatorItemizedOverlay = new NavigatorItemizedOverlay(getActivity(), waypointOverlayItemList);
        mapView.getOverlays().add(navigatorItemizedOverlay);

To Add marker:

navigatorItemizedOverlay.addItem(waypointOverlayItem);

To hide all markers:

navigatorItemizedOverlay.removeAllItems();

There are other methods:

removeItem(position) and removeItem(waypointOverlayItem)

Upvotes: 0

MKer
MKer

Reputation: 3450

In osmdroid, the method to hide/show overlays (markers) is:

Overlay.setEnabled(boolean enabled)

Upvotes: 2

Related Questions