I'm fighting with following problem now: I add a simple overlay to my mapview. It doesn't draw anything, it is just a help overlay for detecting scroll is ended (see response)
Here is the code of it:
public class ScrollDetectionOverlay extends Overlay
{
private static GeoPoint lastLatLon = new GeoPoint(0, 0);
private static GeoPoint currLatLon;
protected boolean isMapMoving = false;
private MapScrollingFinishedListener listener = null;
public void setListener(MapScrollingFinishedListener listener)
{
this.listener = listener;
}
@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView)
{
super.onTouchEvent(e, mapView);
if (e.getAction() == MotionEvent.ACTION_UP)
{
isMapMoving = true;
}
return true;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow)
{
super.draw(canvas, mapView, shadow);
if (!shadow)
{
if (isMapMoving)
{
currLatLon = mapView.getProjection().fromPixels(0, 0);
if (currLatLon.equals(lastLatLon))
{
isMapMoving = false;
listener.onScrollingFinished();
}
else
{
lastLatLon = currLatLon;
}
}
}
}
}
If I'm adding this overlay to my mapview, I can't scroll the map anymore. Below is the code for adding and removing of the overlay from the mapview:
@Override
protected void onResume()
{
super.onResume();
if (!getMapView().getOverlays().contains(scrollDetectionOverlay))
{
scrollDetectionOverlay = new ScrollDetectionOverlay();
scrollDetectionOverlay.setListener(this);
getMapView().getOverlays().add(scrollDetectionOverlay);
}
}
@Override
protected void onPause()
{
super.onPause();
if (getMapView().getOverlays().contains(scrollDetectionOverlay))
{
getMapView().getOverlays().remove(scrollDetectionOverlay);
scrollDetectionOverlay = null;
}
}
What do I'm wrong?
And another thing I noticed. The draw-method of overlay will be called, and called, and called, without user does anything. Some reason for it?
Thank you.