Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't tap on the itemizedoverlay #19

Closed
GoogleCodeExporter opened this issue Jan 13, 2016 · 20 comments
Closed

I can't tap on the itemizedoverlay #19

GoogleCodeExporter opened this issue Jan 13, 2016 · 20 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. open the itemizedoverlay sample
2. click on any overlay
3.

What is the expected output? What do you see instead?
I should see the Toast, instead nothing happens

What version of the product are you using? On what operating system?
Linux - ubuntu

Please provide any additional information below.


Original issue reported on code.google.com by osama.ib...@gmail.com on 1 Mar 2010 at 1:40

@GoogleCodeExporter
Copy link
Author

I have found that the problem is in this line:
OpenStreetMapViewItemizedOverlay:
line 127:
pj.toMapPixels(mItem.mGeoPoint, mCurScreenCoords);

Original comment by osama.ib...@gmail.com on 2 Mar 2010 at 5:02

@GoogleCodeExporter
Copy link
Author

This worked in revision 65, is broken in revision 66.

Original comment by neilboyd on 9 Mar 2010 at 9:17

@GoogleCodeExporter
Copy link
Author

Original comment by neilboyd on 9 Mar 2010 at 9:19

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

I (somehow) solved this problem, what you should do is convert the position 
tapped on
the map to the correct pixels on the view. and also change the origin point of 
the
map to (0,0) of the view ( to the left corner) not in the center. 

Original comment by osama.ib...@gmail.com on 10 Mar 2010 at 11:00

@GoogleCodeExporter
Copy link
Author

Please could you be more explicit about what you changed to get it to work.

Original comment by neilboyd on 12 Mar 2010 at 6:02

@GoogleCodeExporter
Copy link
Author

ok, here is the method I used:
@Override
    public boolean onSingleTapUp(final MotionEvent event, final OpenStreetMapView mapView) {
        final OpenStreetMapViewProjection pj = mapView.getProjection();
        final int eventX = (int)event.getX();
        final int eventY = (int)event.getY();
        final int markerWidth = this.mMarker.getIntrinsicWidth();
        final int markerHeight = this.mMarker.getIntrinsicHeight();

        /* These objects are created to avoid construct new ones every cycle. */
        final Rect curMarkerBounds = new Rect();
        final Point mCurScreenCoords = new Point();
        Point mCurScreenCoords2 = new Point();

        for(int i = 0; i < this.mItemList.size(); i++){
            final T mItem = this.mItemList.get(i);
            Log.d("NEWITEM", "**********************************************");
            pj.toMapPixels(mItem.mGeoPoint, mCurScreenCoords); 
//          pj.toPixels(mItem.mGeoPoint, mCurScreenCoords); 
            Log.d("CURSOR COORDINATES CHECKING(onsingletapup)", mCurScreenCoords.x + " " +
mCurScreenCoords.y);

            final int left = (mCurScreenCoords.x -this.mMarkerHotSpot.x - 15);
            final int right = left + markerWidth + 30;
            final int top = (mCurScreenCoords.y - this.mMarkerHotSpot.y - 15);
            final int bottom = top + markerHeight + 30 ;
            /* checking the marker attributes */
            Log.d("THE MARKER ATTRIBUTES(onsingletapup)", "" + this.mMarkerHotSpot.x + " " +
this.mMarkerHotSpot.y + " " + this.mMarkerWidth + " " + this.mMarkerHeight);
            curMarkerBounds.set(left, top, right, bottom);
            Log.d("THE POSITION ON THE MAP(onsingletapup)", "" + left + " " + right + " " +
top + " " + bottom);
            Log.d("THE EVENT POSITIONS(onsingletapup)", " "+eventX+" "+eventY );
            mCurScreenCoords2 = pj.fromPixels(eventX, eventY,OpenStreetMap.isSlided);
            Log.d("CURSOR COORDINATES CHECKING 2 (onsingletapup)", mCurScreenCoords2.x + " " +
mCurScreenCoords2.y);
            if(curMarkerBounds.contains(mCurScreenCoords2.x , mCurScreenCoords2.y ))
            {

                {if(onTap(i))
                Log.d("TAP HAPPENED", "**********************************************");
                    return true;

                }
            }
        }
        return super.onSingleTapUp(event, mapView);
    }


@Override
    public boolean onSingleTapUp(final MotionEvent event, final OpenStreetMapView mapView) {
        final OpenStreetMapViewProjection pj = mapView.getProjection();
        final int eventX = (int)event.getX();
        final int eventY = (int)event.getY();
        final int markerWidth = this.mMarker.getIntrinsicWidth();
        final int markerHeight = this.mMarker.getIntrinsicHeight();

        /* These objects are created to avoid construct new ones every cycle. */
        final Rect curMarkerBounds = new Rect();
        final Point mCurScreenCoords = new Point();
        Point mCurScreenCoords2 = new Point();

        for(int i = 0; i < this.mItemList.size(); i++){
            final T mItem = this.mItemList.get(i);
            Log.d("NEWITEM", "**********************************************");
            pj.toMapPixels(mItem.mGeoPoint, mCurScreenCoords); 
//          pj.toPixels(mItem.mGeoPoint, mCurScreenCoords); 
            Log.d("CURSOR COORDINATES CHECKING(onsingletapup)", mCurScreenCoords.x + " " +
mCurScreenCoords.y);

            final int left = (mCurScreenCoords.x -this.mMarkerHotSpot.x - 15);
            final int right = left + markerWidth + 30;
            final int top = (mCurScreenCoords.y - this.mMarkerHotSpot.y - 15);
            final int bottom = top + markerHeight + 30 ;
            /* checking the marker attributes */
            Log.d("THE MARKER ATTRIBUTES(onsingletapup)", "" + this.mMarkerHotSpot.x + " " +
this.mMarkerHotSpot.y + " " + this.mMarkerWidth + " " + this.mMarkerHeight);
            curMarkerBounds.set(left, top, right, bottom);
            Log.d("THE POSITION ON THE MAP(onsingletapup)", "" + left + " " + right + " " +
top + " " + bottom);
            Log.d("THE EVENT POSITIONS(onsingletapup)", " "+eventX+" "+eventY );
            mCurScreenCoords2 = pj.fromPixels(eventX, eventY,OpenStreetMap.isSlided);
            Log.d("CURSOR COORDINATES CHECKING 2 (onsingletapup)", mCurScreenCoords2.x + " " +
mCurScreenCoords2.y);
            if(curMarkerBounds.contains(mCurScreenCoords2.x , mCurScreenCoords2.y ))
            {

                {if(onTap(i))
                Log.d("TAP HAPPENED", "**********************************************");
                    return true;

                }
            }
        }
        return super.onSingleTapUp(event, mapView);
    }
