//Setting up translation of GPS coordinates (lattitude and longitude) to Map coordinates (x, y) internal static void SetupGPSToMapTranslation_Start(MapSectionPage mapSectionInstance, List <Team> registeredTeams) { setupOngoing = true; MessageBox.Show(Properties.Resources.MessageBox_EnteringSetup); mapSection = mapSectionInstance; //Get the TeamPins of the registered teams List <TeamPin> registeredTeamPins = new List <TeamPin>(); List <Pin> pinList = Pin.getPinList(); foreach (Pin pin in pinList) { if (registeredTeams.Contains(pin.getRelatedObject())) { registeredTeamPins.Add((TeamPin)pin); } } //Hiding all pins except the pins of registered teams, change their context menu for team selection Pin.ClearAllPins(mapSection.Canvas_map); foreach (TeamPin teamPin in registeredTeamPins) { MenuItem menuItem = new MenuItem(); menuItem.Header = "Use this team for setup"; menuItem.Click += ChooseTeamForSetup_Click; ContextMenu contextMenu = new ContextMenu(); contextMenu.Items.Add(menuItem); teamPin.ContextMenu = contextMenu; mapSection.Canvas_map.Children.Add(teamPin); double[] previousPinPosition = Pin.getPreviousPinPosition(teamPin.getRelatedObject()); if (previousPinPosition == null) { previousPinPosition = new double[] { teamPin.Width / 2, teamPin.Height / 2 }; //Top-left corner } teamPin.setPinPosition(previousPinPosition[0], previousPinPosition[1]); } MessageBox.Show("From the teams that remain on the map, select one of them that will be used for the setup by right-clicking on the team and selecting \"Use this team for setup\"."); }
//Called when team is picked for setup, prepare team pin for setup private static void ChooseTeamForSetup_Click(object sender, RoutedEventArgs e) { MenuItem mi = (MenuItem)sender; ContextMenu cm = (ContextMenu)mi.Parent; TeamPin teamPin = (TeamPin)cm.PlacementTarget; //Hiding all pins except the pin of the selected team, change its context menu for point tagging Pin.ClearAllPins(mapSection.Canvas_map); //Customizing the context menu for the exact use needed MenuItem tagPointMenuItem = new MenuItem(); tagPointMenuItem.Header = "Tag point"; tagPointMenuItem.Click += TagPoint_Click; ContextMenu contextMenu = new ContextMenu(); contextMenu.Items.Add(tagPointMenuItem); teamPin.ContextMenu = contextMenu; //Replacing pin on the map for tagging mapSection.Canvas_map.Children.Add(teamPin); double[] previousPinPosition = Pin.getPreviousPinPosition(teamPin.getRelatedObject()); if (previousPinPosition == null) { previousPinPosition = new double[] { teamPin.Width / 2, teamPin.Height / 2 }; //Top-left corner } teamPin.setPinPosition(previousPinPosition[0], previousPinPosition[1]); //Clearing the reference points in case the user is going through the setup again for any reason if (GPSLocation.gpsConfigured == true || GPSLocation.referencePoints.Count > 0) { GPSLocation.gpsConfigured = false; GPSLocation.referencePoints.Clear(); MessageBox.Show("Previous setup is cleared. You can now proceed to re-setup the GPS"); } MessageBox.Show("Team " + teamPin.getTeam().getName() + " selected. Please ask the team to position themselves at different locations of the site.\n" + "As soon as they reach a particular location, wait at least 10 seconds and then tag the position by placing the team pin on the equivalent point on the map, right click on it, and select \"Tag point\".\n" + "Only 2 points are required. For best results, have the points on two different sides of the map.\nSetup will complete as soon as the second point is tagged."); }
/*Scales the map based on the chosen ration and centers * it about the location of the mouse when the context menu * was first opened.*/ public void ScaleMap(double ratio) { ScaleMapDefault(); if (ratio != 1) { Pin.ClearAllPins(Canvas_map); ScaleTransform ST = new ScaleTransform(); ST.ScaleX = ratio; ST.ScaleY = ratio; imgbrush.RelativeTransform = ST; TranslateTransform TT; TTX = -mouseX * ratio + Canvas_map.ActualWidth / 2; TTY = -mouseY * ratio + Canvas_map.ActualHeight / 2; TT = new TranslateTransform(TTX, TTY); imgbrush.Transform = TT; } }
//Callback when any of the observed objects modified i.e. creation and addition of all pins (including new pins, excluding deleted pins) public void Update() { Pin.ClearAllPins(Canvas_map); //Clearing all pins from the map //Creating all team pins and adding the map to their previous or a new position while detecting newly created collisions foreach (Team team in Team.getTeamList()) { TeamPin teamPin = new TeamPin(team, this); Canvas_map.Children.Add(teamPin); //Redrawing arrow if the pin has one if (Pin.getPinArrow(team) != null && GPSServices.connectedToServer && teamPin.gpsLocation.PhoneOnline()) { Pin.getPinArrow(team).DisplayArrow(); } //Setting the pin to it's previous position, if it exists, or to the top-left corner bool ignoreSpecialCollisions = false; double[] previousPinPosition = Pin.getPreviousPinPosition(team); if (previousPinPosition == null) { ignoreSpecialCollisions = true; previousPinPosition = new double[] { teamPin.Width / 2, teamPin.Height / 2 }; //Top-left corner } teamPin.setPinPosition(previousPinPosition[0], previousPinPosition[1]); teamPin.CollisionDetectionAndResolution(ignoreSpecialCollisions); } //Creating team fragments when a team is split foreach (Team team in Team.getSplitTeamList()) { TeamPin parentTeamPin = null; foreach (Team parentTeam in Team.getTeamList()) { if (team.getID() == parentTeam.getID()) { foreach (Pin pin in Pin.getPinList()) { if (pin.relatedObject == parentTeam) { parentTeamPin = (TeamPin)pin; break; } } break; } } TeamPin teamPin = new TeamPin(team, this, parentTeamPin); Canvas_map.Children.Add(teamPin); //Setting the pin to it's previous position, if it exists, or to the top-left corner bool ignoreSpecialCollisions = false; double[] previousPinPosition = Pin.getPreviousPinPosition(team); if (previousPinPosition == null) { ignoreSpecialCollisions = true; previousPinPosition = new double[] { teamPin.Width / 2, teamPin.Height / 2 }; //Top-left corner } teamPin.setPinPosition(previousPinPosition[0], previousPinPosition[1]); teamPin.CollisionDetectionAndResolution(ignoreSpecialCollisions); } //Creating all intervention pins and adding the map to their previous or a new position while detecting newly created collisions foreach (Intervention intervention in Intervention.getActiveInterventionList()) { InterventionPin interventionPin = new InterventionPin(intervention, this); Canvas_map.Children.Add(interventionPin); //Redrawing arrow if the pin has one if (Pin.getPinArrow(intervention) != null && GPSServices.connectedToServer && interventionPin.gpsLocation != null && interventionPin.gpsLocation.PhoneOnline()) { Pin.getPinArrow(intervention).DisplayArrow(); } //Setting the pin to it's previous position, if it exists, or to the top-left corner bool ignoreSpecialCollisions = false; double[] previousPinPosition = Pin.getPreviousPinPosition(intervention); if (previousPinPosition == null) { ignoreSpecialCollisions = true; previousPinPosition = new double[] { (interventionPin.Width / 2), Canvas_map.ActualHeight - (interventionPin.Height / 2) }; //Bottom-right corner } interventionPin.setPinPosition(previousPinPosition[0], previousPinPosition[1]); interventionPin.Update(); interventionPin.CollisionDetectionAndResolution(ignoreSpecialCollisions); } //Creating all equipment pins and adding the map to their previous or a new position while detecting newly created collisions foreach (Equipment equipment in Equipment.getEquipmentList()) { if (!equipment.IsAssigned()) { EquipmentPin equipmentPin = new EquipmentPin(equipment, this); Canvas_map.Children.Add(equipmentPin); //Setting the pin to it's previous position, if it exists, or to the top-left corner bool ignoreSpecialCollisions = true; double[] previousPinPosition = Pin.getPreviousPinPosition(equipment); if (previousPinPosition == null) { previousPinPosition = new double[] { Canvas_map.ActualWidth - (equipmentPin.Width / 2), (equipmentPin.Height / 2) }; //Top-right corner } equipmentPin.setPinPosition(previousPinPosition[0], previousPinPosition[1]); equipmentPin.CollisionDetectionAndResolution(ignoreSpecialCollisions); } } }