Exemplo n.º 1
0
        /// <summary>
        /// Removes the pin.
        /// </summary>
        /// <param name="index">Index.</param>
        public void RemovePin(int index)
        {
            IPin pin = Pins [index];

            if (pin is DPin)
            {
                var tmp = GetCorespondingSequence(pin as DPin);
                if (tmp != null)
                {
                    RemoveSequence(tmp.Name);
                }
            }
            else if (pin is APin)
            {
                var tmp = GetCorespondingCombination(pin as APin);
                if (tmp != null)
                {
                    RemoveMeasurementCombination(tmp);
                }
            }
            Pins.RemoveAt(index);
            if (OnPinsUpdated != null)
            {
                OnPinsUpdated.Invoke(this, new ControllerPinUpdateArgs(pin, UpdateOperation.Remove));
            }
        }
Exemplo n.º 2
0
        private async void UpdateListCart(object sender, EventArgs e)
        {
            if (Driver.Current == null)
            {
                return;
            }
            var result = await DataService.GetDriverOrdersOnMap();

            if (result == null || result.Status != 0)
            {
                return;
            }
            Device.BeginInvokeOnMainThread(() =>
            {
                //list of showing pins in map
                var availablePins = new List <OrderPin>();
                foreach (var r in result.Data)
                {
                    if (!availableStatus.Contains(r.OrderStatus))
                    {
                        continue;
                    }
                    var existPin   = Pins.FirstOrDefault(x => x.Id == r.OrderId);
                    string namePin = r.OrderStatus == Enums.OrderStatus.NewOrder ? "red_pin" : "green_pin";
                    if (existPin == null)
                    {
                        existPin = new OrderPin
                        {
                            Id          = r.OrderId,
                            Position    = new Position(r.Latitude, r.Longitude),
                            Title       = "Order No:" + r.OrderId,
                            Image       = Device.OnPlatform(namePin, namePin, string.Empty),
                            ShowCallout = true,
                        };
                        Pins.Add(existPin);
                    }
                    else
                    {
                        existPin.Image = Device.OnPlatform(namePin, namePin, string.Empty);
                    }
                    availablePins.Add(existPin);
                }
                //delete older pins
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (availablePins.FirstOrDefault(x => x.Id == Pins[i].Id) == null)
                    {
                        if (Pins != null)
                        {
                            Pins.RemoveAt(i);
                            i--;
                        }
                    }
                }
            });
        }
Exemplo n.º 3
0
        private async void DrawPins()
        {
            var drivers = await DataService.GetDriversAvailablePostion();

            Device.BeginInvokeOnMainThread(() =>
            {
                if (Pins == null || drivers.Status != 0 || drivers.Data == null)
                {
                    return;
                }
                var availablePins = new List <DriverPin>();
                foreach (var driver in drivers.Data)
                {
                    var existPin = Pins.FirstOrDefault(x => x.DriverPosition.DriverId == driver.DriverId);
                    var icon     = driver.ProductType == 0 ? "car1" : "car" + driver.ProductType;
                    if (existPin == null)
                    {
                        existPin = new DriverPin
                        {
                            DriverPosition = driver,
                            ShowCallout    = true,
                            Position       = new Position(driver.Latitude, driver.Longitude),
                            Image          = Device.OnPlatform(icon, icon, string.Empty)
                        };
                        Pins.Add(existPin);
                    }
                    else
                    {
                        existPin.DriverPosition = driver;
                        existPin.Position       = new Position(driver.Latitude, driver.Longitude);
                        existPin.Image          = Device.OnPlatform(icon, icon, string.Empty);
                    }
                    availablePins.Add(existPin);
                }
                //clear not use pins
                for (int i = 0; i < Pins.Count; i++)
                {
                    if (availablePins.FirstOrDefault(x => x.DriverPosition.DriverId == Pins[i].DriverPosition.DriverId) == null)
                    {
                        Pins.RemoveAt(i);
                        i--;
                    }
                }
            });
        }
Exemplo n.º 4
0
        // ===========================================================================
        // = Public Methods
        // ===========================================================================

        public void ClearSearchResults()
        {
            // Clear search results.
            var pinsToRemove = Pins
                               .Select((X, I) => new { Index = I, Object = X })
                               .Where(X => X.Object.IsSearchResult)
                               .Select(X => X.Index)
                               .OrderByDescending(X => X)
                               .ToList();

            foreach (var index in pinsToRemove)
            {
                Pins.RemoveAt(index);
            }

            SearchResults.Clear();

            if (pinsToRemove.Count > 0)
            {
                RaiseChanged();
            }
        }
Exemplo n.º 5
0
        private void OnMapClicked(object sender, MapClickedEventArgs e)
        {
            if (!AreaWithin(e.Position))
            {
                Application.Current.MainPage.DisplayAlert("Warning", "We cannot service your chosen region", "Okay");
                return;
            }

            if (BindingContext is SelectLocationPageViewModel selectLocationVm)
            {
                selectLocationVm.SelectedLocation = new Location {
                    lat = e.Position.Latitude, lng = e.Position.Longitude
                };
                selectLocationVm.SelectionMode = SelectLocationPageViewModel.AddressSelectionMode.Click;
            }

            if (RoutePins.Count > 1)
            {
                for (int i = 1; i < RoutePins.Count; i++)
                {
                    RoutePins.RemoveAt(i);
                }
                Pins.RemoveAt(1);
            }

            var pin = new CustomPin
            {
                Label    = "Selected Address",
                Position = e.Position,
                Type     = PinType.SavedPin,
                ImageUrl = "location_person.png"
            };

            RoutePins.Add(pin);
            Pins.Add(pin);

            MoveToRegion(MapSpan.FromCenterAndRadius(e.Position, Distance.FromKilometers(2)));
        }