iOS Question GoogleMaps marker Zorder

marcick

Well-Known Member
Licensed User
Longtime User
Good morning everyone. In the example shown in the photo, I placed markers on the map, each with an icon containing a number from 0 to 10, and then selected the last one to open its InfoWindow. Unlike in B4A, newly added markers always appear behind the previous ones rather than in the foreground.


My need, for instance, is to select marker number 5 and ensure that not only its InfoWindow, but also its icon (which includes the number inside) appears on top and remains fully visible. I was therefore thinking of deleting all the markers, placing number 5 first, and then re-adding the others so they end up graphically behind. But... what guarantees do I have that this behavior is consistent and not simply the result of incidental or random rendering order?

1746689735591.png
 

marcick

Well-Known Member
Licensed User
Longtime User
B4X:
Dim MyColor As Int=Colors.Blue
    Dim TempMap As Map
    TempMap.Initialize
    For prog =0 To 10
        Dim bmp As Bitmap = CreateNumberedBitmap(prog, MyColor)
        Dim lat As Float=45.57256+prog*.0001
        Dim m As Marker=gmap.AddMarker3(lat,8.93087, "", bmp)
        gextra.SetGroundAnchor(m, 0.5, 0.5)
        gextra.SetSelectedMarker(m)
        m.Title=prog
        m.Snippet=""
        TempMap.Put(prog,m)
    Next
    Return
    
Sub CreateNumberedBitmap(Number As Int, MyColor As Int) As B4XBitmap   
    Dim size As Int = 32
    Dim c As B4XCanvas
    Dim xview As B4XView = xui.CreatePanel("")
    xview.SetLayoutAnimated(0, 0, 0, size, size)
    c.Initialize(xview)
    Dim strokeColor As Int = Colors.White
    c.DrawCircle(size / 2, size / 2, size / 2 - 3dip, MyColor, True, 0)
    c.DrawCircle(size / 2, size / 2, size / 2 - 3dip, strokeColor, False, 2dip)
    Dim fontSize As Float = 14
    Dim MyFont As Font = Font.CreateNewBold(fontSize)
    Dim yOffset As Float = fontSize / 3
    c.DrawText(Number, size / 2, size / 2 + yOffset, MyFont, Colors.White, "CENTER")
    Return c.CreateBitmap
End Sub
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
?
change marker = zIndex

note:
To make a marker appear above others, simply increase the value of its zIndex property. For example, you can set yourGmsMarker.zIndex = 1 to display it above other markers with a zIndex equal to or less than 0.

By default, a marker's zIndex is 0.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
?
change marker = zIndex
Could you explain that more clearly?
When I select a marker and open its InfoWindow, I expect it to come to the foreground — and that's exactly what happens on Android. However, on iOS, it doesn't: the InfoWindow opens, but the marker icon remains hidden behind the others.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
?
change marker = zIndex

note:
To make a marker appear above others, simply increase the value of its zIndex property. For example, you can set yourGmsMarker.zIndex = 1 to display it above other markers with a zIndex equal to or less than 0.

By default, a marker's zIndex is 0.

Where do you see the zindex property in GoogleMaps for IOS ? .....
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
have a look:
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
have a look:
Yes, thank you, I'm definitely using GoogleMapsExtra, but I still can't find anything there to set the zIndex.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
test;
B4X:
Dim no As NativeObject = MyMarker
no.RunMethod("setZIndex:", Array(30))
Thank you for the suggestion, but unfortunately it has no effetc.
I had a look to the Map SDK for IOS documentation and I can't find any Zindex keyword ....
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Thanks, it works. Your first suggestion was already correct, but I must have been doing something wrong. I’ve learned something new about using NativeObject.

Dim z As Object = no.RunMethod("zIndex", Null) (lowercase z) is the method to get the zIndex value, and indeed all markers are placed with a default zIndex of 0.

no.RunMethod("setZIndex:", Array(1)) (uppercase Z) is the method to set the zIndex, and it gives the desired result.

I still struggle a lot with understanding the official Swift/Objective-C documentation, finding what I need, and translating it into B4i — but I’ve definitely understood more than I did before. Thanks again.
 
Upvote 0

Similar Threads

Top