Esempio n. 1
0
        public void PushNewRoutePoint(PointLatLng nextPoint)
        {
            _routePoints.Enqueue(nextPoint);
            if (_routePoints.Count > 100)
            {
                _routePoints.Dequeue();
                var latestPoint = PlayerRoute.Points.First(); //Temp fix
                PlayerRoute.Points.Remove(latestPoint);
            }
            PlayerRoute.Points.Add(nextPoint);

            PlayerRoute.Map?.Dispatcher.Invoke(new ThreadStart(
                                                   delegate
            {
                try
                {
                    PlayerRoute.RegenerateShape(PlayerRoute.Map);
                }
                catch (Exception ex)
                {
                    Logger.Write("[NEWROUTE POINT ERROR] " + ex.Message + " trace: " + ex.StackTrace);
                }
            }
                                                   ));
        }
Esempio n. 2
0
        private async void MovePlayer()
        {
            while (!WindowClosing)
            {
                if (_bot != null && _playerMarker != null && _bot.Started)
                {
                    if (_bot.MoveRequired && _bot.Started)
                    {
                        if (_bot.GotNewCoord && _bot.Started)
                        {
                            _bot.GotNewCoord = false;
                            pokeMap.UpdateLayout();
                            //BotSettingsPage.UpdateCoordBoxes();
                            _playerRoute.RegenerateShape(pokeMap);
                        }

                        _bot._lat += _bot.LatStep;
                        _bot._lng += _bot.LngStep;
                        _playerMarker.Position = new PointLatLng(_bot._lat, _bot._lng);
                        if (Math.Abs(_bot._lat - _bot.Lat) < 0.000000001 && Math.Abs(_bot._lng - _bot.Lng) < 0.000000001)
                        {
                            _bot.MoveRequired = false;
                        }
                        if (_followThePlayerMarker)
                        {
                            pokeMap.Position = new PointLatLng(_bot._lat, _bot._lng);
                        }
                    }
                }
                await Task.Delay(delay);
            }
        }
Esempio n. 3
0
        void flight_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            lock (historicoRuta)
            {
                if (m_Ruta == null)
                {
                    List <PointLatLng> lista = new List <PointLatLng>();

                    foreach (Modelos.IB_MOD_PUNTORUTA d in historicoRuta)
                    {
                        lista.Add(new PointLatLng(d.Latitud, d.Longitud));
                    }

                    m_Ruta = new GMapRoute(lista);
                    m_Ruta.RegenerateShape(this.MainWindow.MainMap);
                    this.MainWindow.MainMap.Markers.Add(m_Ruta);
                }
                else
                {
                    m_Ruta.Points.Add(this.m_title.point);
                    m_Ruta.RegenerateShape(this.MainWindow.MainMap);
                }

                //if (m_Ruta != null)
                //{
                //    this.MainWindow.MainMap.Markers.Remove(m_Ruta);
                //    m_Ruta = null;

                //}
            }
        }
 private void ClearRouteBuilder()
 {
     _currentIndex = 1;
     _currentRoute?.Points.Clear();
     _currentRoute?.RegenerateShape(RouteCreatorMap);
     BuildingProgressBar.Value = 0;
     ProgressText.Text         = TranslationEngine.GetDynamicTranslationString("%ROUTE_PROGRESS_1%", "Route progress");
     _builded = false;
     while (_mapPoints.Any())
     {
         RemoveMarker(_mapPoints[0]);
     }
     RouteCreatorMap.Markers.Clear();
     _pokestops.Clear();
     _pokemons.Clear();
     _mappedPokemons.Clear();
     if (_routeBuilder != null && _routeBuilder.Status == TaskStatus.Running)
     {
         _cts.Cancel();
     }
     _ctsPrev.Cancel();
     _ctsPrev         = new CancellationTokenSource();
     _showPsTask      = null;
     _showHeatMapTask = null;
 }
Esempio n. 5
0
 public void UpdateOptPathRoute(List <Tuple <double, double> > list)
 {
     Dispatcher.Invoke(new ThreadStart(delegate
     {
         if (_optPathRoute == null)
         {
             _optPathRoute = new GMapRoute(new List <PointLatLng>());
         }
         _optPathRoute.Points.Clear();
         if (list.Any())
         {
             var points = list.Select(x => new PointLatLng(x.Item1, x.Item2));
             _optPathRoute.Points.AddRange(points);
         }
         _optPathRoute.RegenerateShape(pokeMap);
         var path = _optPathRoute.Shape as Path;
         if (path != null)
         {
             path.Stroke = new SolidColorBrush(Color.FromRgb(0, 255, 39));
         }
         if (!pokeMap.Markers.Contains(_optPathRoute))
         {
             pokeMap.Markers.Add(_optPathRoute);
         }
     }));
 }
