private async void AddAssociations() { try { // Check if the current viewpoint is outside of the max scale. if (_myMapView.GetCurrentViewpoint(ViewpointType.CenterAndScale)?.TargetScale >= _maxScale) { return; } // Check if the current viewpoint has an extent. Envelope extent = _myMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry)?.TargetGeometry?.Extent; if (extent == null) { return; } // Get all of the associations in extent of the viewpoint. IEnumerable <UtilityAssociation> associations = await _utilityNetwork.GetAssociationsAsync(extent); foreach (UtilityAssociation association in associations) { // Check if the graphics overlay already contains the association. if (_associationsOverlay.Graphics.Any(g => g.Attributes.ContainsKey("GlobalId") && (Guid)g.Attributes["GlobalId"] == association.GlobalId)) { continue; } // Add a graphic for the association. Graphic graphic = new Graphic(association.Geometry); graphic.Attributes["GlobalId"] = association.GlobalId; graphic.Attributes["AssociationType"] = association.AssociationType.ToString(); _associationsOverlay.Graphics.Add(graphic); } } // This is thrown when there are too many associations in the extent. catch (TooManyAssociationsException) { } catch (Exception ex) { new AlertDialog.Builder(this).SetMessage(ex.Message).SetTitle(ex.GetType().Name).Show(); } }