Closed GoogleCodeExporter closed 9 years ago
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
This worked in revision 65, is broken in revision 66.
Original comment by neilboyd
on 9 Mar 2010 at 9:17
Original comment by neilboyd
on 9 Mar 2010 at 9:19
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
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
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
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
Issue 26 has been merged into this issue.
Original comment by neilboyd
on 25 Mar 2010 at 6:12
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
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
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
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
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
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
thanks a lot. it works
Original comment by gefe...@gmail.com
on 25 Mar 2010 at 11:32
you 're welcome ;)
Original comment by osama.ib...@gmail.com
on 25 Mar 2010 at 11:34
Thank you for your detailed instructions! Now it's working!
Original comment by d.sc...@gmail.com
on 25 Mar 2010 at 12:18
Original comment by neilboyd
on 25 Mar 2010 at 2:07
This issue was closed by revision r120.
Original comment by neilboyd
on 26 Mar 2010 at 6:29
Fixed in revision r121.
Original comment by neilboyd
on 26 Mar 2010 at 8:17
Original issue reported on code.google.com by
osama.ib...@gmail.com
on 1 Mar 2010 at 1:40