Esempio n. 6
0
        public void UpdatePathRoute()
        {
            _pathRoute.RegenerateShape(pokeMap);
            var path = _pathRoute.Shape as Path;

            if (path != null)
            {
                path.Stroke = new SolidColorBrush(Color.FromRgb(255, 0, 0));
            }
        }
Esempio n. 7
0
        void CustomMarkerDemo_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed && IsMouseCaptured)
            {
                Point p = e.GetPosition(MainWindow.MainMap);
                IncrementoLatLon     = this.Marker.Position - MainWindow.MainMap.FromLocalToLatLng((int)p.X, (int)p.Y);
                this.Marker.Position = MainWindow.MainMap.FromLocalToLatLng((int)p.X, (int)p.Y);
            }

            if (Marker_Line != null)
            {
                GMapRoute aux = (GMapRoute)Marker_Line;

                aux.Points.Clear();

                List <PointLatLng> route = new List <PointLatLng>();
                double             A     = 26 / 2;
                double             B     = 151 / 2;



                route.Add(this.Marker_link.Position);

                var PC = this.MainWindow.MainMap.FromLatLngToLocal(this.Marker.Position);
                var PM = this.MainWindow.MainMap.FromLatLngToLocal(this.Marker_link.Position);

                double CX = PC.X;
                double CY = PC.Y;

                double AX = PM.X;
                double AY = PM.Y;

                Vector A1 = new Vector(CX - B, CY + A);
                Vector A2 = new Vector(CX + B, CY + A);
                Vector A3 = new Vector(CX + B, CY - A);
                Vector A4 = new Vector(CX - B, CY - A);

                Vector P1 = new Vector(CX, CY);
                Vector P2 = new Vector(AX, AY);

                var Point = Matematicas.Matematicas.PuntoRectangulo(A1, A2, A3, A4, P1, P2);

                route.Add(MainWindow.MainMap.FromLocalToLatLng((int)Point.Value.X, (int)Point.Value.Y));



                aux.Points = route;
                aux.RegenerateShape(this.MainWindow.MainMap);
            }
        }
        private void ShowRoute(PointLatLng end)
        {
            PointLatLng userStart = GetCoordinates(UserCity, UserStreetName, UserStreetNumber);
            PointLatLng endPoint  = end;
            double      distance  = CalculateDistance(userStart.Lat, userStart.Lng, endPoint.Lat, endPoint.Lng);

            GDirections ss;
            var         xx = GMapProviders.GoogleMap.GetDirections(out ss, userStart, endPoint, false, false, true, false, false);

            GMapRoute r = new GMapRoute(ss.Route);

            r.RegenerateShape(mapView);
            ((System.Windows.Shapes.Path)r.Shape).Stroke          = new SolidColorBrush(Colors.Red);
            ((System.Windows.Shapes.Path)r.Shape).StrokeThickness = 5;
            mapView.Markers.Add(r);
        }
        private void CreateShape(GMapRoute r, Brush brush)
        {
            r.RegenerateShape(_gMap);
            var p = (Path)r.Shape;

            var dashes = new DoubleCollection {
                2, 1
            };

            p.StrokeDashArray = dashes;

            p.StrokeThickness = 2;
            p.Stroke          = brush;
            p.Opacity         = 1;
            p.Effect          = null;
        }
        void MostrarLineaPunteada(Point point)
        {
            if (dibujando)
            {
                if (Linea == null)
                {
                    Linea = new GMapRoute(this.ZonaActual.Points.GetRange(0, 1));

                    DoubleCollection dasharray = new DoubleCollection();
                    dasharray.Add(1);
                    dasharray.Add(2);
                    dasharray.Add(1);
                    dasharray.Add(2);
                    var path = new Path()
                    {
                        StrokeDashArray = dasharray, Fill = Brushes.Black
                    };

                    path.Stroke             = Brushes.Navy;
                    path.StrokeThickness    = 5;
                    path.StrokeLineJoin     = PenLineJoin.Round;
                    path.StrokeStartLineCap = PenLineCap.Triangle;
                    path.StrokeEndLineCap   = PenLineCap.Square;
                    path.StrokeDashArray    = dasharray;
                    Linea.Shape             = path;
                    Linea.Points.Add(this.ZonaActual.Points.FirstOrDefault());
                    Linea.Points.Add(mapa.FromLocalToLatLng((int)point.X, (int)point.Y));
                    this.mapa.Markers.Add(Linea);
                }
                else
                {
                    if (Linea.Points.Count == 2)
                    {
                        Linea.Points.Add(mapa.FromLocalToLatLng((int)point.X, (int)point.Y));
                    }
                    else
                    {
                        Linea.Points[2] = this.ZonaActual.Points.LastOrDefault();
                    }

                    Linea.Points[1] = mapa.FromLocalToLatLng((int)point.X, (int)point.Y);

                    Linea.RegenerateShape(mapa);
                }
            }
        }
