Sub DrawWaypointsClustered(gmap As GoogleMap, swLat As Double, swLong As Double, neLat As Double, neLong As Double, mapzoom As Int)
' 1° = 111 km (Or 60 nautical miles)
' 0.1° = 11.1 km
' 0.01° = 1.11 km (2 decimals, km accuracy)
' 0.001° =111 m
' 0.0001° = 11.1 m
' 0.00001° = 1.11 m
' 0.000001° = 0.11 m (7 decimals, cm accuracy)
' Dim lStart As Long = DateTime.Now
If mapzoom < 10 Then Return ' dont draw at larger scales
Dim MarkerCluster As Marker 'ignore
ListClusterMarker.Initialize
Dim ranges As Map = CreateMap(10: 0, 11: 0, 12: 1, 13: 1, 14: 1, 15: 1, 16: 2, 17: 3, 18: 3)
Dim zoomRound As Int = ranges.Get(mapzoom)
Dim strsql As String
strsql = $"Select count(id) As n, avg(lon) As lon, avg(lat) As lat "$ & _
"FROM vw_waypoint " & _
"WHERE " & _
$"(Case WHEN ${swLat} < ${neLat} Then lat BETWEEN ${swLat} And ${neLat} Else lat BETWEEN ${neLat} And ${swLat} End) "$ & _
"AND " & _
$"(Case WHEN ${swLong} < ${neLong} Then lon BETWEEN ${swLong} And ${neLong} Else lon BETWEEN ${neLong} And ${swLong} End) "$ & _
$"GROUP BY Round(lat,${zoomRound}) , Round(lon,${zoomRound})"$
Dim rs As ResultSet = Starter.sql.ExecQuery(strsql)
' Log("draw " & rs.RowCount & " pins")
Do While rs.NextRow = True
MarkerCluster = gmap.AddMarker3(rs.GetDouble("lat"),rs.GetDouble("lon"), "", CreateClusterBitmap(rs.GetString("n")))
ListClusterMarker.Add(MarkerCluster)
Loop
rs.Close
' Dim lEnd As Long = DateTime.Now - lStart
' Log("addWaypointsClustered took " & lEnd & " m seconds") 'ms to seconds
End Sub
Sub CreateClusterBitmap(text As String) As B4XBitmap
Dim xui As XUI
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, 200dip, 200dip)
Dim c As B4XCanvas
c.Initialize(p)
c.DrawCircle(c.TargetRect.CenterX, c.TargetRect.Bottom - 50, 50 ,xui.Color_ARGB(200,255,255,255), True, 1)
c.DrawText(text, c.TargetRect.CenterX, c.TargetRect.Bottom - 40, xui.CreateDefaultBoldFont(20), xui.Color_Black, "CENTER")
c.Invalidate
Return c.CreateBitmap
End Sub