Android Question B4XMap OSM viewer, how to remove polygon

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Using the B4X library as in this link:

I have for now taken the classes from the b4xlib and added them to my project as it makes debugging easier and also makes it easier
to understand it all. It is somewhat complex.
It all works very well, but can't figure out how to remove a polygon I added.
Does anybody using this library have any suggestions?

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Using the B4X library as in this link:

I have for now taken the classes from the b4xlib and added them to my project as it makes debugging easier and also makes it easier
to understand it all. It is somewhat complex.
It all works very well, but can't figure out how to remove a polygon I added.
Does anybody using this library have any suggestions?

RBS
Sorted this now by tracking the polygon lines and final polygon shape in a map:

B4X:
Sub RemovePolygon(bClearPathList As Boolean)
    
    For Each oKey As Object In mapPolygonLines.Keys
        'changed the list in type TMap (holding the shapes) to a map
        mapShapes.Remove(oKey)
    Next
    
    'this map keeps track of the polygon lines and the final polygon shape
    mapPolygonLines.Clear
    
    If bClearPathList Then
        lstPathOverLay1Points2.Clear
    End If

    cvMap1.Draw
    
End Sub

As I am going along, converting from using OSM_Droid to this b4xlib, I am changing a few things in the classes of this library, eg the Sub BoundingBox
in clsMapShapePolygon didn't seem to give the right result and changed that to this:

B4X:
Public Sub BoundingBox(ashape As TMapShapePolygon) As B4XRect
        
    '>>> altered RBS 05/03/2022
    Dim r As B4XRect
    
    Dim dMinLat As Double
    Dim dMaxLat As Double
    Dim dMinLng As Double
    Dim dMaxLng As Double
    
    Dim tLLNW As TMapLatLng
    Dim tLLSE As TMapLatLng
    
    Dim pNW As TMapPoint
    Dim pSE As TMapPoint
    
    dMinLat = 100
    dMaxLat = -100
    dMinLng = 200
    dMaxLng = -200
    
    For Each ll As TMapLatLng In ashape.fLatLng
        If ll.flat > dMaxLat Then
            dMaxLat = ll.flat
        End If
        If ll.flat < dMinLat Then
            dMinLat = ll.flat
        End If
        If ll.flng > dMaxLng Then
            dMaxLng = ll.flng
        End If
        If ll.flng < dMinLng Then
            dMinLng = ll.flng
        End If
    Next
    
    tLLNW.fLat = dMaxLat
    tLLNW.fLng = dMinLng
    tLLSE.fLat = dMinLat
    tLLSE.fLng = dMaxLng
    
    pNW = fcvMap.LatLngToPoint(tLLNW)
    pSE = fcvMap.LatLngToPoint(tLLSE)
    
    r.Initialize(pNW.fx, pNW.fy, pSE.fx, pSE.fy)
    
    Return r
    
End Sub

RBS
 
Upvote 1
Top