Esempio n. 11
0
 public void UpdatePathRoute()
 {
     Dispatcher.Invoke(new ThreadStart(delegate
     {
         try
         {
             _pathRoute?.RegenerateShape(pokeMap);
         }
         catch (Exception ex)
         {
             Logger.Write("[UPDATE PATH ROUTE ERROR] " + ex.Message + " trace: " + ex.StackTrace);
         }
         var path = _pathRoute?.Shape as Path;
         if (path != null)
         {
             path.Stroke = new SolidColorBrush(Color.FromRgb(255, 0, 0));
         }
     }));
 }
Esempio n. 12
0
 private void RenderTracks()
 {
     Map.Markers.Clear();
     foreach (var track in Tracks)
     {
         var route = new GMapRoute(track.Coordinates.Select(c => new PointLatLng(c.Latitude, c.Longitude)));
         if (PointsEnabled)
         {
             var markers = track.Coordinates.Select(c => new GMapMarker(new PointLatLng(c.Latitude, c.Longitude))
             {
                 Shape = new Ellipse()
                 {
                     Fill   = new SolidColorBrush(track.Color),
                     Height = 6,
                     Width  = 6,
                     Margin = new Thickness(-3, -3, 0, 0)
                 }
             });
             foreach (var marker in markers)
             {
                 Map.Markers.Add(marker);
             }
         }
         Map.Markers.Add(route);
         route.RegenerateShape(Map);
         var path = route.Shape as Path;
         if (path != null)
         {
             path.Effect                = null;
             path.Stroke                = new SolidColorBrush(track.Color);
             path.StrokeThickness       = 2;
             path.ToolTip               = String.Format("{0} track, {1} points", track.Name, track.Coordinates.Count);
             path.IsManipulationEnabled = true;
             path.IsHitTestVisible      = true;
         }
     }
 }