////////////////////////////////////////////////////////

the slider is a boolean for the current configuration of the phone, 
@Override
        public void onConfigurationChanged(Configuration newConfig) {
              super.onConfigurationChanged(newConfig);
              isSlided= !isSlided;
            } 



I hope this could help you solve it :D

Original comment by osama.ib...@gmail.com on 12 Mar 2010 at 2:17

@GoogleCodeExporter
Copy link
Author

I would like to know your opinion about this solution as It took me some time, 
and
also I needed help from my supervisor :), but any ways It is now working :D

Original comment by osama.ib...@gmail.com on 12 Mar 2010 at 2:29

@GoogleCodeExporter
Copy link
Author

Issue 26 has been merged into this issue.

Original comment by neilboyd on 25 Mar 2010 at 6:12

@GoogleCodeExporter
Copy link
Author

Hi, 

I just realized that you merged issue 26 with this one. I've seen this issue 
before 
my issue post but I couldn't solve it with the code posted above. Has this 
issue been 
resolved? 
And if the above code is the correct answer - where do I put 
onConfigurationChanged 
and why can't I find OpenStreetMap.isSlided? (or do I have to implement 
isSlided 
myself)

Thanks alot!

Original comment by d.sc...@gmail.com on 25 Mar 2010 at 9:24

@GoogleCodeExporter
Copy link
Author

I have the same problem that d.schre. Where is OpenStreeMap.isSlided and 
onConfigurationChanged? 

Thanks

Original comment by gefe...@gmail.com on 25 Mar 2010 at 11:05

@GoogleCodeExporter
Copy link
Author

The onConfigurationChanged()  should be in the main Activity (the one with the 
map).

Original comment by osama.ib...@gmail.com on 25 Mar 2010 at 11:08

@GoogleCodeExporter
Copy link
Author

the isSlided is a boolean that should be added also to the main Activity.

Original comment by osama.ib...@gmail.com on 25 Mar 2010 at 11:09

@GoogleCodeExporter
Copy link
Author

this method should be added to the openStreetMapView.java, in the
OpenStreetMapViewProjection class, 

public Point fromPixels(int x, int y,final boolean slider) {
            if(!slider){
            Point out = new Point();
            // 1 Pixel equals 
            out.set(x,y);
            out.offset(-160, -230); //orientation !!
            // determine scale and multiply
            out.offset(getScrollX(),getScrollY());
            Log.d("OUT (value)(fromPixels)", "" + out.x + " " + out.y);
            Log.d("OFFSET PROJECTION (offsets)(fromPixels)", "" + offsetX + " " + offsetY);

            //return Mercator.projectPoint((int) x, (int) y, getPixelZoomLevel());
            //return bb.getGeoPointOfRelativePositionWithLinearInterpolation(x / viewWidth_2, y
            //      / viewHeight_2);
            return out;
            }
            else{
                Point out = new Point();
                out.set(x,y);
                out.offset(-230, -160); //orientation !!
                // determine scale and multiply
                out.offset(getScrollX(),getScrollY());
                Log.d("OUT (value)(fromPixels)", "" + out.x + " " + out.y);
                Log.d("OFFSET PROJECTION (offsets)(fromPixels)", "" + offsetX + " " + offsetY);
                return out;
            }

        }

Original comment by osama.ib...@gmail.com on 25 Mar 2010 at 11:12

@GoogleCodeExporter
Copy link
Author

you should also take care where you put the isSlided and the 
onConfigurationChanged,
because you will have to change it in the onSingleTapUp()
specifically in this line:
mCurScreenCoords2 = pj.fromPixels(eventX, eventY,OpenStreetMap.isSlided); 
you can change it to whatever class you use as the main activity.
I hope it is ok now.

Original comment by osama.ib...@gmail.com on 25 Mar 2010 at 11:15

@GoogleCodeExporter
Copy link
Author

thanks a lot. it works

Original comment by gefe...@gmail.com on 25 Mar 2010 at 11:32

@GoogleCodeExporter
Copy link
Author

you 're welcome ;)

Original comment by osama.ib...@gmail.com on 25 Mar 2010 at 11:34

@GoogleCodeExporter
Copy link
Author

Thank you for your detailed instructions! Now it's working!

Original comment by d.sc...@gmail.com on 25 Mar 2010 at 12:18

@GoogleCodeExporter
Copy link
Author

Original comment by neilboyd on 25 Mar 2010 at 2:07

@GoogleCodeExporter
Copy link
Author

This issue was closed by revision r120.

Original comment by neilboyd on 26 Mar 2010 at 6:29

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Fixed in revision r121.

Original comment by neilboyd on 26 Mar 2010 at 8:17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant