Example #1
0
 /// <summary>
 /// Adds new push pin to the tank's collection, and possibly retrieves a route to it from the server.
 /// </summary>
 /// <param name="pushPin">Push-pin to add.</param>
 public void AddPushPin(PushPin pushPin)
 {
     if (currentPushPin == null && pushPins.First.Value == pushPin)
     {
         currentPushPin = pushPins.First;
     }
     else
     {
         LinkedListNode <PushPin> pushPinNode = pushPins.Find(pushPin);
         GetRouteFromServer(viewer.BingMapKey, pushPinNode.Previous.Value.Location, pushPinNode.Value.Location,
                            pushPinNode);
     }
 }
Example #2
0
 /// <summary>
 /// Deletes a push-pin from the tank's collection.
 /// </summary>
 /// <param name="pushPinToDelete">The push-pin to delete.</param>
 public void DeletePushPin(PushPin pushPinToDelete)
 {
     RecalculateRoute();
 }
        /// <summary>
        /// Handle the input of the sample.
        /// </summary>
        private void HandleInput()
        {
            TouchCollection touchCollection = TouchPanel.GetState();

            if (touchCollection.Count > 0)
            {
                TouchLocation touch = touchCollection[0];

                // If the tank is moving he can not be relocated
                if (!tank.IsMoving)
                {
                    if (touch.State == TouchLocationState.Pressed && !isDragingTank)
                    {
                        Rectangle toucRect = new Rectangle((int)touch.Position.X - 5,
                                                           (int)touch.Position.Y - 5, 10, 10);

                        if (tank.Bounds.Intersects(toucRect))
                        {
                            isDragingTank = true;
                        }
                    }
                    else if (touch.State == TouchLocationState.Moved && isDragingTank)
                    {
                        tank.Move(touch.Position);
                    }
                    else if (touch.State == TouchLocationState.Released && isDragingTank)
                    {
                        isDragingTank = false;
                    }
                }
            }

            // Read all gesture
            while (TouchPanel.IsGestureAvailable)
            {
                GestureSample sample = TouchPanel.ReadGesture();

                // If the search button is clicked, the button will handle it.
                if (serachButton.HandleInput(sample))
                {
                    return;
                }

                // If the switch button is clicked, the button will handle it.
                if (switchViewButton.HandleInput(sample))
                {
                    return;
                }

                // If the change mode button is clicked, the button will handle it.
                if (changeRotuingModeButton.HandleInput(sample))
                {
                    return;
                }

                if (tank.IsMoving)
                {
                    // If the draw route button is clicked, the button will handle it.
                    if (drawRouteButton.HandleInput(sample))
                    {
                        return;
                    }

                    // If the clear all pushpins button is clicked, the button will handle it.
                    if (clearPushPinsButton.HandleInput(sample))
                    {
                        return;
                    }
                }

                if (sample.GestureType == GestureType.Tap)
                {
                    // Gets the position on the displayed map
                    Vector2 positionOnMap = TileSystem.LatLongToPixelXY(bingMapsViewer.CenterGeoCoordinate, ZoomLevel)
                                            - bingMapsViewer.Offset;

                    // Gets the distance between the gesture and the center of the screen
                    Vector2 distance = sample.Position - BingMapsViewer.ScreenCenter;
                    // Calculate the distance between the center of the screen and the position on the map
                    Vector2 positionOfGesture = positionOnMap + distance;

                    PushPin pushPin = new PushPin(bingMapsViewer,
                                                  TileSystem.PixelXYToLatLong(positionOfGesture, ZoomLevel), pushPinTexture2D);
                    pushPins.AddLast(pushPin);

                    // Indicates to the Tank that new push pin is added
                    tank.AddPushPin(pushPin);
                }
                else if (sample.GestureType == GestureType.FreeDrag)
                {
                    if (!isDragingTank)
                    {
                        // Move the map when dragging
                        bingMapsViewer.MoveByOffset(sample.Delta);
                    }
                }
                // When an hold gesture is caught on push pin ask if wants to delete
                else if (sample.GestureType == GestureType.Hold)
                {
                    // Creates a rectangle around the gesture
                    Rectangle touchRectangle = new Rectangle(
                        (int)sample.Position.X - 20,
                        (int)sample.Position.Y - 40, 60, 100);


                    foreach (PushPin pushPin in pushPins)
                    {
                        // Gets the center of the map displayed
                        Vector2 center = TileSystem.LatLongToPixelXY(bingMapsViewer.CenterGeoCoordinate,
                                                                     bingMapsViewer.ZoomLevel);

                        // Gets the position of the push pin on the map
                        Vector2 position = TileSystem.LatLongToPixelXY(pushPin.Location, bingMapsViewer.ZoomLevel);

                        // Calculate the distance between them in screen scale
                        Vector2 targetPosition = (position - center) + BingMapsViewer.ScreenCenter +
                                                 bingMapsViewer.Offset;

                        // Checks if the push pin is in side the gesture rectangle
                        if (touchRectangle.Contains(new Rectangle((int)targetPosition.X, (int)targetPosition.Y, 1, 1)))
                        {
                            Guide.BeginShowMessageBox("Warning!", "Are you sure you want to delete this push pin?",
                                                      new List <string>()
                            {
                                "OK", "Cancel"
                            }, 0, MessageBoxIcon.Alert,
                                                      DeletePushPinCallBack, pushPin);
                            return;
                        }
                    }
                }
            }
        }