async Task SetMapStationPins(Station[] stations, float alpha = 1) { var stationsToUpdate = stations.Where(station => { Marker marker; var stats = station.BikeCount + "|" + station.EmptySlotCount; if (existingMarkers.TryGetValue(station.Id, out marker)) { if (marker.Snippet == stats && !showedStale) { return(false); } marker.Remove(); } return(true); }).ToArray(); var pins = await Task.Run(() => stationsToUpdate.ToDictionary(station => station.Id, station => { var w = 24.ToPixels (); var h = 40.ToPixels (); if (station.Locked) { return(pinFactory.GetClosedPin(w, h)); } else if (!station.Installed) { return(pinFactory.GetNonInstalledPin(w, h)); } var ratio = (float)TruncateDigit(station.BikeCount / ((float)station.Capacity), 2); return(pinFactory.GetPin(ratio, station.BikeCount, w, h, alpha: alpha)); })); foreach (var station in stationsToUpdate) { var pin = pins [station.Id]; var snippet = station.BikeCount + "|" + station.EmptySlotCount; if (station.Locked) { snippet = string.Empty; } else if (!station.Installed) { snippet = "not_installed"; } var markerOptions = new MarkerOptions() .SetTitle(station.Id + "|" + station.Street + "|" + station.Name) .SetSnippet(snippet) .SetPosition(new Android.Gms.Maps.Model.LatLng(station.Location.Lat, station.Location.Lon)) .InvokeIcon(BitmapDescriptorFactory.FromBitmap(pin)); existingMarkers [station.Id] = mapFragment.Map.AddMarker(markerOptions); } }
async Task SetMapStationPins(Station[] stations, float alpha = 1) { var stationsToUpdate = stations.Where(station => { ClusterMarkerOptions marker; var stats = station.Locked ? string.Empty : station.BikeCount + "|" + station.EmptySlotCount; if (existingMarkers.TryGetValue(station.Id, out marker)) { if (marker.Options.Snippet == stats && !showedStale) { return(false); } clusterManager.RemoveItem(marker); } return(true); }).ToList(); var w = (int)Math.Round(TypedValue.ApplyDimension(ComplexUnitType.Dip, 32, Resources.DisplayMetrics)); var h = (int)Math.Round(TypedValue.ApplyDimension(ComplexUnitType.Dip, 34, Resources.DisplayMetrics)); var pins = await Task.Run(() => stationsToUpdate.ToDictionary(station => station.Id, station => { if (station.Locked) { return(BitmapDescriptorFactory.FromBitmap(pinFactory.GetClosedPin(w, h))); } var ratio = (float)TruncateDigit(station.BikeCount / ((float)station.Capacity), 2); return(BitmapDescriptorFactory.FromFile(pinFactory.GetPin(ratio, station.BikeCount, w, h, alpha: alpha))); })); var clusterItems = new List <ClusterMarkerOptions> (); foreach (var station in stationsToUpdate) { var pin = pins [station.Id]; var markerOptions = new MarkerOptions() .SetTitle(station.Id + "|" + station.Name) .SetSnippet(station.Locked ? string.Empty : station.BikeCount + "|" + station.EmptySlotCount) .SetPosition(new Android.Gms.Maps.Model.LatLng(station.Location.Lat, station.Location.Lon)) .SetIcon(pin); var markerItem = new ClusterMarkerOptions(markerOptions); existingMarkers [station.Id] = markerItem; clusterItems.Add(markerItem); } clusterManager.AddItems(clusterItems); clusterManager.Cluster(); }