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

How to locate my touch point on tileview? #491

Closed shoneworn closed 5 years ago

shoneworn commented 5 years ago

when i touch tileview , if i setOnTouchListener , i just get point of window postion . how can i get the position of tileview when i touch it . So I can add a point wherever i touched .

shoneworn commented 5 years ago

maybe I have know how to deal with it .

moagrius commented 5 years ago

what version are you using?

shoneworn commented 5 years ago

what version are you using?

2.7.7 I have find the method . thank you !

tva-TIS commented 5 years ago

what version are you using?

2.7.7 I have find the method . thank you !

Could you provide the method name? Looking for the same.

moagrius commented 5 years ago

I'm not sure there's a built in way in that version. Basically it's getScrollX/Y + event.getX/Y. If you want to scale it, do that.

tva-TIS commented 5 years ago

Yeah thanks. Wasn't sure which methods to use. (tileView.getScrollX() + event.getX()) / tileView.getScale() Does the trick.

moagrius commented 5 years ago

awesome, glad you figured it out

shoneworn commented 5 years ago

` @Override public boolean onSingleTapConfirmed( MotionEvent event ) { int x = getScrollX() + (int) event.getX() - getOffsetX(); int y = getScrollY() + (int) event.getY() - getOffsetY(); mMarkerLayout.processHit( x, y ); mHotSpotManager.processHit( x, y ); if(onSingleTapListener!=null){ onSingleTapListener.onSingleTap(x,y); } return super.onSingleTapConfirmed( event ); }

@Override public void onLongPress(MotionEvent event) { int x = getScrollX() + (int) event.getX() - getOffsetX(); int y = getScrollY() + (int) event.getY() - getOffsetY(); if(onLongPressListener!=null){ int mX =(int)( x/getScale()mCoordinateTranslater.getRight()/mDetailLevelManager.getBaseWidth()); int mY = (int)(y/getScale()mCoordinateTranslater.getBottom()/mDetailLevelManager.getBaseHeight()); onLongPressListener.onLongPress(mX,mY); } super.onLongPress(event); }` this two function is useful to listen click event . you must calculate your scale value to find real location. good luck.