moagrius / TileView

TileView is a subclass of android.view.ViewGroup that asynchronously displays, pans and zooms tile-based images. Plugins are available for features like markers, hotspots, and path drawing.
MIT License
1.46k stars 337 forks source link

Marker Tap event not triggered after dynamic add #19

Closed Tristus1er closed 11 years ago

Tristus1er commented 11 years ago

I add dynamically a marker, it works fine, but the event onTap is not triggered. But if I zoom a bit (out or in) the the event is trigged on the markers :-/

What is done during the zoom that help the Marker to be triggered after.

Note: I launch a redraw() after adding the marker (so the clip is recalculated).

moagrius commented 11 years ago

i'm not following - can you use code or psuedo-code to describe step-by-step what you're experiencing?

moagrius commented 11 years ago

per email exchange, this issue was resolved by calling requestLayout after adding a marker, to make sure the layout rect was registered with the hit-testing map. The latest release has this functionality built-in.

Eteokles commented 11 years ago

For me it's not working. When i add a marker dynamically and if i don't zoom in or out onTap is not triggered. I use the last src version and i've called requestLayout (after a test without) but it doesn't work...

Tristus1er commented 11 years ago

Same here !

moagrius commented 11 years ago

can you guys try calling both invalidate* and postInvalidate on the MarkerManager after the marker is added?

or... can you provide step-by-step instructions to recreate?

Eteokles commented 11 years ago

in my onFingerDown method i do handler.postdelayed( runnable, ViewConfiguration.getLongPressTimeout() );

runnable : public void run() { if (!movedFinger) { ImageView marker = new ImageView(ctx); marker.setImageResource(R.drawable.marker); marker.setTag("Test"); tileview.addMarker(marker, xPoint, yPoint, -0.5f, -1f); } }

I've tried both invalidate and postInvalidate but without result.

moagrius commented 11 years ago

I see - so the marker is rendering but it's not being registered for the onMarkerTap event, right? If that's not correct, please explain.

Assuming that is correct, a little background: onMakerTap just compares the coordinates of the tap event to a map of all the marker's layout as Rects. This is calculated in onLayout.

I suspect the problem is because you're both adding markers from a handler, off the UI thread. So, try this:

At the end of your run method (on the line after tileview.addMarker(marker, xPoint, yPoint, -0.5f, -1f);), add something like this

tileview.post(new Runnable(){
  @Override
  public void run(){
    tileview.requestLayout();
  }
});

post will be called on the TileView's UI thread, and hopefully force a recalculation of the marker layouts which would register them with the onMarkerTap map of Rects.

LMK if that helps. If not, I'll try to recreate locally to find a patch.

Eteokles commented 11 years ago

nop... it still not work.

moagrius commented 11 years ago

ok, i'll create a debug build and post back within the next couple days, hopefully with a patch to commit

thanks for the feedback

Eteokles commented 11 years ago

in the onLayout method of MarkerManager if i comment

if(!changed){ 
    return; 
}

It's work. The Rect is not define.

moagrius commented 11 years ago

awesome - looks like a premature optimization - I'll make the change and commit as soon as I get a chance.

thanks!

moagrius commented 11 years ago

@skaor this patch has been included in the latest commit and release. thanks for contributing!

Eteokles commented 11 years ago

yeahhh my first contrib to a github project :p !

moagrius commented 11 years ago

you're even mentioned in the release - you're basically famous now ;)