bobanf89 / osmdroid

Automatically exported from code.google.com/p/osmdroid
0 stars 0 forks source link

OverlayItem and ItemizedOverlay do not support real-time position updates #408

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have an item on the map who's geo position changes often. I need to update 
its placement on the map without removing and re-adding it. This works in 
Google's map API.

What steps will reproduce the problem?
1. Override OverlayItem.getPoint() and return an updated geo point
2. Call MapView.invalidate()

What is the expected output? What do you see instead?
The item is redrawn but its position is not changed. 

What version of the product are you using? On what operating system?
3.0.8 on Android

Please provide any additional information below.
The problem is caused by a bug in ItemizedOverlay.draw. It does not invoke 
getPoint() to an item's location. 
This line:
   pj.toMapPixels(item.mGeoPoint, mCurScreenCoords);
should be changed to:
   pj.toMapPixels(item.getPoint(), mCurScreenCoords);

It looks like OverlayItem started life as a POD but evolved into something 
more. I spent hours trying to get this to work. Another alternative (less 
compatible with Google's API) is to make all of the methods of OverlayItem 
final so it doesn't mislead people.

Work around:
Override this method in your ItemizedOverlay implementation:

protected void onDrawItem(final Canvas canvas, final MyOverlayItem item, 
      final Point incorrectScreenCoords) 
{
  Projection proj = mapView_.getProjection();
  Point correctScreenCoords = proj.toMapPixels(item.getPoint(), null);
  super.onDrawItem(canvas, item, correctScreenCoords);
}

Original issue reported on code.google.com by james.st...@gmail.com on 1 Mar 2013 at 10:04

GoogleCodeExporter commented 8 years ago
You are correct - this is a bug. I don't know why the all the member variables 
are public (it appears they have been that way since very early on). The Google 
API shows that they should be protected and (even though ItemizedOverlay would 
have access to the protected variables) the getters should be used to access 
those properties.

Original comment by kurtzm...@gmail.com on 14 Jun 2013 at 2:08

GoogleCodeExporter commented 8 years ago
This issue was updated by revision r1244.

Make Uid, Title, Description/Snippet, and Point variables protected rather than 
public which matches the Google API. This forces use of the getters for those 
variables and permits subclasses to provide custom behavior.

Original comment by kurtzm...@gmail.com on 14 Jun 2013 at 7:27

GoogleCodeExporter commented 8 years ago

Original comment by kurtzm...@gmail.com on 14 Jun 2013 at 7:56

GoogleCodeExporter commented 8 years ago
This has been released in 4.0.

Original comment by kurtzm...@gmail.com on 25 Oct 2013 at 1:36