B4J Question [SOLVED] How to hide Google Maps traffic layer?

javiers

Active Member
Licensed User
Longtime User
Hi all, this code works great and activates the traffic layer on the map.

https://www.b4x.com/android/forum/threads/traffic-layer-on-jgoogle-maps.102370/post-642587


But I would like to disable it...How to do it?
 
Solution
Please use [code]code here...[/code] tags when posting code.

B4X:
Private Sub RemoveTrafficLayer
    ExecuteJS($"
        window.trafficLayer.setMap(null);
    "$)
    TrafficVisibie = False
End Sub

Private Sub AddTrafficLayer
    Dim JSMap As JavaObject = gmap
    Dim r As Reflector
    r.Target = JSMap.GetField("map")
    Dim MapJSName As String = r.GetField("variableName")
    ExecuteJS($"
    if (window.trafficLayer == null)
        window.trafficLayer = new google.maps.TrafficLayer();
window.trafficLayer.setMap(${MapJSName});
"$)
    TrafficVisibie = True 'global boolean variable
End Sub

Private Sub ExecuteJS(js As String)
    Dim javascript As JavaObject
    javascript =...

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

B4X:
Private Sub RemoveTrafficLayer
    ExecuteJS($"
        window.trafficLayer.setMap(null);
    "$)
    TrafficVisibie = False
End Sub

Private Sub AddTrafficLayer
    Dim JSMap As JavaObject = gmap
    Dim r As Reflector
    r.Target = JSMap.GetField("map")
    Dim MapJSName As String = r.GetField("variableName")
    ExecuteJS($"
    if (window.trafficLayer == null)
        window.trafficLayer = new google.maps.TrafficLayer();
window.trafficLayer.setMap(${MapJSName});
"$)
    TrafficVisibie = True 'global boolean variable
End Sub

Private Sub ExecuteJS(js As String)
    Dim javascript As JavaObject
    javascript = javascript.InitializeStatic("com.lynden.gmapsfx.javascript.JavascriptRuntime").RunMethod("getInstance", Null)
    Log(javascript.RunMethod("execute", Array(js)))
End Sub


Private Sub btnToggle_Click
    If TrafficVisibie Then RemoveTrafficLayer Else AddTrafficLayer
End Sub
 
Upvote 0
Solution

maleche

Active Member
Licensed User
Longtime User
I have 2 different list markers mapHazard (HazID,Lat,Lon) and mapRoadSign(RSID,Lat,Lon)
they both will show up on a MapFragment.
i would like to separate each to show/unshow. Similar to show/hide a Panel or Canvas.
I have learned by trial that making (MapFragment) mfHazard and mfRoadSign are layers which are not transparent to overlay both, but hide the underlaying MapFragment.
Is there a way to make the MapFragement transparent and still show the markers or method to hide/unhide the specific marker set.
There is a Clear method, however it clears ALL markers.
How about a custom layer similar to Traffic, Buildings, etc.?
thanks for the help!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…