Esempio n. 13
0
        private async void BuildTheRoute_Click(object sender, RoutedEventArgs e)
        {
            if (_mapPoints.Count < 2)
            {
                return;
            }
            CheckRouteServicePreffer();
            if (_mapPoints.Count > 47 && !_manualRoute)
            {
                MessageBox.Show(
                    "Too many waypoints, try to reduce them to 47, or wait for next releases, where that limit will be increased!",
                    "Routing Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            BuildingProgressBar.Value = 0;
            BotWindowData bot;
            var           route = GetWorkingRouting(out bot);

            if (route == "error" && !_manualRoute)
            {
                MessageBox.Show(
                    "You have to enter Google Direction API or Mapzen Valhalla API to any of your bots, before creating a route",
                    "API Key Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            var start = _mapPoints.FirstOrDefault(x => x.IsStart) ?? _mapPoints.First();

            BuildingProgressBar.Value = 10;

            RoutingResponse response = null;
            var             cycleWp  = _mapPoints.Where(x => !x.IsStart).Select(x => x.Location).ToList();

            cycleWp.Add(start.Location);
            List <GeoCoordinate> routePoints;

            if (!_manualRoute)
            {
                if (route == "google")
                {
                    response = GoogleRouting.GetRoute(start.Location, null, bot.Session, cycleWp, true);
                }
                else if (route == "mapzen")
                {
                    response = MapzenRouting.GetRoute(start.Location, null, bot.Session, cycleWp, true);
                }
                if (response?.Coordinates == null || response.Coordinates.Count == 0)
                {
                    return;
                }
                routePoints = response.Coordinates.Select(wp => new GeoCoordinate(wp[0], wp[1])).ToList();
            }
            else
            {
                cycleWp.Insert(0, start.Location);
                routePoints = new List <GeoCoordinate>(cycleWp);
            }
            BuildingProgressBar.Value = 60;
            _currentRoute?.Points?.Clear();
            if (_currentRoute == null)
            {
                _currentRoute = new GMapRoute(new List <PointLatLng>());
                RouteCreatorMap.Markers.Add(_currentRoute);
            }
            BuildingProgressBar.Value = 70;
            _buildedRoute             = new List <GeoCoordinate>(routePoints);

            foreach (var item in routePoints)
            {
                _currentRoute.Points?.Add(new PointLatLng(item.Latitude, item.Longitude));
            }

            _currentRoute?.RegenerateShape(RouteCreatorMap);
            var path = _currentRoute?.Shape as Path;

            if (path != null)
            {
                path.Stroke = new SolidColorBrush(Color.FromRgb(255, 0, 0));
            }


            bot = MainWindow.BotsCollection.FirstOrDefault(
                x => !string.IsNullOrEmpty(x.GlobalSettings.LocationSettings.MapzenApiElevationKey));
            if (bot != null)
            {
                await bot.Session.MapzenApi.FillAltitude(_buildedRoute.ToList());
            }
            BuildingProgressBar.Value = 100;
            _builded = true;
        }
        private async Task BuildTheRouteTask(CancellationToken token)
        {
            try
            {
                token.ThrowIfCancellationRequested();
                if (_mapPoints.Count < 2)
                {
                    return;
                }
                await Dispatcher.BeginInvoke(new ThreadStart(CheckRouteServicePrefer));

                if (_mapPoints.Count > 47 && !_manualRoute)
                {
                    Dispatcher.Invoke(new ThreadStart(delegate
                    {
                        MessageBox.Show(
                            TranslationEngine.GetDynamicTranslationString("%TOO_MANY_ROUTE_POINTS%",
                                                                          "Too many waypoints, try to reduce them to 47, or wait for next releases, where that limit will be increased!"),
                            "Routing Error", MessageBoxButton.OK, MessageBoxImage.Information);
                    }));
                    return;
                }
                UpdateProgress(TranslationEngine.GetDynamicTranslationString("%ROUTE_PROGRESS_2%", "Started!..."), 0);
                BotWindowData bot;
                var           route = GetWorkingRouting(out bot);
                if (route == "error" && !_manualRoute)
                {
                    MessageBox.Show(
                        TranslationEngine.GetDynamicTranslationString("%NO_ROUTE_API_FOUND%",
                                                                      "You have to enter Google Direction API or Mapzen Valhalla API to any of your bots, before creating a route"),
                        "API Key Error", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                var start = _mapPoints.FirstOrDefault(x => x.IsStart) ?? _mapPoints.First();
                UpdateProgress(TranslationEngine.GetDynamicTranslationString("%ROUTE_PROGRESS_3%", "Started!..."), 10);
                RoutingResponse response = null;
                var             cycleWp  = _mapPoints.Where(x => !x.IsStart).Select(x => x.Location).ToList();
                cycleWp.Add(start.Location);
                List <GeoCoordinate> routePoints;
                token.ThrowIfCancellationRequested();
                if (!_manualRoute)
                {
                    if (route == "google")
                    {
                        response = GoogleRouting.GetRoute(start.Location, null, bot.Session, cycleWp, true);
                    }
                    else if (route == "mapzen")
                    {
                        response = MapzenRouting.GetRoute(start.Location, null, bot.Session, cycleWp, true);
                    }
                    if (response?.Coordinates == null || response.Coordinates.Count == 0)
                    {
                        return;
                    }
                    routePoints = response.Coordinates.Select(wp => new GeoCoordinate(wp[0], wp[1])).ToList();
                }
                else
                {
                    cycleWp.Insert(0, start.Location);
                    routePoints = new List <GeoCoordinate>(cycleWp);
                }
                token.ThrowIfCancellationRequested();
                UpdateProgress(
                    TranslationEngine.GetDynamicTranslationString("%ROUTE_PROGRESS_4%", "Handling result..."), 60);
                _currentRoute?.Points?.Clear();
                if (_currentRoute == null)
                {
                    _currentRoute = new GMapRoute(new List <PointLatLng>());
                }

                await RouteCreatorMap.Dispatcher.BeginInvoke(new ThreadStart(delegate
                {
                    RouteCreatorMap.Markers.Add(_currentRoute);
                }));

                token.ThrowIfCancellationRequested();
                UpdateProgress(
                    TranslationEngine.GetDynamicTranslationString("%ROUTE_PROGRESS_5%", "Requesting altitude..."), 70);
                _buildedRoute = new List <GeoCoordinate>(routePoints);
                token.ThrowIfCancellationRequested();
                foreach (var item in routePoints)
                {
                    _currentRoute.Points?.Add(new PointLatLng(item.Latitude, item.Longitude));
                }
                await Dispatcher.BeginInvoke(new ThreadStart(delegate
                {
                    try
                    {
                        _currentRoute.RegenerateShape(RouteCreatorMap);
                    }
                    catch (Exception)
                    {
                        //ignore
                    }
                }));

                var path = _currentRoute?.Shape as Path;
                await Dispatcher.BeginInvoke(new ThreadStart(delegate
                {
                    if (path != null)
                    {
                        path.Stroke = new SolidColorBrush(Color.FromRgb(255, 0, 0));
                    }
                }));


                bot = MainWindow.BotsCollection.FirstOrDefault(
                    x => !string.IsNullOrEmpty(x.GlobalSettings.LocationSettings.MapzenApiKey));
                if (bot != null)
                {
                    await bot.Session.MapzenApi.FillAltitude(_buildedRoute.ToList(), token : token);
                }
                UpdateProgress(TranslationEngine.GetDynamicTranslationString("%ROUTE_PROGRESS_6%", "Done!"), 100);
                _builded = true;
            }
            catch (OperationCanceledException)
            {
                //ignore
            }
        }