public async static Task <ConcurrentDictionary <int, MapOverlay> > LoadProximalCells(LatLng targetLatLng) { var Overlays = new ConcurrentDictionary <int, MapOverlay>(); var ProximalCells = await RetrieveProximalCells(targetLatLng); var NewSubscriptions = new HashSet <int>(); await Task.Run(() => { foreach (Cell cell in ProximalCells.Values) { if (!CellsInView.ContainsKey(cell.ID)) { CellsInView.TryAdd(cell.ID, cell); NewSubscriptions.Add(cell.ID); } if (cell.TeamID > 0) { Overlays.TryAdd(cell.ID, new MapOverlay(cell)); } } }); if (NewSubscriptions.Count > 0) { await CellHub.SubscribeToUpdates(NewSubscriptions); } return(Overlays); }
private async void TagButton_Click(object sender, EventArgs e) { if (locationFound == false) { Toast.MakeText(this, "Tag failed... location unknown", ToastLength.Long).Show(); } else { decimal decLat = (decimal)(mMap.MyLocation.Latitude); decimal decLng = (decimal)(mMap.MyLocation.Longitude); int playerCellID = Cell.FindID(decLat, decLng); Cell cell; if (!GameModel.CellsInView.ContainsKey(playerCellID)) { // Generate the new cell and add it to CellsInView cell = new Cell(decLat, decLng); GameModel.CellsInView.TryAdd(cell.ID, cell); await CellHub.SubscribeToCellUpdates(cell.ID); } else { cell = GameModel.CellsInView[playerCellID]; } try { if (!cell.MapOverlay.CellIsOnMap) { cell.MapOverlay.Draw(mMap); } await cell.Tag(); } catch (AggregateException exc) { foreach (Exception ie in exc.InnerExceptions) { Console.WriteLine(ie.ToString()); } } catch (Exception o) { Console.WriteLine(o.ToString()); } } }
public async static Task LoadProximalCells(LatLng targetLatLng) { int targetCellID = Cell.FindID((decimal)targetLatLng.Latitude, (decimal)targetLatLng.Longitude); var ProximalCells = await Database.GetProxyCells(viewRadius, frontierInterval, (decimal)targetLatLng.Latitude, (decimal)targetLatLng.Longitude); var NewSubscriptions = new HashSet <int>(); await Task.Run(() => { foreach (Cell cell in ProximalCells.Values) { if (!CellsInView.ContainsKey(cell.ID)) { CellsInView.TryAdd(cell.ID, cell); NewSubscriptions.Add(cell.ID); } } for (int row = -viewRadius; row <= viewRadius; row++) { for (int col = -viewRadius; col <= viewRadius; col++) { int cellID = (int)(targetCellID + (row * GridWidth) + col); if (!CellsInView.ContainsKey(cellID)) { NewSubscriptions.Add(cellID); } } } }); if (NewSubscriptions.Count > 0) { await CellHub.SubscribeToCellUpdates(NewSubscriptions); } }