My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 245: ItemizedOverlay<OverlayItem>:onTap on called when tapping
14 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  ----
Closed:  Apr 2013


Sign in to add a comment
 
Reported by erezbars...@gmail.com, Jul 27, 2011
I'm using osmdroid-android-3.0.5.jar‬ to embed OSMap in my app.
What steps will reproduce the problem?
1. Open the app.
2. Tap an item.
3. onTap(index i) not called

What is the expected output? What do you see instead?
breakpoint inside onTap nor reached.


What version of the product are you using? On what operating system?
2.2 emulator and also device - samsung galaxy


Please provide any additional information below.
same problem with osmdroid-android-3.0.4.jar


code:
MapActivity:

       MapView mapView = new MapView(this, 256);
        mapView.setClickable(true);
        mapView.setBuiltInZoomControls(true);
 
        mapView.getController().setZoom(10);
        mapView.getController().setCenter(new GeoPoint(39.461078, 2.856445));
        
        List<Overlay> mapOverlays = mapView.getOverlays();
		Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
		

		MapItemizedOverlay itemizedoverlay = new MapItemizedOverlay(drawable,this);
		itemizedoverlay.setEnabled(true);

		
		double lat = 39.461078;
		double lng = 2.856445;
		
		GeoPoint homePoint = new GeoPoint(lat,lng);
		OverlayItem overlayitem = new OverlayItem("Home Sweet Home", "name", homePoint);
		
		mapView.getController().setZoom(18);
		mapView.getController().setCenter(homePoint);
		
		itemizedoverlay.addOverlay(overlayitem);
		mapOverlays.add(itemizedoverlay);
 
        setContentView(mapView);


MapItemizedOverlay:

public class MapItemizedOverlay extends ItemizedOverlay<OverlayItem>
{
	 private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	 private Context mContext;
	
	 
	 public MapItemizedOverlay(Drawable defaultMarker, Context context)
	 {
		 //super(boundCenterBottom(defaultMarker));
		 super(defaultMarker, new DefaultResourceProxyImpl(context));
		 mContext = context;
	 }
	
	 public void addOverlay(OverlayItem overlay)
	 {
		 mOverlays.add(overlay);
		 populate();
	 }
	 @Override
	 protected OverlayItem createItem(int i)
	 {
		 return mOverlays.get(i);
	 }
	 @Override
	 public int size()
	 {
		 return mOverlays.size();
	 }
	
	 protected boolean onTap(int index)
	 {
		 OverlayItem item = mOverlays.get(index);
		 AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		 dialog.setTitle(item.getTitle());
		 dialog.setMessage(item.getSnippet());
		 dialog.show();
		 return true;
	}
	 
	 //boolean onTap(GeoPoint p, MapView mapView)
	 //{
	//	 return false;
	 //}

	
	@Override
	public boolean onSnapToItem(int arg0, int arg1, Point arg2, MapView arg3) {
		// TODO Auto-generated method stub
		return false;
	}
	
	
	

}



Aug 9, 2011
#1 reinhard...@gmail.com
Doesn't work for me either.
Is there a workaround or another way on how to execute methods for each marker?
Aug 18, 2011
#2 rui.mtd....@gmail.com
Same here. Just ported an app from Google Maps to osmdroid, and the onTap doesn't work. I use it a lot on driving directions, to tap on the turn markers to get some text info in a popup window.

In my original code, I'm using the @Override annotation in the onTap method. In osmdroid, I can't. That method doesn't exist.

Aug 27, 2011
#3 azq...@gmail.com
doesntr work for me teither
Sep 11, 2011
#4 zero...@gmail.com
Hi. I've the same issue. anybody knows how to solve it?
Oct 25, 2011
#6 javi.xanxez@gmail.com
I have the same problem with that. I think they change one method by the other one (onSnapToItem by onTap).
Oct 27, 2011
#7 kako1...@gmail.com
Why it says:

	@Override
	public boolean onSnapToItem(int pX, int pY, Point pSnapPoint, MapView pMapView) {
		// TODO Implement this!
		return false;
	}

TODO?
Feb 20, 2012
#8 marc.pou...@gmail.com
'up' !

I'm porting an application that uses an old snapshot of osmdroid, and it tries to override onTap() in an ItemizedOverlay<> class. But since r417 (https://code.google.com/p/osmdroid/source/detail?spec=svn417&r=417 ), this method has been removed.

It is still documented in 4.0 docs of Android API:

https://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/ItemizedOverlay.html

Is this a bug ? Maybe there is a known workaround on how to get the same behavior, but I could not find it after searching different forums/groups/source code.

Any help very appreciated :)

May 2, 2012
#9 jyee.dis...@onescreen.com
Has anyone solved this?
May 2, 2012
#10 90.se...@gmail.com
Hi,

