Android Question Problem updating view

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Using OSMDroid 4.1 and have a TouchOverLay to add GeoPoints to a PathOverLay.
Both OverLays are added to a MapView, named MapView1.

B4X:
Sub TouchOverLay1_Click(GeoPoint1 As OSMDroid_GeoPoint) As Boolean
 
    AddAreaPoint(GeoPoint1)
    Return(False)
 
End Sub

Sub AddAreaPoint(GeoPoint1 As OSMDroid_GeoPoint)
 
    'as there seems no way to get these back from the PathOverLay!
    PathOverLay1Points.Add(GeoPoint1)
    PathOverlay1.AddPoint(GeoPoint1)
 
End Sub

This works fine and the GeoPoints are added OK. Problem it doesn't show directly in the MapView.
Moving the MapView refreshes the image and makes the path show with the new GeoPoint. Tried all sorts of constructions to fix this, Sleep(X), DoEvents (I know is deprecated and caused indeed a crash), waiting loops and also constructions with ResumableSub, but all with no good result.

In the end I came up with this and that seems to work:

B4X:
Sub RefreshView(oView As View)
    oView.Visible = False
    oView.Visible = True
End Sub

Sub AddAreaPoint(GeoPoint1 As OSMDroid_GeoPoint)

    'as there seems no way to get these back from the PathOverLay!
    PathOverLay1Points.Add(GeoPoint1)
    PathOverlay1.AddPoint(GeoPoint1)
    RefreshView(MapView1)

End Sub

This seems to work fine as it doens't give a flicker and updates the appearance of the MapView.
Is there anything wrong with this approach? Are there better ways to handle this?


RBS
 

OliverA

Expert
Licensed User
Longtime User
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
A guess. Instead of
B4X:
RefreshView(MapView1)
try
B4X:
MapView1.Invalidate

Ah, yes that is simpler and neater.
I looked at all the methods of MapView, but but never guessed Invalidate would do a Refresh.
Not sure why it is called Invalidate.

RBS
 
Upvote 0
Top