B4J Question Transfer routines from GMap to OSM

bvonlaar

Member
Licensed User
Longtime User
Hello,
I need help to adapt jgooglemaps routines to openstreetmaps.

The data are read in as csv-file into a table (TV2). Each location is read in as M (Marker).
M is stored into MMap() as Map. So I have access to each point also for remove operation.

jgooglemaps lib:

B4X:
For i=0 To  Itcount-1
        TV2.SelectedRow = i
        rrow=TV2.SelectedRowvalues
        llat=rrow(1)
        llong=rrow(2)
        lblLat.Text=rrow(1)
        lblLng.Text=rrow(2)
        Eevent=REvent
        If Eevent="none" Then
            MLabel=" "
        Else
            Select Eevent
                'Case "none"
                '        MLabel=""
                Case "Event1"
                    EVSel= 4
                Case "Event2"
                    EVSel= 5
                Case "Event3"
                    EVSel= 6
            End Select
            TVLayer.SelectedRow=RNoC-1 'sf.Val(RNo)
            'TVLayer.SelectedRow
            row=TVLayer.SelectedRowvalues
            MLabel=rrow(EVSel)
            rrow=TV2.SelectedRowvalues
        End If
        
        If llat <> "" And llong <> "" Then                       
           If MLabel=" " Then
    
                Dim M As Marker =gmap.AddMarker2(llat, llong, "",File.GetUri(File.DirAssets,RMarkTyp))
                MMap(RPNoC).Put(i,M)

           Else   

                Dim M As Marker =gmap.AddMarker2(llat, llong, "",File.GetUri(File.DirAssets,RMarkTyp))
                'Dim MMarkLabel=
                Dim MMarkLabel As Marker = M

                SetMarkerLabel(M,MLabel,RLColor,"8px")
                
                MMap(RPNoC).Put(i,M)
                MMarkMap(RPNoC).Put(i,MMarkLabel)
                'MMap(RNoC-1).Put(i,M)
           End If           
            Label2.Text=RMarkTyp
        End If
    Next

Now I try to change it to openstreetmaps:

B4X:
For i=0 To  Itcount-1
        TV2.SelectedRow = i
        rrow=TV2.SelectedRowvalues
        llat=rrow(1)
        llong=rrow(2)
        lblLat.Text=rrow(1)
        lblLng.Text=rrow(2)
        Eevent=REvent
        If Eevent="none" Then
            MLabel=" "
        Else
            Select Eevent
                'Case "none"
                '        MLabel=""
                Case "Event1"
                    EVSel= 4
                Case "Event2"
                    EVSel= 5
                Case "Event3"
                    EVSel= 6
            End Select
            TVLayer.SelectedRow=RNoC-1 'sf.Val(RNo)
            'TVLayer.SelectedRow
            row=TVLayer.SelectedRowvalues
            MLabel=rrow(EVSel)
            rrow=TV2.SelectedRowvalues
        End If
        
        If llat <> "" And llong <> "" Then
            If MLabel=" " Then

'                Dim M As Marker =gmap.AddMarker2(llat, llong, "",File.GetUri(File.DirAssets,RMarkTyp))
'                MMap(RPNoC).Put(i,M)

                Spot2.Initialize2("RiyadhSpot", 10, fx.Colors.RGB(120,120,0),2, llat,llong)
'                Spot2.SetCursor(fx.Cursors.HAND)
'                Spot2.Title="Riyadh Spot"
'                Spot2.Description = "This is draggable."
                OSM.AddSpot(Spot2)
            Else

'                Dim M As Marker =gmap.AddMarker2(llat, llong, "",File.GetUri(File.DirAssets,RMarkTyp))
'                Dim MMarkLabel As Marker = M
'                SetMarkerLabel(M,MLabel,RLColor,"8px")
                
'                MMap(RPNoC).Put(i,M)
'                MMarkMap(RPNoC).Put(i,MMarkLabel)
                'MMap(RNoC-1).Put(i,M)
                Spot2.Initialize2("RiyadhSpot", 20, fx.Colors.RGB(120,120,0),2, llat,llong)
                OSM.AddSpot(Spot2)
            End If
'            Label2.Text=RMarkTyp
        End If
    Next

Well the markers are set, but I have no access to a complete list/map. I don´t know how I can work with a map of markers like in gmaps.
I think I´ll change in future to the pin type intializing type 3 there with this method own icons are usable.
The use of spot type is only for testing purpose.
After reading about the use of pin type I have the same problem like in spot type.

Thanks in advance
Benedikt
 

bvonlaar

Member
Licensed User
Longtime User
Maybe I found the direction by myself:





B4X:
For i=0 To  Itcount-1
        TV2.SelectedRow = i
        rrow=TV2.SelectedRowvalues
        llat=rrow(1)
        llong=rrow(2)
        lblLat.Text=rrow(1)
        lblLng.Text=rrow(2)
        Eevent=REvent
        If Eevent="none" Then
            MLabel=" "
        Else
            Select Eevent
                'Case "none"
                '        MLabel=""
                Case "Event1"
                    EVSel= 4
                Case "Event2"
                    EVSel= 5
                Case "Event3"
                    EVSel= 6
            End Select
            TVLayer.SelectedRow=RNoC-1 'sf.Val(RNo)
            'TVLayer.SelectedRow
            row=TVLayer.SelectedRowvalues
            MLabel=rrow(EVSel)
            rrow=TV2.SelectedRowvalues
        End If
      
        If llat <> "" And llong <> "" Then
            If MLabel=" " Then

'                Dim M As Marker =gmap.AddMarker2(llat, llong, "",File.GetUri(File.DirAssets,RMarkTyp))
'                MMap(RPNoC).Put(i,M)

                Spot2.Initialize2("RiyadhSpot", 10, fx.Colors.RGB(120,120,0),2, llat,llong)
'                Spot2.SetCursor(fx.Cursors.HAND)
'                Spot2.Title="Riyadh Spot"
'                Spot2.Description = "This is draggable."
                OSM.AddSpot(Spot2)
                ListP.Add(Spot2) 'Each Spot2 is written into a list !!!
            Else

'

            End If
'            Label2.Text=RMarkTyp
        End If
    Next

The remove routine I solved in this way. It seems to work, but maybe it´s dirty ;-)

B4X:
For i=0 To ListP.Size-1
    Spot2= ListP.Get(i)
    OSM.RemoveMarker(Spot2)
                   
Next

Next step will be to test whether it can be also used to switch sets of marker themes visible and not visible.
If someone know a better way please tell it.

Thanks in advance
Benedikt
 
Upvote 0
Top