I also got this problem some weeks ago... Finally, I solved it using ItemizedOverlayWithFocus class and its onItemSingleTapUp method.
May 9, 2012
#11 siile...@gmail.com
sergi, can you post an example of using ItemizedOverlayWithFocus within a class? Thanks!
May 16, 2012
#12 www.trad...@free.fr
I encountered exactly the same issue. And this is probably the only real issue when porting an app from GoogleAPI to osmdroid. So solutions should be documented well. Here is my modest contribution. 

First of all, look at ItemizedIconOverlay, as it does most of what we want. 
After struggling a lot trying to sub-class ItemizedIconOverlay with my custom onSingleTapUpHelper, I finally made a class containing ItemizedIconOverlay. 
Applied to your implementation, it looks like this:


public class MyOwnItemizedOverlay {
	protected ItemizedIconOverlay<OverlayItem> mOverlay;
	protected Context mContext;
	protected Drawable mMarker;

	public MyOwnItemizedOverlay(Drawable marker, Context context) {
		mContext = context;
		ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
		ResourceProxy resourceProxy = (ResourceProxy) new DefaultResourceProxyImpl(mContext);
		mMarker = marker;

		mOverlay = new ItemizedIconOverlay<OverlayItem>(
				items, mMarker, 
				new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
			@Override public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
				return onSingleTapUpHelper(index, item);
			}
	
			@Override public boolean onItemLongPress(final int index, final OverlayItem item) {
				return true;
			}
		}, resourceProxy);

	}
	
	public boolean onSingleTapUpHelper(int i, OverlayItem item) {
		//Toast.makeText(mContext, "Item " + i + " has been tapped!", Toast.LENGTH_SHORT).show();
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;
	}
	
	public void addItem(OverlayItem item){
		mOverlay.addItem(item);
	}
	
	public ItemizedIconOverlay<OverlayItem> getOverlay(){
		return mOverlay;
	}
}


Using this class is nearly identical to using a sub-class of ItemizedOverlay (as you did in your MapActivity), except that adding the overlay to the map is done this way: 
	mapView.getOverlays().add(itemizedoverlay.getOverlay());

Note that you can also easily implement onItemLongPress, if desired. 


May 17, 2012
#13 siile...@gmail.com
Thanks man, that worked out just awesomely! :)
May 17, 2012
Project Member #14 neilboyd
See also  issue 343 
Jun 23, 2012
#16 mathieu....@gmail.com
Guys, 
Find below a very simple and "regular" implementation, as MyOwnItemizedOverlay is now a "true" overlay. 


class MyOwnItemizedOverlay extends ItemizedIconOverlay<OverlayItem> {
	protected Context mContext;
	
	public MyItemizedOverlay(final Context context, final List<OverlayItem> aList) {
		 super(context, aList, new OnItemGestureListener<OverlayItem>() {
            @Override public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
                    return false;
            }
            @Override public boolean onItemLongPress(final int index, final OverlayItem item) {
                    return false;
            }
    	  } );
	  mContext = context;
	}
	
	@Override protected boolean onSingleTapUpHelper(final int index, final OverlayItem item, final MapView mapView) {
		//Toast.makeText(mContext, "Item " + index + " has been tapped!", Toast.LENGTH_SHORT).show();
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;
	}
}

And to use it in your activity:
ArrayList<OverlayItem> list = new ArrayList<OverlayItem>();
MyOwnItemizedOverlay<OverlayItem> overlay = new MyOwnItemizedOverlay(this, list);
mapView.getOverlays.add(overlay);

Aug 21, 2012
#18 carlos...@gmail.com
Thanks for sharing matheu.  The constructor name is wrong in comment 16 above, it should be public MyOwnItemizedOverlay(...)
Jan 25, 2013
Project Member #20 kurtzm...@gmail.com
This issue should be closed. We have a samples app that covers handling item clicks.

If there is any issue here it is that we aren't implementing an onTap() method as the Google Maps API does (how did that happen?).
Jan 25, 2013
Project Member #21 kurtzm...@gmail.com
 Issue 343  has been merged into this issue.
Apr 11, 2013
Project Member #22 kurtzm...@gmail.com
 Issue 225  has been merged into this issue.
Apr 11, 2013
Project Member #23 kurtzm...@gmail.com
In r1209 we have added onTap and OnFocusChangedListenerSupport.

Status: Fixed
Apr 12, 2013
#24 devemu...@gmail.com
Hi kurtzmarc,

If we want to catch a tap event at an overlay, what's the difference between new way with ItemizedOverlay's onTap and old way with ItemizedIconOverlay's onSingleTapUpHelper ?
Personally I extend ItemizedIconOverlay and use helper methods for both single tap and long press.
Now we can catch the tap event with 2 ways?

Thanks
Apr 12, 2013
Project Member #25 kurtzm...@gmail.com
ItemizedIconOverlay is a concrete implementation of the ItemizedOverlay - it really belongs in the samples app because it's more of an example of how you can implement ItemizedOverlay. It could probably be rewritten to take advantage of onTap().

It's up to you which one you use. It looks like the ItemizedIconOverlay does not take the "hotspot" into account, so you may have better results with onTap().
Sign in to add a comment

Powered by Google Project Hosting