コード例 #1
0
ファイル: PinGroup.cs プロジェクト: brekooname/HLab
        public T GetOrAddPin <T>(Action <T> factory, string id, GraphValueType type = null) where T : IPin, new()
        {
            if (string.IsNullOrEmpty(id))
            {
                var pins = Pins.Where(p => p.Id.StartsWith("#")).ToList();
                id = "#" + (pins.Count == 0?0:pins.Max(p => int.Parse(p.Id.TrimStart('#'))) + 1);
            }
            else
            {
                var pin = Pins.FirstOrDefault(p => p.Id == id);
                if (pin is T tp)
                {
                    return(tp);
                }
            }

            var newPin = new T
            {
                Id    = id,
                Group = this,
            };

            if (type != null)
            {
                newPin.ValueType = type;
            }

            factory?.Invoke(newPin);

            Pins.Add(newPin);
            return(newPin);
        }
コード例 #2
0
        private void HandleMouseLeftButtonDown(object sender, MouseButtonEventArgs eventArgs)
        {
            var targetElementUserControl = DesignCanvas.Children.Cast <UIElement>()
                                           .Where(uiElement => uiElement is IElementUserControl)
                                           .FirstOrDefault(elementUserControl => elementUserControl.InputHitTest(Mouse.GetPosition(elementUserControl)) != null);

            if (targetElementUserControl == null)
            {
                return;
            }

            // creating a wire
            var originPin = (targetElementUserControl as IElementUserControl) !.Pins
                            .FirstOrDefault(connectionPin => connectionPin.InputHitTest(Mouse.GetPosition(connectionPin)) != null);

            if (originPin != null)
            {
                // if not an output pin
                if ((targetElementUserControl as IElementUserControl) !.Pins[0] != originPin)
                {
                    return;
                }
                StartWireCreation(targetElementUserControl, originPin);
                return;
            }

            // moving an element
            StartElementMove(targetElementUserControl);
        }
コード例 #3
0
        async void Update(Xamarin.Forms.GoogleMaps.Position position)
        {
            if (Pins.Count == 1 && Polylines != null && Polylines?.Count > 1)
            {
                return;
            }

            var cPin = Pins.FirstOrDefault();

            if (cPin != null)
            {
                cPin.Position = new Position(position.Latitude, position.Longitude);
                cPin.Icon     = (Device.RuntimePlatform == Device.Android) ? BitmapDescriptorFactory.FromBundle("ic_taxi.png") : BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_taxi.png", WidthRequest = 25, HeightRequest = 25
                });

                await MoveCamera(CameraUpdateFactory.NewPosition(new Position(position.Latitude, position.Longitude)));

                var previousPosition = Polylines?.FirstOrDefault()?.Positions?.FirstOrDefault();
                Polylines?.FirstOrDefault()?.Positions?.Remove(previousPosition.Value);
            }
            else
            {
                //END TRIP
                Polylines?.FirstOrDefault()?.Positions?.Clear();
            }
        }
コード例 #4
0
 private void FavAddressSearch_OnSelectedAction(object sender, EventArgs e)
 {
     if (sender is AddressesSearch asS)
     {
         if (asS.SelectedAddress == null)
         {
             return;
         }
         var currPin = Pins?.FirstOrDefault();
         if (currPin != null)
         {
             Pins.Clear();
             currPin.Location = new Location(asS.SelectedAddress.Lat, asS.SelectedAddress.Lon);
             Pins.Add(currPin);
         }
         else
         {
             if (!Locations.Any(p => p.Address == asS.SelectedAddress))
             {
                 Pins.Clear();
                 Pins.Add(new Pushpin()
                 {
                     Location = new Location(asS.SelectedAddress.Lat, asS.SelectedAddress.Lon), Content = Tools.CreateIcon((Editing == null) ? PackIconKind.Plus : PackIconKind.Edit)
                 });
             }
         }
         if (!(currPin != null && (Math.Abs(currPin.Location.Latitude - asS.SelectedAddress.Lat) < 1 || Math.Abs(currPin.Location.Longitude - asS.SelectedAddress.Lon) < 1)))
         {
             FavMap.Center = new Location(asS.SelectedAddress.Lat, asS.SelectedAddress.Lon);
         }
     }
 }
コード例 #5
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--;
                        }
                    }
                }
            });
        }
コード例 #6
0
        private void OnMapClicked(Position position)
        {
            string title       = "my location";
            var    existingPin = Pins.FirstOrDefault();

            if (existingPin != null)
            {
                title = existingPin.Title;
            }
            Pins.Clear(); //TODO: Add PinSelectionMode.Single / Multiple
            AddPin(position, title);
        }
コード例 #7
0
ファイル: Page2ViewModel.cs プロジェクト: pitrouA/tp-xamarin
        private void SetSelectedItem(int direction)
        {
            if (SelectedItem == null)
            {
                SelectedItem = Pins.FirstOrDefault();
            }

            var index    = Pins.IndexOf(SelectedItem as IMapPin);
            var newIndex = (index + direction) % (Pins.Count);

            if (newIndex < 0)
            {
                newIndex = Pins.Count - 1;
            }

            SelectedItem = Pins[newIndex];
        }
コード例 #8
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--;
                    }
                }
            });
        }